Skip to content

Instantly share code, notes, and snippets.

@Sekiphp
Created June 18, 2019 08:56
Show Gist options
  • Save Sekiphp/8bb6ae54814734b9644f6376fcb95862 to your computer and use it in GitHub Desktop.
Save Sekiphp/8bb6ae54814734b9644f6376fcb95862 to your computer and use it in GitHub Desktop.
This script lists all Magento cronjobs by this command: # clear && php /shell/cron_lister.php
<?php
require_once __DIR__ . '/../abstract.php';
/**
* @see https://gist.github.com/werdan/5827225
*/
class Mage_Shell_CronLister extends Mage_Shell_Abstract
{
public function run()
{
$cronJobs = Mage::app()->getConfig()->getNode('crontab/jobs');
$outputFormat = "%-60s %-20s %-50s";
$datas = [];
printf($outputFormat . "\n", "Job name", "m h dom mon dow", "Object::Method to execute");
foreach($cronJobs->children() as $key => $job) {
$expr = '';
if (isset($job->schedule)) {
$expr = (string) $job->schedule->cron_expr;
if (empty($expr)) {
$expr = (string) Mage::getStoreConfig($job->schedule->config_path);
}
}
$expr = trim($expr);
$datas[$key] = sprintf($outputFormat, trim($job->getName()), $expr, trim((string) $job->run->model));
}
uksort($datas, array($this, 'compareTimes'));
foreach($datas as $job) {
echo $job . "\n";
}
}
public function compareTimes($time1, $time2)
{
$times1 = explode(' ', $time1);
$times2 = explode(' ', $time2);
if(( ! isset($times1[1])) || ($times1[1] == '*')) return -1;
if(( ! isset($times2[1])) || ($times2[1] == '*')) return 1;
$times1[1] = (int) trim($times1[1]);
$times2[1] = (int) trim($times2[1]);
$times1[0] = (int) trim($times1[0]);
$times2[0] = (int) trim($times2[0]);
if($times1[1] != $times2[1]) {
$res = ($times1[1] - $times2[1]) * 1000;
return $res;
}
return $times1[0] - $times2[0];
}
}
$cronLister = new Mage_Shell_CronLister();
$cronLister->run();
@jaimestuardo
Copy link

Is this only for Magento 1? I have Magento 2 and abstract.php file is missing so the script does not work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment