Skip to content

Instantly share code, notes, and snippets.

@molotovbliss
Forked from werdan/Magento cron lister
Last active December 17, 2015 18:57
Show Gist options
  • Save molotovbliss/7bc71a6936836badce6c to your computer and use it in GitHub Desktop.
Save molotovbliss/7bc71a6936836badce6c to your computer and use it in GitHub Desktop.
Lists all Magento cron jobs with tables output
<?php
// shell/listAllCron.php
require_once 'abstract.php';
class Mage_Shell_CronLister extends Mage_Shell_Abstract
{
public function run()
{
$cronJobs = Mage::app()->getConfig()->getNode('crontab/jobs');
$outputFormat = "%-60s %-20s %-50s";
echo "<table>";
printf($outputFormat . "\n", "<tr><th>Job name</th>", "<th>m h dom mon dow</th>", "<th>Object::Method to execute</th></tr>");
$lines = "Job name, m h dom mon dow, Object::Method to execute";
foreach($cronJobs->children() as $key => $job) {
$expr = "<td>".trim((string) $job->schedule->cron_expr)."</td>";
$datas[$key] = "<td>".sprintf($outputFormat, trim($job->getName()."</td>"), $expr, "<td>".trim((string) $job->run->model)."</td>");
$datas_csv[$key] = array(trim($job->getName()), $expr, trim((string) $job->run->model));
}
uksort($datas, array($this, 'compareTimes'));
foreach($datas as $job) {
echo "<tr>".$job . "</tr>\n";
}
echo "</table>";
}
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();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment