Added script for automatic poll purge (#3150).
This commit is contained in:
parent
ebe9add057
commit
cb10c87d07
91
admin/cron_purge.php
Normal file
91
admin/cron_purge.php
Normal file
@ -0,0 +1,91 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright 2018 Christian P. MOMON <cmomon@april.org>
|
||||
*
|
||||
* This software is governed by the CeCILL-B license. If a copy of this license
|
||||
* is not distributed with this file, you can obtain one at
|
||||
* http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.txt
|
||||
*
|
||||
*/
|
||||
|
||||
use Framadate\Services\InputService;
|
||||
use Framadate\Services\LogService;
|
||||
use Framadate\Services\PurgeService;
|
||||
use Framadate\Services\SecurityService;
|
||||
|
||||
// /////////////////////////////////////////////////
|
||||
// ////////// include_once __DIR__ . '/../app/inc/init.php';
|
||||
use Framadate\FramaDB;
|
||||
use Framadate\Repositories\RepositoryFactory;
|
||||
|
||||
define('ROOT_DIR', __DIR__ . '/../');
|
||||
|
||||
// Autoloading of dependencies with Composer
|
||||
require_once ROOT_DIR . '/vendor/autoload.php';
|
||||
require_once ROOT_DIR . '/vendor/o80/i18n/src/shortcuts.php';
|
||||
|
||||
if (ini_get('date.timezone') === '') {
|
||||
date_default_timezone_set('Europe/Paris');
|
||||
}
|
||||
|
||||
require_once ROOT_DIR . '/app/inc/constants.php';
|
||||
|
||||
define('CONF_FILENAME', ROOT_DIR . '/app/inc/config.php');
|
||||
if (is_file(CONF_FILENAME)) {
|
||||
@include_once CONF_FILENAME;
|
||||
|
||||
// Connection to database
|
||||
$connect = new FramaDB(DB_CONNECTION_STRING, DB_USER, DB_PASSWORD);
|
||||
RepositoryFactory::init($connect);
|
||||
$err = 0;
|
||||
} else {
|
||||
define('NOMAPPLICATION', 'Framadate');
|
||||
define('DEFAULT_LANGUAGE', 'fr');
|
||||
define('IMAGE_TITRE', 'images/logo-framadate.png');
|
||||
define('LOG_FILE', 'admin/stdout.log');
|
||||
}
|
||||
|
||||
require_once ROOT_DIR . '/app/inc/i18n.php';
|
||||
|
||||
// /////////////////////////////////////////////////
|
||||
|
||||
/* Variables */
|
||||
/* --------- */
|
||||
|
||||
/* Services */
|
||||
/*----------*/
|
||||
$logService = new LogService();
|
||||
$purgeService = new PurgeService($connect, $logService);
|
||||
$securityService = new SecurityService();
|
||||
$inputService = new InputService();
|
||||
|
||||
/* Action */
|
||||
/* ------ */
|
||||
$logService->log('CRON PURGE', 'Cron purge starting…');
|
||||
|
||||
$ended = false;
|
||||
$iterationCount = 0;
|
||||
$totalCount = 0;
|
||||
while (!$ended)
|
||||
{
|
||||
$count = $purgeService->purgeOldPolls();
|
||||
$logService->log('CRON PURGE', 'count='.$count);
|
||||
if ($count == 0)
|
||||
{
|
||||
$ended = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$iterationCount += 1;
|
||||
$totalCount += $count;
|
||||
}
|
||||
}
|
||||
|
||||
$logService->log('CRON PURGE', 'Purged '.$totalCount.' poll(s) in '.$iterationCount.' iterations.');
|
||||
$logService->log('CRON PURGE', 'Cron purge done.');
|
||||
|
||||
/* PAGE */
|
||||
/* ---- */
|
||||
echo date("Y-m-d H:i:s").": cron purge done.\n"
|
||||
|
||||
?>
|
Loading…
Reference in New Issue
Block a user