Skip to content

Commit

Permalink
PSR-2 Formatting
Browse files Browse the repository at this point in the history
Pretty much all indentation related.
  • Loading branch information
Patrick McLain committed Jan 14, 2018
1 parent 7e72c98 commit be692d0
Show file tree
Hide file tree
Showing 21 changed files with 567 additions and 523 deletions.
14 changes: 8 additions & 6 deletions Block/Adminhtml/Cronjob/Edit/DeleteButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@ class DeleteButton extends GenericButton implements ButtonProviderInterface
*/
public function getButtonData()
{
$params = $this->getRequestParams();
$cronId = $params['id'];
$params = $this->getRequestParams();
$cronId = $params['id'];

$data = [
$data = [
'label' => __('Delete'),
'class' => 'delete',
'on_click' => 'deleteConfirm(\'' . __(
'Are you sure you want to delete this?'
) . '\', \'' . $this->urlBuilder->getUrl('*/manage_job/delete', ['id' => $cronId]) . '\')',
'on_click' => 'deleteConfirm(\''
. __('Are you sure you want to delete this?')
. '\', \''
. $this->urlBuilder->getUrl('*/manage_job/delete', ['id' => $cronId])
. '\')',
'sort_order' => 20,
];
return $data;
Expand Down
9 changes: 4 additions & 5 deletions Block/Adminhtml/Cronjob/Edit/GenericButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace EthanYehuda\CronjobManager\Block\Adminhtml\Cronjob\Edit;

use EthanYehuda\CronjobManager\Model\RegistryConstants;
use Magento\Framework\Registry;

class GenericButton
{
Expand All @@ -19,11 +18,11 @@ class GenericButton
*
* @var \Magento\Framework\Registry
*/
protected $registry;
protected $registry;

/**
* Constructor
*
*
* @param \Magento\Backend\Block\Widget\Context $context
* @param \Magento\Framework\Registry $registry
*/
Expand All @@ -34,10 +33,10 @@ public function __construct(
$this->urlBuilder = $context->getUrlBuilder();
$this->registry = $registry;
}

public function getRequestParams()
{
return $this->registry->registry(RegistryConstants::CURRENT_CRON_JOB);
return $this->registry->registry(RegistryConstants::CURRENT_CRON_JOB);
}

/**
Expand Down
10 changes: 5 additions & 5 deletions Block/Adminhtml/Cronjob/Edit/SaveAndContinueButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ public function getButtonData()
$data = [
'label' => __('Save and Continue'),
'class' => 'save',
'data_attribute' => [
'mage-init' => [
'button' => ['event' => 'saveAndContinue'],
]
],
'data_attribute' => [
'mage-init' => [
'button' => ['event' => 'saveAndContinue'],
]
],
'sort_order' => 90,
];
return $data;
Expand Down
12 changes: 6 additions & 6 deletions Block/Adminhtml/Cronjob/Edit/SaveButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ public function getButtonData()
$data = [
'label' => __('Save'),
'class' => 'save primary',
'data_attribute' => [
'mage-init' => [
'button' => ['event' => 'save']
],
'form-role' => 'save',
],
'data_attribute' => [
'mage-init' => [
'button' => ['event' => 'save']
],
'form-role' => 'save',
],
];
return $data;
}
Expand Down
135 changes: 69 additions & 66 deletions Command/Runjob.php
Original file line number Diff line number Diff line change
@@ -1,79 +1,82 @@
<?php

namespace EthanYehuda\CronjobManager\Command;

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

use EthanYehuda\CronjobManager\Model\ManagerFactory;
use \Magento\Framework\App\State;
use \Magento\Framework\Console\Cli;
use \Magento\Framework\Stdlib\DateTime\DateTimeFactory;
use Magento\Framework\App\State;
use Magento\Framework\Console\Cli;
use Magento\Framework\Stdlib\DateTime\DateTimeFactory;

class Runjob extends Command
{
const INPUT_KEY_JOB_CODE = 'job_code';

/**
* @var ManagerFactory $managerFactory
*/
private $managerFactory;

/**
* @var \Magento\Framework\App\State $state
*/
private $state;

/**
* @var DateTimeFactory $dateTimeFactory
*/
private $dateTimeFactory;

public function __construct(
State $state,
ManagerFactory $managerFactory,
DateTimeFactory $dateTimeFactory
) {
$this->managerFactory = $managerFactory;
$this->state = $state;
$this->dateTimeFactory = $dateTimeFactory;
parent::__construct();
}
protected function configure()
{
$arguments = [
new InputArgument(
self::INPUT_KEY_JOB_CODE,
InputArgument::REQUIRED,
'Job code input (ex. \'sitemap_generate\')'
)
];

$this->setName("cronmanager:runjob");
$this->setDescription("Run a specific cron job by its job_code ");
$this->setDefinition($arguments);
parent::configure();
}

protected function execute(InputInterface $input, OutputInterface $output)
{
$manager = $this->managerFactory->create();
$dateTime = $this->dateTimeFactory->create();
const INPUT_KEY_JOB_CODE = 'job_code';

/**
* @var ManagerFactory $managerFactory
*/
private $managerFactory;

/**
* @var \Magento\Framework\App\State $state
*/
private $state;

/**
* @var DateTimeFactory $dateTimeFactory
*/
private $dateTimeFactory;

public function __construct(
State $state,
ManagerFactory $managerFactory,
DateTimeFactory $dateTimeFactory
) {
$this->managerFactory = $managerFactory;
$this->state = $state;
$this->dateTimeFactory = $dateTimeFactory;
parent::__construct();
}

protected function configure()
{
$arguments = [
new InputArgument(
self::INPUT_KEY_JOB_CODE,
InputArgument::REQUIRED,
'Job code input (ex. \'sitemap_generate\')'
)
];

$this->setName("cronmanager:runjob");
$this->setDescription("Run a specific cron job by its job_code ");
$this->setDefinition($arguments);
parent::configure();
}

protected function execute(InputInterface $input, OutputInterface $output)
{
$manager = $this->managerFactory->create();
$dateTime = $this->dateTimeFactory->create();

try {
$this->state->setAreaCode('adminhtml');

// 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());

try {
$this->state->setAreaCode('adminhtml');

// 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());

$schedule = $manager->createCronJob($jobCode, $now);
$manager->dispatchCron(null, $jobCode, $schedule);
$output->writeln("$jobCode successfully ran");
return Cli::RETURN_SUCCESS;
} catch (\Magento\Framework\Exception\LocalizedException $e) {
$output->writeln($e->getMessage());
return Cli::RETURN_FAILURE;
}
}
$schedule = $manager->createCronJob($jobCode, $now);
$manager->dispatchCron(null, $jobCode, $schedule);
$output->writeln("$jobCode successfully ran");
return Cli::RETURN_SUCCESS;
} catch (\Magento\Framework\Exception\LocalizedException $e) {
$output->writeln($e->getMessage());
return Cli::RETURN_FAILURE;
}
}
}
103 changes: 53 additions & 50 deletions Command/Showjobs.php
Original file line number Diff line number Diff line change
@@ -1,38 +1,41 @@
<?php

namespace EthanYehuda\CronjobManager\Command;

use Magento\Framework\App\Area;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use EthanYehuda\CronjobManager\Model\ManagerFactory;
use \Magento\Framework\App\State;
use \Magento\Framework\Console\Cli;
use Magento\Framework\App\State;
use Magento\Framework\Console\Cli;

class Showjobs extends Command
{
/**
* @var \EthanYehuda\CronjobManager\Model\ManagerFactory $managerFactory
*/
private $managerFactory;

/**
* @var \Magento\Framework\App\State $state
*/
private $state;

/**
* @var Array $headers
*/
private $headers = ['Job Code', 'Group', 'Frequency', 'Class'];

public function __construct(
State $state,
ManagerFactory $managerFactory
) {
$this->managerFactory = $managerFactory;
$this->state = $state;
parent::__construct();
}
/**
* @var \EthanYehuda\CronjobManager\Model\ManagerFactory $managerFactory
*/
private $managerFactory;

/**
* @var \Magento\Framework\App\State $state
*/
private $state;

/**
* @var array $headers
*/
private $headers = ['Job Code', 'Group', 'Frequency', 'Class'];

public function __construct(
State $state,
ManagerFactory $managerFactory
) {
$this->managerFactory = $managerFactory;
$this->state = $state;
parent::__construct();
}

protected function configure()
{
$this->setName("cronmanager:showjobs");
Expand All @@ -45,31 +48,31 @@ protected function execute(InputInterface $input, OutputInterface $output)
$manager = $this->managerFactory->create();

try {
$this->state->setAreaCode('adminhtml');
$jobs = $manager->getCronJobs();
$table = $this->getHelperSet()->get('table')->setHeaders($this->headers);
foreach ($jobs as $group => $crons) {
foreach ($crons as $code => $job) {
$instance = $job['instance'];
$method = $job['method'];
$schedule = (isset($job['schedule']) ? $job['schedule'] : "");
$jobData = [
$code,
$group,
$schedule,
"$instance::$method"
];
$table->addRow($jobData);
}
}
$table->render($output);
return Cli::RETURN_SUCCESS;
$this->state->setAreaCode(Area::AREA_ADMINHTML);

$jobs = $manager->getCronJobs();
$table = $this->getHelperSet()->get('table')->setHeaders($this->headers);

foreach ($jobs as $group => $crons) {
foreach ($crons as $code => $job) {
$instance = $job['instance'];
$method = $job['method'];
$schedule = (isset($job['schedule']) ? $job['schedule'] : "");
$jobData = [
$code,
$group,
$schedule,
"$instance::$method"
];
$table->addRow($jobData);
}
}

$table->render($output);
return Cli::RETURN_SUCCESS;
} catch (\Magento\Framework\Exception\LocalizedException $e) {
$output->writeln($e->getMessage());
return Cli::RETURN_FAILURE;
$output->writeln($e->getMessage());
return Cli::RETURN_FAILURE;
}
}
}
}
9 changes: 4 additions & 5 deletions Controller/Adminhtml/Manage/Create.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php


namespace EthanYehuda\CronjobManager\Controller\Adminhtml\Manage;

class Create extends \Magento\Backend\App\Action
Expand All @@ -16,19 +15,19 @@ class Create extends \Magento\Backend\App\Action
*/
public function __construct(
\Magento\Framework\View\Result\PageFactory $resultPageFactory,
\Magento\Backend\App\Action\Context $context
\Magento\Backend\App\Action\Context $context
) {
parent::__construct($context);
parent::__construct($context);
$this->resultPageFactory = $resultPageFactory;
}

/**
* {@inheritDoc}
* @see \Magento\Backend\App\AbstractAction::_isAllowed()
*/
protected function _isAllowed()
{
return $this->_authorization->isAllowed('EthanYehuda_CronjobManager::cronjobmanager');
return $this->_authorization->isAllowed('EthanYehuda_CronjobManager::cronjobmanager');
}

/**
Expand Down
Loading

0 comments on commit be692d0

Please sign in to comment.