magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.52k stars 9.31k forks source link

Cron when defined in db has no name property #4719

Closed redboxmarcins closed 8 years ago

redboxmarcins commented 8 years ago

Steps to reproduce

  1. As example I use xtento product feed generator, but it doesn't matter as any will do
  2. In core_config_data table there are entries:
|       262 | default |        0 | crontab/default/jobs/xtento_productexport_profile_1_cron/schedule/cron_expr | 0 * * * *                                 |
|       263 | default |        0 | crontab/default/jobs/xtento_productexport_profile_1_cron/run/model          | Xtento\ProductExport\Cron\Export::execute |
  1. When \Magento\Cron\Model\Config::getJobs() is executed - array of the jobs from database will not have name property as xml ones.
  2. This f.e. will break n98magerun sys:cron:list as it expects name to be set - https://github.com/netz98/n98-magerun2/blob/master/src/N98/Magento/Command/System/Cron/AbstractCronCommand.php#L67

    Expected result

  3. Consistent array of cron jobs with same properties
Array
(
    [schedule] => "0 * * * *"
    [instance] => "Xtento\ProductExport\Cron\Export"
    [method] => "execute"
    [name] => "something here"
)

Actual result

  1. Cronjobs from database have no name
Array
(
    [schedule] => "0 * * * *"
    [instance] => "Xtento\ProductExport\Cron\Export"
    [method] => "execute"
)

Fix:

in Magento\Cron\Model\Config\Converter\Db _extractParams() method should have process name method f.e.

    protected function _extractParams(array $cronTab)
    {
        $result = [];
        foreach ($cronTab as $groupName => $groupConfig) {
            $jobs = $groupConfig['jobs'];
            foreach ($jobs as $jobName => $value) {
                $result[$groupName][$jobName] = $value;

                if (isset($value['schedule']) && is_array($value['schedule'])) {
                    $this->_processConfigParam($value, $jobName, $result[$groupName]);
                    $this->_processScheduleParam($value, $jobName, $result[$groupName]);
                }

                $this->_processRunModel($value, $jobName, $result[$groupName]);
                $this->_processName($value, $jobName, $result[$groupName]);
            }
        }
        return $result;
    }

    /**
     * @param array $jobConfig
     * @param       $jobName
     * @param array $result
     */
    protected function _processName(array $jobConfig, $jobName, array &$result)
    {
        $result[$jobName]['name'] = strtolower($jobName);
    }
wert2all commented 8 years ago

Please, provide the used version. If the problem is actual for a specific branch, please, specify it and be sure that the latest update was used.

palamar commented 8 years ago

According to contributor guide, tickets without response for two weeks should be closed. Please feel free to reopen if it's needed.