SystemModule::getTemplate()   B
last analyzed

Complexity

Conditions 6
Paths 12

Size

Total Lines 26
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 20
nc 12
nop 3
dl 0
loc 26
rs 8.9777
c 0
b 0
f 0
1
<?php
2
/*
3
 You may not change or alter any portion of this comment or credits
4
 of supporting developers from this source code or any supporting source code
5
 which is considered copyrighted (c) material of the original comment or credit authors.
6
7
 This program is distributed in the hope that it will be useful,
8
 but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
*/
11
12
use Xoops\Core\Database\Schema\ImportSchema;
13
use Xoops\Core\FixedGroups;
14
use Xoops\Core\Kernel\Criteria;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Criteria. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
15
use Xoops\Core\Kernel\CriteriaCompo;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, CriteriaCompo. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
16
use Xoops\Core\Kernel\Handlers\XoopsBlock;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, XoopsBlock. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
17
use Xoops\Core\Kernel\Handlers\XoopsModule;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, XoopsModule. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
18
use Xoops\Core\Psr4ClassLoader;
19
use Xoops\Module\Plugin\ConfigCollector;
20
use Xmf\Yaml;
21
use Doctrine\DBAL\DBALException;
22
use Doctrine\DBAL\Schema\Synchronizer\SingleDatabaseSynchronizer;
23
24
/**
25
 * System Module
26
 *
27
 * @category  SystemModule
28
 * @package   SystemModule
29
 * @author    Andricq Nicolas (AKA MusS)
30
 * @copyright 2000-2015 XOOPS Project (http://xoops.org)
31
 * @license   GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
32
 * @link      http://xoops.org
33
 */
