Completed
Push — master ( 812d3d...c578fd )
by Michael
01:56
created

cleanit.php (4 issues)

Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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
    // Access module configs from block:
30
    /** @var XoopsModuleHandler $moduleHandler */
31
    $moduleHandler = xoops_getHandler('module');
32
    $module        = $moduleHandler->getByDirname($dir);
33
    $configHandler = xoops_getHandler('config');
34
    $moduleConfig  = $configHandler->getConfigsByCat(0, $module->getVar('mid'));
35
36
    $retaindays = (int)$moduleConfig['retain_days'];
37
    if ($retaindays <= 0) {
38
        return;
39
    }
40
41
    $lastmodifiedbefore = time() - ($retaindays * 24 * 3600);
42
    $sql                = 'DELETE FROM ' . $xoopsDB->prefix('gwiki_pages') . " WHERE active = 0 AND lastmodified< $lastmodifiedbefore";
43
    $result             = $xoopsDB->queryF($sql);
0 ignored issues
show
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
44
    $cnt                = $xoopsDB->getAffectedRows();
45 View Code Duplication
    if ($cnt > 0) {
46
        $sql = 'SELECT image_file FROM ' . $xoopsDB->prefix('gwiki_page_images');
47
        $sql .= ' WHERE keyword NOT IN (SELECT keyword from ' . $xoopsDB->prefix('gwiki_pages') . ')';
48
        $result = $xoopsDB->query($sql);
49
        while ($f = $xoopsDB->fetchArray($result)) {
50
            unlink(XOOPS_ROOT_PATH . '/uploads/' . $dir . '/' . $f['image_file']);
51
        }
52
        $sql = 'DELETE FROM ' . $xoopsDB->prefix('gwiki_page_images');
53
        $sql .= ' WHERE keyword NOT IN (SELECT keyword from ' . $xoopsDB->prefix('gwiki_pages') . ')';
54
        $result = $xoopsDB->queryF($sql);
0 ignored issues
show
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
55
56
        $sql = 'SELECT file_path FROM ' . $xoopsDB->prefix('gwiki_page_files');
57
        $sql .= ' WHERE keyword NOT IN (SELECT keyword from ' . $xoopsDB->prefix('gwiki_pages') . ')';
58
        $result = $xoopsDB->query($sql);
59
        while ($f = $xoopsDB->fetchArray($result)) {
60
            unlink(XOOPS_ROOT_PATH . '/uploads/' . $dir . '/' . $f['file_path']);
61
        }
62
        $sql = 'DELETE FROM ' . $xoopsDB->prefix('gwiki_page_files');
63
        $sql .= ' WHERE keyword NOT IN (SELECT keyword from ' . $xoopsDB->prefix('gwiki_pages') . ')';
64
        $result = $xoopsDB->queryF($sql);
65
66
        $sql    = 'DELETE FROM ' . $xoopsDB->prefix('gwiki_pageids') . ' WHERE keyword NOT IN (SELECT keyword from ' . $xoopsDB->prefix('gwiki_pages') . ')';
67
        $result = $xoopsDB->queryF($sql);
0 ignored issues
show
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
68
        $sql    = 'OPTIMIZE TABLE ' . $xoopsDB->prefix('gwiki_pages');
69
        $result = $xoopsDB->queryF($sql);
0 ignored issues
show
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
70
    }
71
}
72