-
Notifications
You must be signed in to change notification settings - Fork 14
/
cron.php
59 lines (50 loc) · 1.79 KB
/
cron.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
/**
* Calculate the popularity per plugin/template from the popularity database tables
* Check for version and base discrepancies and update the 'devel:badextensions' page
*/
$TIMEFRAME = 60 * 60 * 24 * 365 * 2; // in seconds
$TIME = time() - $TIMEFRAME;
if (!defined('DOKU_INC')) {
define('DOKU_INC', __DIR__ . '/../../../');
}
const NOSESSION = true;
require_once(DOKU_INC . 'inc/init.php');
/** @var helper_plugin_pluginrepo_repository $hlp */
$hlp = plugin_load('helper', 'pluginrepo_repository');
$db = $hlp->getPluginsDB();
if (!$db) {
die('failed to connect to DB');
}
// update all plugins
$sql = "SELECT count(*) as cnt, A.value as plugin
FROM popularity A, popularity B
WHERE A.uid = B.uid
AND A.`key` = 'plugin'
AND B.`key` = 'now'
AND B.value > $TIME
GROUP BY A.value";
$stmt = $db->prepare($sql);
$stmt->execute();
$updt = $db->prepare("UPDATE plugins SET popularity = :pop WHERE plugin = :name");
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$updt->execute([':pop' => $row['cnt'], ':name' => $row['plugin']]);
}
// update all templates
$sql = "SELECT count(*) as cnt, A.value as template
FROM popularity A, popularity B
WHERE A.uid = B.uid
AND A.`key` = 'conf_template'
AND B.`key` = 'now'
AND B.value > $TIME
GROUP BY A.value";
$stmt = $db->prepare($sql);
$stmt->execute();
$updt = $db->prepare("UPDATE plugins SET popularity = :pop WHERE plugin = :name");
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$updt->execute([':pop' => $row['cnt'], ':name' => 'template:' . $row['template']]);
}
// create info on bad extension versions
/** @var helper_plugin_pluginrepo_version $version */
$version = plugin_load('helper', 'pluginrepo_version');
$version->execute();