diff --git a/app/code/community/Aoe/Scheduler/Block/Adminhtml/Job.php b/app/code/community/Aoe/Scheduler/Block/Adminhtml/Job.php index aa443c1..f90a78f 100644 --- a/app/code/community/Aoe/Scheduler/Block/Adminhtml/Job.php +++ b/app/code/community/Aoe/Scheduler/Block/Adminhtml/Job.php @@ -28,25 +28,15 @@ protected function _prepareLayout() $this->removeButton('add'); $this->_addButton( 'add_new_job', - array( - 'label' => $this->__('Create new job'), - 'onclick' => "setLocation('{$this->getUrl('*/*/new')}')", - 'class' => 'add' - ) + ['label' => $this->__('Create new job'), 'onclick' => "setLocation('{$this->getUrl('*/*/new')}')", 'class' => 'add'] ); $this->_addButton( 'add_new', - array( - 'label' => $this->__('Generate Schedule'), - 'onclick' => "setLocation('{$this->getUrl('*/*/generateSchedule')}')", - ) + ['label' => $this->__('Generate Schedule'), 'onclick' => "setLocation('{$this->getUrl('*/*/generateSchedule')}')"] ); $this->_addButton( 'configure', - array( - 'label' => $this->__('Cron Configuration'), - 'onclick' => "setLocation('{$this->getUrl('adminhtml/system_config/edit', array('section' => 'system'))}#system_cron')", - ) + ['label' => $this->__('Cron Configuration'), 'onclick' => "setLocation('{$this->getUrl('adminhtml/system_config/edit', ['section' => 'system'])}#system_cron')"] ); return parent::_prepareLayout(); } diff --git a/app/code/community/Aoe/Scheduler/Block/Adminhtml/Job/Edit.php b/app/code/community/Aoe/Scheduler/Block/Adminhtml/Job/Edit.php index e1303ee..07e75b4 100644 --- a/app/code/community/Aoe/Scheduler/Block/Adminhtml/Job/Edit.php +++ b/app/code/community/Aoe/Scheduler/Block/Adminhtml/Job/Edit.php @@ -63,6 +63,6 @@ public function getHeaderText() */ public function getSaveUrl() { - return $this->getUrl('*/*/save', array('_current'=>true, 'back'=>null)); + return $this->getUrl('*/*/save', ['_current'=>true, 'back'=>null]); } } diff --git a/app/code/community/Aoe/Scheduler/Block/Adminhtml/Job/Edit/Form.php b/app/code/community/Aoe/Scheduler/Block/Adminhtml/Job/Edit/Form.php index f011b50..2f1d188 100644 --- a/app/code/community/Aoe/Scheduler/Block/Adminhtml/Job/Edit/Form.php +++ b/app/code/community/Aoe/Scheduler/Block/Adminhtml/Job/Edit/Form.php @@ -14,11 +14,7 @@ class Aoe_Scheduler_Block_Adminhtml_Job_Edit_Form extends Mage_Adminhtml_Block_W */ protected function _prepareForm() { - $form = new Varien_Data_Form(array( - 'id' => 'edit_form', - 'action' => $this->getData('action'), - 'method' => 'post' - )); + $form = new Varien_Data_Form(['id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post']); $form->setUseContainer(true); $this->setForm($form); return parent::_prepareForm(); diff --git a/app/code/community/Aoe/Scheduler/Block/Adminhtml/Job/Edit/Tab/Form.php b/app/code/community/Aoe/Scheduler/Block/Adminhtml/Job/Edit/Tab/Form.php index f44e579..1ccd2c5 100644 --- a/app/code/community/Aoe/Scheduler/Block/Adminhtml/Job/Edit/Tab/Form.php +++ b/app/code/community/Aoe/Scheduler/Block/Adminhtml/Job/Edit/Tab/Form.php @@ -78,175 +78,87 @@ protected function _prepareForm() { $job = $this->getJob(); $form = new Varien_Data_Form( - array( - 'id' => 'edit_form', - 'action' => $this->getData('action'), - 'method' => 'post' - ) + ['id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post'] ); - $fieldset = $form->addFieldset('base_fieldset', array('legend' => $this->__('General'))); + $fieldset = $form->addFieldset('base_fieldset', ['legend' => $this->__('General')]); $this->_addElementTypes($fieldset); $fieldset->addField( 'job_code', 'text', - array( - 'name' => 'job_code', - 'label' => $this->__('Job code'), - 'title' => $this->__('Job code'), - 'class' => '', - 'required' => true, - 'disabled' => $job->getJobCode() ? true : false, - ) + ['name' => 'job_code', 'label' => $this->__('Job code'), 'title' => $this->__('Job code'), 'class' => '', 'required' => true, 'disabled' => $job->getJobCode() ? true : false] ); $fieldset->addField( 'name', 'text', - array( - 'name' => 'name', - 'label' => $this->__('Name'), - 'title' => $this->__('Name'), - 'class' => '', - 'required' => false, - 'after_element_html' => $this->getOriginalValueSnippet($job, 'name'), - ) + ['name' => 'name', 'label' => $this->__('Name'), 'title' => $this->__('Name'), 'class' => '', 'required' => false, 'after_element_html' => $this->getOriginalValueSnippet($job, 'name')] ); $fieldset->addField( 'short_description', 'textarea', - array( - 'name' => 'short_description', - 'label' => $this->__('Short description'), - 'title' => $this->__('Short description'), - 'class' => '', - 'required' => false, - 'after_element_html' => $this->getOriginalValueSnippet($job, 'short_description'), - ) + ['name' => 'short_description', 'label' => $this->__('Short description'), 'title' => $this->__('Short description'), 'class' => '', 'required' => false, 'after_element_html' => $this->getOriginalValueSnippet($job, 'short_description')] ); $fieldset->addField( 'description', 'textarea', - array( - 'name' => 'description', - 'label' => $this->__('Description'), - 'title' => $this->__('Description'), - 'class' => '', - 'required' => false, - 'after_element_html' => $this->getOriginalValueSnippet($job, 'description'), - ) + ['name' => 'description', 'label' => $this->__('Description'), 'title' => $this->__('Description'), 'class' => '', 'required' => false, 'after_element_html' => $this->getOriginalValueSnippet($job, 'description')] ); $fieldset->addField( 'run_model', 'text', - array( - 'name' => 'run_model', - 'label' => $this->__('Run model'), - 'title' => $this->__('Run model'), - 'class' => '', - 'required' => true, - 'note' => $this->__('e.g. "aoe_scheduler/task_heartbeat::run"'), - 'after_element_html' => $this->getOriginalValueSnippet($job, 'run/model'), - ) + ['name' => 'run_model', 'label' => $this->__('Run model'), 'title' => $this->__('Run model'), 'class' => '', 'required' => true, 'note' => $this->__('e.g. "aoe_scheduler/task_heartbeat::run"'), 'after_element_html' => $this->getOriginalValueSnippet($job, 'run/model')] ); $fieldset->addField( 'is_active', 'select', - array( - 'name' => 'is_active', - 'label' => $this->__('Status'), - 'title' => $this->__('Status'), - 'required' => true, - 'options' => array( - 0 => $this->__('Disabled'), - 1 => $this->__('Enabled') - ), - 'after_element_html' => $this->getOriginalValueSnippetFlag($job, 'is_active', 'Enabled', 'Disabled'), - ) + ['name' => 'is_active', 'label' => $this->__('Status'), 'title' => $this->__('Status'), 'required' => true, 'options' => [0 => $this->__('Disabled'), 1 => $this->__('Enabled')], 'after_element_html' => $this->getOriginalValueSnippetFlag($job, 'is_active', 'Enabled', 'Disabled')] ); - $fieldset = $form->addFieldset('cron_fieldset', array('legend' => $this->__('Scheduling'))); + $fieldset = $form->addFieldset('cron_fieldset', ['legend' => $this->__('Scheduling')]); $this->_addElementTypes($fieldset); $fieldset->addField( 'schedule_config_path', 'text', - array( - 'name' => 'schedule_config_path', - 'label' => $this->__('Cron configuration path'), - 'title' => $this->__('Cron configuration path'), - 'class' => '', - 'required' => false, - 'note' => $this->__( - 'Path to system configuration containing the cron configuration for this job. (e.g. system/cron/scheduler_cron_expr_heartbeat) This configuration - if set - has a higher priority over the cron expression configured with the job directly.' - ), - 'after_element_html' => $this->getOriginalValueSnippet($job, 'schedule/config_path'), - ) + ['name' => 'schedule_config_path', 'label' => $this->__('Cron configuration path'), 'title' => $this->__('Cron configuration path'), 'class' => '', 'required' => false, 'note' => $this->__( + 'Path to system configuration containing the cron configuration for this job. (e.g. system/cron/scheduler_cron_expr_heartbeat) This configuration - if set - has a higher priority over the cron expression configured with the job directly.' + ), 'after_element_html' => $this->getOriginalValueSnippet($job, 'schedule/config_path')] ); $fieldset->addField( 'schedule_cron_expr', 'text', - array( - 'name' => 'schedule_cron_expr', - 'label' => $this->__('Cron expression'), - 'title' => $this->__('Cron expression'), - 'required' => false, - 'note' => $this->__('e.g "*/5 * * * *" or "always"'), - 'after_element_html' => $this->getOriginalValueSnippet($job, 'schedule/cron_expr'), - ) + ['name' => 'schedule_cron_expr', 'label' => $this->__('Cron expression'), 'title' => $this->__('Cron expression'), 'required' => false, 'note' => $this->__('e.g "*/5 * * * *" or "always"'), 'after_element_html' => $this->getOriginalValueSnippet($job, 'schedule/cron_expr')] ); - $fieldset = $form->addFieldset('parameter_fieldset', array('legend' => $this->__('Extras'))); + $fieldset = $form->addFieldset('parameter_fieldset', ['legend' => $this->__('Extras')]); $this->_addElementTypes($fieldset); $fieldset->addField( 'parameters', 'textarea', - array( - 'name' => 'parameters', - 'label' => $this->__('Parameters'), - 'title' => $this->__('Parameters'), - 'class' => 'textarea', - 'required' => false, - 'note' => $this->__('These parameters will be passed to the model. It is up to the model to specify the format of these parameters (e.g. json/xml/...'), - 'after_element_html' => $this->getOriginalValueSnippet($job, 'parameters'), - ) + ['name' => 'parameters', 'label' => $this->__('Parameters'), 'title' => $this->__('Parameters'), 'class' => 'textarea', 'required' => false, 'note' => $this->__('These parameters will be passed to the model. It is up to the model to specify the format of these parameters (e.g. json/xml/...'), 'after_element_html' => $this->getOriginalValueSnippet($job, 'parameters')] ); $fieldset->addField( 'groups', 'textarea', - array( - 'name' => 'groups', - 'label' => $this->__('Groups'), - 'title' => $this->__('Groups'), - 'class' => 'textarea', - 'required' => false, - 'note' => $this->__('Comma-separated list of groups (tags) that can be used with the include/exclude command line options of scheduler.php'), - 'after_element_html' => $this->getOriginalValueSnippet($job, 'groups'), - ) + ['name' => 'groups', 'label' => $this->__('Groups'), 'title' => $this->__('Groups'), 'class' => 'textarea', 'required' => false, 'note' => $this->__('Comma-separated list of groups (tags) that can be used with the include/exclude command line options of scheduler.php'), 'after_element_html' => $this->getOriginalValueSnippet($job, 'groups')] ); - $fieldset = $form->addFieldset('dependency_fieldset', array('legend' => $this->__('Dependencies'))); + $fieldset = $form->addFieldset('dependency_fieldset', ['legend' => $this->__('Dependencies')]); $this->_addElementTypes($fieldset); $fieldset->addField( 'on_success', 'textarea', - array( - 'name' => 'on_success', - 'label' => $this->__('Run jobs on success'), - 'title' => $this->__('Run jobs on success'), - 'class' => 'textarea', - 'required' => false, - 'note' => $this->__('Comma-separated list of job codes that will be scheduled after the current cron job has completed successfully.') - ) + ['name' => 'on_success', 'label' => $this->__('Run jobs on success'), 'title' => $this->__('Run jobs on success'), 'class' => 'textarea', 'required' => false, 'note' => $this->__('Comma-separated list of job codes that will be scheduled after the current cron job has completed successfully.')] ); $this->setForm($form); @@ -284,7 +196,7 @@ protected function getOriginalValueSnippetFlag(Aoe_Scheduler_Model_Job $job, $ke return ''; } - $value = $this->__(!in_array($xmlJobData[$key], array(false, 'false', 0, '0'), true) ? $trueLabel : $falseLabel); + $value = $this->__(!in_array($xmlJobData[$key], [false, 'false', 0, '0'], true) ? $trueLabel : $falseLabel); return '

Original: ' . $value . '

'; } diff --git a/app/code/community/Aoe/Scheduler/Block/Adminhtml/Job/Grid.php b/app/code/community/Aoe/Scheduler/Block/Adminhtml/Job/Grid.php index a21e0dc..e434724 100644 --- a/app/code/community/Aoe/Scheduler/Block/Adminhtml/Job/Grid.php +++ b/app/code/community/Aoe/Scheduler/Block/Adminhtml/Job/Grid.php @@ -44,33 +44,21 @@ protected function _prepareMassaction() $this->getMassactionBlock()->setFormFieldName('codes'); $this->getMassactionBlock()->addItem( 'schedule', - array( - 'label' => $this->__('Schedule now'), - 'url' => $this->getUrl('*/*/scheduleNow'), - ) + ['label' => $this->__('Schedule now'), 'url' => $this->getUrl('*/*/scheduleNow')] ); if (Mage::getStoreConfig('system/cron/enableRunNow')) { $this->getMassactionBlock()->addItem( 'run', - array( - 'label' => $this->__('Run now'), - 'url' => $this->getUrl('*/*/runNow'), - ) + ['label' => $this->__('Run now'), 'url' => $this->getUrl('*/*/runNow')] ); } $this->getMassactionBlock()->addItem( 'disable', - array( - 'label' => $this->__('Disable'), - 'url' => $this->getUrl('*/*/disable'), - ) + ['label' => $this->__('Disable'), 'url' => $this->getUrl('*/*/disable')] ); $this->getMassactionBlock()->addItem( 'enable', - array( - 'label' => $this->__('Enable'), - 'url' => $this->getUrl('*/*/enable'), - ) + ['label' => $this->__('Enable'), 'url' => $this->getUrl('*/*/enable')] ); return $this; } @@ -85,82 +73,42 @@ protected function _prepareColumns() { $this->addColumn( 'job_code', - array( - 'header' => $this->__('Job code'), - 'index' => 'job_code', - 'sortable' => false, - ) + ['header' => $this->__('Job code'), 'index' => 'job_code', 'sortable' => false] ); $this->addColumn( 'name', - array( - 'header' => $this->__('Name'), - 'index' => 'name', - 'sortable' => false, - ) + ['header' => $this->__('Name'), 'index' => 'name', 'sortable' => false] ); $this->addColumn( 'short_description', - array( - 'header' => $this->__('Short Description'), - 'index' => 'short_description', - 'sortable' => false, - ) + ['header' => $this->__('Short Description'), 'index' => 'short_description', 'sortable' => false] ); $this->addColumn( 'schedule_cron_expr', - array( - 'header' => $this->__('Cron expression'), - 'index' => 'schedule_cron_expr', - 'sortable' => false, - 'frame_callback' => array($this, 'decorateCronExpression'), - ) + ['header' => $this->__('Cron expression'), 'index' => 'schedule_cron_expr', 'sortable' => false, 'frame_callback' => [$this, 'decorateCronExpression']] ); $this->addColumn( 'run_model', - array( - 'header' => $this->__('Run model'), - 'index' => 'run_model', - 'sortable' => false, - ) + ['header' => $this->__('Run model'), 'index' => 'run_model', 'sortable' => false] ); $this->addColumn( 'parameters', - array( - 'header' => $this->__('Parameters'), - 'index' => 'parameters', - 'sortable' => false, - 'frame_callback' => array($this, 'decorateTrim'), - ) + ['header' => $this->__('Parameters'), 'index' => 'parameters', 'sortable' => false, 'frame_callback' => [$this, 'decorateTrim']] ); $this->addColumn( 'groups', - array( - 'header' => $this->__('Groups'), - 'index' => 'groups', - 'sortable' => false, - 'frame_callback' => array($this, 'decorateTrim'), - ) + ['header' => $this->__('Groups'), 'index' => 'groups', 'sortable' => false, 'frame_callback' => [$this, 'decorateTrim']] ); $this->addColumn( 'type', - array( - 'header' => $this->__('Type'), - 'sortable' => false, - 'frame_callback' => array($this, 'decorateType'), - ) + ['header' => $this->__('Type'), 'sortable' => false, 'frame_callback' => [$this, 'decorateType']] ); $this->addColumn( 'is_active', - array( - 'header' => $this->__('Status'), - 'index' => 'is_active', - 'sortable' => false, - 'frame_callback' => array($this, 'decorateStatus'), - ) + ['header' => $this->__('Status'), 'index' => 'is_active', 'sortable' => false, 'frame_callback' => [$this, 'decorateStatus']] ); return parent::_prepareColumns(); } @@ -188,7 +136,6 @@ public function decorateStatus($value) * Decorate cron expression * * @param $value - * @param Aoe_Scheduler_Model_Job $job * * @return string */ @@ -215,7 +162,6 @@ public function decorateTrim($value) * Decorate cron expression * * @param $value - * @param Aoe_Scheduler_Model_Job $job * * @return string */ @@ -233,7 +179,7 @@ public function decorateType($value, Aoe_Scheduler_Model_Job $job) */ public function getRowUrl($row) { - return $this->getUrl('*/*/edit', array('job_code' => $row->getJobCode())); + return $this->getUrl('*/*/edit', ['job_code' => $row->getJobCode()]); } /** @@ -243,6 +189,6 @@ public function getRowUrl($row) */ public function getGridUrl() { - return $this->getUrl('adminhtml/job/index', array('_current' => true)); + return $this->getUrl('adminhtml/job/index', ['_current' => true]); } } diff --git a/app/code/community/Aoe/Scheduler/Block/Adminhtml/Scheduler.php b/app/code/community/Aoe/Scheduler/Block/Adminhtml/Scheduler.php index bde863b..8b25759 100644 --- a/app/code/community/Aoe/Scheduler/Block/Adminhtml/Scheduler.php +++ b/app/code/community/Aoe/Scheduler/Block/Adminhtml/Scheduler.php @@ -29,17 +29,11 @@ protected function _prepareLayout() $this->removeButton('add'); $this->_addButton( 'add_new', - array( - 'label' => $this->__('Generate Schedule'), - 'onclick' => "setLocation('{$this->getUrl('*/*/generateSchedule')}')", - ) + ['label' => $this->__('Generate Schedule'), 'onclick' => "setLocation('{$this->getUrl('*/*/generateSchedule')}')"] ); $this->_addButton( 'configure', - array( - 'label' => $this->__('Cron Configuration'), - 'onclick' => "setLocation('{$this->getUrl('adminhtml/system_config/edit', array('section' => 'system'))}#system_cron')", - ) + ['label' => $this->__('Cron Configuration'), 'onclick' => "setLocation('{$this->getUrl('adminhtml/system_config/edit', ['section' => 'system'])}#system_cron')"] ); return parent::_prepareLayout(); } diff --git a/app/code/community/Aoe/Scheduler/Block/Adminhtml/Scheduler/Grid.php b/app/code/community/Aoe/Scheduler/Block/Adminhtml/Scheduler/Grid.php index e234aed..c74f763 100755 --- a/app/code/community/Aoe/Scheduler/Block/Adminhtml/Scheduler/Grid.php +++ b/app/code/community/Aoe/Scheduler/Block/Adminhtml/Scheduler/Grid.php @@ -46,17 +46,11 @@ protected function _prepareMassaction() $this->getMassactionBlock()->setFormFieldName('schedule_ids'); $this->getMassactionBlock()->addItem( 'delete', - array( - 'label' => $this->__('Delete'), - 'url' => $this->getUrl('*/*/delete'), - ) + ['label' => $this->__('Delete'), 'url' => $this->getUrl('*/*/delete')] ); $this->getMassactionBlock()->addItem( 'kill', - array( - 'label' => $this->__('Kill'), - 'url' => $this->getUrl('*/*/kill'), - ) + ['label' => $this->__('Kill'), 'url' => $this->getUrl('*/*/kill')] ); return $this; } @@ -73,15 +67,9 @@ protected function _prepareColumns() $this->addColumn( 'schedule_id', - array( - 'header' => $this->__('Id'), - 'index' => 'schedule_id', - ) - ); - $config = array( - 'header' => $this->__('Job'), - 'index' => 'job_code', + ['header' => $this->__('Id'), 'index' => 'schedule_id'] ); + $config = ['header' => $this->__('Job'), 'index' => 'job_code']; switch (Mage::getStoreConfig('system/cron/listCodeFilterType')) { case Aoe_Scheduler_Model_Adminhtml_System_Config_Source_List_Code_Filtertype::SELECT: $config['type'] = 'options'; @@ -97,93 +85,47 @@ protected function _prepareColumns() ); $this->addColumn( 'created_at', - array( - 'header' => $this->__('Created'), - 'index' => 'created_at', - 'type' => 'datetime' - ) + ['header' => $this->__('Created'), 'index' => 'created_at', 'type' => 'datetime'] ); $this->addColumn( 'scheduled_at', - array( - 'header' => $this->__('Scheduled'), - 'index' => 'scheduled_at', - 'type' => 'datetime' - ) + ['header' => $this->__('Scheduled'), 'index' => 'scheduled_at', 'type' => 'datetime'] ); $this->addColumn( 'executed_at', - array( - 'header' => $this->__('Executed'), - 'index' => 'executed_at', - 'type' => 'datetime' - ) + ['header' => $this->__('Executed'), 'index' => 'executed_at', 'type' => 'datetime'] ); $this->addColumn( 'last_seen', - array( - 'header' => $this->__('Last seen'), - 'index' => 'last_seen', - 'type' => 'datetime' - ) + ['header' => $this->__('Last seen'), 'index' => 'last_seen', 'type' => 'datetime'] ); $this->addColumn( 'eta', - array( - 'header' => $this->__('ETA'), - 'index' => 'eta', - 'type' => 'datetime' - ) + ['header' => $this->__('ETA'), 'index' => 'eta', 'type' => 'datetime'] ); $this->addColumn( 'finished_at', - array( - 'header' => $this->__('Finished'), - 'index' => 'finished_at', - 'type' => 'datetime' - ) + ['header' => $this->__('Finished'), 'index' => 'finished_at', 'type' => 'datetime'] ); $this->addColumn( 'messages', - array( - 'header' => $this->__('Messages'), - 'index' => 'messages', - 'frame_callback' => array($this, 'decorateMessages') - ) + ['header' => $this->__('Messages'), 'index' => 'messages', 'frame_callback' => [$this, 'decorateMessages']] ); $this->addColumn( 'memory_usage', - array( - 'header' => $this->__('Memory Usage'), - 'index' => 'memory_usage', - 'type' => 'number', - 'renderer' => 'aoe_scheduler/adminhtml_scheduler_renderer_memory', - ) + ['header' => $this->__('Memory Usage'), 'index' => 'memory_usage', 'type' => 'number', 'renderer' => 'aoe_scheduler/adminhtml_scheduler_renderer_memory'] ); $this->addColumn( 'host', - array( - 'header' => $this->__('Host'), - 'index' => 'host', - ) + ['header' => $this->__('Host'), 'index' => 'host'] ); $this->addColumn( 'pid', - array( - 'header' => $this->__('Pid'), - 'index' => 'pid', - 'width' => '50', - ) + ['header' => $this->__('Pid'), 'index' => 'pid', 'width' => '50'] ); $this->addColumn( 'status', - array( - 'header' => $this->__('Status'), - 'index' => 'status', - 'frame_callback' => array($viewHelper, 'decorateStatus'), - 'type' => 'options', - 'options' => Mage::getSingleton('cron/schedule')->getAllStatuses() - ) + ['header' => $this->__('Status'), 'index' => 'status', 'frame_callback' => [$viewHelper, 'decorateStatus'], 'type' => 'options', 'options' => Mage::getSingleton('cron/schedule')->getAllStatuses()] ); return parent::_prepareColumns(); @@ -194,7 +136,6 @@ protected function _prepareColumns() * Decorate message * * @param string $value - * @param Aoe_Scheduler_Model_Schedule $row * * @return string */ @@ -245,6 +186,6 @@ protected function _filterStoreCondition($collection, $column) */ public function getGridUrl() { - return $this->getUrl('adminhtml/scheduler/index', array('_current' => true)); + return $this->getUrl('adminhtml/scheduler/index', ['_current' => true]); } } diff --git a/app/code/community/Aoe/Scheduler/Block/Adminhtml/Timeline.php b/app/code/community/Aoe/Scheduler/Block/Adminhtml/Timeline.php index c4afbb6..107b072 100644 --- a/app/code/community/Aoe/Scheduler/Block/Adminhtml/Timeline.php +++ b/app/code/community/Aoe/Scheduler/Block/Adminhtml/Timeline.php @@ -26,7 +26,7 @@ class Aoe_Scheduler_Block_Adminhtml_Timeline extends Mage_Adminhtml_Block_Widget /** * @var array schedules */ - protected $schedules = array(); + protected $schedules = []; /** @@ -50,14 +50,8 @@ protected function _construct() protected function _prepareLayout() { $this->removeButton('add'); - $this->_addButton('add_new', array( - 'label' => $this->__('Generate Schedule'), - 'onclick' => "setLocation('{$this->getUrl('*/*/generateSchedule')}')", - )); - $this->_addButton('configure', array( - 'label' => $this->__('Cron Configuration'), - 'onclick' => "setLocation('{$this->getUrl('adminhtml/system_config/edit', array('section' => 'system'))}#system_cron')", - )); + $this->_addButton('add_new', ['label' => $this->__('Generate Schedule'), 'onclick' => "setLocation('{$this->getUrl('*/*/generateSchedule')}')"]); + $this->_addButton('configure', ['label' => $this->__('Cron Configuration'), 'onclick' => "setLocation('{$this->getUrl('adminhtml/system_config/edit', ['section' => 'system'])}#system_cron')"]); return parent::_prepareLayout(); } @@ -192,7 +186,6 @@ public function getEndtime() /** * Get attributes for div representing a gantt element * - * @param Aoe_Scheduler_Model_Schedule $schedule * @return string */ public function getGanttDivAttributes(Aoe_Scheduler_Model_Schedule $schedule) @@ -201,7 +194,7 @@ public function getGanttDivAttributes(Aoe_Scheduler_Model_Schedule $schedule) if ($schedule->getStatus() == Aoe_Scheduler_Model_Schedule::STATUS_RUNNING) { $duration = time() - strtotime($schedule->getStarttime()); } else { - $duration = $schedule->getDuration() ? $schedule->getDuration() : 0; + $duration = $schedule->getDuration() ?: 0; } $duration = $duration / $this->zoom; $duration = ceil($duration / 4) * 4 - 1; // round to numbers dividable by 4, then remove 1 px border @@ -247,7 +240,7 @@ public function _toHtml() { $html = parent::_toHtml(); if (!$html && !Mage::getStoreConfigFlag('dev/template/allow_symlink')) { - $url = $this->getUrl('adminhtml/system_config/edit', array('section' => 'dev')) . '#dev_template'; + $url = $this->getUrl('adminhtml/system_config/edit', ['section' => 'dev']) . '#dev_template'; $html = $this->__('Warning: You installed Aoe_Scheduler using symlinks (e.g. via modman), but forgot to allow symlinks for template files! Please go to System > Configuration > Advanced > Developer > Template Settings and set "Allow Symlinks" to "yes"', $url); } return $html; diff --git a/app/code/community/Aoe/Scheduler/Block/Adminhtml/TimelineDetail.php b/app/code/community/Aoe/Scheduler/Block/Adminhtml/TimelineDetail.php index 3a5935b..4da781c 100644 --- a/app/code/community/Aoe/Scheduler/Block/Adminhtml/TimelineDetail.php +++ b/app/code/community/Aoe/Scheduler/Block/Adminhtml/TimelineDetail.php @@ -22,7 +22,6 @@ class Aoe_Scheduler_Block_Adminhtml_TimelineDetail extends Mage_Adminhtml_Block_ /** * Set schedule * - * @param Aoe_Scheduler_Model_Schedule $schedule * @return Aoe_Scheduler_Block_Adminhtml_TimelineDetail */ public function setSchedule(Aoe_Scheduler_Model_Schedule $schedule) diff --git a/app/code/community/Aoe/Scheduler/Controller/AbstractController.php b/app/code/community/Aoe/Scheduler/Controller/AbstractController.php index 76f2d6d..78127ab 100755 --- a/app/code/community/Aoe/Scheduler/Controller/AbstractController.php +++ b/app/code/community/Aoe/Scheduler/Controller/AbstractController.php @@ -38,7 +38,7 @@ protected function _initAction() // check configuration if (Mage::getStoreConfig('system/cron/schedule_generate_every') > Mage::getStoreConfig('system/cron/schedule_ahead_for')) { - $this->_getSession()->addError($this->__('Configuration problem. "Generate Schedules Every" is higher than "Schedule Ahead for". Please check your configuration settings.', $this->getUrl('adminhtml/system_config/edit', array('section' => 'system')) . '#system_cron')); + $this->_getSession()->addError($this->__('Configuration problem. "Generate Schedules Every" is higher than "Schedule Ahead for". Please check your configuration settings.', $this->getUrl('adminhtml/system_config/edit', ['section' => 'system']) . '#system_cron')); } // Check the cron is being run as the configured user and whether or not to show the message @@ -115,7 +115,7 @@ protected function _checkCronUser() 'Scheduler appears to be running as system user "%s". It should be running as "%s". Use %s.%s Don\'t show this again.', $helper->getLastRunUser(), $configuredUser, - $this->getUrl('adminhtml/scheduler/setConfiguredUser', array('user' => $helper->getLastRunUser())), + $this->getUrl('adminhtml/scheduler/setConfiguredUser', ['user' => $helper->getLastRunUser()]), $helper->getLastRunUser(), ($helper->getShouldKillOnWrongUser()) ? ' Warning! Jobs will not run until this is resolved!.' : '', $this->getUrl('adminhtml/scheduler/hideUserWarning') @@ -127,7 +127,7 @@ protected function _checkCronUser() $this->__( 'No default user is configured for who should run the cron. Click here to define one. We suggest ' . 'using "%s". Don\'t show this again.', - $this->getUrl('adminhtml/system_config/edit', array('section' => 'system')) . '#system_cron', + $this->getUrl('adminhtml/system_config/edit', ['section' => 'system']) . '#system_cron', $helper->getRunningUser(), // suggest the user that runs the web server, makes sense $this->getUrl('adminhtml/scheduler/hideUserWarning') ) diff --git a/app/code/community/Aoe/Scheduler/Helper/Data.php b/app/code/community/Aoe/Scheduler/Helper/Data.php index 02e94d6..3272ebe 100644 --- a/app/code/community/Aoe/Scheduler/Helper/Data.php +++ b/app/code/community/Aoe/Scheduler/Helper/Data.php @@ -8,16 +8,16 @@ class Aoe_Scheduler_Helper_Data extends Mage_Core_Helper_Abstract { - const XML_PATH_MAX_RUNNING_TIME = 'system/cron/max_running_time'; - const XML_PATH_EMAIL_TEMPLATE = 'system/cron/error_email_template'; - const XML_PATH_EMAIL_IDENTITY = 'system/cron/error_email_identity'; - const XML_PATH_EMAIL_RECIPIENT = 'system/cron/error_email'; - const XML_PATH_CRON_USER = 'system/cron/cronUser'; - const XML_PATH_KILL_ON_WRONG_USER = 'system/cron/killOnIncorrectUser'; - const XML_PATH_SHOW_WRONG_USER_MSG = 'system/cron/showCronUserMessage'; - const XML_PATH_RUN_ONLY_IF_CACHE_PREFIX_ID_MATCHES = 'system/cron/runOnlyIfCachePrefixIdMatches'; + public const XML_PATH_MAX_RUNNING_TIME = 'system/cron/max_running_time'; + public const XML_PATH_EMAIL_TEMPLATE = 'system/cron/error_email_template'; + public const XML_PATH_EMAIL_IDENTITY = 'system/cron/error_email_identity'; + public const XML_PATH_EMAIL_RECIPIENT = 'system/cron/error_email'; + public const XML_PATH_CRON_USER = 'system/cron/cronUser'; + public const XML_PATH_KILL_ON_WRONG_USER = 'system/cron/killOnIncorrectUser'; + public const XML_PATH_SHOW_WRONG_USER_MSG = 'system/cron/showCronUserMessage'; + public const XML_PATH_RUN_ONLY_IF_CACHE_PREFIX_ID_MATCHES = 'system/cron/runOnlyIfCachePrefixIdMatches'; - const VAR_LAST_RUN_USER_CODE = 'aoescheduler_lastrunuser'; + public const VAR_LAST_RUN_USER_CODE = 'aoescheduler_lastrunuser'; protected $groupsToJobsMap = null; @@ -38,7 +38,7 @@ public function trimExplode($delim, $string, $removeEmptyValues = false) $result = array_map('trim', $explodedValues); if ($removeEmptyValues) { - $temp = array(); + $temp = []; foreach ($result as $value) { if ($value !== '') { $temp[] = $value; @@ -114,11 +114,12 @@ public function decorateTime($value, $echoToday = false, $dateFormat = null) } else { $dateConverter = Mage::getModel('core/date'); $value = $dateConverter->date($dateFormat, $value); - $replace = array( - $dateConverter->date('Y-m-d ', time()) => $echoToday ? Mage::helper('aoe_scheduler')->__('Today') . ', ' : '', // today + $replace = [ + $dateConverter->date('Y-m-d ', time()) => $echoToday ? Mage::helper('aoe_scheduler')->__('Today') . ', ' : '', + // today $dateConverter->date('Y-m-d ', strtotime('+1 day')) => Mage::helper('aoe_scheduler')->__('Tomorrow') . ', ', $dateConverter->date('Y-m-d ', strtotime('-1 day')) => Mage::helper('aoe_scheduler')->__('Yesterday') . ', ', - ); + ]; $value = str_replace(array_keys($replace), array_values($replace), $value); } return $value; @@ -146,16 +147,13 @@ public function getLastExecutionTime($jobCode) $schedules = Mage::getModel('cron/schedule')->getCollection(); /* @var $schedules Mage_Cron_Model_Mysql4_Schedule_Collection */ $schedules->getSelect()->limit(1)->order('executed_at DESC'); $schedules->addFieldToFilter( - array('status'), - array( - array('eq' => Aoe_Scheduler_Model_Schedule::STATUS_SUCCESS), - array('eq' => Aoe_Scheduler_Model_Schedule::STATUS_REPEAT) - ) + ['status'], + [['eq' => Aoe_Scheduler_Model_Schedule::STATUS_SUCCESS], ['eq' => Aoe_Scheduler_Model_Schedule::STATUS_REPEAT]] ); $schedules->addFieldToFilter('job_code', $jobCode); $schedules->load(); - if (count($schedules) == 0) { + if ((is_countable($schedules) ? count($schedules) : 0) == 0) { return false; } $executedAt = $schedules->getFirstItem()->getExecutedAt(); @@ -197,8 +195,6 @@ public function isDisabled($jobCode) * Check if a job matches the group include/exclude lists * * @param $jobCode - * @param array $include - * @param array $exclude * @return mixed */ public function matchesIncludeExclude($jobCode, array $include, array $exclude) @@ -210,7 +206,7 @@ public function matchesIncludeExclude($jobCode, array $include, array $exclude) sort($exclude); $key = $jobCode . '|' . implode(',', $include) . '|' . implode(',', $exclude); - static $cache = array(); + static $cache = []; if (!isset($cache[$key])) { if (count($include) == 0 && count($exclude) == 0) { $cache[$key] = true; @@ -236,7 +232,7 @@ public function matchesIncludeExclude($jobCode, array $include, array $exclude) public function getGroupsToJobsMap($forceRebuild = false) { if ($this->groupsToJobsMap === null || $forceRebuild) { - $map = array(); + $map = []; /* @var $jobs Aoe_Scheduler_Model_Resource_Job_Collection */ $jobs = Mage::getSingleton('aoe_scheduler/job')->getCollection(); @@ -272,7 +268,6 @@ public function addGroupJobs(array $jobs, array $groups) /** * Send error mail * - * @param Aoe_Scheduler_Model_Schedule $schedule * @param $error * @return void */ @@ -289,13 +284,13 @@ public function sendErrorMail(Aoe_Scheduler_Model_Schedule $schedule, $error) foreach ($recipients as $recipient) { $emailTemplate = Mage::getModel('core/email_template'); /* @var $emailTemplate Mage_Core_Model_Email_Template */ - $emailTemplate->setDesignConfig(array('area' => 'backend')); + $emailTemplate->setDesignConfig(['area' => 'backend']); $emailTemplate->sendTransactional( Mage::getStoreConfig(self::XML_PATH_EMAIL_TEMPLATE), Mage::getStoreConfig(self::XML_PATH_EMAIL_IDENTITY), $recipient, null, - array('error' => $error, 'schedule' => $schedule) + ['error' => $error, 'schedule' => $schedule] ); } @@ -319,7 +314,7 @@ public function getCallBack($runModel) if (!method_exists($model, $run[2])) { Mage::throwException(Mage::helper('cron')->__('Invalid callback: Method for %s::%s does not exist', $run[1], $run[2])); } - $callback = array($model, $run[2]); + $callback = [$model, $run[2]]; return $callback; } @@ -335,7 +330,7 @@ public function validateCronExpression($cronExpression) $schedule = Mage::getModel('cron/schedule'); /* @var $schedule Mage_Cron_Model_Schedule */ $schedule->setCronExpr($cronExpression); - } catch (Exception $e) { + } catch (Exception) { return false; } return true; diff --git a/app/code/community/Aoe/Scheduler/Helper/GracefulDead.php b/app/code/community/Aoe/Scheduler/Helper/GracefulDead.php index 7e2105f..016537b 100644 --- a/app/code/community/Aoe/Scheduler/Helper/GracefulDead.php +++ b/app/code/community/Aoe/Scheduler/Helper/GracefulDead.php @@ -16,11 +16,11 @@ public static function configure() { static $configured = false; if (!$configured) { - register_shutdown_function(array('Aoe_Scheduler_Helper_GracefulDead', 'beforeDyingShutdown')); + register_shutdown_function(['Aoe_Scheduler_Helper_GracefulDead', 'beforeDyingShutdown']); if (extension_loaded('pcntl') && function_exists('pcntl_signal')) { declare(ticks = 1); - pcntl_signal(SIGINT, array('Aoe_Scheduler_Helper_GracefulDead', 'beforeDyingSigint')); // CTRL + C - pcntl_signal(SIGTERM, array('Aoe_Scheduler_Helper_GracefulDead', 'beforeDyingSigterm')); // kill + pcntl_signal(SIGINT, ['Aoe_Scheduler_Helper_GracefulDead', 'beforeDyingSigint']); // CTRL + C + pcntl_signal(SIGTERM, ['Aoe_Scheduler_Helper_GracefulDead', 'beforeDyingSigterm']); // kill } $configured = true; } diff --git a/app/code/community/Aoe/Scheduler/Model/Adminhtml/System/Config/Source/List/Code/Filtertype.php b/app/code/community/Aoe/Scheduler/Model/Adminhtml/System/Config/Source/List/Code/Filtertype.php index bde78cb..ff2a624 100644 --- a/app/code/community/Aoe/Scheduler/Model/Adminhtml/System/Config/Source/List/Code/Filtertype.php +++ b/app/code/community/Aoe/Scheduler/Model/Adminhtml/System/Config/Source/List/Code/Filtertype.php @@ -6,8 +6,8 @@ */ class Aoe_Scheduler_Model_Adminhtml_System_Config_Source_List_Code_Filtertype { - const SELECT = 'select'; - const TEXT = 'text'; + public const SELECT = 'select'; + public const TEXT = 'text'; /** * Options getter @@ -16,9 +16,6 @@ class Aoe_Scheduler_Model_Adminhtml_System_Config_Source_List_Code_Filtertype */ public function toOptionArray() { - return array( - array('value' => self::SELECT, 'label' => Mage::helper('adminhtml')->__('Select')), - array('value' => self::TEXT, 'label' => Mage::helper('adminhtml')->__('Text')), - ); + return [['value' => self::SELECT, 'label' => Mage::helper('adminhtml')->__('Select')], ['value' => self::TEXT, 'label' => Mage::helper('adminhtml')->__('Text')]]; } } diff --git a/app/code/community/Aoe/Scheduler/Model/Job.php b/app/code/community/Aoe/Scheduler/Model/Job.php index 16f6942..3203f5b 100755 --- a/app/code/community/Aoe/Scheduler/Model/Job.php +++ b/app/code/community/Aoe/Scheduler/Model/Job.php @@ -62,7 +62,7 @@ public function getName() */ public function setIsActive($flag) { - return $this->setData('is_active', !in_array($flag, array(false, 'false', 0, '0'), true)); + return $this->setData('is_active', !in_array($flag, [false, 'false', 0, '0'], true)); } /** @@ -70,7 +70,7 @@ public function setIsActive($flag) */ public function getIsActive() { - return !in_array($this->getData('is_active'), array(false, 'false', 0, '0'), true); + return !in_array($this->getData('is_active'), [false, 'false', 0, '0'], true); } /** @@ -89,7 +89,7 @@ public function setXmlJobData(array $jobData) public function getXmlJobData() { $jobData = $this->getData('xml_job_data'); - return (is_array($jobData) ? $jobData : array()); + return (is_array($jobData) ? $jobData : []); } /** @@ -117,7 +117,7 @@ public function getDbJobData() } $jobData = $this->getData('db_job_data'); - return (is_array($jobData) ? $jobData : array()); + return (is_array($jobData) ? $jobData : []); } /** diff --git a/app/code/community/Aoe/Scheduler/Model/Observer.php b/app/code/community/Aoe/Scheduler/Model/Observer.php index a67bc10..ebdabdc 100755 --- a/app/code/community/Aoe/Scheduler/Model/Observer.php +++ b/app/code/community/Aoe/Scheduler/Model/Observer.php @@ -11,8 +11,6 @@ class Aoe_Scheduler_Model_Observer /* extends Mage_Cron_Model_Observer */ * Process cron queue * Generate tasks schedule * Cleanup tasks schedule - * - * @param Varien_Event_Observer $observer */ public function dispatch(Varien_Event_Observer $observer) { @@ -48,8 +46,6 @@ public function dispatch(Varien_Event_Observer $observer) /** * Process cron queue for tasks marked as 'always' - * - * @param Varien_Event_Observer $observer */ public function dispatchAlways(Varien_Event_Observer $observer) { diff --git a/app/code/community/Aoe/Scheduler/Model/ProcessManager.php b/app/code/community/Aoe/Scheduler/Model/ProcessManager.php index 56ad81b..41ab02c 100644 --- a/app/code/community/Aoe/Scheduler/Model/ProcessManager.php +++ b/app/code/community/Aoe/Scheduler/Model/ProcessManager.php @@ -9,8 +9,8 @@ class Aoe_Scheduler_Model_ProcessManager { - const XML_PATH_MARK_AS_ERROR = 'system/cron/mark_as_error_after'; - const XML_PATH_MAX_JOB_RUNTIME = 'system/cron/max_job_runtime'; + public const XML_PATH_MARK_AS_ERROR = 'system/cron/mark_as_error_after'; + public const XML_PATH_MAX_JOB_RUNTIME = 'system/cron/max_job_runtime'; /** * Get all schedules running on this server @@ -37,7 +37,7 @@ public function getAllRunningSchedules($host = null) public function getAllKillRequests($host = null) { $collection = $this->getAllRunningSchedules($host); - $collection->addFieldToFilter('kill_request', array('lt' => strftime('%Y-%m-%d %H:%M:00', time()+60))); + $collection->addFieldToFilter('kill_request', ['lt' => strftime('%Y-%m-%d %H:%M:00', time()+60)]); return $collection; } @@ -55,7 +55,7 @@ public function isJobCodeRunning($jobCode, $ignoreId = null) ->addFieldToFilter('status', Aoe_Scheduler_Model_Schedule::STATUS_RUNNING) ->addFieldToFilter('job_code', $jobCode); if (!is_null($ignoreId)) { - $collection->addFieldToFilter('schedule_id', array('neq' => $ignoreId)); + $collection->addFieldToFilter('schedule_id', ['neq' => $ignoreId]); } foreach ($collection as $schedule) { /* @var $schedule Aoe_Scheduler_Model_Schedule */ $alive = $schedule->isAlive(); @@ -94,7 +94,7 @@ public function checkRunningJobs() if ($markAsErrorAfter) { $schedules = Mage::getModel('cron/schedule')->getCollection()/* @var $schedules Mage_Cron_Model_Resource_Schedule_Collection */ ->addFieldToFilter('status', Aoe_Scheduler_Model_Schedule::STATUS_RUNNING) - ->addFieldToFilter('last_seen', array('lt' => strftime('%Y-%m-%d %H:%M:00', $maxAge))) + ->addFieldToFilter('last_seen', ['lt' => strftime('%Y-%m-%d %H:%M:00', $maxAge)]) ->load(); foreach ($schedules as $schedule) { /* @var $schedule Aoe_Scheduler_Model_Schedule */ @@ -110,10 +110,10 @@ public function checkRunningJobs() // by robinfritze. @see https://github.com/AOEpeople/Aoe_Scheduler/issues/40#issuecomment-67749476 $schedules = Mage::getModel('cron/schedule')->getCollection() /* @var $schedules Mage_Cron_Model_Resource_Schedule_Collection */ ->addFieldToFilter('status', Aoe_Scheduler_Model_Schedule::STATUS_RUNNING) - ->addFieldToFilter('last_seen', array('null' => true)) - ->addFieldToFilter('host', array('null' => true)) - ->addFieldToFilter('pid', array('null' => true)) - ->addFieldToFilter('scheduled_at', array('lt' => strftime('%Y-%m-%d %H:%M:00', $maxAge))) + ->addFieldToFilter('last_seen', ['null' => true]) + ->addFieldToFilter('host', ['null' => true]) + ->addFieldToFilter('pid', ['null' => true]) + ->addFieldToFilter('scheduled_at', ['lt' => strftime('%Y-%m-%d %H:%M:00', $maxAge)]) ->load(); foreach ($schedules->getIterator() as $schedule) { /* @var $schedule Aoe_Scheduler_Model_Schedule */ @@ -129,11 +129,11 @@ public function checkRunningJobs() */ $schedules = Mage::getModel('cron/schedule')->getCollection() /* @var $schedules Mage_Cron_Model_Resource_Schedule_Collection */ ->addFieldToFilter('status', Aoe_Scheduler_Model_Schedule::STATUS_RUNNING) - ->addFieldToFilter('last_seen', array('null' => true)) - ->addFieldToFilter('host', array('null' => true)) - ->addFieldToFilter('pid', array('null' => true)) - ->addFieldToFilter('scheduled_at', array('null' => true)) - ->addFieldToFilter('created_at', array('lt' => strftime('%Y-%m-%d %H:%M:00', $maxAge))) + ->addFieldToFilter('last_seen', ['null' => true]) + ->addFieldToFilter('host', ['null' => true]) + ->addFieldToFilter('pid', ['null' => true]) + ->addFieldToFilter('scheduled_at', ['null' => true]) + ->addFieldToFilter('created_at', ['lt' => strftime('%Y-%m-%d %H:%M:00', $maxAge)]) ->load(); foreach ($schedules->getIterator() as $schedule) { /* @var $schedule Aoe_Scheduler_Model_Schedule */ diff --git a/app/code/community/Aoe/Scheduler/Model/Resource/Job.php b/app/code/community/Aoe/Scheduler/Model/Resource/Job.php index 268fa18..860302a 100644 --- a/app/code/community/Aoe/Scheduler/Model/Resource/Job.php +++ b/app/code/community/Aoe/Scheduler/Model/Resource/Job.php @@ -6,7 +6,7 @@ class Aoe_Scheduler_Model_Resource_Job extends Mage_Core_Model_Resource_Db_Abstr protected $loaded = false; /** @var Aoe_Scheduler_Model_Job[] */ - protected $jobs = array(); + protected $jobs = []; /** * Resource initialization @@ -18,9 +18,9 @@ protected function _construct() public function getJobCodes() { - $codes = array(); + $codes = []; - $nodes = array('crontab/jobs', 'default/crontab/jobs'); + $nodes = ['crontab/jobs', 'default/crontab/jobs']; foreach ($nodes as $node) { $jobs = Mage::getConfig()->getNode($node); if ($jobs && $jobs->hasChildren()) { @@ -41,15 +41,13 @@ public function getJobCodes() /** * @param Aoe_Scheduler_Model_Job $object - * @param mixed $value * @param null $field - * * @return $this */ - public function load(Mage_Core_Model_Abstract $object, $value, $field = null) + public function load(Mage_Core_Model_Abstract $object, mixed $value, $field = null) { if (!$object instanceof Aoe_Scheduler_Model_Job) { - throw new InvalidArgumentException(sprintf("Expected object of type 'Aoe_Scheduler_Model_Job' got '%s'", get_class($object))); + throw new InvalidArgumentException(sprintf("Expected object of type 'Aoe_Scheduler_Model_Job' got '%s'", $object::class)); } /** @var Aoe_Scheduler_Model_Job $object */ @@ -59,10 +57,10 @@ public function load(Mage_Core_Model_Abstract $object, $value, $field = null) } if (empty($value)) { - $this->setModelFromJobData($object, array()); + $this->setModelFromJobData($object, []); $object->setJobCode(''); - $object->setXmlJobData(array()); - $object->setDbJobData(array()); + $object->setXmlJobData([]); + $object->setDbJobData([]); return $this; } @@ -91,7 +89,7 @@ public function save(Mage_Core_Model_Abstract $object) } if (!$object instanceof Aoe_Scheduler_Model_Job) { - throw new InvalidArgumentException(sprintf("Expected object of type 'Aoe_Scheduler_Model_Job' got '%s'", get_class($object))); + throw new InvalidArgumentException(sprintf("Expected object of type 'Aoe_Scheduler_Model_Job' got '%s'", $object::class)); } if (!$object->getJobCode()) { @@ -131,33 +129,20 @@ public function save(Mage_Core_Model_Abstract $object) foreach ($updateValues as $k => $v) { $adapter->update( $this->getMainTable(), - array('value' => $v), - array( - 'scope = ?' => 'default', - 'scope_id = ?' => 0, - 'path = ?' => $pathPrefix . $k - ) + ['value' => $v], + ['scope = ?' => 'default', 'scope_id = ?' => 0, 'path = ?' => $pathPrefix . $k] ); } foreach ($insertValues as $k => $v) { $adapter->insert( $this->getMainTable(), - array( - 'scope' => 'default', - 'scope_id' => 0, - 'path' => $pathPrefix . $k, - 'value' => $v - ) + ['scope' => 'default', 'scope_id' => 0, 'path' => $pathPrefix . $k, 'value' => $v] ); } foreach ($deleteValues as $k => $v) { $adapter->delete( $this->getMainTable(), - array( - 'scope = ?' => 'default', - 'scope_id = ?' => 0, - 'path = ?' => $pathPrefix . $k - ) + ['scope = ?' => 'default', 'scope_id = ?' => 0, 'path = ?' => $pathPrefix . $k] ); } @@ -187,7 +172,7 @@ public function forsedSave(Mage_Core_Model_Abstract $object) public function delete(Mage_Core_Model_Abstract $object) { if (!$object instanceof Aoe_Scheduler_Model_Job) { - throw new InvalidArgumentException(sprintf("Expected object of type 'Aoe_Scheduler_Model_Job' got '%s'", get_class($object))); + throw new InvalidArgumentException(sprintf("Expected object of type 'Aoe_Scheduler_Model_Job' got '%s'", $object::class)); } $this->_beforeDelete($object); @@ -199,11 +184,7 @@ public function delete(Mage_Core_Model_Abstract $object) $adapter = $this->_getWriteAdapter(); $adapter->delete( $this->getMainTable(), - array( - 'path LIKE ?' => $this->getJobSearchPath($object->getJobCode()), - 'scope = ?' => 'default', - 'scope_id = ?' => 0 - ) + ['path LIKE ?' => $this->getJobSearchPath($object->getJobCode()), 'scope = ?' => 'default', 'scope_id = ?' => 0] ); Mage::getConfig()->reinit(); @@ -220,19 +201,19 @@ protected function getJobPathPrefix($jobCode) protected function getJobSearchPath($jobCode) { - return str_replace(array('\\', '%', '_'), array('\\\\', '\\%', '\\_'), $this->getJobPathPrefix($jobCode)) . '/%'; + return str_replace(['\\', '%', '_'], ['\\\\', '\\%', '\\_'], $this->getJobPathPrefix($jobCode)) . '/%'; } private function getJobDataFromConfig($jobCode, $useDefaultScope = false, $default = null) { $config = Mage::getConfig()->getNode(($useDefaultScope ? 'default/' : '') . $this->getJobPathPrefix($jobCode)); if (!$config) { - return array(); + return []; } $config = $config->asArray(); - $values = array(); + $values = []; if (isset($config['name'])) { $values['name'] = $config['name']; @@ -301,15 +282,15 @@ public function getJobDataFromDb($jobCode) $adapter = $this->_getWriteAdapter(); $select = $adapter->select() - ->from($this->getMainTable(), array('path', 'value')) + ->from($this->getMainTable(), ['path', 'value']) ->where('scope = ?', 'default') ->where('scope_id = ?', '0') ->where('path LIKE ?', $this->getJobSearchPath($jobCode)); $pathPrefix = $this->getJobPathPrefix($jobCode) . '/'; - $values = array(); + $values = []; foreach ($adapter->query($select)->fetchAll() as $row) { - if (strpos($row['path'], $pathPrefix) === 0) { + if (str_starts_with($row['path'], $pathPrefix)) { $values[substr($row['path'], strlen($pathPrefix))] = $row['value']; } } @@ -322,18 +303,7 @@ public function getJobDataFromDb($jobCode) public function getJobDataFromModel(Aoe_Scheduler_Model_Job $job) { - $values = array( - 'name' => $job->getName(), - 'description' => $job->getDescription(), - 'short_description' => $job->getShortDescription(), - 'run/model' => $job->getRunModel(), - 'schedule/config_path' => $job->getScheduleConfigPath(), - 'schedule/cron_expr' => $job->getScheduleCronExpr(), - 'parameters' => $job->getParameters(), - 'groups' => $job->getGroups(), - 'is_active' => ($job->getIsActive() ? '1' : '0'), - 'on_success' => $job->getOnSuccess() - ); + $values = ['name' => $job->getName(), 'description' => $job->getDescription(), 'short_description' => $job->getShortDescription(), 'run/model' => $job->getRunModel(), 'schedule/config_path' => $job->getScheduleConfigPath(), 'schedule/cron_expr' => $job->getScheduleCronExpr(), 'parameters' => $job->getParameters(), 'groups' => $job->getGroups(), 'is_active' => ($job->getIsActive() ? '1' : '0'), 'on_success' => $job->getOnSuccess()]; // Strip out the auto-generated name if ($values['name'] === $job->getJobCode()) { @@ -348,16 +318,16 @@ public function getJobDataFromModel(Aoe_Scheduler_Model_Job $job) public function setModelFromJobData(Aoe_Scheduler_Model_Job $job, array $data) { - $job->setName(isset($data['name']) ? $data['name'] : ''); - $job->setDescription(isset($data['description']) ? $data['description'] : ''); - $job->setShortDescription(isset($data['short_description']) ? $data['short_description'] : ''); - $job->setRunModel(isset($data['run/model']) ? $data['run/model'] : ''); - $job->setScheduleConfigPath(isset($data['schedule/config_path']) ? $data['schedule/config_path'] : ''); - $job->setScheduleCronExpr(isset($data['schedule/cron_expr']) ? $data['schedule/cron_expr'] : ''); - $job->setParameters(isset($data['parameters']) ? $data['parameters'] : ''); - $job->setGroups(isset($data['groups']) ? $data['groups'] : ''); - $job->setIsActive(isset($data['is_active']) ? $data['is_active'] : ''); - $job->setOnSuccess(isset($data['on_success']) ? $data['on_success'] : ''); + $job->setName($data['name'] ?? ''); + $job->setDescription($data['description'] ?? ''); + $job->setShortDescription($data['short_description'] ?? ''); + $job->setRunModel($data['run/model'] ?? ''); + $job->setScheduleConfigPath($data['schedule/config_path'] ?? ''); + $job->setScheduleCronExpr($data['schedule/cron_expr'] ?? ''); + $job->setParameters($data['parameters'] ?? ''); + $job->setGroups($data['groups'] ?? ''); + $job->setIsActive($data['is_active'] ?? ''); + $job->setOnSuccess($data['on_success'] ?? ''); return $job; } } diff --git a/app/code/community/Aoe/Scheduler/Model/Resource/Job/Collection.php b/app/code/community/Aoe/Scheduler/Model/Resource/Job/Collection.php index 2b2a440..c7d1c82 100755 --- a/app/code/community/Aoe/Scheduler/Model/Resource/Job/Collection.php +++ b/app/code/community/Aoe/Scheduler/Model/Resource/Job/Collection.php @@ -4,8 +4,8 @@ class Aoe_Scheduler_Model_Resource_Job_Collection extends Varien_Data_Collection { protected $model; protected $resourceModel; - protected $whiteList = array(); - protected $blackList = array(); + protected $whiteList = []; + protected $blackList = []; protected $activeOnly = false; protected $dbOnly = false; @@ -26,7 +26,7 @@ public function getResource() sprintf( 'Invalid resource class. Expected "%s" and received "%s".', 'Aoe_Scheduler_Model_Resource_Job', - (is_object($resource) ? get_class($resource) : 'UNKNOWN') + (is_object($resource) ? $resource::class : 'UNKNOWN') ) ); } @@ -47,7 +47,7 @@ public function getNewEmptyItem() sprintf( 'Invalid model class. Expected "%s" and received "%s".', 'Aoe_Scheduler_Model_Job', - (is_object($model) ? get_class($model) : 'UNKNOWN') + (is_object($model) ? $model::class : 'UNKNOWN') ) ); } @@ -202,7 +202,7 @@ public function addItem(Varien_Object $item) sprintf( 'Invalid model class. Expected "%s" and received "%s".', 'Aoe_Scheduler_Model_Job', - get_class($item) + $item::class ) ); } @@ -238,7 +238,7 @@ public function getAllIds() */ public function getColumnValues($column) { - $values = array(); + $values = []; foreach ($this as $item) { /** @var Aoe_Scheduler_Model_Job $item */ $values[] = $item->getDataUsingMethod($column); @@ -250,13 +250,12 @@ public function getColumnValues($column) * Search all items by field value * * @param string $column - * @param mixed $value * * @return Aoe_Scheduler_Model_Job[] */ - public function getItemsByColumnValue($column, $value) + public function getItemsByColumnValue($column, mixed $value) { - $items = array(); + $items = []; foreach ($this as $item) { /** @var Aoe_Scheduler_Model_Job $item */ if ($item->getDataUsingMethod($column) == $value) { @@ -270,11 +269,10 @@ public function getItemsByColumnValue($column, $value) * Search first item by field value * * @param string $column - * @param mixed $value * * @return Aoe_Scheduler_Model_Job|null */ - public function getItemByColumnValue($column, $value) + public function getItemByColumnValue($column, mixed $value) { foreach ($this as $item) { /** @var Aoe_Scheduler_Model_Job $item */ @@ -288,12 +286,10 @@ public function getItemByColumnValue($column, $value) /** * Setting data for all collection items * - * @param mixed $key - * @param mixed $value * * @return $this */ - public function setDataToAll($key, $value = null) + public function setDataToAll(mixed $key, mixed $value = null) { if (is_array($key)) { foreach ($key as $k => $v) { @@ -310,7 +306,7 @@ public function setDataToAll($key, $value = null) return $this; } - public function toOptionArray($valueField = 'job_code', $labelField = 'name', array $additional = array()) + public function toOptionArray($valueField = 'job_code', $labelField = 'name', array $additional = []) { return $this->_toOptionArray($valueField, $labelField, $additional); } @@ -329,16 +325,16 @@ public function toOptionHash($valueField = 'job_code', $labelField = 'name') * * @return array */ - protected function _toOptionArray($valueField = 'job_code', $labelField = 'name', $additional = array()) + protected function _toOptionArray($valueField = 'job_code', $labelField = 'name', $additional = []) { - $options = array(); + $options = []; $additional['value'] = $valueField; $additional['label'] = $labelField; foreach ($this as $item) { /** @var Aoe_Scheduler_Model_Job $item */ - $data = array(); + $data = []; foreach ($additional as $code => $field) { $data[$code] = $item->getDataUsingMethod($field); } @@ -358,7 +354,7 @@ protected function _toOptionArray($valueField = 'job_code', $labelField = 'name' */ protected function _toOptionHash($valueField = 'job_code', $labelField = 'name') { - $res = array(); + $res = []; foreach ($this as $item) { /** @var Aoe_Scheduler_Model_Job $item */ $res[$item->getDataUsingMethod($valueField)] = $item->getDataUsingMethod($labelField); diff --git a/app/code/community/Aoe/Scheduler/Model/Schedule.php b/app/code/community/Aoe/Scheduler/Model/Schedule.php index 9a54e57..4972717 100755 --- a/app/code/community/Aoe/Scheduler/Model/Schedule.php +++ b/app/code/community/Aoe/Scheduler/Model/Schedule.php @@ -42,30 +42,30 @@ class Aoe_Scheduler_Model_Schedule extends Mage_Cron_Model_Schedule { // if a job returns 'repeat' it will be re-executed right away - const STATUS_REPEAT = 'repeat'; + public const STATUS_REPEAT = 'repeat'; - const STATUS_KILLED = 'killed'; - const STATUS_DISAPPEARED = 'gone'; - const STATUS_DIDNTDOANYTHING = 'nothing'; + public const STATUS_KILLED = 'killed'; + public const STATUS_DISAPPEARED = 'gone'; + public const STATUS_DIDNTDOANYTHING = 'nothing'; - const STATUS_SKIP_OTHERJOBRUNNING = 'other_job_running'; - const STATUS_SKIP_WRONGUSER = 'wrong_user'; - const STATUS_SKIP_PILINGUP = 'skipped'; + public const STATUS_SKIP_OTHERJOBRUNNING = 'other_job_running'; + public const STATUS_SKIP_WRONGUSER = 'wrong_user'; + public const STATUS_SKIP_PILINGUP = 'skipped'; - const STATUS_DIED = 'died'; // note that died != killed + public const STATUS_DIED = 'died'; // note that died != killed - const REASON_RUNNOW_WEB = 'run_now_web'; - const REASON_SCHEDULENOW_WEB = 'schedule_now_web'; - const REASON_RUNNOW_CLI = 'run_now_cli'; - const REASON_SCHEDULENOW_CLI = 'schedule_now_cli'; - const REASON_RUNNOW_API = 'run_now_api'; - const REASON_SCHEDULENOW_API = 'schedule_now_api'; - const REASON_GENERATESCHEDULES = 'generate_schedules'; - const REASON_DEPENDENCY_ALL = 'dependency_all'; - const REASON_DEPENDENCY_SUCCESS = 'dependency_success'; - const REASON_DEPENDENCY_FAILURE = 'dependency_failure'; - const REASON_ALWAYS = 'always'; - const REASON_REPEAT = 'repeat'; + public const REASON_RUNNOW_WEB = 'run_now_web'; + public const REASON_SCHEDULENOW_WEB = 'schedule_now_web'; + public const REASON_RUNNOW_CLI = 'run_now_cli'; + public const REASON_SCHEDULENOW_CLI = 'schedule_now_cli'; + public const REASON_RUNNOW_API = 'run_now_api'; + public const REASON_SCHEDULENOW_API = 'schedule_now_api'; + public const REASON_GENERATESCHEDULES = 'generate_schedules'; + public const REASON_DEPENDENCY_ALL = 'dependency_all'; + public const REASON_DEPENDENCY_SUCCESS = 'dependency_success'; + public const REASON_DEPENDENCY_FAILURE = 'dependency_failure'; + public const REASON_ALWAYS = 'always'; + public const REASON_REPEAT = 'repeat'; /** * Event name prefix for events that are dispatched by this class @@ -113,13 +113,12 @@ class Aoe_Scheduler_Model_Schedule extends Mage_Cron_Model_Schedule * * @var array */ - protected $errorSettingsBackup = array(); + protected $errorSettingsBackup = []; /** * Initialize from job * - * @param Aoe_Scheduler_Model_Job $job * @return $this */ public function initializeFromJob(Aoe_Scheduler_Model_Job $job) @@ -199,8 +198,8 @@ public function runNow($tryLockJob = true, $forceRun = false) Mage::register('currently_running_schedule', $this); - Mage::dispatchEvent('cron_' . $this->getJobCode() . '_before', array('schedule' => $this)); - Mage::dispatchEvent('cron_before', array('schedule' => $this)); + Mage::dispatchEvent('cron_' . $this->getJobCode() . '_before', ['schedule' => $this]); + Mage::dispatchEvent('cron_before', ['schedule' => $this]); Mage::unregister('current_cron_task'); Mage::register('current_cron_task', $this); @@ -214,7 +213,7 @@ public function runNow($tryLockJob = true, $forceRun = false) try { // this is where the magic happens - $messages = call_user_func_array($callback, array($this)); + $messages = call_user_func_array($callback, [$this]); $this->restoreErrorContext(); $this->_stopBufferToMessages(); @@ -228,7 +227,7 @@ public function runNow($tryLockJob = true, $forceRun = false) if (!empty($messages)) { if (is_object($messages)) { - $messages = get_class($messages); + $messages = $messages::class; } elseif (!is_scalar($messages)) { $messages = var_export($messages, 1); } @@ -240,20 +239,20 @@ public function runNow($tryLockJob = true, $forceRun = false) if ((is_string($messages) && strtoupper(substr($messages, 0, 6)) == 'ERROR:') || $this->getStatus() === Aoe_Scheduler_Model_Schedule::STATUS_ERROR) { $this->setStatus(Aoe_Scheduler_Model_Schedule::STATUS_ERROR); Mage::helper('aoe_scheduler')->sendErrorMail($this, $messages); - Mage::dispatchEvent('cron_' . $this->getJobCode() . '_after_error', array('schedule' => $this)); - Mage::dispatchEvent('cron_after_error', array('schedule' => $this)); + Mage::dispatchEvent('cron_' . $this->getJobCode() . '_after_error', ['schedule' => $this]); + Mage::dispatchEvent('cron_after_error', ['schedule' => $this]); } elseif ((is_string($messages) && strtoupper(substr($messages, 0, 7)) == 'NOTHING') || $this->getStatus() === Aoe_Scheduler_Model_Schedule::STATUS_DIDNTDOANYTHING) { $this->setStatus(Aoe_Scheduler_Model_Schedule::STATUS_DIDNTDOANYTHING); - Mage::dispatchEvent('cron_' . $this->getJobCode() . '_after_nothing', array('schedule' => $this)); - Mage::dispatchEvent('cron_after_nothing', array('schedule' => $this)); + Mage::dispatchEvent('cron_' . $this->getJobCode() . '_after_nothing', ['schedule' => $this]); + Mage::dispatchEvent('cron_after_nothing', ['schedule' => $this]); } elseif ((is_string($messages) && strtoupper(substr($messages, 0, 6)) == 'REPEAT') || $this->getStatus() === Aoe_Scheduler_Model_Schedule::STATUS_REPEAT) { $this->setStatus(Aoe_Scheduler_Model_Schedule::STATUS_REPEAT); - Mage::dispatchEvent('cron_' . $this->getJobCode() . '_after_repeat', array('schedule' => $this)); - Mage::dispatchEvent('cron_after_repeat', array('schedule' => $this)); + Mage::dispatchEvent('cron_' . $this->getJobCode() . '_after_repeat', ['schedule' => $this]); + Mage::dispatchEvent('cron_after_repeat', ['schedule' => $this]); } else { $this->setStatus(Aoe_Scheduler_Model_Schedule::STATUS_SUCCESS); - Mage::dispatchEvent('cron_' . $this->getJobCode() . '_after_success', array('schedule' => $this)); - Mage::dispatchEvent('cron_after_success', array('schedule' => $this)); + Mage::dispatchEvent('cron_' . $this->getJobCode() . '_after_success', ['schedule' => $this]); + Mage::dispatchEvent('cron_after_success', ['schedule' => $this]); $this->scheduleOnSuccessDependencies(); } @@ -261,15 +260,15 @@ public function runNow($tryLockJob = true, $forceRun = false) } catch (Exception $e) { $this->setStatus(Aoe_Scheduler_Model_Schedule::STATUS_ERROR); $this->addMessages(PHP_EOL . '---EXCEPTION---' . PHP_EOL . $e->__toString()); - Mage::dispatchEvent('cron_' . $this->getJobCode() . '_exception', array('schedule' => $this, 'exception' => $e)); - Mage::dispatchEvent('cron_exception', array('schedule' => $this, 'exception' => $e)); + Mage::dispatchEvent('cron_' . $this->getJobCode() . '_exception', ['schedule' => $this, 'exception' => $e]); + Mage::dispatchEvent('cron_exception', ['schedule' => $this, 'exception' => $e]); Mage::helper('aoe_scheduler')->sendErrorMail($this, $e->__toString()); } $this->setFinishedAt(strftime('%Y-%m-%d %H:%M:%S', time())); - $this->setMemoryUsage(memory_get_peak_usage(true) / pow(1024, 2)); // convert bytes to megabytes - Mage::dispatchEvent('cron_' . $this->getJobCode() . '_after', array('schedule' => $this)); - Mage::dispatchEvent('cron_after', array('schedule' => $this)); + $this->setMemoryUsage(memory_get_peak_usage(true) / 1024 ** 2); // convert bytes to megabytes + Mage::dispatchEvent('cron_' . $this->getJobCode() . '_after', ['schedule' => $this]); + Mage::dispatchEvent('cron_after', ['schedule' => $this]); $this->save(); Mage::unregister('currently_running_schedule'); @@ -367,7 +366,7 @@ public function getStarttime() * * @return bool|int time in seconds, or false */ - public function getDuration() + public function getDuration(): bool|int { $duration = false; if ($this->getExecutedAt() && ($this->getExecutedAt() != '0000-00-00 00:00:00')) { @@ -567,7 +566,7 @@ protected function _beforeSave() ->addFieldToFilter('job_code', $this->getJobCode()) ->addFieldToFilter('scheduled_at', $this->getScheduledAt()); if ($this->getId() !== null) { - $collection->addFieldToFilter('schedule_id', array('neq' => $this->getId())); + $collection->addFieldToFilter('schedule_id', ['neq' => $this->getId()]); } $count = $collection->count(); if ($count > 0) { @@ -652,12 +651,7 @@ protected function jobErrorContext() return; } - $settings = array( - 'error_reporting' => intval(Mage::getStoreConfig('system/cron/errorLevel')), - 'log_errors' => true, - 'display_errors' => true, - 'error_log' => $this->getErrorLogFile() - ); + $settings = ['error_reporting' => intval(Mage::getStoreConfig('system/cron/errorLevel')), 'log_errors' => true, 'display_errors' => true, 'error_log' => $this->getErrorLogFile()]; restore_error_handler(); // (doesn't work for PHP 5.3) set_error_handler(null); // switch to PHP default error handling @@ -696,11 +690,7 @@ protected function restoreErrorContext() */ public function getErrorLogFile() { - $replace = array( - '###PID###' => $this->getPid(), - '###ID###' => $this->getId(), - '###JOBCODE###' => $this->getJobCode() - ); + $replace = ['###PID###' => $this->getPid(), '###ID###' => $this->getId(), '###JOBCODE###' => $this->getJobCode()]; $basedir = Mage::getBaseDir('log') . DS . 'cron' . DS; return $basedir . str_replace(array_keys($replace), array_values($replace), Mage::getStoreConfig('system/cron/errorLogFilename')); } @@ -724,7 +714,7 @@ protected function _startBufferToMessages() $this->addMessages('---START---' . PHP_EOL); ob_start( - array($this, '_addBufferToMessages'), + [$this, '_addBufferToMessages'], $this->_redirectOutputHandlerChunkSize ); @@ -807,8 +797,8 @@ public function saveMessages() $count = $connection ->update( $this->getResource()->getMainTable(), - array('messages' => $this->getMessages()), - array('schedule_id = ?' => $this->getId()) + ['messages' => $this->getMessages()], + ['schedule_id = ?' => $this->getId()] ); if (!$count) { @@ -830,7 +820,6 @@ public function saveMessages() /** * Retrieve the last PDO warning. * - * @param PDO $pdo * @return mixed */ protected function _getPdoWarning(PDO $pdo) @@ -875,7 +864,7 @@ public function getStatuses() ->columns('status'); $statuses = $schedules->getConnection() ->fetchCol($schedules->getSelect()); - $statusArray = array(); + $statusArray = []; foreach ($statuses as $status) { $statusArray[$status] = $status; } @@ -894,11 +883,11 @@ public function refresh() public function getAllStatuses() { - $reflect = new ReflectionClass(get_class($this)); + $reflect = new ReflectionClass(static::class); $constants = $reflect->getConstants(); - $statuses = array(); + $statuses = []; foreach ($constants as $key => $value) { - if (strpos($key, 'STATUS_') === 0) { + if (str_starts_with($key, 'STATUS_')) { $statuses[$value] = $value; } } diff --git a/app/code/community/Aoe/Scheduler/Model/ScheduleManager.php b/app/code/community/Aoe/Scheduler/Model/ScheduleManager.php index ae1243d..16a39c3 100755 --- a/app/code/community/Aoe/Scheduler/Model/ScheduleManager.php +++ b/app/code/community/Aoe/Scheduler/Model/ScheduleManager.php @@ -8,8 +8,8 @@ */ class Aoe_Scheduler_Model_ScheduleManager { - const XML_PATH_HISTORY_MAXNO = 'system/cron/maxNoOfSuccessfulTasks'; - const CACHE_KEY_SCHEDULER_LASTRUNS = 'cron_lastruns'; + public const XML_PATH_HISTORY_MAXNO = 'system/cron/maxNoOfSuccessfulTasks'; + public const CACHE_KEY_SCHEDULER_LASTRUNS = 'cron_lastruns'; /** * Mark missed schedule records by changing status @@ -21,13 +21,13 @@ public function skipMissedSchedules() { $schedules = Mage::getModel('cron/schedule')->getCollection() ->addFieldToFilter('status', Aoe_Scheduler_Model_Schedule::STATUS_PENDING) - ->addFieldToFilter('scheduled_at', array('lt' => strftime('%Y-%m-%d %H:%M:%S', time()))) + ->addFieldToFilter('scheduled_at', ['lt' => strftime('%Y-%m-%d %H:%M:%S', time())]) ->addOrder('scheduled_at', 'DESC') ->load(); Mage::getSingleton('cron/schedule')->getResource()->beginTransaction(TRUE); try { - $seenJobs = array(); + $seenJobs = []; foreach ($schedules as $key => $schedule) { /* @var Aoe_Scheduler_Model_Schedule $schedule */ if (isset($seenJobs[$schedule->getJobCode()])) { @@ -58,26 +58,24 @@ public function skipMissedSchedules() /** * Get pending schedules * - * @param array $whitelist - * @param array $blacklist * * @return Mage_Cron_Model_Resource_Schedule_Collection */ - public function getPendingSchedules(array $whitelist = array(), array $blacklist = array()) + public function getPendingSchedules(array $whitelist = [], array $blacklist = []) { $pendingSchedules = Mage::getModel('cron/schedule')->getCollection() ->addFieldToFilter('status', Aoe_Scheduler_Model_Schedule::STATUS_PENDING) - ->addFieldToFilter('scheduled_at', array('lt' => strftime('%Y-%m-%d %H:%M:%S', time()))) + ->addFieldToFilter('scheduled_at', ['lt' => strftime('%Y-%m-%d %H:%M:%S', time())]) ->addOrder('scheduled_at', 'ASC'); $whitelist = array_filter(array_map('trim', $whitelist)); if (!empty($whitelist)) { - $pendingSchedules->addFieldToFilter('job_code', array('in' => $whitelist)); + $pendingSchedules->addFieldToFilter('job_code', ['in' => $whitelist]); } $blacklist = array_filter(array_map('trim', $blacklist)); if (!empty($blacklist)) { - $pendingSchedules->addFieldToFilter('job_code', array('nin' => $blacklist)); + $pendingSchedules->addFieldToFilter('job_code', ['nin' => $blacklist]); } return $pendingSchedules; @@ -89,16 +87,15 @@ public function getPendingSchedules(array $whitelist = array(), array $blacklist * (Instead of reusing existing one - which results in loosing the history - create a new one every time) * * @param $jobCode - * @return Aoe_Scheduler_Model_Schedule|false */ - public function getScheduleForAlwaysJob($jobCode, $reason=null) + public function getScheduleForAlwaysJob($jobCode, $reason=null): \Aoe_Scheduler_Model_Schedule|false { $processManager = Mage::getModel('aoe_scheduler/processManager'); /* @var $processManager Aoe_Scheduler_Model_ProcessManager */ if (!$processManager->isJobCodeRunning($jobCode)) { $ts = strftime('%Y-%m-%d %H:%M:00', time()); $schedule = Mage::getModel('cron/schedule'); /* @var $schedule Aoe_Scheduler_Model_Schedule */ $schedule - ->setScheduledReason($reason ? $reason : Aoe_Scheduler_Model_Schedule::REASON_ALWAYS) + ->setScheduledReason($reason ?: Aoe_Scheduler_Model_Schedule::REASON_ALWAYS) ->setJobCode($jobCode) ->setStatus(Aoe_Scheduler_Model_Schedule::STATUS_RUNNING) ->setCreatedAt($ts) @@ -168,7 +165,7 @@ public function generateSchedules() /** * save time schedules generation was ran with no expiration */ - Mage::app()->saveCache(time(), Mage_Cron_Model_Observer::CACHE_KEY_LAST_SCHEDULE_GENERATE_AT, array('crontab'), null); + Mage::app()->saveCache(time(), Mage_Cron_Model_Observer::CACHE_KEY_LAST_SCHEDULE_GENERATE_AT, ['crontab'], null); $this->deleteDuplicates(); @@ -198,7 +195,7 @@ public function flushSchedules($jobCode = null) /* @var $pendingSchedules Mage_Cron_Model_Resource_Schedule_Collection */ $pendingSchedules = Mage::getModel('cron/schedule')->getCollection() ->addFieldToFilter('status', Aoe_Scheduler_Model_Schedule::STATUS_PENDING) - ->addFieldToFilter('scheduled_at', array('gt' => strftime('%Y-%m-%d %H:%M:%S', time()))) + ->addFieldToFilter('scheduled_at', ['gt' => strftime('%Y-%m-%d %H:%M:%S', time())]) ->addOrder('scheduled_at', 'ASC'); if (!empty($jobCode)) { $pendingSchedules->addFieldToFilter('job_code', $jobCode); @@ -207,7 +204,7 @@ public function flushSchedules($jobCode = null) /* @var Aoe_Scheduler_Model_Schedule $schedule */ $schedule->delete(); } - Mage::app()->saveCache(0, Mage_Cron_Model_Observer::CACHE_KEY_LAST_SCHEDULE_GENERATE_AT, array('crontab'), null); + Mage::app()->saveCache(0, Mage_Cron_Model_Observer::CACHE_KEY_LAST_SCHEDULE_GENERATE_AT, ['crontab'], null); return $this; } @@ -223,14 +220,13 @@ public function deleteAll() foreach ($schedules as $key => $schedule) { /* @var Aoe_Scheduler_Model_Schedule $schedule */ $schedule->delete(); } - Mage::app()->saveCache(0, Mage_Cron_Model_Observer::CACHE_KEY_LAST_SCHEDULE_GENERATE_AT, array('crontab'), null); + Mage::app()->saveCache(0, Mage_Cron_Model_Observer::CACHE_KEY_LAST_SCHEDULE_GENERATE_AT, ['crontab'], null); return $this; } /** * Generate jobs for config information * - * @param Aoe_Scheduler_Model_Job $job * * @return $this */ @@ -240,8 +236,8 @@ public function generateSchedulesForJob(Aoe_Scheduler_Model_Job $job) return $this; } - $exists = array(); - foreach ($this->getPendingSchedules(array($job->getJobCode()), array()) as $schedule) { + $exists = []; + foreach ($this->getPendingSchedules([$job->getJobCode()], []) as $schedule) { /* @var Aoe_Scheduler_Model_Schedule $schedule */ $exists[$schedule->getJobCode() . '/' . $schedule->getScheduledAt()] = 1; } @@ -287,24 +283,10 @@ public function cleanup() $startTime = microtime(true); $history = Mage::getModel('cron/schedule')->getCollection() - ->addFieldToFilter('status', array('nin' => array( - Aoe_Scheduler_Model_Schedule::STATUS_PENDING, - Aoe_Scheduler_Model_Schedule::STATUS_RUNNING - ))) + ->addFieldToFilter('status', ['nin' => [Aoe_Scheduler_Model_Schedule::STATUS_PENDING, Aoe_Scheduler_Model_Schedule::STATUS_RUNNING]]) ->load(); - $historyLifetimes = array( - Aoe_Scheduler_Model_Schedule::STATUS_KILLED => Mage::getStoreConfig(Mage_Cron_Model_Observer::XML_PATH_HISTORY_SUCCESS)*60, - Aoe_Scheduler_Model_Schedule::STATUS_DISAPPEARED => Mage::getStoreConfig(Mage_Cron_Model_Observer::XML_PATH_HISTORY_FAILURE)*60, - Aoe_Scheduler_Model_Schedule::STATUS_DIDNTDOANYTHING => Mage::getStoreConfig(Mage_Cron_Model_Observer::XML_PATH_HISTORY_SUCCESS)*60, - Aoe_Scheduler_Model_Schedule::STATUS_SUCCESS => Mage::getStoreConfig(Mage_Cron_Model_Observer::XML_PATH_HISTORY_SUCCESS)*60, - Aoe_Scheduler_Model_Schedule::STATUS_REPEAT => Mage::getStoreConfig(Mage_Cron_Model_Observer::XML_PATH_HISTORY_SUCCESS)*60, - Aoe_Scheduler_Model_Schedule::STATUS_MISSED => Mage::getStoreConfig(Mage_Cron_Model_Observer::XML_PATH_HISTORY_FAILURE)*60, - Aoe_Scheduler_Model_Schedule::STATUS_SKIP_PILINGUP => Mage::getStoreConfig(Mage_Cron_Model_Observer::XML_PATH_HISTORY_FAILURE)*60, - Aoe_Scheduler_Model_Schedule::STATUS_ERROR => Mage::getStoreConfig(Mage_Cron_Model_Observer::XML_PATH_HISTORY_FAILURE)*60, - Aoe_Scheduler_Model_Schedule::STATUS_DIED => Mage::getStoreConfig(Mage_Cron_Model_Observer::XML_PATH_HISTORY_FAILURE)*60, - Aoe_Scheduler_Model_Schedule::STATUS_SKIP_OTHERJOBRUNNING => Mage::getStoreConfig(Mage_Cron_Model_Observer::XML_PATH_HISTORY_FAILURE)*60, - ); + $historyLifetimes = [Aoe_Scheduler_Model_Schedule::STATUS_KILLED => Mage::getStoreConfig(Mage_Cron_Model_Observer::XML_PATH_HISTORY_SUCCESS)*60, Aoe_Scheduler_Model_Schedule::STATUS_DISAPPEARED => Mage::getStoreConfig(Mage_Cron_Model_Observer::XML_PATH_HISTORY_FAILURE)*60, Aoe_Scheduler_Model_Schedule::STATUS_DIDNTDOANYTHING => Mage::getStoreConfig(Mage_Cron_Model_Observer::XML_PATH_HISTORY_SUCCESS)*60, Aoe_Scheduler_Model_Schedule::STATUS_SUCCESS => Mage::getStoreConfig(Mage_Cron_Model_Observer::XML_PATH_HISTORY_SUCCESS)*60, Aoe_Scheduler_Model_Schedule::STATUS_REPEAT => Mage::getStoreConfig(Mage_Cron_Model_Observer::XML_PATH_HISTORY_SUCCESS)*60, Aoe_Scheduler_Model_Schedule::STATUS_MISSED => Mage::getStoreConfig(Mage_Cron_Model_Observer::XML_PATH_HISTORY_FAILURE)*60, Aoe_Scheduler_Model_Schedule::STATUS_SKIP_PILINGUP => Mage::getStoreConfig(Mage_Cron_Model_Observer::XML_PATH_HISTORY_FAILURE)*60, Aoe_Scheduler_Model_Schedule::STATUS_ERROR => Mage::getStoreConfig(Mage_Cron_Model_Observer::XML_PATH_HISTORY_FAILURE)*60, Aoe_Scheduler_Model_Schedule::STATUS_DIED => Mage::getStoreConfig(Mage_Cron_Model_Observer::XML_PATH_HISTORY_FAILURE)*60, Aoe_Scheduler_Model_Schedule::STATUS_SKIP_OTHERJOBRUNNING => Mage::getStoreConfig(Mage_Cron_Model_Observer::XML_PATH_HISTORY_FAILURE)*60]; $now = time(); foreach ($history->getIterator() as $record) { /* @var $record Aoe_Scheduler_Model_Schedule */ @@ -316,7 +298,7 @@ public function cleanup() } // save time history cleanup was ran with no expiration - Mage::app()->saveCache(time(), Mage_Cron_Model_Observer::CACHE_KEY_LAST_HISTORY_CLEANUP_AT, array('crontab'), null); + Mage::app()->saveCache(time(), Mage_Cron_Model_Observer::CACHE_KEY_LAST_HISTORY_CLEANUP_AT, ['crontab'], null); // delete successful tasks (beyond the configured max number of tasks to keep) @@ -324,15 +306,12 @@ public function cleanup() if ($maxNo) { $history = Mage::getModel('cron/schedule')->getCollection() ->addFieldToFilter( - array('status'), - array( - array('eq' => Aoe_Scheduler_Model_Schedule::STATUS_SUCCESS), - array('eq' => Aoe_Scheduler_Model_Schedule::STATUS_REPEAT) - ) + ['status'], + [['eq' => Aoe_Scheduler_Model_Schedule::STATUS_SUCCESS], ['eq' => Aoe_Scheduler_Model_Schedule::STATUS_REPEAT]] ) ->setOrder('finished_at', 'desc') ->load(); - $counter = array(); + $counter = []; foreach ($history->getIterator() as $record) { /* @var $record Aoe_Scheduler_Model_Schedule */ $jobCode = $record->getJobCode(); if (!isset($counter[$jobCode])) { @@ -362,13 +341,11 @@ public function logRun() $lastRuns = explode(',', $lastRuns); $lastRuns[] = time(); $lastRuns = array_slice($lastRuns, -100); - Mage::app()->saveCache(implode(',', $lastRuns), self::CACHE_KEY_SCHEDULER_LASTRUNS, array('crontab'), null); + Mage::app()->saveCache(implode(',', $lastRuns), self::CACHE_KEY_SCHEDULER_LASTRUNS, ['crontab'], null); } /** * Create some statistics based on self::CACHE_KEY_SCHEDULER_LASTRUNS - * - * @return array|bool */ public function getMeasuredCronInterval() { @@ -378,18 +355,12 @@ public function getMeasuredCronInterval() // not enough data points return false; } - $gaps = array(); + $gaps = []; foreach ($lastRuns as $index => $run) { if ($index > 0) { $gaps[$index] = intval($lastRuns[$index]) - intval($lastRuns[$index-1]); } } - return array( - 'average' => round((array_sum($gaps) / count($gaps)) / 60, 2), - 'max' => round(max($gaps) / 60, 2), - 'min' => round(min($gaps) / 60, 2), - 'count' => count($gaps), - 'last' => end($lastRuns) - ); + return ['average' => round((array_sum($gaps) / count($gaps)) / 60, 2), 'max' => round(max($gaps) / 60, 2), 'min' => round(min($gaps) / 60, 2), 'count' => count($gaps), 'last' => end($lastRuns)]; } } diff --git a/app/code/community/Aoe/Scheduler/Model/Task/QueueProcessorExample.php b/app/code/community/Aoe/Scheduler/Model/Task/QueueProcessorExample.php index 9cb096d..98b6e62 100755 --- a/app/code/community/Aoe/Scheduler/Model/Task/QueueProcessorExample.php +++ b/app/code/community/Aoe/Scheduler/Model/Task/QueueProcessorExample.php @@ -12,12 +12,12 @@ class Aoe_Scheduler_Model_Task_QueueProcessorExample /** * Run * - * @param Aoe_Scheduler_Model_Schedule $schedule * @return string * @throws Exception */ public function run(Aoe_Scheduler_Model_Schedule $schedule) { + $sqsClient = null; // in case you're interested how often this was repeated so far... $currentRepetition = $schedule->getRepetition(); @@ -31,7 +31,7 @@ public function run(Aoe_Scheduler_Model_Schedule $schedule) ]); $messages = $result->search('Messages[]'); - if (count($messages) == 0) { + if ((is_countable($messages) ? count($messages) : 0) == 0) { $schedule->setStatus(Aoe_Scheduler_Model_Schedule::STATUS_DIDNTDOANYTHING); return; } @@ -46,7 +46,7 @@ public function run(Aoe_Scheduler_Model_Schedule $schedule) ]); } - if (count($messages) == $numberOfMessagesToFetch) { + if ((is_countable($messages) ? count($messages) : 0) == $numberOfMessagesToFetch) { // there might be more messages on the queue $schedule->setStatus(Aoe_Scheduler_Model_Schedule::STATUS_REPEAT); } else { diff --git a/app/code/community/Aoe/Scheduler/Model/Task/Test.php b/app/code/community/Aoe/Scheduler/Model/Task/Test.php index 704c570..dd744ed 100755 --- a/app/code/community/Aoe/Scheduler/Model/Task/Test.php +++ b/app/code/community/Aoe/Scheduler/Model/Task/Test.php @@ -13,7 +13,6 @@ class Aoe_Scheduler_Model_Task_Test * General purpose test task. * Behavior can be controlled via parameters * - * @param Aoe_Scheduler_Model_Schedule $schedule * @return string * @throws Exception */ @@ -21,7 +20,7 @@ public function run(Aoe_Scheduler_Model_Schedule $schedule) { $parameters = $schedule->getParameters(); if ($parameters) { - $parameters = json_decode($parameters, true); + $parameters = json_decode($parameters, true, 512, JSON_THROW_ON_ERROR); } // fake duration diff --git a/app/code/community/Aoe/Scheduler/Test/Helper/Data.php b/app/code/community/Aoe/Scheduler/Test/Helper/Data.php index ae18f6c..d9d26f1 100644 --- a/app/code/community/Aoe/Scheduler/Test/Helper/Data.php +++ b/app/code/community/Aoe/Scheduler/Test/Helper/Data.php @@ -28,7 +28,7 @@ public function testShouldReturnTrueWhenUserCronMessageDisabled() */ public function testShouldCallCorrectUserMethodAndPerformMatch($method, $user, $useRunningUser) { - $mock = $this->getHelperMock('aoe_scheduler', array('getRunningUser', 'getLastRunUser')); + $mock = $this->getHelperMock('aoe_scheduler', ['getRunningUser', 'getLastRunUser']); $mock->expects($this->once())->method($method)->will($this->returnValue($user)); diff --git a/app/code/community/Aoe/Scheduler/Test/Model/Schedule/Runnow.php b/app/code/community/Aoe/Scheduler/Test/Model/Schedule/Runnow.php index 735a414..082c659 100755 --- a/app/code/community/Aoe/Scheduler/Test/Model/Schedule/Runnow.php +++ b/app/code/community/Aoe/Scheduler/Test/Model/Schedule/Runnow.php @@ -35,14 +35,7 @@ public function runJob() $this->assertEquals(Aoe_Scheduler_Model_Schedule::STATUS_SUCCESS, $loadedSchedule->getStatus()); $this->assertEventDispatched( - array( - 'cron_after', - 'cron_after_success', - 'cron_' . $jobCode . '_after', - 'cron_' . $jobCode . '_after_success', - 'cron_before', - 'cron_' . $jobCode . '_before', - ) + ['cron_after', 'cron_after_success', 'cron_' . $jobCode . '_after', 'cron_' . $jobCode . '_after_success', 'cron_before', 'cron_' . $jobCode . '_before'] ); } @@ -55,10 +48,10 @@ public function runJobWithError() $jobCode = 'aoescheduler_testtask'; - $parameter = array('outcome' => 'error'); + $parameter = ['outcome' => 'error']; $schedule->setJobCode($jobCode); - $schedule->setParameters(json_encode($parameter)); + $schedule->setParameters(json_encode($parameter, JSON_THROW_ON_ERROR)); $schedule->runNow(false); $scheduleId = $schedule->getId(); @@ -74,14 +67,7 @@ public function runJobWithError() $this->assertEquals(Aoe_Scheduler_Model_Schedule::STATUS_ERROR, $loadedSchedule->getStatus()); $this->assertEventDispatched( - array( - 'cron_after', - 'cron_after_error', - 'cron_' . $jobCode . '_after', - 'cron_' . $jobCode . '_after_error', - 'cron_before', - 'cron_' . $jobCode . '_before', - ) + ['cron_after', 'cron_after_error', 'cron_' . $jobCode . '_after', 'cron_' . $jobCode . '_after_error', 'cron_before', 'cron_' . $jobCode . '_before'] ); } @@ -94,7 +80,7 @@ public function runJobWithNothing() $jobCode = 'aoescheduler_testtask'; - $parameter = array('outcome' => 'nothing'); + $parameter = ['outcome' => 'nothing']; $schedule->setJobCode($jobCode); $schedule->setParameters(json_encode($parameter)); @@ -113,14 +99,7 @@ public function runJobWithNothing() $this->assertEquals(Aoe_Scheduler_Model_Schedule::STATUS_DIDNTDOANYTHING, $loadedSchedule->getStatus()); $this->assertEventDispatched( - array( - 'cron_after', - 'cron_after_nothing', - 'cron_' . $jobCode . '_after', - 'cron_' . $jobCode . '_after_nothing', - 'cron_before', - 'cron_' . $jobCode . '_before', - ) + ['cron_after', 'cron_after_nothing', 'cron_' . $jobCode . '_after', 'cron_' . $jobCode . '_after_nothing', 'cron_before', 'cron_' . $jobCode . '_before'] ); } @@ -133,10 +112,10 @@ public function runJobWithException() $jobCode = 'aoescheduler_testtask'; - $parameter = array('outcome' => 'exception'); + $parameter = ['outcome' => 'exception']; $schedule->setJobCode($jobCode); - $schedule->setParameters(json_encode($parameter)); + $schedule->setParameters(json_encode($parameter, JSON_THROW_ON_ERROR)); $schedule->runNow(false); $scheduleId = $schedule->getId(); @@ -152,14 +131,7 @@ public function runJobWithException() $this->assertEquals(Aoe_Scheduler_Model_Schedule::STATUS_ERROR, $loadedSchedule->getStatus()); $this->assertEventDispatched( - array( - 'cron_after', - 'cron_exception', - 'cron_' . $jobCode . '_after', - 'cron_' . $jobCode . '_exception', - 'cron_before', - 'cron_' . $jobCode . '_before', - ) + ['cron_after', 'cron_exception', 'cron_' . $jobCode . '_after', 'cron_' . $jobCode . '_exception', 'cron_before', 'cron_' . $jobCode . '_before'] ); } @@ -193,7 +165,7 @@ public function testShouldNotKillWhenKillSwitchIsOffButUserIsWrong() */ protected function _performConfiguredUserTest() { - $helperMock = $this->getHelperMock('aoe_scheduler', array('runningAsConfiguredUser')); + $helperMock = $this->getHelperMock('aoe_scheduler', ['runningAsConfiguredUser']); $helperMock->expects($this->once())->method('runningAsConfiguredUser')->will($this->returnValue(false)); $this->replaceByMock('helper', 'aoe_scheduler', $helperMock); diff --git a/app/code/community/Aoe/Scheduler/controllers/Adminhtml/JobController.php b/app/code/community/Aoe/Scheduler/controllers/Adminhtml/JobController.php index e78dc93..7d58edd 100644 --- a/app/code/community/Aoe/Scheduler/controllers/Adminhtml/JobController.php +++ b/app/code/community/Aoe/Scheduler/controllers/Adminhtml/JobController.php @@ -107,7 +107,7 @@ public function runNowAction() $messages = $schedule->getMessages(); - if (in_array($schedule->getStatus(), array(Aoe_Scheduler_Model_Schedule::STATUS_SUCCESS, Aoe_Scheduler_Model_Schedule::STATUS_DIDNTDOANYTHING))) { + if (in_array($schedule->getStatus(), [Aoe_Scheduler_Model_Schedule::STATUS_SUCCESS, Aoe_Scheduler_Model_Schedule::STATUS_DIDNTDOANYTHING])) { $this->_getSession()->addSuccess($this->__('Ran "%s" (Duration: %s sec)', $key, intval($schedule->getDuration()))); if ($messages) { $this->_getSession()->addSuccess($this->__('"%s" messages:
%s
', $key, $messages)); @@ -139,7 +139,7 @@ protected function getMassActionCodes($key = 'codes') { $codes = $this->getRequest()->getParam($key); if (!is_array($codes)) { - return array(); + return []; } $allowedCodes = Mage::getSingleton('aoe_scheduler/job')->getResource()->getJobCodes(); $codes = array_intersect(array_unique(array_filter(array_map('trim', $codes))), $allowedCodes); @@ -202,7 +202,7 @@ public function saveAction() $job->addData($data); //validating if (!$this->_validatePostData($data)) { - $this->_redirect('*/*/edit', array('job_code' => $job->getJobCode(), '_current' => true)); + $this->_redirect('*/*/edit', ['job_code' => $job->getJobCode(), '_current' => true]); return; } @@ -218,7 +218,7 @@ public function saveAction() $this->_getSession()->setFormData(false); // check if 'Save and Continue' if ($this->getRequest()->getParam('back', false)) { - $this->_redirect('*/*/edit', array('job_code' => $job->getJobCode(), '_current' => true)); + $this->_redirect('*/*/edit', ['job_code' => $job->getJobCode(), '_current' => true]); return; } @@ -241,11 +241,11 @@ public function saveAction() } $this->_getSession()->setFormData($data); - $this->_redirect('*/*/edit', array('job_code' => $this->getRequest()->getParam('job_code'))); + $this->_redirect('*/*/edit', ['job_code' => $this->getRequest()->getParam('job_code')]); return; } - $this->_redirect('*/*/', array('_current' => true)); + $this->_redirect('*/*/', ['_current' => true]); } /** diff --git a/app/code/community/Aoe/Scheduler/data/aoescheduler_setup/data-upgrade-0.5.4-0.5.5.php b/app/code/community/Aoe/Scheduler/data/aoescheduler_setup/data-upgrade-0.5.4-0.5.5.php index c6b5f3e..957151a 100644 --- a/app/code/community/Aoe/Scheduler/data/aoescheduler_setup/data-upgrade-0.5.4-0.5.5.php +++ b/app/code/community/Aoe/Scheduler/data/aoescheduler_setup/data-upgrade-0.5.4-0.5.5.php @@ -9,12 +9,7 @@ foreach ($codes as $code) { $this->getConnection()->insertOnDuplicate( $this->getTable('core/config_data'), - array( - 'scope' => 'default', - 'scope_id' => 0, - 'path' => 'crontab/jobs/' . $code . '/is_active', - 'value' => 0, - ) + ['scope' => 'default', 'scope_id' => 0, 'path' => 'crontab/jobs/' . $code . '/is_active', 'value' => 0] ); } } @@ -22,9 +17,5 @@ // Remove old config setting $this->getConnection()->delete( $this->getTable('core/config_data'), - array( - 'scope = ?' => 'default', - 'scope_id = ?' => 0, - 'path = ?' => 'system/cron/disabled_crons' - ) + ['scope = ?' => 'default', 'scope_id = ?' => 0, 'path = ?' => 'system/cron/disabled_crons'] ); diff --git a/app/code/community/Aoe/Scheduler/sql/aoescheduler_setup/install-1.0.0.php b/app/code/community/Aoe/Scheduler/sql/aoescheduler_setup/install-1.0.0.php index 3e47713..cabf6bc 100644 --- a/app/code/community/Aoe/Scheduler/sql/aoescheduler_setup/install-1.0.0.php +++ b/app/code/community/Aoe/Scheduler/sql/aoescheduler_setup/install-1.0.0.php @@ -12,29 +12,7 @@ 'parameters' ); -$columns = array( - 'parameters' => "TEXT NULL COMMENT 'Serialized Parameters' AFTER finished_at", - 'eta' => "timestamp NULL DEFAULT NULL COMMENT 'Estimated Time of Arrival'", - 'host' => "varchar(255) NULL COMMENT 'Host running this job'", - 'pid' => "varchar(255) NULL COMMENT 'Process id of this job'", - 'progress_message' => "TEXT NULL COMMENT 'Progress message'", - 'last_seen' => "timestamp NULL DEFAULT NULL COMMENT 'Last seen'", - 'kill_request' => "timestamp NULL DEFAULT NULL COMMENT 'Kill Request'", - 'scheduled_by' => array ( - 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, - 'unsigned' => true, - 'nullable' => true, - 'default' => null, - 'comment' => 'Scheduled by' - ), - 'scheduled_reason' => array( - 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, - 'length' => 256, - 'nullable' => true, - 'default' => null, - 'comment' => 'Scheduled Reason' - ) -); +$columns = ['parameters' => "TEXT NULL COMMENT 'Serialized Parameters' AFTER finished_at", 'eta' => "timestamp NULL DEFAULT NULL COMMENT 'Estimated Time of Arrival'", 'host' => "varchar(255) NULL COMMENT 'Host running this job'", 'pid' => "varchar(255) NULL COMMENT 'Process id of this job'", 'progress_message' => "TEXT NULL COMMENT 'Progress message'", 'last_seen' => "timestamp NULL DEFAULT NULL COMMENT 'Last seen'", 'kill_request' => "timestamp NULL DEFAULT NULL COMMENT 'Kill Request'", 'scheduled_by' => ['type' => Varien_Db_Ddl_Table::TYPE_INTEGER, 'unsigned' => true, 'nullable' => true, 'default' => null, 'comment' => 'Scheduled by'], 'scheduled_reason' => ['type' => Varien_Db_Ddl_Table::TYPE_TEXT, 'length' => 256, 'nullable' => true, 'default' => null, 'comment' => 'Scheduled Reason']]; foreach ($columns as $columnName => $definition) { if ($this->getConnection()->tableColumnExists($tableName, $columnName)) { diff --git a/app/code/community/Aoe/Scheduler/sql/aoescheduler_setup/mysql4-upgrade-0.4.0-0.4.1.php b/app/code/community/Aoe/Scheduler/sql/aoescheduler_setup/mysql4-upgrade-0.4.0-0.4.1.php index 6e12db5..33be2a8 100644 --- a/app/code/community/Aoe/Scheduler/sql/aoescheduler_setup/mysql4-upgrade-0.4.0-0.4.1.php +++ b/app/code/community/Aoe/Scheduler/sql/aoescheduler_setup/mysql4-upgrade-0.4.0-0.4.1.php @@ -9,7 +9,7 @@ try { $installer->getConnection()->dropColumn($tableName, 'parameters'); -} catch (Exception $e) { +} catch (Exception) { // ignored intentionally } diff --git a/app/code/community/Aoe/Scheduler/sql/aoescheduler_setup/mysql4-upgrade-0.5.0-0.5.1.php b/app/code/community/Aoe/Scheduler/sql/aoescheduler_setup/mysql4-upgrade-0.5.0-0.5.1.php index 273c3b7..621e22b 100644 --- a/app/code/community/Aoe/Scheduler/sql/aoescheduler_setup/mysql4-upgrade-0.5.0-0.5.1.php +++ b/app/code/community/Aoe/Scheduler/sql/aoescheduler_setup/mysql4-upgrade-0.5.0-0.5.1.php @@ -4,20 +4,8 @@ $installer->startSetup(); -$installer->getConnection()->addColumn($installer->getTable('cron/schedule'), 'scheduled_by', array( - 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, - 'unsigned' => true, - 'nullable' => true, - 'default' => null, - 'comment' => 'Scheduled by' -)); +$installer->getConnection()->addColumn($installer->getTable('cron/schedule'), 'scheduled_by', ['type' => Varien_Db_Ddl_Table::TYPE_INTEGER, 'unsigned' => true, 'nullable' => true, 'default' => null, 'comment' => 'Scheduled by']); -$installer->getConnection()->addColumn($installer->getTable('cron/schedule'), 'scheduled_reason', array( - 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, - 'length' => 256, - 'nullable' => true, - 'default' => null, - 'comment' => 'Scheduled Reason' -)); +$installer->getConnection()->addColumn($installer->getTable('cron/schedule'), 'scheduled_reason', ['type' => Varien_Db_Ddl_Table::TYPE_TEXT, 'length' => 256, 'nullable' => true, 'default' => null, 'comment' => 'Scheduled Reason']); $installer->endSetup(); diff --git a/app/code/community/Aoe/Scheduler/sql/aoescheduler_setup/mysql4-upgrade-0.5.4-1.1.0.php b/app/code/community/Aoe/Scheduler/sql/aoescheduler_setup/mysql4-upgrade-0.5.4-1.1.0.php index 576c978..c6cde4f 100644 --- a/app/code/community/Aoe/Scheduler/sql/aoescheduler_setup/mysql4-upgrade-0.5.4-1.1.0.php +++ b/app/code/community/Aoe/Scheduler/sql/aoescheduler_setup/mysql4-upgrade-0.5.4-1.1.0.php @@ -5,13 +5,7 @@ $this->getConnection()->modifyColumn( $this->getTable('cron/schedule'), 'status', - array( - 'type' => Varien_Db_Ddl_Table::TYPE_TEXT, - 'length' => 30, - 'nullable' => false, - 'default' => 'pending', - 'comment' => 'Status' - ) + ['type' => Varien_Db_Ddl_Table::TYPE_TEXT, 'length' => 30, 'nullable' => false, 'default' => 'pending', 'comment' => 'Status'] ); $this->endSetup(); diff --git a/app/code/community/Aoe/Scheduler/sql/aoescheduler_setup/mysql4-upgrade-1.4.0-1.5.0.php b/app/code/community/Aoe/Scheduler/sql/aoescheduler_setup/mysql4-upgrade-1.4.0-1.5.0.php index 2ac07c5..d124c32 100644 --- a/app/code/community/Aoe/Scheduler/sql/aoescheduler_setup/mysql4-upgrade-1.4.0-1.5.0.php +++ b/app/code/community/Aoe/Scheduler/sql/aoescheduler_setup/mysql4-upgrade-1.4.0-1.5.0.php @@ -4,13 +4,6 @@ $installer->startSetup(); -$installer->getConnection()->addColumn($installer->getTable('cron/schedule'), 'memory_usage', array( - 'type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, - 'length' => '12,4', - 'unsigned' => true, - 'nullable' => true, - 'default' => null, - 'comment' => 'Memory Used in MB', -)); +$installer->getConnection()->addColumn($installer->getTable('cron/schedule'), 'memory_usage', ['type' => Varien_Db_Ddl_Table::TYPE_DECIMAL, 'length' => '12,4', 'unsigned' => true, 'nullable' => true, 'default' => null, 'comment' => 'Memory Used in MB']); $installer->endSetup(); diff --git a/dev/tests/aoe_scheduler/AbstractTest.php b/dev/tests/aoe_scheduler/AbstractTest.php index a368e9e..3a16da9 100755 --- a/dev/tests/aoe_scheduler/AbstractTest.php +++ b/dev/tests/aoe_scheduler/AbstractTest.php @@ -3,8 +3,8 @@ abstract class AbstractTest extends PHPUnit_Framework_TestCase { - protected $jobs = array(); - protected $schedules = array(); + protected $jobs = []; + protected $schedules = []; protected function setUp() { @@ -45,37 +45,29 @@ protected function exec($command) */ public function runCronAlwaysProvider() { - return array( - array(function () { - // trigger dispatch - $observer = Mage::getModel('aoe_scheduler/observer'); /* @var $observer Aoe_Scheduler_Model_Observer */ - $observer->dispatchAlways(new Varien_Event_Observer()); - }), - array(function () { - shell_exec('php ' . Mage::getBaseDir() . '/cron.php'); - shell_exec('cd ' . Mage::getBaseDir() . '/shell && php scheduler.php --action wait'); - }), - array(function () { - shell_exec('/bin/sh ' . Mage::getBaseDir() . '/cron.sh'); - shell_exec('cd ' . Mage::getBaseDir() . '/shell && php scheduler.php --action wait'); - }), - array(function () { - shell_exec('/bin/sh ' . Mage::getBaseDir() . '/cron.sh cron.php -mdefault 1'); - shell_exec('cd ' . Mage::getBaseDir() . '/shell && php scheduler.php --action wait'); - }), - array(function () { - shell_exec('cd ' . Mage::getBaseDir() . '/shell && php scheduler.php --action cron --mode default'); - shell_exec('cd ' . Mage::getBaseDir() . '/shell && php scheduler.php --action wait'); - }), - array(function () { - shell_exec('/bin/bash ' . Mage::getBaseDir() . '/scheduler_cron.sh'); - shell_exec('cd ' . Mage::getBaseDir() . '/shell && php scheduler.php --action wait'); - }), - array(function () { - shell_exec('/bin/bash ' . Mage::getBaseDir() . '/scheduler_cron.sh --mode default'); - shell_exec('cd ' . Mage::getBaseDir() . '/shell && php scheduler.php --action wait'); - }) - ); + return [[function () { + // trigger dispatch + $observer = Mage::getModel('aoe_scheduler/observer'); /* @var $observer Aoe_Scheduler_Model_Observer */ + $observer->dispatchAlways(new Varien_Event_Observer()); + }], [function () { + shell_exec('php ' . Mage::getBaseDir() . '/cron.php'); + shell_exec('cd ' . Mage::getBaseDir() . '/shell && php scheduler.php --action wait'); + }], [function () { + shell_exec('/bin/sh ' . Mage::getBaseDir() . '/cron.sh'); + shell_exec('cd ' . Mage::getBaseDir() . '/shell && php scheduler.php --action wait'); + }], [function () { + shell_exec('/bin/sh ' . Mage::getBaseDir() . '/cron.sh cron.php -mdefault 1'); + shell_exec('cd ' . Mage::getBaseDir() . '/shell && php scheduler.php --action wait'); + }], [function () { + shell_exec('cd ' . Mage::getBaseDir() . '/shell && php scheduler.php --action cron --mode default'); + shell_exec('cd ' . Mage::getBaseDir() . '/shell && php scheduler.php --action wait'); + }], [function () { + shell_exec('/bin/bash ' . Mage::getBaseDir() . '/scheduler_cron.sh'); + shell_exec('cd ' . Mage::getBaseDir() . '/shell && php scheduler.php --action wait'); + }], [function () { + shell_exec('/bin/bash ' . Mage::getBaseDir() . '/scheduler_cron.sh --mode default'); + shell_exec('cd ' . Mage::getBaseDir() . '/shell && php scheduler.php --action wait'); + }]]; } /** @@ -85,36 +77,28 @@ public function runCronAlwaysProvider() */ public function runCronDefaultProvider() { - return array( - array(function () { - // trigger dispatch - $observer = Mage::getModel('aoe_scheduler/observer'); /* @var $observer Aoe_Scheduler_Model_Observer */ - $observer->dispatch(new Varien_Event_Observer()); - }), - array(function () { - shell_exec('php ' . Mage::getBaseDir() . '/cron.php'); - shell_exec('cd ' . Mage::getBaseDir() . '/shell && php scheduler.php --action wait'); - }), - array(function () { - shell_exec('/bin/sh ' . Mage::getBaseDir() . '/cron.sh'); - shell_exec('cd ' . Mage::getBaseDir() . '/shell && php scheduler.php --action wait'); - }), - array(function () { - shell_exec('/bin/sh ' . Mage::getBaseDir() . '/cron.sh cron.php -mdefault 1'); - shell_exec('cd ' . Mage::getBaseDir() . '/shell && php scheduler.php --action wait'); - }), - array(function () { - shell_exec('cd ' . Mage::getBaseDir() . '/shell && php scheduler.php --action cron --mode default'); - shell_exec('cd ' . Mage::getBaseDir() . '/shell && php scheduler.php --action wait'); - }), - array(function () { - shell_exec('/bin/bash ' . Mage::getBaseDir() . '/scheduler_cron.sh'); - shell_exec('cd ' . Mage::getBaseDir() . '/shell && php scheduler.php --action wait'); - }), - array(function () { - shell_exec('/bin/bash ' . Mage::getBaseDir() . '/scheduler_cron.sh --mode default'); - shell_exec('cd ' . Mage::getBaseDir() . '/shell && php scheduler.php --action wait'); - }) - ); + return [[function () { + // trigger dispatch + $observer = Mage::getModel('aoe_scheduler/observer'); /* @var $observer Aoe_Scheduler_Model_Observer */ + $observer->dispatch(new Varien_Event_Observer()); + }], [function () { + shell_exec('php ' . Mage::getBaseDir() . '/cron.php'); + shell_exec('cd ' . Mage::getBaseDir() . '/shell && php scheduler.php --action wait'); + }], [function () { + shell_exec('/bin/sh ' . Mage::getBaseDir() . '/cron.sh'); + shell_exec('cd ' . Mage::getBaseDir() . '/shell && php scheduler.php --action wait'); + }], [function () { + shell_exec('/bin/sh ' . Mage::getBaseDir() . '/cron.sh cron.php -mdefault 1'); + shell_exec('cd ' . Mage::getBaseDir() . '/shell && php scheduler.php --action wait'); + }], [function () { + shell_exec('cd ' . Mage::getBaseDir() . '/shell && php scheduler.php --action cron --mode default'); + shell_exec('cd ' . Mage::getBaseDir() . '/shell && php scheduler.php --action wait'); + }], [function () { + shell_exec('/bin/bash ' . Mage::getBaseDir() . '/scheduler_cron.sh'); + shell_exec('cd ' . Mage::getBaseDir() . '/shell && php scheduler.php --action wait'); + }], [function () { + shell_exec('/bin/bash ' . Mage::getBaseDir() . '/scheduler_cron.sh --mode default'); + shell_exec('cd ' . Mage::getBaseDir() . '/shell && php scheduler.php --action wait'); + }]]; } } diff --git a/dev/tests/aoe_scheduler/bootstrap.php b/dev/tests/aoe_scheduler/bootstrap.php index 252b753..75c92c1 100755 --- a/dev/tests/aoe_scheduler/bootstrap.php +++ b/dev/tests/aoe_scheduler/bootstrap.php @@ -1,13 +1,13 @@ jobs['jobWithGroupAandB'] = $jobWithGroupAandB; // fake schedule generation to avoid it to be generated on the next run: - Mage::app()->saveCache(time(), Mage_Cron_Model_Observer::CACHE_KEY_LAST_SCHEDULE_GENERATE_AT, array('crontab'), null); + Mage::app()->saveCache(time(), Mage_Cron_Model_Observer::CACHE_KEY_LAST_SCHEDULE_GENERATE_AT, ['crontab'], null); } /** @@ -52,7 +52,7 @@ public function scheduleJobAndRunCron() if ($sameRequest) { // dispatch event - $event = new Varien_Event_Observer(array('include_groups' => array($this->groups['groupA']))); + $event = new Varien_Event_Observer(['include_groups' => [$this->groups['groupA']]]); $observer = new Aoe_Scheduler_Model_Observer(); $observer->dispatch($event); } else { diff --git a/dev/tests/aoe_scheduler/tests/CronGroupsWhiteListTest.php b/dev/tests/aoe_scheduler/tests/CronGroupsWhiteListTest.php index 9f2cbce..6b29303 100755 --- a/dev/tests/aoe_scheduler/tests/CronGroupsWhiteListTest.php +++ b/dev/tests/aoe_scheduler/tests/CronGroupsWhiteListTest.php @@ -3,7 +3,7 @@ class CronGroupsWhiteListTest extends AbstractTest { - protected $groups = array(); + protected $groups = []; protected function setUp() { @@ -46,7 +46,7 @@ protected function setUp() } // fake schedule generation to avoid it to be generated on the next run: - Mage::app()->saveCache(time(), Mage_Cron_Model_Observer::CACHE_KEY_LAST_SCHEDULE_GENERATE_AT, array('crontab'), null); + Mage::app()->saveCache(time(), Mage_Cron_Model_Observer::CACHE_KEY_LAST_SCHEDULE_GENERATE_AT, ['crontab'], null); } /** @@ -72,11 +72,11 @@ public function scheduleJobAndRunCron() $this->assertTrue(in_array($this->schedules['jobWithGroupAandB']->getJobCode(), $map[$this->groups['groupA']])); $this->assertTrue(in_array($this->schedules['jobWithGroupAandB']->getJobCode(), $map[$this->groups['groupB']])); - $includeJobs = $helper->addGroupJobs(array(), array($this->groups['groupA'])); + $includeJobs = $helper->addGroupJobs([], [$this->groups['groupA']]); $this->assertTrue(in_array($this->schedules['jobWithGroupA']->getJobCode(), $includeJobs)); $this->assertTrue(in_array($this->schedules['jobWithGroupAandB']->getJobCode(), $includeJobs)); - $includeJobs = $helper->addGroupJobs(array(), array($this->groups['groupB'])); + $includeJobs = $helper->addGroupJobs([], [$this->groups['groupB']]); $this->assertTrue(in_array($this->schedules['jobWithGroupB']->getJobCode(), $includeJobs)); $this->assertTrue(in_array($this->schedules['jobWithGroupAandB']->getJobCode(), $includeJobs)); @@ -84,7 +84,7 @@ public function scheduleJobAndRunCron() if ($sameRequest) { // dispatch event - $event = new Varien_Event_Observer(array('include_groups' => array($this->groups['groupA']))); + $event = new Varien_Event_Observer(['include_groups' => [$this->groups['groupA']]]); $observer = new Aoe_Scheduler_Model_Observer(); $observer->dispatch($event); } else { diff --git a/dev/tests/aoe_scheduler/tests/SchedulingTest.php b/dev/tests/aoe_scheduler/tests/SchedulingTest.php index 8f458b0..2fe1170 100755 --- a/dev/tests/aoe_scheduler/tests/SchedulingTest.php +++ b/dev/tests/aoe_scheduler/tests/SchedulingTest.php @@ -35,7 +35,7 @@ public function scheduleJobAndRunCron($runCronCallBack) $scheduleManager->deleteAll(); // fake schedule generation to avoid it to be generated on the next run: - Mage::app()->saveCache(time(), Mage_Cron_Model_Observer::CACHE_KEY_LAST_SCHEDULE_GENERATE_AT, array('crontab'), null); + Mage::app()->saveCache(time(), Mage_Cron_Model_Observer::CACHE_KEY_LAST_SCHEDULE_GENERATE_AT, ['crontab'], null); $schedule = Mage::getModel('cron/schedule'); /* @var $schedule Aoe_Scheduler_Model_Schedule */ $jobCode = 'aoescheduler_testtask'; diff --git a/shell/scheduler.php b/shell/scheduler.php index 0115b1d..90c97b3 100644 --- a/shell/scheduler.php +++ b/shell/scheduler.php @@ -109,11 +109,8 @@ public function lastRunAction() $collection->addFieldToFilter('job_code', $code) ->addFieldToFilter( - array('status'), - array( - array('eq' => Aoe_Scheduler_Model_Schedule::STATUS_SUCCESS), - array('eq' => Aoe_Scheduler_Model_Schedule::STATUS_REPEAT) - ) + ['status'], + [['eq' => Aoe_Scheduler_Model_Schedule::STATUS_SUCCESS], ['eq' => Aoe_Scheduler_Model_Schedule::STATUS_REPEAT]] ) ->addOrder('finished_at', Varien_Data_Collection_Db::SORT_ORDER_DESC) ->getSelect()->limit(1); @@ -335,7 +332,7 @@ public function enableJobActionHelp() */ public function waitAction() { - $timeout = $this->getArg('timeout') ? $this->getArg('timeout') : 60; + $timeout = $this->getArg('timeout') ?: 60; $startTime = time(); $sleepBetweenPolls = 2; $processManager = Mage::getModel('aoe_scheduler/processManager'); /* @var $processManager Aoe_Scheduler_Model_ProcessManager */ @@ -356,9 +353,9 @@ public function waitAction() echo sprintf( "%-30s %-10s %-10s %-10s %-10s\n", $schedule->getJobCode(), - $schedule->getHost() ? $schedule->getHost() : '(no host)', - $schedule->getPid() ? $schedule->getPid() : '(no pid)', - $schedule->getLastSeen() ? $schedule->getLastSeen() : '(never)', + $schedule->getHost() ?: '(no host)', + $schedule->getPid() ?: '(no pid)', + $schedule->getLastSeen() ?: '(never)', $status ); } @@ -429,9 +426,9 @@ public function listAllRunningSchedulesAction() echo sprintf( "%-30s %-10s %-10s %-10s %-10s\n", $schedule->getJobCode(), - $schedule->getHost() ? $schedule->getHost() : '(no host)', - $schedule->getPid() ? $schedule->getPid() : '(no pid)', - $schedule->getLastSeen() ? $schedule->getLastSeen() : '(never)', + $schedule->getHost() ?: '(no host)', + $schedule->getPid() ?: '(no pid)', + $schedule->getLastSeen() ?: '(never)', $status ); } @@ -511,12 +508,7 @@ public function cronAction() $excludeGroups = array_filter(array_map('trim', explode(',', $this->getArg('excludeGroups')))); $includeJobs = array_filter(array_map('trim', explode(',', $this->getArg('includeJobs')))); $excludeJobs = array_filter(array_map('trim', explode(',', $this->getArg('excludeJobs')))); - Mage::dispatchEvent($mode, array( - 'include_groups' => $includeGroups, - 'exclude_groups' => $excludeGroups, - 'include_jobs' => $includeJobs, - 'exclude_jobs' => $excludeJobs, - )); + Mage::dispatchEvent($mode, ['include_groups' => $includeGroups, 'exclude_groups' => $excludeGroups, 'include_jobs' => $includeJobs, 'exclude_jobs' => $excludeJobs]); break; default: echo "\nInvalid mode!\n\n";