Completed
Pull Request — master (#11)
by
unknown
01:56
created

action.module.php ➔ xoops_module_uninstall_about()   B

Complexity

Conditions 5
Paths 8

Size

Total Lines 30
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 17
nc 8
nop 1
dl 0
loc 30
rs 8.439
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 12 and the first side effect is on line 2.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
defined('XOOPS_ROOT_PATH') || exit('Restricted access');
3
4
/**
5
 *
6
 * Prepares system prior to attempting to install module
7
 *
8
 * @param XoopsModule $module
9
 *
10
 * @return bool true if ready to install, false if not
11
 */
12 View Code Duplication
function xoops_module_pre_install_about(XoopsModule $module)
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in 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...
13
{
14
    $utilsClass = ucfirst($module->dirname()) . "Utilities";
15
    if (!class_exists($utilsClass)) {
16
        xoops_load('utilities', $module->dirname());
17
    }
18
19
    $xoopsSuccess = $utilsClass::checkXoopsVer($module);
20
    $phpSuccess   = $utilsClass::checkPHPVer($module);
21
    return $xoopsSuccess && $phpSuccess;
22
}
23
24
/**
25
 * @param  XoopsObject $module
0 ignored issues
show
Documentation introduced by
Should the type for parameter $module not be XoopsModule?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
26
 * @return bool
27
 */
28
function xoops_module_install_about(XoopsModule $module)
0 ignored issues
show
Coding Style introduced by
xoops_module_install_about uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
29
{
30
    $success = true;
31
    $data_file = XOOPS_ROOT_PATH . '/modules/about/sql/mysql.about.sql';
32
    $GLOBALS['xoopsDB']->queryF('SET NAMES utf8');
33
    if (!$GLOBALS['xoopsDB']->queryFromFile($data_file)) {
34
        $module->setErrors('Pre-set data was not installed');
35
        // preset info not set, but don't 'fail' install because of this
36
        //$success = false;
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
37
    }
38
39
    // Delete files from previous version (if they exist)
40
    // this is only executed if this version copied over old version without running module update
41
    $oldFiles = array(XOOPS_ROOT_PATH . "/modules/" . $module->dirname() . "/include/xoopsformloader.php",
42
                      XOOPS_ROOT_PATH . "/modules/" . $module->dirname() . "/include/blockform.php"
43
    );
44
    foreach($oldFiles as $file) {
45
        if (is_file($file)) {
46
            $delOk = unlink($file);
47
            if (false === $delOk) {
48
                $module->setErrors(sprintf(_AM_ABOUT_ERROR_BAD_REMOVE, $file));
49
            } else {
50
                $module->setErrors(sprintf("%s deleted", $file));
51
            }
52
            $success = $success && $delOk;
53
        }
54
    }
55
    return $success;
56
}
57
58
/**
59
 *
60
 * Prepares system prior to attempting to install module
61
 *
62
 * @param XoopsModule $module
63
 *
64
 * @return bool true if ready to install, false if not
65
 */
66 View Code Duplication
function xoops_module_pre_update_about(XoopsModule $module)
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in 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...
67
{
68
    $utilsClass = ucfirst($module->dirname()) . "Utilities";
69
    if (!class_exists($utilsClass)) {
70
        xoops_load('utilities', $module->dirname());
71
    }
72
73
    $xoopsSuccess = $utilsClass::checkXoopsVer($module);
74
    $phpSuccess   = $utilsClass::checkPHPVer($module);
75
    return $xoopsSuccess && $phpSuccess;
76
}
77
78
79
/**
80
 * @param  XoopsModule $module
81
 * @param  null        $prev_version
82
 * @return bool
83
 */
84
function xoops_module_update_about(XoopsModule $module, $prev_version = null)
0 ignored issues
show
Unused Code introduced by
The parameter $prev_version is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
85
{
86
    $success = true;
87
    // Delete files from previous version (if they exist)
88
    $oldFiles = array(XOOPS_ROOT_PATH . "/modules/" . $module->dirname() . "/include/xoopsformloader.php",
89
                      XOOPS_ROOT_PATH . "/modules/" . $module->dirname() . "/include/blockform.php"
90
    );
91 View Code Duplication
    foreach($oldFiles as $file) {
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...
92
        if (is_file($file)) {
93
            if (false === ($delOk = unlink($file))) {
94
                $module->setErrors(sprintf(_AM_ABOUT_ERROR_BAD_REMOVE, $file));
95
            }
96
            $success = $success && $delOk;
97
        }
98
    }
99
100
    // Delete files from previous version (if they exist)
101
    // this is only executed if this version copied over old version without running module update
102
    $oldFiles = array(XOOPS_PATH . "/modules/" . $module->dirname() . "/include/xoopsformloader.php",
103
        XOOPS_PATH . "/modules/" . $module->dirname() . "/include/blockform.php"
104
    );
105 View Code Duplication
    foreach($oldFiles as $file) {
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...
106
        if (is_file($file)) {
107
            if (false === ($delOk = unlink($file))) {
108
                $module->setErrors(sprintf(_AM_ABOUT_ERROR_BAD_REMOVE, $file));
109
            }
110
            $success = $success && $delOk;
111
        }
112
    }
113
    return $success;
114
}
115
116
/**
117
 *
118
 * Function to complete upon module uninstall
119
 *
120
 * @param XoopsModule $module
121
 *
122
 * @return bool true if successfully executed uninstall of module, false if not
123
 */
124
function xoops_module_uninstall_about(XoopsModule $module)
125
{
126
    $moduleDirName = $module->dirname();
127
    $aboutHelper = \Xmf\Module\Helper::getHelper($moduleDirName);
128
    $utilsClass = ucfirst($moduleDirName) . 'Utilities';
129
    if (!class_exists($utilsClass)) {
130
        xoops_load('utilities', $moduleDirName);
131
    }
132
133
    $success = true;
134
    $aboutHelper->loadLanguage('admin');
135
136
    //------------------------------------------------------------------
137
    // Remove module uploads folder (and all subfolders) if they exist
138
    //------------------------------------------------------------------
139
140
    $old_directories = array(XOOPS_UPLOAD_PATH . "/{$moduleDirName}");
141
    foreach ($old_directories as $old_dir) {
142
        $dirInfo = new SplFileInfo($old_dir);
143
        if ($dirInfo->isDir()) {
144
            // The directory exists so delete it
145
            if (false === $utilsClass::rrmdir($old_dir)) {
146
                $module->setErrors(sprintf(_AM_ABOUT_ERROR_BAD_DEL_PATH, $old_dir));
147
                $success = false;
148
            }
149
        }
150
        unset($dirInfo);
151
    }
152
    return $success;
153
}
154