Skip to content

Commit

Permalink
Removed objectManager
Browse files Browse the repository at this point in the history
  • Loading branch information
rommmka committed Mar 31, 2023
1 parent 1879b3f commit 612d9e6
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions Controller/Adminhtml/Theme/FixAll.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,31 @@

namespace Swissup\Core\Controller\Adminhtml\Theme;

use Magento\Backend\App\Action\Context;
use Magento\Framework\Controller\ResultFactory;
use Magento\Theme\Model\ResourceModel\Theme\CollectionFactory;

class FixAll extends \Magento\Backend\App\Action
{
const ADMIN_RESOURCE = 'Swissup_Core::theme_fixall';
private CollectionFactory $collectionFactory;

public function __construct(
Context $context,
CollectionFactory $collectionFactory
) {
parent::__construct($context);
$this->collectionFactory = $collectionFactory;
}

public function execute()
{
{
$virtualThemes = $this->collectionFactory->create()->addFieldToFilter('type', 1);
foreach ($virtualThemes as $theme) {
$theme->setType(0)->save();
}

$resultJson = $this->resultFactory->create(ResultFactory::TYPE_JSON);
$resultJson->setData(['message' => 'Virtual themes fixed. Please, clear the cache!']);

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();

$connection = $objectManager->create('\Magento\Framework\App\ResourceConnection')->getConnection();
$tableName = $connection->getTableName('theme');
$connection->update($tableName, ['type' => 0]);

return $resultJson;
}
Expand Down

0 comments on commit 612d9e6

Please sign in to comment.