34
class SystemModule
35
{
36
    public $error = array();
37
    public $trace = array();
38
    protected $modulesList = array();
39
    protected $modulesDirnames = array();
40
    protected $config_delng = array();
41
    protected $template_delng = array();
42
    protected $config_old = array();
43
    protected $reservedTables = array(
44
        'system_blockmodule',
45
        'system_config',
46
        'system_configoption',
47
        'system_group',
48
        'system_usergroup',
49
        'system_permission',
50
        'system_module',
51
        'system_block',
52
        'system_online',
53
        'system_privatemessage',
54
        'system_session',
55
        'system_tplfile',
56
        'system_tplset',
57
        'system_tplsource',
58
        'system_user',
59
    );
60
61
    /**
62
     * Constructor
63
     */
64
    public function __construct()
65
    {
66
        // Get main instance
67
        $xoops = Xoops::getInstance();
68
        $module_handler = $xoops->getHandlerModule();
69
70
        $this->modulesList = XoopsLists::getModulesList();
71
72
        $modules = $module_handler->getObjectsArray();
73
        /* @var $module XoopsModule */
74
        foreach ($modules as $module) {
75
            $this->modulesDirnames[] = $module->getInfo('dirname');
76
        }
77
    }
78
79
    /**
80
     * getModuleList
81
     *
82
     * @return array of modules
83
     */
84
    public function getModuleList()
85
    {
86
        // Get main instance
87
        $xoops = Xoops::getInstance();
88
        $module_handler = $xoops->getHandlerModule();
89
        $moduleperm_handler = $xoops->getHandlerGroupPermission();
90
91
        $criteria = new CriteriaCompo();
92
        $criteria->setSort('weight');
93
        // Get all installed modules
94
        $modules = $module_handler->getObjects($criteria, true);
95
        $list = array();
96
        /* @var $module XoopsModule */
97
        foreach ($modules as $module) {
98
            if (!$module->getInfo('extension')) {
99
                if ($module->getInfo('dirname') === 'system') {
100
                    $module->setInfo('can_delete', false);
101
                    $module->setInfo('can_disable', false);
102
                } else {
103
                    $module->setInfo('can_delete', true);
104
                    $module->setInfo('can_disable', true);
105
                }
106
                if (round($module->getInfo('version'), 2) != $module->getVar('version')) {
107
                    $module->setInfo('warning_update', true);
108
                }
109
                if (XoopsLoad::fileExists(
110
                    \XoopsBaseConfig::get('root-path') . '/modules/' . $module->getVar('dirname') . '/icons/logo_small.png'
111
                )) {
112
                    $module->setInfo(
113
                        'logo_small',
114
                        \XoopsBaseConfig::get('url') . '/modules/' . $module->getVar('dirname') . '/icons/logo_small.png'
115
                    );
116
                } else {
117
                    $module->setInfo('logo_small', \XoopsBaseConfig::get('url') . '/media/xoops/images/icons/16/default.png');
118
                }
119
                $module->setInfo('version', round($module->getVar('version') / 100, 2));
120
                $module->setInfo('update', XoopsLocale::formatTimestamp($module->getVar('last_update'), 's'));
121
                $module->setInfo(
122
                    'link_admin',
123
                    \XoopsBaseConfig::get('url') . '/modules/' . $module->getVar('dirname') . '/' . $module->getInfo('adminindex')
124
                );
125
126
                if ($module->getVar('isactive')) {
127
                    $module->setInfo('options', $module->getAdminMenu());
128
                }
129
130
                $groups = array();
131
                if (is_object($xoops->user)) {
132
                    $groups = $xoops->user->getGroups();
133
                }
134
135
                $sadmin = $moduleperm_handler->checkRight(
136
                    'module_admin',
137
                    $module->getVar('mid'),
138
                    $groups
139
                );
140
                if ($sadmin && ($module->getVar('hasnotification')
141
                    || is_array($module->getInfo('config')) || is_array($module->getInfo('comments')))
142
                ) {
143
                    $module->setInfo(
144
                        'link_pref',
145
                        \XoopsBaseConfig::get('url') . '/modules/system/admin.php?fct=preferences&amp;op=showmod&amp;mod='
146
                        . $module->getVar('mid')
147
                    );
148
                }
149
150
                $list[] = $module;
151
            }
152
        }
153
        return $list;
154
    }
155
156
    /**
157
     * getInstalledModules
158
     *
159
     * @return array of installed modules
160
     */
161
    public function getInstalledModules()
162
    {
163
        // Get main instance
164
        $xoops = Xoops::getInstance();
165
        $module_handler = $xoops->getHandlerModule();
166
167
        $ret = array();
168
        $i = 0;
169
        foreach ($this->modulesList as $file) {
170
            if (XoopsLoad::fileExists(\XoopsBaseConfig::get('root-path') . '/modules/' . $file . '/xoops_version.php')) {
171
                clearstatcache();
172
                $file = trim($file);
173
                if (!in_array($file, $this->modulesDirnames)) {
174
                    /* @var $module XoopsModule */
175
                    $module = $module_handler->create();
176
                    $module->loadInfo($file);
177
                    if (!$module->getInfo('extension')) {
178
                        $module->setInfo('mid', $i);
179
                        $module->setInfo('version', round($module->getInfo('version'), 2));
0 ignored issues
show
Bug introduced by
$module->getInfo('version') of type string|string[] is incompatible with the type double|integer expected by parameter $num of round(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

179
                        $module->setInfo('version', round(/** @scrutinizer ignore-type */ $module->getInfo('version'), 2));
Loading history...
180
                        $ret[] = $module;
181
                        unset($module);
182
                        ++$i;
183
                    }
184
                }
185
            }
186
        }
187
        return $ret;
188
    }
189
190
    /**
191
     * install a module
192
     *
193
     * @param string  $mod   module dirname
194
     * @param boolean $force force query
195
     *
196
     * @return bool|XoopsModule|XoopsObject
197
     */
198
    public function install($mod = '', $force = false)
0 ignored issues
show
Unused Code introduced by
The parameter $force is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

198
    public function install($mod = '', /** @scrutinizer ignore-unused */ $force = false)

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

Loading history...
199
    {
200
        $xoops = Xoops::getInstance();
201
        $module_handler = $xoops->getHandlerModule();
202
        $mod = trim($mod);
203
        try {
204
            $cnt = $module_handler->getCount(new Criteria('dirname', $mod));
205
        } catch (DBALException $e) {
206
            $cnt = 0;
207
        }
208
        if ($cnt == 0) {
209
            /* @var $module XoopsModule */
210
            $module = $module_handler->create();
211
            $module->loadInfoAsVar($mod);
212
            $module->setVar('weight', 1);
213
            $module->setVar('isactive', 1);
214
            $module->setVar('last_update', time());
215
            $this->addTemporaryAutoloader($module);
216
            $install_script = $module->getInfo('onInstall');
217
            if ($install_script && trim($install_script) != '') {
0 ignored issues
show
Bug introduced by
It seems like $install_script can also be of type string[]; however, parameter $string of trim() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

217
            if ($install_script && trim(/** @scrutinizer ignore-type */ $install_script) != '') {
Loading history...
218
                XoopsLoad::loadFile($xoops->path('modules/' . $mod . '/' . trim($install_script)));
219
            }
220
            $func = "xoops_module_pre_install_{$mod}";
221
            // If pre install function is defined, execute
222
            if (function_exists($func)) {
223
                $result = $func($module);
224
                if (!$result) {
225
                    $this->error[] = sprintf(XoopsLocale::EF_NOT_EXECUTED, $func);
226
                    $this->error = array_merge($this->error, $module->getErrors());
227
                    return false;
228
                } else {
229
                    $this->trace[] = sprintf(XoopsLocale::SF_EXECUTED, "<strong>{$func}</strong>");
230
                    $this->trace = array_merge($this->trace, $module->getMessages());
231
                }
232
            }
233
            // Create tables
234
            $created_tables = array();
235
            if (count($this->error) == 0) {
236
                $schema_file = $module->getInfo('schema');
237
                $sql_file = $module->getInfo('sqlfile');
238
                if (!empty($schema_file)) {
239
                    $schema_file_path = \XoopsBaseConfig::get('root-path') . '/modules/' . $mod . '/' . $schema_file;
0 ignored issues
show
Bug introduced by
Are you sure $schema_file of type string|string[] can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

239
                    $schema_file_path = \XoopsBaseConfig::get('root-path') . '/modules/' . $mod . '/' . /** @scrutinizer ignore-type */ $schema_file;
Loading history...
240
                    if (!XoopsLoad::fileExists($schema_file_path)) {
241
                        $this->error[] =
242
                            sprintf(SystemLocale::EF_SQL_FILE_NOT_FOUND, "<strong>{$schema_file}</strong>");
243
                        return false;
244
                    }
245
                    $importer = new ImportSchema(\XoopsBaseConfig::get('db-prefix') . '_');
246
                    $importSchema = $importer->importSchemaArray(Yaml::read($schema_file_path));
0 ignored issues
show
Bug introduced by
It seems like Xmf\Yaml::read($schema_file_path) can also be of type boolean; however, parameter $schemaArray of Xoops\Core\Database\Sche...ma::importSchemaArray() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

246
                    $importSchema = $importer->importSchemaArray(/** @scrutinizer ignore-type */ Yaml::read($schema_file_path));
Loading history...
247
                    $synchronizer = new SingleDatabaseSynchronizer($xoops->db());
248
                    $synchronizer->updateSchema($importSchema, true);
249
                } elseif (is_array($sql_file) && !empty($sql_file[\XoopsBaseConfig::get('db-type')])) {
250
                    $xoops->deprecated('Install SQL files are deprecated since 2.6.0. Convert to portable Schemas');
251
252
                    $sql_file_path = \XoopsBaseConfig::get('root-path') . '/modules/' . $mod . '/' . $sql_file[\XoopsBaseConfig::get('db-type')];
253
                    if (!XoopsLoad::fileExists($sql_file_path)) {
254
                        $this->error[] =
255
                            sprintf(SystemLocale::EF_SQL_FILE_NOT_FOUND, "<strong>{$sql_file_path}</strong>");
256
                        return false;
257
                    } else {
258
                        $this->trace[] = sprintf(SystemLocale::SF_SQL_FILE_FOUND, "<strong>{$sql_file_path}</strong>");
259
                        $this->trace[] = SystemLocale::MANAGING_TABLES;
260
261
                        $sql_query = fread(fopen($sql_file_path, 'r'), filesize($sql_file_path));
262
                        $sql_query = trim($sql_query);
263
                        SqlUtility::splitMySqlFile($pieces, $sql_query);
264
                        foreach ($pieces as $piece) {
265
                            // [0] contains the prefixed query
266
                            // [4] contains unprefixed table name
267
                            $prefixed_query = SqlUtility::prefixQuery($piece, $xoops->db()->prefix());
268
                            if (!$prefixed_query) {
269
                                $this->error[]['sub'] = '<span class="red">' . sprintf(
270
                                    XoopsLocale::EF_INVALID_SQL,
271
                                    '<strong>' . $piece . '</strong>'
272
                                ) . '</span>';
273
                                break;
274
                            }
275
                            // check if the table name is reserved
276
                            if (!in_array($prefixed_query[4], $this->reservedTables) || $mod === 'system') {
277
                                // not reserved, so try to create one
278
                                try {
279
                                    $result = $xoops->db()->query($prefixed_query[0]);
280
                                } catch (Exception $e) {
281
                                    $xoops->events()->triggerEvent('core.exception', $e);
282
                                    $result=false;
283
                                }
284
285
                                if (!$result) {
286
                                    $this->error[] = $xoops->db()->errorInfo();
287
                                    break;
288
                                } else {
289
                                    if (!in_array($prefixed_query[4], $created_tables)) {
290
                                        $this->trace[]['sub'] = sprintf(
291
                                            XoopsLocale::SF_TABLE_CREATED,
292
                                            '<strong>' . $xoops->db()->prefix($prefixed_query[4]) . '</strong>'
293
                                        );
294
                                        $created_tables[] = $prefixed_query[4];
295
                                    } else {
296
                                        $this->trace[]['sub'] = sprintf(
297
                                            XoopsLocale::SF_DATA_INSERTED_TO_TABLE,
298
                                            '<strong>' . $xoops->db()->prefix($prefixed_query[4]) . '</strong>'
299
                                        );
300
                                    }
301
                                }
302
                            } else {
303
                                // the table name is reserved, so halt the installation
304
                                $this->error[]['sub'] = sprintf(
305
                                    SystemLocale::EF_TABLE_IS_RESERVED,
306
                                    '<strong>' . $prefixed_query[4] . '</strong>'
307
                                );
308
                                break;
309
                            }
310
                        }
311
                        // if there was an error, delete the tables created so far,
312
                        // so the next installation will not fail
313
                        if (count($this->error) > 0) {
314
                            foreach ($created_tables as $table) {
315
                                try {
316
                                    $xoops->db()->query('DROP TABLE ' . $xoops->db()->prefix($table));
317
                                } catch (Exception $e) {
318
                                    $xoops->events()->triggerEvent('core.exception', $e);
319
                                }
320
                            }
321
                            return false;
322
                        }
323
                    }
324
                }
325
            }
326
            // Save module info, blocks, templates and perms
327
            if (count($this->error) == 0) {
328
                if (!$module_handler->insertModule($module)) {
329
                    $this->error[] = sprintf(
330
                        XoopsLocale::EF_NOT_INSERTED_TO_DATABASE,
331
                        '<strong>' . $module->getVar('name') . '</strong>'
332
                    );
333
                    foreach ($created_tables as $ct) {
334
                        try {
335
                            $xoops->db()->query('DROP TABLE ' . $xoops->db()->prefix($ct));
336
                        } catch (Exception $e) {
337
                            $xoops->events()->triggerEvent('core.exception', $e);
338
                        }
339
                    }
340
                    $this->error[] = sprintf(XoopsLocale::EF_NOT_INSTALLED, "<strong>" . $module->name() . "</strong>");
341
                    $this->error[] = XoopsLocale::C_ERRORS;
342
                    unset($module);
343
                    unset($created_tables);
344
                    return false;
345
                }
346
                unset($created_tables);
347
                $this->trace[] = XoopsLocale::S_DATA_INSERTED . sprintf(
348
                    SystemLocale::F_MODULE_ID,
349
                    '<strong>' . $module->getVar('mid') . '</strong>'
350
                );
351
                $xoops->db()->beginTransaction();
352
                // install Templates
353
                $this->installTemplates($module);
354
355
                $xoops->templateClearModuleCache($module->getVar('mid'));
356
357
                // install blocks
358
                $this->installBlocks($module);
359
360
                // Install Configs
361
                $this->installConfigs($module);
362
363
                if ($module->getInfo('hasMain')) {
364
                    $groups = array(FixedGroups::ADMIN, FixedGroups::USERS, FixedGroups::ANONYMOUS);
365
                } else {
366
                    $groups = array(FixedGroups::ADMIN);
367
                }
368
                // retrieve all block ids for this module
369
                $block_handler = $xoops->getHandlerBlock();
370
                $blocks = $block_handler->getByModule($module->getVar('mid'), false);
371
                $this->trace[] = SystemLocale::MANAGING_PERMISSIONS;
372
                $gperm_handler = $xoops->getHandlerGroupPermission();
373
                foreach ($groups as $mygroup) {
374
                    if ($gperm_handler->checkRight('module_admin', 0, $mygroup)) {
375
                        $mperm = $gperm_handler->create();
376
                        $mperm->setVar('gperm_groupid', $mygroup);
377
                        $mperm->setVar('gperm_itemid', $module->getVar('mid'));
378
                        $mperm->setVar('gperm_name', 'module_admin');
379
                        $mperm->setVar('gperm_modid', 1);
380
                        if (!$gperm_handler->insert($mperm)) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $gperm_handler->insert($mperm) of type false|integer is loosely compared to false; this is ambiguous if the integer can be 0. You might want to explicitly use === false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
381
                            $this->trace[]['sub'] = '<span class="red">' . sprintf(
382
                                SystemLocale::EF_GROUP_ID_ADMIN_ACCESS_RIGHT_NOT_ADDED,
383
                                '<strong>' . $mygroup . '</strong>'
384
                            ) . '</span>';
385
                        } else {
386
                            $this->trace[]['sub'] = sprintf(
387
                                SystemLocale::SF_GROUP_ID_ADMIN_ACCESS_RIGHT_ADDED,
388
                                '<strong>' . $mygroup . '</strong>'
389
                            );
390
                        }
391
                        unset($mperm);
392
                    }
393
                    $mperm = $gperm_handler->create();
394
                    $mperm->setVar('gperm_groupid', $mygroup);
395
                    $mperm->setVar('gperm_itemid', $module->getVar('mid'));
396
                    $mperm->setVar('gperm_name', 'module_read');
397
                    $mperm->setVar('gperm_modid', 1);
398
                    if (!$gperm_handler->insert($mperm)) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $gperm_handler->insert($mperm) of type false|integer is loosely compared to false; this is ambiguous if the integer can be 0. You might want to explicitly use === false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
399
                        $this->trace[]['sub'] = '<span class="red">' . sprintf(
400
                            SystemLocale::EF_GROUP_ID_USER_ACCESS_RIGHT_NOT_ADDED,
401
                            '<strong>' . $mygroup . '</strong>'
402
                        ) . '</span>';
403
                    } else {
404
                        $this->trace[]['sub'] = sprintf(
405
                            SystemLocale::SF_GROUP_ID_USER_ACCESS_RIGHT_ADDED,
406
                            '<strong>' . $mygroup . '</strong>'
407
                        );
408
                    }
409
                    unset($mperm);
410
                    foreach ($blocks as $blc) {
411
                        $bperm = $gperm_handler->create();
412
                        $bperm->setVar('gperm_groupid', $mygroup);
413
                        $bperm->setVar('gperm_itemid', $blc);
414
                        $bperm->setVar('gperm_name', 'block_read');
415
                        $bperm->setVar('gperm_modid', 1);
416
                        if (!$gperm_handler->insert($bperm)) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $gperm_handler->insert($bperm) of type false|integer is loosely compared to false; this is ambiguous if the integer can be 0. You might want to explicitly use === false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
417
                            $this->trace[]['sub'] = '<span class="red">'
418
                            . SystemLocale::E_BLOCK_ACCESS_NOT_ADDED . ' Block ID: <strong>'
419
                            . $blc . '</strong> Group ID: <strong>' . $mygroup . '</strong></span>';
420
                        } else {
421
                            $this->trace[]['sub'] = SystemLocale::S_BLOCK_ACCESS_ADDED
422
                                . sprintf(SystemLocale::F_BLOCK_ID, "<strong>" . $blc . "</strong>")
423
                                . sprintf(SystemLocale::F_GROUP_ID, "<strong>" . $mygroup . "</strong>");
424
                        }
425
                        unset($bperm);
426
                    }
427
                }
428
                unset($blocks);
429
                unset($groups);
430
431
                // execute module specific install script if any
432
                // If pre install function is defined, execute
433
                $func = "xoops_module_install_{$mod}";
434
                if (function_exists($func)) {
435
                    $result = $func($module);
436
                    if (!$result) {
437
                        $this->trace[] = sprintf(XoopsLocale::EF_NOT_EXECUTED, $func);
438
                        $this->trace = array_merge($this->trace, $module->getErrors());
439
                    } else {
440
                        $this->trace[] = sprintf(XoopsLocale::SF_EXECUTED, "<strong>{$func}</strong>");
441
                        $this->trace = array_merge($this->trace, $module->getMessages());
442
                    }
443
                }
444
445
                $this->trace[] = sprintf(
446
                    XoopsLocale::SF_INSTALLED,
447
                    '<strong>' . $module->getVar('name', 's') . '</strong>'
448
                );
449
                unset($blocks);
450
451
                $xoops->db()->commit();
452
453
                $xoops->events()->triggerEvent('system.module.install', $module);
454
                return $module;
455
            }
456
        } else {
457
            $this->error[] = sprintf(
458
                XoopsLocale::EF_NOT_INSTALLED,
459
                '<strong>' . $mod . '</strong>'
460
            ) . "&nbsp;" . XoopsLocale::C_ERRORS;
461
            return false;
462
        }
463
        return false;
464
    }
