cleanit.php ➔ do_clean()   B
last analyzed

Complexity

Conditions 6
Paths 6

Size

Total Lines 43
Code Lines 30

Duplication

Lines 26
Ratio 60.47 %

Importance

Changes 0
Metric Value
cc 6
eloc 30
nc 6
nop 0
dl 26
loc 43
rs 8.439
c 0
b 0
f 0
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
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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);
0 ignored issues
show
Unused Code introduced by
$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...
39
    $cnt                = $xoopsDB->getAffectedRows();
40 View Code Duplication
    if ($cnt > 0) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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);
0 ignored issues
show
Unused Code introduced by
$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...
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);
0 ignored issues
show
Unused Code introduced by
$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...
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);
0 ignored issues
show
Unused Code introduced by
$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...
63
        $sql    = 'OPTIMIZE TABLE ' . $xoopsDB->prefix('gwiki_pages');
64
        $result = $xoopsDB->queryF($sql);
0 ignored issues
show
Unused Code introduced by
$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...
65
    }
66
}
67