mirror of
https://github.com/Mibew/mibew.git
synced 2025-04-25 15:56:07 +03:00
Replace "cron.php" with a controller
This commit is contained in:
parent
457045d81a
commit
66a68d0f23
@ -1,53 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* Copyright 2005-2014 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Import namespaces and classes of the core
|
|
||||||
use Mibew\EventDispatcher;
|
|
||||||
use Mibew\Settings;
|
|
||||||
|
|
||||||
// Initialize libraries
|
|
||||||
require_once(dirname(__FILE__) . '/libs/init.php');
|
|
||||||
|
|
||||||
$cron_key = empty($_GET['cron_key']) ? '' : $_GET['cron_key'];
|
|
||||||
|
|
||||||
// Check cron security key
|
|
||||||
if ($cron_key != Settings::get('cron_key')) {
|
|
||||||
die();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Determine use or not quiet mode
|
|
||||||
$quiet = isset($_GET['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
|
|
||||||
echo('All cron jobs done.');
|
|
||||||
}
|
|
68
src/mibew/libs/classes/Mibew/Controller/CronController.php
Normal file
68
src/mibew/libs/classes/Mibew/Controller/CronController.php
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* Copyright 2005-2014 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Mibew\Controller;
|
||||||
|
|
||||||
|
use Mibew\EventDispatcher;
|
||||||
|
use Mibew\Settings;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Contains actions which are related with cron.
|
||||||
|
*/
|
||||||
|
class CronController extends AbstractController
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Runs the cron.
|
||||||
|
*
|
||||||
|
* @param Request $request Incoming request.
|
||||||
|
* @return string Rendered page content.
|
||||||
|
*/
|
||||||
|
public function runAction(Request $request)
|
||||||
|
{
|
||||||
|
$cron_key = $request->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.';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -23,6 +23,7 @@ use Mibew\Style\ChatStyle;
|
|||||||
use Mibew\Style\InvitationStyle;
|
use Mibew\Style\InvitationStyle;
|
||||||
use Mibew\Style\PageStyle;
|
use Mibew\Style\PageStyle;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains actions which are related with common system settings.
|
* 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['invitationStylePreviewPath'] = $this->generateUrl('style_preview', array('type' => 'invitation'));
|
||||||
$page['stored'] = $request->query->has('stored');
|
$page['stored'] = $request->query->has('stored');
|
||||||
$page['enabletracking'] = Settings::get('enabletracking');
|
$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['title'] = getlocal('settings.title');
|
||||||
$page['menuid'] = 'settings';
|
$page['menuid'] = 'settings';
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@ namespace Mibew\Controller;
|
|||||||
use Mibew\Http\Exception\BadRequestException;
|
use Mibew\Http\Exception\BadRequestException;
|
||||||
use Mibew\Settings;
|
use Mibew\Settings;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display all statistics-related pages
|
* Display all statistics-related pages
|
||||||
@ -55,11 +56,16 @@ class StatisticsController extends AbstractController
|
|||||||
$page['showbyagent'] = ($statistics_type == self::TYPE_BY_OPERATOR);
|
$page['showbyagent'] = ($statistics_type == self::TYPE_BY_OPERATOR);
|
||||||
$page['showbypage'] = ($statistics_type == self::TYPE_BY_PAGE);
|
$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(
|
$page['pageDescription'] = getlocal2(
|
||||||
'statistics.description.full',
|
'statistics.description.full',
|
||||||
array(
|
array(
|
||||||
date_to_text(Settings::get('_last_cron_run')),
|
date_to_text(Settings::get('_last_cron_run')),
|
||||||
cron_get_uri(Settings::get('cron_key')),
|
$cron_uri,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -1,30 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* Copyright 2005-2014 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generates cron URI
|
|
||||||
*
|
|
||||||
* @param string $cron_key Cron security key
|
|
||||||
* @return string Cron URI
|
|
||||||
*/
|
|
||||||
function cron_get_uri($cron_key)
|
|
||||||
{
|
|
||||||
$path = get_app_location(true, is_secure_request()) . '/cron.php';
|
|
||||||
$path .= empty($cron_key) ? '' : '?cron_key=' . $cron_key;
|
|
||||||
|
|
||||||
return $path;
|
|
||||||
}
|
|
@ -99,7 +99,6 @@ if (!empty($plugins_list)) {
|
|||||||
require_once(MIBEW_FS_ROOT . '/libs/canned.php');
|
require_once(MIBEW_FS_ROOT . '/libs/canned.php');
|
||||||
require_once(MIBEW_FS_ROOT . '/libs/captcha.php');
|
require_once(MIBEW_FS_ROOT . '/libs/captcha.php');
|
||||||
require_once(MIBEW_FS_ROOT . '/libs/chat.php');
|
require_once(MIBEW_FS_ROOT . '/libs/chat.php');
|
||||||
require_once(MIBEW_FS_ROOT . '/libs/cron.php');
|
|
||||||
require_once(MIBEW_FS_ROOT . '/libs/getcode.php');
|
require_once(MIBEW_FS_ROOT . '/libs/getcode.php');
|
||||||
require_once(MIBEW_FS_ROOT . '/libs/groups.php');
|
require_once(MIBEW_FS_ROOT . '/libs/groups.php');
|
||||||
require_once(MIBEW_FS_ROOT . '/libs/invitation.php');
|
require_once(MIBEW_FS_ROOT . '/libs/invitation.php');
|
||||||
|
@ -86,6 +86,10 @@ captcha:
|
|||||||
path: /captcha
|
path: /captcha
|
||||||
defaults: { _controller: Mibew\Controller\CaptchaController::drawAction }
|
defaults: { _controller: Mibew\Controller\CaptchaController::drawAction }
|
||||||
|
|
||||||
|
cron:
|
||||||
|
path: /cron
|
||||||
|
defaults: { _controller: Mibew\Controller\CronController::runAction }
|
||||||
|
|
||||||
license:
|
license:
|
||||||
path: /license
|
path: /license
|
||||||
defaults: { _controller: Mibew\Controller\LicenseController::indexAction }
|
defaults: { _controller: Mibew\Controller\LicenseController::indexAction }
|
||||||
|
Loading…
Reference in New Issue
Block a user