|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* cleanit.php - purge old revisions as specified in preferences |
|
4
|
|
|
* |
|
5
|
|
|
* @copyright Copyright © 2013 geekwright, LLC. All rights reserved. |
|
6
|
|
|
* @license gwiki/docs/license.txt GNU General Public License (GPL) |
|
7
|
|
|
* @since 1.0 |
|
8
|
|
|
* @author Richard Griffith <[email protected]> |
|
9
|
|
|
* @package gwiki |
|
10
|
|
|
*/ |
|
11
|
|
|
// trigger_error("Clean Invoked"); |
|
12
|
|
|
include __DIR__ . '/../../mainfile.php'; |
|
13
|
|
View Code Duplication |
if (empty($_POST['check'])) { // this is set by the admin page option, not by a regular call |
|
14
|
|
|
$GLOBALS['xoopsOption']['template_main'] = 'gwiki_view.tpl'; |
|
15
|
|
|
include XOOPS_ROOT_PATH . '/header.php'; |
|
16
|
|
|
do_clean(); |
|
17
|
|
|
include XOOPS_ROOT_PATH . '/footer.php'; |
|
18
|
|
|
} else { |
|
19
|
|
|
$xoopsLogger->activated = false; |
|
20
|
|
|
do_clean(); |
|
21
|
|
|
exit; |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
function do_clean() |
|
25
|
|
|
{ |
|
26
|
|
|
global $xoopsDB; |
|
27
|
|
|
|
|
28
|
|
|
$dir = basename(__DIR__); |
|
29
|
|
|
$moduleHelper = Xmf\Module\Helper::getHelper($dir); |
|
30
|
|
|
|
|
31
|
|
|
$retaindays = (int) $moduleHelper->getConfig('retain_days', 0); |
|
32
|
|
|
if ($retaindays <= 0) { |
|
33
|
|
|
return; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
$lastmodifiedbefore = time() - ($retaindays * 24 * 3600); |
|
37
|
|
|
$sql = 'DELETE FROM ' . $xoopsDB->prefix('gwiki_pages') . " WHERE active = 0 AND lastmodified< $lastmodifiedbefore"; |
|
38
|
|
|
$result = $xoopsDB->queryF($sql); |
|
|
|
|
|
|
39
|
|
|
$cnt = $xoopsDB->getAffectedRows(); |
|
40
|
|
View Code Duplication |
if ($cnt > 0) { |
|
41
|
|
|
$sql = 'SELECT image_file FROM ' . $xoopsDB->prefix('gwiki_page_images'); |
|
42
|
|
|
$sql .= ' WHERE keyword NOT IN (SELECT keyword from ' . $xoopsDB->prefix('gwiki_pages') . ')'; |
|
43
|
|
|
$result = $xoopsDB->query($sql); |
|
44
|
|
|
while ($f = $xoopsDB->fetchArray($result)) { |
|
45
|
|
|
unlink(XOOPS_ROOT_PATH . '/uploads/' . $dir . '/' . $f['image_file']); |
|
46
|
|
|
} |
|
47
|
|
|
$sql = 'DELETE FROM ' . $xoopsDB->prefix('gwiki_page_images'); |
|
48
|
|
|
$sql .= ' WHERE keyword NOT IN (SELECT keyword from ' . $xoopsDB->prefix('gwiki_pages') . ')'; |
|
49
|
|
|
$result = $xoopsDB->queryF($sql); |
|
|
|
|
|
|
50
|
|
|
|
|
51
|
|
|
$sql = 'SELECT file_path FROM ' . $xoopsDB->prefix('gwiki_page_files'); |
|
52
|
|
|
$sql .= ' WHERE keyword NOT IN (SELECT keyword from ' . $xoopsDB->prefix('gwiki_pages') . ')'; |
|
53
|
|
|
$result = $xoopsDB->query($sql); |
|
54
|
|
|
while ($f = $xoopsDB->fetchArray($result)) { |
|
55
|
|
|
unlink(XOOPS_ROOT_PATH . '/uploads/' . $dir . '/' . $f['file_path']); |
|
56
|
|
|
} |
|
57
|
|
|
$sql = 'DELETE FROM ' . $xoopsDB->prefix('gwiki_page_files'); |
|
58
|
|
|
$sql .= ' WHERE keyword NOT IN (SELECT keyword from ' . $xoopsDB->prefix('gwiki_pages') . ')'; |
|
59
|
|
|
$result = $xoopsDB->queryF($sql); |
|
|
|
|
|
|
60
|
|
|
|
|
61
|
|
|
$sql = 'DELETE FROM ' . $xoopsDB->prefix('gwiki_pageids') . ' WHERE keyword NOT IN (SELECT keyword from ' . $xoopsDB->prefix('gwiki_pages') . ')'; |
|
62
|
|
|
$result = $xoopsDB->queryF($sql); |
|
|
|
|
|
|
63
|
|
|
$sql = 'OPTIMIZE TABLE ' . $xoopsDB->prefix('gwiki_pages'); |
|
64
|
|
|
$result = $xoopsDB->queryF($sql); |
|
|
|
|
|
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.