Skip to content

Commit

Permalink
Added swissup:info:virtualfix command
Browse files Browse the repository at this point in the history
  • Loading branch information
dimdimich committed Jan 19, 2024
1 parent 96fa59b commit 825d24a
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 7 deletions.
9 changes: 3 additions & 6 deletions Console/Command/InfoCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

class InfoCommand extends Command
{

/**
* @var \Magento\Framework\App\State
*/
Expand All @@ -32,7 +31,6 @@ public function __construct(State $appState)
$this->appState = $appState;
}


protected function configure()
{
$this->setName('swissup:info')
Expand All @@ -45,7 +43,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
'php_version' => 'php -v | head -n 1 && whereis php',
'magento_version' => 'php bin/magento --version',
'composer_version' => 'composer --version && whereis composer',
'nginx_apache_user' => 'whoami',
'nginx_user' => 'whoami',
];

$folderPaths = [
Expand All @@ -56,7 +54,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
];

try {

// Environment Check commands

foreach ($commands as $key => $value) {
Expand All @@ -69,17 +66,17 @@ protected function execute(InputInterface $input, OutputInterface $output)
$this->checkFolder($folderPath, $output);
}

$output->writeln('_____________________________');

// Output Magento 2 "theme" table data
$this->outputMagentoThemeData($input, $output);


return Command::SUCCESS;
} catch (\Exception $e) {
$output->writeln("<error>Error: " . $e->getMessage() . "</error>");
return Command::FAILURE;
}


return Command::SUCCESS;
}

Expand Down
53 changes: 53 additions & 0 deletions Console/Command/InfoVirtualfixCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace Swissup\Diagnostic\Console\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

use Magento\Theme\Model\ResourceModel\Theme\CollectionFactory;
use Psr\Log\LoggerInterface;

class InfoVirtualFixCommand extends Command
{
private CollectionFactory $collectionFactory;
private LoggerInterface $logger;

public function __construct(
CollectionFactory $collectionFactory,
LoggerInterface $logger
) {
parent::__construct();

$this->collectionFactory = $collectionFactory;
$this->logger = $logger;
}

protected function configure()
{
$this->setName('swissup:info:virtualfix')
->setDescription('Fix Virtual themes');
}

protected function execute(InputInterface $input, OutputInterface $output)
{
try {
$virtualThemes = $this->collectionFactory->create()->addFieldToFilter('type', 1);
foreach ($virtualThemes as $theme) {
$theme->setType(0)->save();
}

$this->logger->info('Virtual themes fixed successfully.');
$output->writeln('<info>Executing swissup:info:virtualfix command...</info>');
$output->writeln('<info>Virtual fix operations completed.</info>');

return Command::SUCCESS;
} catch (\Exception $e) {
$this->logger->error('Error fixing virtual themes: ' . $e->getMessage());
$output->writeln('<error>Error fixing virtual themes: ' . $e->getMessage() . '</error>');

return Command::FAILURE;
}
}
}
2 changes: 1 addition & 1 deletion etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<arguments>
<argument name="commands" xsi:type="array">
<item name="swissupInfoCommand" xsi:type="object">Swissup\Diagnostic\Console\Command\InfoCommand</item>
<!-- Add more commands if needed -->
<item name="swissupInfoVirtualfixCommand" xsi:type="object">Swissup\Diagnostic\Console\Command\InfoVirtualFixCommand</item>
</argument>
</arguments>
</type>
Expand Down

0 comments on commit 825d24a

Please sign in to comment.