diff --git a/Console/Command/Runjob.php b/Console/Command/Runjob.php index 207412d8..dde04eaf 100644 --- a/Console/Command/Runjob.php +++ b/Console/Command/Runjob.php @@ -7,6 +7,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Input\InputArgument; +use Magento\Framework\App\Area; use Magento\Framework\App\State; use Magento\Framework\Console\Cli; use Magento\Framework\Stdlib\DateTime\DateTimeFactory; @@ -34,7 +35,8 @@ public function __construct( State $state, ManagerFactory $managerFactory, DateTimeFactory $dateTimeFactory - ) { + ) + { $this->managerFactory = $managerFactory; $this->state = $state; $this->dateTimeFactory = $dateTimeFactory; @@ -63,8 +65,12 @@ protected function execute(InputInterface $input, OutputInterface $output) $dateTime = $this->dateTimeFactory->create(); try { - $this->state->setAreaCode('adminhtml'); + $this->state->setAreaCode(Area::AREA_ADMINHTML); + } catch (\Magento\Framework\Exception\LocalizedException $exception) { + // Area code is already set + } + try { // lets create a new cron job and dispatch it $jobCode = $input->getArgument(self::INPUT_KEY_JOB_CODE); $now = strftime('%Y-%m-%dT%H:%M:%S', $dateTime->gmtTimestamp()); diff --git a/Console/Command/Showjobs.php b/Console/Command/Showjobs.php index 7c882298..eedcefe4 100644 --- a/Console/Command/Showjobs.php +++ b/Console/Command/Showjobs.php @@ -6,6 +6,7 @@ use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Helper\Table; use Magento\Framework\App\Area; use Magento\Framework\App\State; use Magento\Framework\Console\Cli; @@ -30,7 +31,8 @@ class Showjobs extends Command public function __construct( State $state, ManagerFactory $managerFactory - ) { + ) + { $this->managerFactory = $managerFactory; $this->state = $state; parent::__construct(); @@ -49,9 +51,14 @@ protected function execute(InputInterface $input, OutputInterface $output) try { $this->state->setAreaCode(Area::AREA_ADMINHTML); + } catch (\Magento\Framework\Exception\LocalizedException $exception) { + // Area code is already set + } + try { $jobs = $manager->getCronJobs(); - $table = $this->getHelperSet()->get('table')->setHeaders($this->headers); + $table = new Table($output); + $table->setHeaders($this->headers); foreach ($jobs as $group => $crons) { foreach ($crons as $code => $job) { diff --git a/composer.json b/composer.json index a28ff046..9c7904fd 100755 --- a/composer.json +++ b/composer.json @@ -2,8 +2,8 @@ "name": "ethanyehuda/magento2-cronjobmanager", "description": "A module for managing scheduled cron jobs from magento's admin panel", "require": { - "php": "~7.0.0||~7.1.0", - "magento/framework": "~100.3.0-dev|~101.0.0" + "php": "~7.0.0||~7.1.0||~7.2.0", + "magento/framework": "~100.3.0-dev|~101.0.0|~102.0.0" }, "type": "magento2-module", "license": "OSL-3.0",