465
466
    /**
467
     * uninstall
468
     *
469
     * @param string $mod module dirname
470
     *
471
     * @return false|XoopsModule false on failure, module context on success
472
     */
473
    public function uninstall($mod = '')
474
    {
475
        $xoops = Xoops::getInstance();
476
        $module_handler = $xoops->getHandlerModule();
477
        $module = $module_handler->getByDirname($mod);
478
        $xoops->templateClearModuleCache($module->getVar('mid'));
479
480
        if ($module->getVar('dirname') === 'system') {
481
            $this->error[] = sprintf(
482
                XoopsLocale::EF_NOT_UNINSTALLED,
483
                '<strong>' . $module->getVar('name') . '</strong>'
484
            ) . "&nbsp;" . XoopsLocale::C_ERRORS;
485
            $this->error[] = " - " . SystemLocale::E_SYSTEM_MODULE_CANNOT_BE_DEACTIVATED;
486
            return false;
487
        } elseif ($module->getVar('dirname') == $xoops->getConfig('startpage')) {
488
            $this->error[] = sprintf(
489
                XoopsLocale::EF_NOT_UNINSTALLED,
490
                '<strong>' . $module->getVar('name') . '</strong>'
491
            ) . "&nbsp;" . XoopsLocale::C_ERRORS;
492
            $this->error[] = " - " . SystemLocale::E_THIS_MODULE_IS_SET_AS_DEFAULT_START_PAGE;
493
            return false;
494
        } else {
495
            // Load module specific install script if any
496
            $uninstall_script = $module->getInfo('onUninstall');
497
            if ($uninstall_script && trim($uninstall_script) != '') {
0 ignored issues
show
Bug introduced by
It seems like $uninstall_script can also be of type string[]; however, parameter $string of trim() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

497
            if ($uninstall_script && trim(/** @scrutinizer ignore-type */ $uninstall_script) != '') {
Loading history...
498
                XoopsLoad::loadFile($xoops->path('modules/' . $mod . '/' . trim($uninstall_script)));
499
            }
500
            $func = "xoops_module_pre_uninstall_{$mod}";
501
            // If pre uninstall function is defined, execute
502
            if (function_exists($func)) {
503
                $result = $func($module);
504
                if (!$result) {
505
                    $this->error[] = sprintf(XoopsLocale::EF_NOT_EXECUTED, $func);
506
                    $this->error[] = sprintf(
507
                        XoopsLocale::EF_NOT_UNINSTALLED,
508
                        '<strong>' . $module->getVar('name') . '</strong>'
509
                    ) . "&nbsp;" . XoopsLocale::C_ERRORS;
510
                    $this->error = array_merge($this->error, $module->getErrors());
511
                    return false;
512
                } else {
513
                    $this->trace[] = sprintf(XoopsLocale::SF_EXECUTED, "<strong>{$func}</strong>");
514
                    $this->trace = array_merge($this->trace, $module->getMessages());
515
                }
516
            }
517
518
            if (false === $module_handler->deleteModule($module)) {
0 ignored issues
show
Bug introduced by
It seems like $module can also be of type false; however, parameter $module of Xoops\Core\Kernel\Handle...Handler::deleteModule() does only seem to accept Xoops\Core\Kernel\Handlers\XoopsModule, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

518
            if (false === $module_handler->deleteModule(/** @scrutinizer ignore-type */ $module)) {
Loading history...
519
                $this->error[] = sprintf(XoopsLocale::EF_NOT_DELETED, $module->getVar('name'));
0 ignored issues
show
Bug introduced by
It seems like $module->getVar('name') can also be of type string[]; however, parameter $values of sprintf() does only seem to accept double|integer|string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

519
                $this->error[] = sprintf(XoopsLocale::EF_NOT_DELETED, /** @scrutinizer ignore-type */ $module->getVar('name'));
Loading history...
520
                return false;
521
            } else {
522
                // delete templates
523
                $this->deleteTemplates($module);
0 ignored issues
show
Bug introduced by
It seems like $module can also be of type false; however, parameter $module of SystemModule::deleteTemplates() does only seem to accept Xoops\Core\Kernel\Handlers\XoopsModule, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

523
                $this->deleteTemplates(/** @scrutinizer ignore-type */ $module);
Loading history...
524
525
                // Delete blocks and block template files
526
                $this->deleteBlocks($module);
0 ignored issues
show
Bug introduced by
It seems like $module can also be of type false; however, parameter $module of SystemModule::deleteBlocks() does only seem to accept Xoops\Core\Kernel\Handlers\XoopsModule, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

526
                $this->deleteBlocks(/** @scrutinizer ignore-type */ $module);
Loading history...
527
528
                // Delete tables used by this module
529
                $modtables = $module->getInfo('tables');
530
                if ($modtables != false && is_array($modtables)) {
531
                    // get a schema manager
532
                    $schemaManager = $xoops->db()->getSchemaManager();
533
                    // create schema from the current database
534
                    $toSchema = $schemaManager->createSchema();
535
536
                    $this->trace[] = SystemLocale::MANAGING_TABLES;
537
                    foreach ($modtables as $table) {
538
                        // prevent deletion of reserved core tables!
539
                        if (!in_array($table, $this->reservedTables)) {
540
                            $toSchema->dropTable($xoops->db()->prefix($table));
541
                            $this->trace[]['sub'] = sprintf(
542
                                XoopsLocale::SF_TABLE_DROPPED,
543
                                '<strong>' . $xoops->db()->prefix($table) . '</strong>'
544
                            );
545
                        } else {
546
                            $this->trace[]['sub'] = '<span class="red">' . sprintf(
547
                                XoopsLocale::EF_TABLE_DROP_NOT_ALLOWED,
548
                                '<strong>' . $xoops->db()->prefix($table) . '</strong>'
549
                            ) . '</span>';
550
                        }
551
                    }
552
                    $synchronizer = new SingleDatabaseSynchronizer($xoops->db());
553
                    $synchronizer->updateSchema($toSchema, false);
554
                }
555
556
                // delete permissions if any
557
                $gperm_handler = $xoops->getHandlerGroupPermission();
558
                if (false === $gperm_handler->deleteByModule($module->getVar('mid'))) {
559
                    $this->trace[] = '<span class="red">' . SystemLocale::E_GROUP_PERMISSIONS_NOT_DELETED . '</span>';
560
                } else {
561
                    $this->trace[] = SystemLocale::S_GROUP_PERMISSIONS_DELETED;
562
                }
563
564
                // delete module config options if any
565
                $this->deleteConfigs($module);
0 ignored issues
show
Bug introduced by
It seems like $module can also be of type false; however, parameter $module of SystemModule::deleteConfigs() does only seem to accept Xoops\Core\Kernel\Handlers\XoopsModule, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

565
                $this->deleteConfigs(/** @scrutinizer ignore-type */ $module);
Loading history...
566
567
                // execute module specific install script if any
568
                $func = 'xoops_module_uninstall_' . $mod;
569
                if (function_exists($func)) {
570
                    $result = $func($module);
571
                    if (!$result) {
572
                        $this->trace[] = sprintf(XoopsLocale::EF_NOT_EXECUTED, $func);
573
                        $this->trace = array_merge($this->error, $module->getErrors());
574
                    } else {
575
                        $this->trace[] = sprintf(XoopsLocale::SF_EXECUTED, "<strong>{$func}</strong>");
576
                        $this->trace = array_merge($this->trace, $module->getMessages());
577
                    }
578
                }
579
                $this->trace[] = sprintf(
580
                    XoopsLocale::SF_UNINSTALLED,
581
                    '<strong>' . $module->getVar('name') . '</strong>'
582
                );
583
                $xoops->events()->triggerEvent('system.module.uninstall', $module);
584
                return $module;
585
            }
586
        }
587
    }
588
589
    /**
590
     * update
591
     *
592
     * @param string $mod module dirname
593
     *
594
     * @return mixed boolean false if failed, XoopsModule if success
595
     */
596
    public function update($mod = '')
597
    {
598
        $xoops = Xoops::getInstance();
599
        $module_handler = $xoops->getHandlerModule();
600
        $module = $module_handler->getByDirname($mod);
601
        $xoops->templateClearModuleCache($module->getVar('mid'));
602
        // Save current version for use in the update function
603
        $prev_version = $module->getVar('version');
604
        // we don't want to change the module name set by admin
605
        $temp_name = $module->getVar('name');
606
        $module->loadInfoAsVar($module->getVar('dirname'));
0 ignored issues
show
Bug introduced by
It seems like $module->getVar('dirname') can also be of type string[]; however, parameter $dirname of Xoops\Core\Kernel\Handle...Module::loadInfoAsVar() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

606
        $module->loadInfoAsVar(/** @scrutinizer ignore-type */ $module->getVar('dirname'));
Loading history...
607
        $module->setVar('name', $temp_name);
608
        $module->setVar('last_update', time());
609
        $this->addTemporaryAutoloader($module);
0 ignored issues
show
Bug introduced by
It seems like $module can also be of type false; however, parameter $module of SystemModule::addTemporaryAutoloader() does only seem to accept Xoops\Core\Kernel\Handlers\XoopsModule, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

609
        $this->addTemporaryAutoloader(/** @scrutinizer ignore-type */ $module);
Loading history...
610
611
        if (!$module_handler->insertModule($module)) {
0 ignored issues
show
Bug introduced by
It seems like $module can also be of type false; however, parameter $module of Xoops\Core\Kernel\Handle...Handler::insertModule() does only seem to accept Xoops\Core\Kernel\Handlers\XoopsModule, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

611
        if (!$module_handler->insertModule(/** @scrutinizer ignore-type */ $module)) {
Loading history...
612
            $this->error[] = sprintf(XoopsLocale::EF_NOT_UPDATED, "<strong>" . $module->getVar('name') . "</strong>");
613
            return false;
614
        } else {
615
            // execute module specific preupdate script if any
616
            $update_script = $module->getInfo('onUpdate');
617
            if (false != $update_script && trim($update_script) != '') {
0 ignored issues
show
Bug introduced by
It seems like $update_script can also be of type string[]; however, parameter $string of trim() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

617
            if (false != $update_script && trim(/** @scrutinizer ignore-type */ $update_script) != '') {
Loading history...
618
                XoopsLoad::loadFile($xoops->path('modules/' . $mod . '/' . trim($update_script)));
619
                $func = 'xoops_module_pre_update_' . $mod;
620
                if (function_exists($func)) {
621
                    $result = $func($module, $prev_version);
622
                    if (!$result) {
623
                        $this->trace[] = sprintf(XoopsLocale::EF_NOT_EXECUTED, $func);
624
                        $this->trace = array_merge($this->error, $module->getErrors());
625
                    } else {
626
                        $this->trace[] = sprintf(XoopsLocale::SF_EXECUTED, "<strong>{$func}</strong>");
627
                        $this->trace = array_merge($this->trace, $module->getMessages());
628
                    }
629
                }
630
            }
631
632
            // update schema
633
            $schema_file = $module->getInfo('schema');
634
            if (!empty($schema_file)) {
635
                $schema_file_path = \XoopsBaseConfig::get('root-path') . '/modules/' . $mod . '/' . $schema_file;
0 ignored issues
show
Bug introduced by
Are you sure $schema_file of type string|string[] can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

635
                $schema_file_path = \XoopsBaseConfig::get('root-path') . '/modules/' . $mod . '/' . /** @scrutinizer ignore-type */ $schema_file;
Loading history...
636
                if (!XoopsLoad::fileExists($schema_file_path)) {
637
                    $this->error[] =
638
                        sprintf(SystemLocale::EF_SQL_FILE_NOT_FOUND, "<strong>{$schema_file}</strong>");
639
                    return false;
640
                }
641
                $importer = new ImportSchema(\XoopsBaseConfig::get('db-prefix') . '_');
642
                $importSchema = $importer->importSchemaArray(Yaml::read($schema_file_path));
0 ignored issues
show
Bug introduced by
It seems like Xmf\Yaml::read($schema_file_path) can also be of type boolean; however, parameter $schemaArray of Xoops\Core\Database\Sche...ma::importSchemaArray() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

642
                $importSchema = $importer->importSchemaArray(/** @scrutinizer ignore-type */ Yaml::read($schema_file_path));
Loading history...
643
                $synchronizer = new SingleDatabaseSynchronizer($xoops->db());
644
                $synchronizer->updateSchema($importSchema, true);
645
            }
646
647
            // delete templates
648
            $this->deleteTemplates($module);
0 ignored issues
show
Bug introduced by
It seems like $module can also be of type false; however, parameter $module of SystemModule::deleteTemplates() does only seem to accept Xoops\Core\Kernel\Handlers\XoopsModule, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

648
            $this->deleteTemplates(/** @scrutinizer ignore-type */ $module);
Loading history...
649
650
            // install templates
651
            $this->installTemplates($module);
0 ignored issues
show
Bug introduced by
It seems like $module can also be of type false; however, parameter $module of SystemModule::installTemplates() does only seem to accept Xoops\Core\Kernel\Handlers\XoopsModule, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

651
            $this->installTemplates(/** @scrutinizer ignore-type */ $module);
Loading history...
652
653
            // install blocks
654
            $this->installBlocks($module);
0 ignored issues
show
Bug introduced by
It seems like $module can also be of type false; however, parameter $module of SystemModule::installBlocks() does only seem to accept Xoops\Core\Kernel\Handlers\XoopsModule, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

654
            $this->installBlocks(/** @scrutinizer ignore-type */ $module);
Loading history...
655
656
            // reset compile_id
657
            $xoops->tpl()->setCompileId();
658
659
            // first delete all config entries
660
            $this->deleteConfigs($module);
0 ignored issues
show
Bug introduced by
It seems like $module can also be of type false; however, parameter $module of SystemModule::deleteConfigs() does only seem to accept Xoops\Core\Kernel\Handlers\XoopsModule, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

660
            $this->deleteConfigs(/** @scrutinizer ignore-type */ $module);
Loading history...
661
662
            // Install Configs
663
            $this->installConfigs($module);
0 ignored issues
show
Bug introduced by
It seems like $module can also be of type false; however, parameter $module of SystemModule::installConfigs() does only seem to accept Xoops\Core\Kernel\Handlers\XoopsModule, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

663
            $this->installConfigs(/** @scrutinizer ignore-type */ $module);
Loading history...
664
665
            // execute module specific update script if any
666
            $update_script = $module->getInfo('onUpdate');
667
            if (false != $update_script && trim($update_script) != '') {
668
                XoopsLoad::loadFile($xoops->path('modules/' . $mod . '/' . trim($update_script)));
669
                $func = 'xoops_module_update_' . $mod;
670
                if (function_exists($func)) {
671
                    $result = $func($module, $prev_version);
672
                    if (!$result) {
673
                        $this->trace[] = sprintf(XoopsLocale::EF_NOT_EXECUTED, $func);
674
                        $this->trace = array_merge($this->error, $module->getErrors());
675
                    } else {
676
                        $this->trace[] = sprintf(XoopsLocale::SF_EXECUTED, "<strong>{$func}</strong>");
677
                        $this->trace = array_merge($this->trace, $module->getMessages());
678
                    }
679
                }
680
            }
681
            $this->trace[] = sprintf(XoopsLocale::SF_UPDATED, '<strong>' . $module->getVar('name', 's') . '</strong>');
682
            return $module;
683
        }
684
    }
685
686
    /**
687
     * getTemplate
688
     *
689
     * @param string $dirname  module directory
690
     * @param string $template template name
691
     * @param string $type     template type - blocks, admin
692
     *
693
     * @return string
694
     */
695
    public function getTemplate($dirname, $template, $type = '')
696
    {
697
        $xoops = Xoops::getInstance();
698
        $ret = '';
699
        switch ($type) {
700
            case 'blocks':
701
            case 'admin':
702
                $path = $xoops->path('modules/' . $dirname . '/templates/' . $type . '/' . $template);
703
                break;
704
            default:
705
                $path = $xoops->path('modules/' . $dirname . '/templates/' . $template);
706
                break;
707
        }
708
        if (!XoopsLoad::fileExists($path)) {
709
            return $ret;
710
        } else {
711
            $lines = file($path);
712
        }
713
        if (!$lines) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $lines of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
714
            return $ret;
715
        }
716
        $count = count($lines);
717
        for ($i = 0; $i < $count; ++$i) {
718
            $ret .= str_replace("\n", "\r\n", str_replace("\r\n", "\n", $lines[$i]));
719
        }
720
        return $ret;
721
    }
722
723
    /**
724
     * installTemplates
725
     *
726
     * @param XoopsModule $module module context
727
     *
728
     * @return void
729
     */
730
    public function installTemplates(XoopsModule $module)
731
    {
732
        $xoops = Xoops::getInstance();
733
        $templates = $module->getInfo('templates');
734
        if (is_array($templates) && count($templates) > 0) {
735
            $this->trace[] = SystemLocale::MANAGING_TEMPLATES;
736
            $tplfile_handler = $xoops->getHandlerTplFile();
737
            foreach ($templates as $tpl) {
738
                $tpl['file'] = trim($tpl['file']);
739
                if (!in_array($tpl['file'], $this->template_delng)) {
740
                    $type = (isset($tpl['type']) ? $tpl['type'] : 'module');
741
                    $tpldata = $this->getTemplate($module->getVar('dirname'), $tpl['file'], $type);
0 ignored issues
show
Bug introduced by
It seems like $module->getVar('dirname') can also be of type string[]; however, parameter $dirname of SystemModule::getTemplate() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

741
                    $tpldata = $this->getTemplate(/** @scrutinizer ignore-type */ $module->getVar('dirname'), $tpl['file'], $type);
Loading history...
742
                    $tplfile = $tplfile_handler->create();
743
                    $tplfile->setVar('tpl_refid', $module->getVar('mid'));
744
                    $tplfile->setVar('tpl_lastimported', 0);
745
                    $tplfile->setVar('tpl_lastmodified', time());
746
747
                    if (preg_match("/\.css$/i", $tpl['file'])) {
748
                        $tplfile->setVar('tpl_type', 'css');
749
                    } else {
750
                        $tplfile->setVar('tpl_type', $type);
751
                    }
752
                    $tplfile->setVar('tpl_source', $tpldata);
753
                    $tplfile->setVar('tpl_module', $module->getVar('dirname'));
754
                    $tplfile->setVar('tpl_tplset', 'default');
755
                    $tplfile->setVar('tpl_file', $tpl['file']);
756
                    $tplfile->setVar('tpl_desc', $tpl['description']);
757
                    if (!$tplfile_handler->insertTpl($tplfile)) {
758
                        $this->trace[]['sub'] = '<span class="red">' . sprintf(
759
                            SystemLocale::EF_TEMPLATE_NOT_ADDED_TO_DATABASE,
760
                            '<strong>' . $tpl['file'] . '</strong>'
761
                        ) . '</span>';
762
                    } else {
763
                        $newid = $tplfile->getVar('tpl_id');
764
                        $this->trace[]['sub'] = sprintf(
765
                            SystemLocale::SF_TEMPLATE_ADDED,
766
                            '<strong>' . $tpl['file'] . '</strong>'
767
                        );
768
                        if ($module->getVar('dirname') === 'system') {
769
                            if (!$xoops->templateTouch($newid)) {
770
                                $this->trace[]['sub'] = '<span class="red">' . sprintf(
771
                                    SystemLocale::EF_TEMPLATE_NOT_RECOMPILED,
772
                                    '<strong>' . $tpl['file'] . '</strong>'
773
                                ) . '</span>';
774
                            } else {
775
                                $this->trace[]['sub'] = sprintf(
776
                                    SystemLocale::SF_TEMPLATE_RECOMPILED,
777
                                    '<strong>' . $tpl['file'] . '</strong>'
778
                                );
779
                            }
780
                        } else {
781
                            if ($xoops->config['template_set'] === 'default') {
782
                                if (!$xoops->templateTouch($newid)) {
783
                                    $this->trace[]['sub'] = '<span class="red">' . sprintf(
784
                                        SystemLocale::EF_TEMPLATE_NOT_RECOMPILED,
785
                                        '<strong>' . $tpl['file'] . '</strong>'
786
                                    ) . '</span>';
787
                                } else {
788
                                    $this->trace[]['sub'] = sprintf(
789
                                        SystemLocale::SF_TEMPLATE_RECOMPILED,
790
                                        '<strong>' . $tpl['file'] . '</strong>'
791
                                    );
792
                                }
793
                            }
794
                        }
795
                    }
796
                    unset($tpldata);
797
                } else {
798
                    $this->trace[]['sub'] = '<span class="red">' . sprintf(
799
                        SystemLocale::EF_TEMPLATE_NOT_DELETED,
800
                        '<strong>' . $tpl['file'] . '</strong>'
801
                    ) . '</span>';
802
                }
803
            }
804
        }
805
    }
806
807
    /**
808
     * deleteTemplates
809
     *
810
     * @param XoopsModule $module module context
811
     *
812
     * @return void
813
     */
814
    public function deleteTemplates(XoopsModule $module)
815
    {
816
        $xoops = Xoops::getInstance();
817
        $tplfile_handler = $xoops->getHandlerTplFile();
818
        $templates = $tplfile_handler->find('default', 'module', $module->getVar('mid'));
0 ignored issues
show
Bug introduced by
It seems like $module->getVar('mid') can also be of type string[]; however, parameter $refid of Xoops\Core\Kernel\Handle...sTplFileHandler::find() does only seem to accept null|string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

818
        $templates = $tplfile_handler->find('default', 'module', /** @scrutinizer ignore-type */ $module->getVar('mid'));
Loading history...
819
        if (is_array($templates) && count($templates) > 0) {
820
            $this->trace[] = SystemLocale::MANAGING_TEMPLATES;
821
            // delete template file entry in db
822
            /* @var $template XoopsTplFile */
823
            foreach ($templates as $template) {
824
                if (!$tplfile_handler->deleteTpl($template)) {
825
                    $this->template_delng[] = $template->getVar('tpl_file');
826
                }
827
            }
828
        }
829
    }
830
831
    /**
832
     * installBlocks
833
     *
834
     * @param XoopsModule $module module context
835
     *
836
     * @return void
837
     */
838
    public function installBlocks(XoopsModule $module)
839
    {
840
        $xoops = Xoops::getInstance();
841
        $blocks = $module->getInfo('blocks');
842
        $this->trace[] = SystemLocale::MANAGING_BLOCKS;
843
        $block_handler = $xoops->getHandlerBlock();
844
        $blockmodulelink_handler = $xoops->getHandlerBlockModuleLink();
845
        $tplfile_handler = $xoops->getHandlerTplFile();
846
        $showfuncs = array();
847
        $funcfiles = array();
848
        if (is_array($blocks) && count($blocks) > 0) {
849
            foreach ($blocks as $i => $block) {
850
                if (isset($block['show_func']) && $block['show_func'] != ''
851
                    && isset($block['file']) && $block['file'] != ''
852
                ) {
853
                    $showfuncs[] = $block['show_func'];
854
                    $funcfiles[] = $block['file'];
855
856
                    $criteria = new CriteriaCompo();
857
                    $criteria->add(new Criteria('mid', $module->getVar('mid')));
0 ignored issues
show
Bug introduced by
It seems like $module->getVar('mid') can also be of type string[]; however, parameter $value of Xoops\Core\Kernel\Criteria::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

857
                    $criteria->add(new Criteria('mid', /** @scrutinizer ignore-type */ $module->getVar('mid')));
Loading history...
858
                    $criteria->add(new Criteria('func_num', $i));
859
860
                    $block_obj = $block_handler->getObjects($criteria);
861
                    if (count($block_obj) == 0) {
862
                        $block_obj[0] = $block_handler->create();
863
                        $block_obj[0]->setVar('func_num', $i);
864
                        $block_obj[0]->setVar('mid', $module->getVar('mid'));
865
                        $block_obj[0]->setVar('name', addslashes($block['name']));
866
                        $block_obj[0]->setVar('title', addslashes($block['name']));
867
                        $block_obj[0]->setVar('side', 0);
868
                        $block_obj[0]->setVar('weight', 0);
869
                        $block_obj[0]->setVar('visible', 0);
870
                        $block_obj[0]->setVar(
871
                            'block_type',
872
                            ($module->getVar('dirname') === 'system')
873
                                ? XoopsBlock::BLOCK_TYPE_SYSTEM
874
                                : XoopsBlock::BLOCK_TYPE_MODULE
875
                        );
876
                        $block_obj[0]->setVar('isactive', 1);
877
                        $block_obj[0]->setVar('content', '');
878
                        $block_obj[0]->setVar('c_type', XoopsBlock::CUSTOM_HTML);
879
                        $block_obj[0]->setVar('dirname', $module->getVar('dirname'));
880
                        $block_obj[0]->setVar('options', isset($block['options']) ? $block['options'] : '');
881
                    }
882
                    $block_obj[0]->setVar('func_file', $block['file']);
883
                    $block_obj[0]->setVar('show_func', isset($block['show_func']) ? $block['show_func'] : '');
884
                    $block_obj[0]->setVar('edit_func', isset($block['edit_func']) ? $block['edit_func'] : '');
885
                    $template = $this->getTemplate($module->getVar('dirname'), $block['template'], 'blocks');
0 ignored issues
show
Bug introduced by
It seems like $module->getVar('dirname') can also be of type string[]; however, parameter $dirname of SystemModule::getTemplate() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

885
                    $template = $this->getTemplate(/** @scrutinizer ignore-type */ $module->getVar('dirname'), $block['template'], 'blocks');
Loading history...
886
                    $block_obj[0]->setVar('template', !empty($template) ? $block['template'] : '');
887
                    $block_obj[0]->setVar('last_modified', time());
888
889
                    if (!$block_handler->insert($block_obj[0])) {
890
                        $this->trace[]['sub'] = '<span class="red">' . sprintf(
891
                            XoopsLocale::EF_NOT_UPDATED,
892
                            $block_obj[0]->getVar('name')
893
                        ) . '</span>';
894
                    } else {
895
                        $this->trace[]['sub'] = sprintf(
896
                            SystemLocale::SF_BLOCK_UPDATED,
897
                            '<strong>' . $block_obj[0]->getVar('name')
898
                        ) . '</strong>' . sprintf(
899
                            SystemLocale::F_BLOCK_ID,
900
                            '<strong>' . $block_obj[0]->getVar('bid') . '</strong>'
901
                        );
902
903
                        if (0 == $blockmodulelink_handler->getCount(new Criteria('block_id', $block_obj[0]->getVar('bid')))) {
904
                            $blockmodulelink = $blockmodulelink_handler->create();
905
                            $blockmodulelink->setVar('block_id', $block_obj[0]->getVar('bid'));
906
                            $blockmodulelink->setVar('module_id', 0); //show on all pages
907
                            $blockmodulelink_handler->insert($blockmodulelink);
908
                        }
909
910
                        if ($template != '') {
911
                            $tplfile = $tplfile_handler->find('default', 'block', $block_obj[0]->getVar('bid'));
912
                            if (count($tplfile) == 0) {
913
                                $tplfile_new = $tplfile_handler->create();
914
                                $tplfile_new->setVar('tpl_module', $module->getVar('dirname'));
915
                                $tplfile_new->setVar('tpl_refid', $block_obj[0]->getVar('bid'));
916
                                $tplfile_new->setVar('tpl_tplset', 'default');
917
                                $tplfile_new->setVar('tpl_file', $block_obj[0]->getVar('template'));
918
                                $tplfile_new->setVar('tpl_type', 'block');
919
                            } else {
920
                                /* @var $tplfile_new XoopsTplFile */
921
                                $tplfile_new = $tplfile[0];
922
                                $tplfile_new->setVars($tplfile_new->getValues());
923
                            }
924
                            $tplfile_new->setVar('tpl_source', $template);
925
                            $tplfile_new->setVar('tpl_desc', $block['description']);
926
                            $tplfile_new->setVar('tpl_lastmodified', time());
927
                            $tplfile_new->setVar('tpl_lastimported', 0);
928
                            if (!$tplfile_handler->insertTpl($tplfile_new)) {
929
                                $this->trace[]['sub'] = '<span class="red">' . sprintf(
930
                                    SystemLocale::EF_TEMPLATE_NOT_UPDATED,
931
                                    '<strong>' . $block['template'] . '</strong>'
932
                                ) . '</span>';
933
                            } else {
934
                                $this->trace[]['sub'] = sprintf(
935
                                    SystemLocale::SF_TEMPLATE_UPDATED,
936
                                    '<strong>' . $block['template'] . '</strong>'
937
                                );
938
                                if ($module->getVar('dirname') === 'system') {
939
                                    if (!$xoops->templateTouch($tplfile_new->getVar('tpl_id'))) {
0 ignored issues
show
Bug introduced by
It seems like $tplfile_new->getVar('tpl_id') can also be of type string[]; however, parameter $tpl_id of Xoops::templateTouch() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

939
                                    if (!$xoops->templateTouch(/** @scrutinizer ignore-type */ $tplfile_new->getVar('tpl_id'))) {
Loading history...
940
                                        $this->trace[]['sub'] = '<span class="red">' . sprintf(
941
                                            SystemLocale::EF_TEMPLATE_NOT_RECOMPILED,
942
                                            '<strong>' . $block['template'] . '</strong>'
943
                                        ) . '</span>';
944
                                    } else {
945
                                        $this->trace[]['sub'] = sprintf(
946
                                            SystemLocale::SF_TEMPLATE_RECOMPILED,
947
                                            '<strong>' . $block['template'] . '</strong>'
948
                                        );
949
                                    }
950
                                } else {
951
                                    if ($xoops->config['template_set'] === 'default') {
952
                                        if (!$xoops->templateTouch($tplfile_new->getVar('tpl_id'))) {
953
                                            $this->trace[]['sub'] = '<span class="red">' . sprintf(
954
                                                SystemLocale::EF_TEMPLATE_NOT_RECOMPILED,
955
                                                '<strong>' . $block['template'] . '</strong>'
956
                                            ) . '</span>';
957
                                        } else {
958
                                            $this->trace[]['sub'] = sprintf(
959
                                                SystemLocale::SF_TEMPLATE_RECOMPILED,
960
                                                '<strong>' . $block['template'] . '</strong>'
961
                                            );
962
                                        }
963
                                    }
964
                                }
965
                            }
966
                        }
967
                    }
968
                }
969
            }
970
        }
971
        $blocks = $block_handler->getByModule($module->getVar('mid'));
972
        foreach ($blocks as $block) {
973
            /* @var $block XoopsBlock */
974
            if (!in_array($block->getVar('show_func'), $showfuncs)
975
                || !in_array($block->getVar('func_file'), $funcfiles)
976
            ) {
977
                if (!$block_handler->delete($block)) {
978
                    $this->trace[]['sub'] = '<span class="red">' . sprintf(
979
                        SystemLocale::EF_BLOCK_NOT_DELETED,
980
                        "<strong>" . $block->getVar('name') . "</strong>"
981
                    ) . sprintf(
982
                        SystemLocale::F_BLOCK_ID,
983
                        "<strong>" . $block->getVar('bid') . "</strong>"
984
                    ) . '</span>';
985
                } else {
986
                    $this->trace[]['sub'] = sprintf(
987
                        SystemLocale::SF_BLOCK_DELETED,
988
                        '<strong>' . $block->getVar('name') . '</strong>'
989
                    ) . '&nbsp;' . sprintf(
990
                        SystemLocale::F_BLOCK_ID,
991
                        '<strong>' . $block->getVar('bid') . '</strong>'
992
                    );
993
                    if ($block->getVar('template') != '') {
994
                        $tplfiles = $tplfile_handler->find(null, 'block', $block->getVar('bid'));
0 ignored issues
show
Bug introduced by
It seems like $block->getVar('bid') can also be of type string[]; however, parameter $refid of Xoops\Core\Kernel\Handle...sTplFileHandler::find() does only seem to accept null|string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

994
                        $tplfiles = $tplfile_handler->find(null, 'block', /** @scrutinizer ignore-type */ $block->getVar('bid'));
Loading history...
995
                        if (is_array($tplfiles)) {
996
                            /* @var $tplfile XoopsTplFile */
997
                            foreach ($tplfiles as $tplfile) {
998
                                if (!$tplfile_handler->deleteTpl($tplfile)) {
999
                                    $this->trace[]['sub'] = '<span class="red">'
1000
                                        . SystemLocale::E_BLOCK_TEMPLATE_DEPRECATED_NOT_REMOVED
1001
                                        . '(ID: <strong>' . $tplfile->getVar('tpl_id') . '</strong>)</span>';
1002
                                } else {
1003
                                    $this->trace[]['sub'] = sprintf(
1004
                                        SystemLocale::SF_BLOCK_TEMPLATE_DEPRECATED,
1005
                                        "<strong>" . $tplfile->getVar('tpl_file') . "</strong>"
1006
                                    );
1007
                                }
1008
                            }
1009
                        }
1010
                    }
1011
                }
1012
            }
1013
        }
1014
    }
1015
1016
    /**
1017
     * deleteBlocks
1018
     *
1019
     * @param XoopsModule $module module
1020
     *
1021
     * @return void
1022
     */
1023
    public function deleteBlocks(XoopsModule $module)
1024
    {
1025
        $xoops = Xoops::getInstance();
1026
        $block_handler = $xoops->getHandlerBlock();
1027
        $blocks = $block_handler->getByModule($module->getVar('mid'));
1028
        if (is_array($blocks) && count($blocks) > 0) {
1029
            $tplfile_handler = $xoops->getHandlerTplFile();
1030
            $this->trace[] = SystemLocale::MANAGING_BLOCKS;
1031
            /* @var $block XoopsBlock */
1032
            foreach ($blocks as $block) {
1033
                if (false === $block_handler->deleteBlock($block)) {
1034
                    $this->trace[]['sub'] = '<span class="red">' . sprintf(
1035
                        SystemLocale::EF_BLOCK_NOT_DELETED,
1036
                        "<strong>" . $block->getVar('name') . "</strong>"
1037
                    ) . sprintf(
1038
                        SystemLocale::F_BLOCK_ID,
1039
                        "<strong>" . $block->getVar('bid') . "</strong>"
1040
                    ) . '</span>';
1041
                } else {
1042
                    $this->trace[]['sub'] = sprintf(
1043
                        SystemLocale::SF_BLOCK_DELETED,
1044
                        "<strong>" . $block->getVar('name') . "</strong>"
1045
                    ) . sprintf(
1046
                        SystemLocale::F_BLOCK_ID,
1047
                        "<strong>" . $block->getVar('bid') . "</strong>"
1048
                    );
1049
                }
1050
                if ($block->getVar('template') != '') {
1051
                    $templates = $tplfile_handler->find(null, 'block', $block->getVar('bid'));
1052
                    /* @var $template XoopsTplFile */
1053
                    foreach ($templates as $template) {
1054
                        if (!$tplfile_handler->delete($template)) {
1055
                            $this->trace[]['sub'] = '<span class="red">' . sprintf(
1056
                                SystemLocale::EF_BLOCK_TEMPLATE_NOT_DELETED,
1057
                                $template->getVar('tpl_file')
1058
                            ) . sprintf(
1059
                                SystemLocale::F_TEMPLATE_ID,
1060
                                "<strong>" . $template->getVar('tpl_id') . "</strong>"
1061
                            ) . '</span>';
1062
                        } else {
1063
                            $this->trace[]['sub'] = sprintf(
1064
                                SystemLocale::SF_BLOCK_TEMPLATE_DELETED,
1065
                                "<strong>" . $template->getVar('tpl_file') . "</strong>"
1066
                            ) . sprintf(
1067
                                SystemLocale::F_TEMPLATE_ID,
1068
                                "<strong>" . $template->getVar('tpl_id') . "</strong>"
1069
                            );
1070
                        }
1071
                    }
1072
                    unset($templates);
1073
                }
1074
            }
1075
        }
1076
    }
1077
1078
    /**
1079
     * deleteConfigs
1080
     *
1081
     * @param XoopsModule $module module
1082
     *
1083
     * @return void
1084
     */
1085
    public function deleteConfigs(XoopsModule $module)
1086
    {
1087
        $xoops = Xoops::getInstance();
1088
1089
        $config_handler = $xoops->getHandlerConfig();
1090
        $configs = $config_handler->getConfigs(new Criteria('conf_modid', $module->getVar('mid')));
0 ignored issues
show
Bug introduced by
It seems like $module->getVar('mid') can also be of type string[]; however, parameter $value of Xoops\Core\Kernel\Criteria::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1090
        $configs = $config_handler->getConfigs(new Criteria('conf_modid', /** @scrutinizer ignore-type */ $module->getVar('mid')));
Loading history...
1091
        if (is_array($configs) && count($configs) > 0) {
1092
            $this->trace[] = SystemLocale::MANAGING_PREFERENCES;
1093
            /* @var $config XoopsConfigItem */
1094
            foreach ($configs as $config) {
1095
                if (!$config_handler->deleteConfig($config)) {
1096
                    $this->trace[]['sub'] = '<span class="red">'
1097
                        . SystemLocale::E_CONFIG_DATA_NOT_DELETED
1098
                        . sprintf(SystemLocale::F_CONFIG_ID, "<strong>" . $config->getVar('conf_id') . "</strong>")
1099
                        . '</span>';
1100
                    // save the name of config failed to delete for later use
1101
                    $this->config_delng[] = $config->getVar('conf_name');
1102
                } else {
1103
                    $this->config_old[$config->getVar('conf_name')]['value'] = $config->getVar('conf_value', 'N');
1104
                    $this->config_old[$config->getVar('conf_name')]['formtype'] = $config->getVar('conf_formtype');
1105
                    $this->config_old[$config->getVar('conf_name')]['valuetype'] = $config->getVar('conf_valuetype');
1106
                    $this->trace[]['sub'] = SystemLocale::S_CONFIG_DATA_DELETED
1107
                        . sprintf(SystemLocale::F_CONFIG_ID, "<strong>" . $config->getVar('conf_id') . "</strong>");
1108
                }
1109
            }
1110
        }
1111
    }
1112
1113
    /**
1114
     * installconfigs
1115
     *
1116
     * @param XoopsModule $module module being installed
1117
     *
1118
     * @return void
1119
     */
1120
    public function installConfigs(XoopsModule $module)
1121
    {
1122
        $xoops = Xoops::getInstance();
1123
        // now reinsert them with the new settings
1124
        $configs = $module->getInfo('config');
1125
        if (!is_array($configs)) {
1126
            $configs = array();
1127
        }
1128
1129
        $collector = new ConfigCollector($module, $configs);
1130
        $xoops->events()->triggerEvent('system.module.update.configs', $collector);
1131
1132
        if (is_array($configs) && count($configs) > 0) {
1133
            $this->trace[] = SystemLocale::MANAGING_PREFERENCES;
1134
            $config_handler = $xoops->getHandlerConfig();
1135
            $order = 0;
1136
            foreach ($configs as $config) {
1137
                // only insert ones that have been deleted previously with success
1138
                if (!in_array($config['name'], $this->config_delng)) {
1139
                    $confobj = $config_handler->createConfig();
1140
                    $confobj->setVar('conf_modid', $module->getVar('mid'));
1141
                    $confobj->setVar('conf_catid', 0);
1142
                    $confobj->setVar('conf_name', $config['name']);
1143
                    $confobj->setVar('conf_title', $config['title']);
1144
                    $confobj->setVar('conf_desc', $config['description']);
1145
                    $confobj->setVar('conf_formtype', $config['formtype']);
1146
                    $confobj->setVar('conf_valuetype', $config['valuetype']);
1147
                    if (isset($this->config_old[$config['name']]['value'])
1148
                        && $this->config_old[$config['name']]['formtype'] == $config['formtype']
1149
                        && $this->config_old[$config['name']]['valuetype'] == $config['valuetype']
1150
                    ) {
1151
                        // preserver the old value if any
1152
                        // form type and value type must be the same
1153
                        $confobj->setVar('conf_value', $this->config_old[$config['name']]['value']);
1154
                    } else {
1155
                        $confobj->setConfValueForInput($config['default']);
1156
                        //$confobj->setVar('conf_value', $config['default']);
1157
                    }
1158
                    $confobj->setVar('conf_order', $order);
1159
                    $confop_msgs = '';
1160
                    if (isset($config['options']) && is_array($config['options'])) {
1161
                        foreach ($config['options'] as $key => $value) {
1162
                            $confop = $config_handler->createConfigOption();
1163
                            $confop->setVar('confop_name', $key);
1164
                            $confop->setVar('confop_value', $value);
1165
                            $confobj->setConfOptions($confop);
1166
                            $confop_msgs .= '<br />&nbsp;&nbsp;&nbsp;&nbsp;';
1167
                            $confop_msgs .= SystemLocale::S_CONFIG_OPTION_ADDED;
1168
                            $confop_msgs .= '&nbsp;';
1169
                            $confop_msgs .= XoopsLocale::C_NAME;
1170
                            $confop_msgs .= ' <strong>'
1171
                                . \Xoops\Locale::translate($key, $module->getVar('dirname'))
0 ignored issues
show
Bug introduced by
It seems like $module->getVar('dirname') can also be of type string[]; however, parameter $dirname of Xoops\Locale::translate() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1171
                                . \Xoops\Locale::translate($key, /** @scrutinizer ignore-type */ $module->getVar('dirname'))
Loading history...
1172
                                . '</strong> ';
1173
                            $confop_msgs .= XoopsLocale::C_VALUE . ' <strong>' . $value . '</strong> ';
1174
                            unset($confop);
1175
                        }
1176
                    }
1177
                    ++$order;
1178
                    if (false != $config_handler->insertConfig($confobj)) {
1179
                        $this->trace[]['sub'] = sprintf(
1180
                            SystemLocale::SF_CONFIG_ADDED,
1181
                            "<strong>" . $config['name'] . "</strong>"
1182
                        ) . $confop_msgs;
1183
                    } else {
1184
                        $this->trace[]['sub'] = '<span class="red">'
1185
                            . sprintf(SystemLocale::EF_CONFIG_NOT_ADDED, "<strong>" . $config['name'] . "</strong>")
1186
                            . '</span>';
1187
                    }
1188
                    unset($confobj);
1189
                }
1190
            }
1191
            unset($configs);
1192
        }
1193
    }
1194
1195
    /**
1196
     * addTemporaryAutoloader
1197
     *
1198
     * Add an autoloader for the module being installed or updated.
1199
     * This makes the module's autoloaded classes available for use
1200
     * in onInstall/onUpdate scripts.
1201
     *
1202
     * @param XoopsModule $module module object here namespace is defined
1203
     *
1204
     * @return void
1205
     */
1206
    protected function addTemporaryAutoloader(XoopsModule $module) : void
1207
    {
1208
        $prefix = $module->getVar('namespace');
1209
        if (empty($prefix)) {
1210
            return;
1211
        }
1212
        $xoops = Xoops::getInstance();
1213
        $base_dir = $xoops->path('modules/' . $module->getVar('dirname') . '/src');
1214
        $loader = new Psr4ClassLoader;
1215
        $loader->register();
1216
        $loader->addNamespace($prefix, $base_dir);
0 ignored issues
show
Bug introduced by
It seems like $prefix can also be of type string[]; however, parameter $prefix of Xoops\Core\Psr4ClassLoader::addNamespace() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1216
        $loader->addNamespace(/** @scrutinizer ignore-type */ $prefix, $base_dir);
Loading history...
1217
    }
1218
}
1219