-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcleanit.php
66 lines (60 loc) · 2.74 KB
/
cleanit.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
60
61
62
63
64
65
66
<?php
/**
* cleanit.php - purge old revisions as specified in preferences
*
* @copyright Copyright © 2013 geekwright, LLC. All rights reserved.
* @license gwiki/docs/license.txt GNU General Public License (GPL)
* @since 1.0
* @author Richard Griffith <[email protected]>
* @package gwiki
*/
// trigger_error("Clean Invoked");
include __DIR__ . '/../../mainfile.php';
if (empty($_POST['check'])) { // this is set by the admin page option, not by a regular call
$GLOBALS['xoopsOption']['template_main'] = 'gwiki_view.tpl';
include XOOPS_ROOT_PATH . '/header.php';
do_clean();
include XOOPS_ROOT_PATH . '/footer.php';
} else {
$xoopsLogger->activated = false;
do_clean();
exit;
}
function do_clean()
{
global $xoopsDB;
$dir = basename(__DIR__);
$moduleHelper = Xmf\Module\Helper::getHelper($dir);
$retaindays = (int) $moduleHelper->getConfig('retain_days', 0);
if ($retaindays <= 0) {
return;
}
$lastmodifiedbefore = time() - ($retaindays * 24 * 3600);
$sql = 'DELETE FROM ' . $xoopsDB->prefix('gwiki_pages') . " WHERE active = 0 AND lastmodified< $lastmodifiedbefore";
$result = $xoopsDB->queryF($sql);
$cnt = $xoopsDB->getAffectedRows();
if ($cnt > 0) {
$sql = 'SELECT image_file FROM ' . $xoopsDB->prefix('gwiki_page_images');
$sql .= ' WHERE keyword NOT IN (SELECT keyword from ' . $xoopsDB->prefix('gwiki_pages') . ')';
$result = $xoopsDB->query($sql);
while ($f = $xoopsDB->fetchArray($result)) {
unlink(XOOPS_ROOT_PATH . '/uploads/' . $dir . '/' . $f['image_file']);
}
$sql = 'DELETE FROM ' . $xoopsDB->prefix('gwiki_page_images');
$sql .= ' WHERE keyword NOT IN (SELECT keyword from ' . $xoopsDB->prefix('gwiki_pages') . ')';
$result = $xoopsDB->queryF($sql);
$sql = 'SELECT file_path FROM ' . $xoopsDB->prefix('gwiki_page_files');
$sql .= ' WHERE keyword NOT IN (SELECT keyword from ' . $xoopsDB->prefix('gwiki_pages') . ')';
$result = $xoopsDB->query($sql);
while ($f = $xoopsDB->fetchArray($result)) {
unlink(XOOPS_ROOT_PATH . '/uploads/' . $dir . '/' . $f['file_path']);
}
$sql = 'DELETE FROM ' . $xoopsDB->prefix('gwiki_page_files');
$sql .= ' WHERE keyword NOT IN (SELECT keyword from ' . $xoopsDB->prefix('gwiki_pages') . ')';
$result = $xoopsDB->queryF($sql);
$sql = 'DELETE FROM ' . $xoopsDB->prefix('gwiki_pageids') . ' WHERE keyword NOT IN (SELECT keyword from ' . $xoopsDB->prefix('gwiki_pages') . ')';
$result = $xoopsDB->queryF($sql);
$sql = 'OPTIMIZE TABLE ' . $xoopsDB->prefix('gwiki_pages');
$result = $xoopsDB->queryF($sql);
}
}