Files
web-doc-editor/scripts/cron/compute_usage_statistics.php
Peter Kokot f06fee3640 Sync final newlines
This patch adds some missing newlines and trims multiple final newlines
into a single newline.

According to POSIX, a line is a sequence of zero or more non-' <newline>'
characters plus a terminating '<newline>' character. [1] Files should
normally have at least one final newline character.

C89 [2] and later standards [3] mention a final newline:
"A source file that is not empty shall end in a new-line character,
which shall not be immediately preceded by a backslash character."

Although it is not mandatory for all files to have a final newline
fixed, a more consistent and homogeneous approach brings less of commit
differences issues and a better development experience in certain text
editors and IDEs.

[1] http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_206
[2] https://port70.net/~nsz/c/c89/c89-draft.html#2.1.1.2
[3] https://port70.net/~nsz/c/c99/n1256.html#5.1.1.2
2018-10-02 03:44:40 +02:00

51 lines
1.6 KiB
PHP

<?php
/***
* This script is intended to be placed in a cronjob.
* It must be run every Thursday, at 01hOO for example.
* On Unix, you can use crontab -e and place this :
* 00 01 * * 4 /path/php/binary /path/to/your/vcs/dir/doc-editor/scripts/cron/compute_usage_statistics.php
****/
require_once dirname(__FILE__) . '/../../php/Conf.php';
require_once dirname(__FILE__) . '/../../php/ProjectManager.php';
require_once dirname(__FILE__) . '/../../php/UsageStatistics.php';
require_once dirname(__FILE__) . '/../../php/DBConnection.php';
require_once dirname(__FILE__) . '/../../php/RepositoryManager.php';
$pm = ProjectManager::getInstance();
$db = DBConnection::getInstance();
$us = UsageStatistics::getInstance();
$rm = RepositoryManager::getInstance();
$availableProject = $pm->getAvailableProject();
while( list($key, $project) = each($availableProject) ) {
// Define it as a project
$pm->setProject($project['code']);
// Just for the first run - We check if the usageStatistics table is empty
$s = 'SELECT COUNT(*) as total FROM `usageStatistics`';
$r = $db->query($s, array());
$a = $r->fetch_object();
if( $a->total == 0 ) {
$us->computeAll('2010'); // Place here the Year we want to start to compute statistics (this Year was included)
$rm->setStaticValue('info', 'computeUsageStatistics', '', true);
exit;
}
// We start compute stats for yesterday's month
$yesterday = new DateTime();
$yesterday->sub(new DateInterval('P1D'));
$us->computeMonth($yesterday->format('Y-m'));
$rm->setStaticValue('info', 'computeUsageStatistics', '', true);
}
?>