From 66a68d0f23b03a85ed55096abf47469f1fd77c7f Mon Sep 17 00:00:00 2001 From: Dmitriy Simushev Date: Tue, 3 Jun 2014 13:34:08 +0000 Subject: [PATCH] Replace "cron.php" with a controller --- src/mibew/cron.php | 53 --------------- .../Mibew/Controller/CronController.php | 68 +++++++++++++++++++ .../Controller/Settings/CommonController.php | 7 +- .../Mibew/Controller/StatisticsController.php | 8 ++- src/mibew/libs/cron.php | 30 -------- src/mibew/libs/init.php | 1 - src/mibew/libs/routing.yml | 4 ++ 7 files changed, 85 insertions(+), 86 deletions(-) delete mode 100644 src/mibew/cron.php create mode 100644 src/mibew/libs/classes/Mibew/Controller/CronController.php delete mode 100644 src/mibew/libs/cron.php diff --git a/src/mibew/cron.php b/src/mibew/cron.php deleted file mode 100644 index eed0e96c..00000000 --- a/src/mibew/cron.php +++ /dev/null @@ -1,53 +0,0 @@ -triggerEvent('cronRun'); - -// Update time of last cron run -Settings::set('_last_cron_run', time()); -Settings::update(); - -if (!$quiet) { - // TODO: May be localize it - echo('All cron jobs done.'); -} diff --git a/src/mibew/libs/classes/Mibew/Controller/CronController.php b/src/mibew/libs/classes/Mibew/Controller/CronController.php new file mode 100644 index 00000000..df884fe3 --- /dev/null +++ b/src/mibew/libs/classes/Mibew/Controller/CronController.php @@ -0,0 +1,68 @@ +query->get('cron_key', ''); + + // Check cron security key + if ($cron_key != Settings::get('cron_key')) { + // Return an empty response + return ''; + } + + // Determine use or not quiet mode + $quiet = $request->query->has('q'); + + set_time_limit(0); + + // Run cron jobs of the core + calculate_thread_statistics(); + calculate_operator_statistics(); + calculate_page_statistics(); + + // Trigger cron event + $dispatcher = EventDispatcher::getInstance(); + $dispatcher->triggerEvent('cronRun'); + + // Update time of last cron run + Settings::set('_last_cron_run', time()); + Settings::update(); + + if (!$quiet) { + // TODO: May be localize it + return 'All cron jobs done.'; + } + } +} diff --git a/src/mibew/libs/classes/Mibew/Controller/Settings/CommonController.php b/src/mibew/libs/classes/Mibew/Controller/Settings/CommonController.php index fabec1fe..aafe1f8f 100644 --- a/src/mibew/libs/classes/Mibew/Controller/Settings/CommonController.php +++ b/src/mibew/libs/classes/Mibew/Controller/Settings/CommonController.php @@ -23,6 +23,7 @@ use Mibew\Style\ChatStyle; use Mibew\Style\InvitationStyle; use Mibew\Style\PageStyle; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\Routing\Generator\UrlGeneratorInterface; /** * Contains actions which are related with common system settings. @@ -98,7 +99,11 @@ class CommonController extends AbstractController $page['invitationStylePreviewPath'] = $this->generateUrl('style_preview', array('type' => 'invitation')); $page['stored'] = $request->query->has('stored'); $page['enabletracking'] = Settings::get('enabletracking'); - $page['cron_path'] = cron_get_uri($params['cron_key']); + $page['cron_path'] = $this->generateUrl( + 'cron', + array('cron_key' => $params['cron_key']), + UrlGeneratorInterface::ABSOLUTE_URL + ); $page['title'] = getlocal('settings.title'); $page['menuid'] = 'settings'; diff --git a/src/mibew/libs/classes/Mibew/Controller/StatisticsController.php b/src/mibew/libs/classes/Mibew/Controller/StatisticsController.php index 93326ce7..21870f02 100644 --- a/src/mibew/libs/classes/Mibew/Controller/StatisticsController.php +++ b/src/mibew/libs/classes/Mibew/Controller/StatisticsController.php @@ -20,6 +20,7 @@ namespace Mibew\Controller; use Mibew\Http\Exception\BadRequestException; use Mibew\Settings; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\Routing\Generator\UrlGeneratorInterface; /** * Display all statistics-related pages @@ -55,11 +56,16 @@ class StatisticsController extends AbstractController $page['showbyagent'] = ($statistics_type == self::TYPE_BY_OPERATOR); $page['showbypage'] = ($statistics_type == self::TYPE_BY_PAGE); + $cron_uri = $this->generateUrl( + 'cron', + array('cron_key' => Settings::get('cron_key')), + UrlGeneratorInterface::ABSOLUTE_URL + ); $page['pageDescription'] = getlocal2( 'statistics.description.full', array( date_to_text(Settings::get('_last_cron_run')), - cron_get_uri(Settings::get('cron_key')), + $cron_uri, ) ); diff --git a/src/mibew/libs/cron.php b/src/mibew/libs/cron.php deleted file mode 100644 index abb72271..00000000 --- a/src/mibew/libs/cron.php +++ /dev/null @@ -1,30 +0,0 @@ -