1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
You may not change or alter any portion of this comment or credits |
5
|
|
|
of supporting developers from this source code or any supporting source code |
6
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
7
|
|
|
|
8
|
|
|
This program is distributed in the hope that it will be useful, |
9
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
10
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Module: randomquote |
15
|
|
|
* |
16
|
|
|
* @category Module |
17
|
|
|
* @package randomquote |
18
|
|
|
* @author XOOPS Development Team <[email protected]> - <https://xoops.org> |
19
|
|
|
* @copyright {@link https://xoops.org/ XOOPS Project} |
20
|
|
|
* @license GPL 2.0 or later |
21
|
|
|
* @link https://xoops.org/ |
22
|
|
|
* @since 1.0.0 |
23
|
|
|
*/ |
24
|
|
|
|
25
|
|
|
use Xoopsmodules\randomquote; |
26
|
|
|
use Xoopsmodules\randomquote\common; |
27
|
|
|
|
28
|
|
|
require_once __DIR__ . '/../../../mainfile.php'; |
29
|
|
|
|
30
|
|
|
include __DIR__ . '/../preloads/autoloader.php'; |
31
|
|
|
|
32
|
|
|
$op = \Xmf\Request::getCmd('op', ''); |
33
|
|
|
|
34
|
|
|
switch ($op) { |
35
|
|
|
case 'load': |
36
|
|
|
loadSampleData(); |
37
|
|
|
break; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
// XMF TableLoad for SAMPLE data |
41
|
|
|
|
42
|
|
|
function loadSampleData() |
43
|
|
|
{ |
44
|
|
|
$moduleDirName = basename(dirname(__DIR__)); |
45
|
|
|
$helper = randomquote\Helper::getInstance(); |
46
|
|
|
$utility = new randomquote\Utility(); |
47
|
|
|
$configurator = new common\Configurator(); |
48
|
|
|
// Load language files |
49
|
|
|
$helper->loadLanguage('admin'); |
50
|
|
|
$helper->loadLanguage('modinfo'); |
51
|
|
|
$helper->loadLanguage('common'); |
52
|
|
|
$quotesData = \Xmf\Yaml::readWrapped('quotes.yml'); |
53
|
|
|
\Xmf\Database\TableLoad::truncateTable($moduleDirName . '_quotes'); |
54
|
|
|
\Xmf\Database\TableLoad::loadTableFromArray($moduleDirName . '_quotes', $quotesData); |
55
|
|
|
|
56
|
|
|
$categoryData = \Xmf\Yaml::readWrapped('category.yml'); |
57
|
|
|
\Xmf\Database\TableLoad::truncateTable($moduleDirName . '_category'); |
58
|
|
|
\Xmf\Database\TableLoad::loadTableFromArray($moduleDirName . '_category', $categoryData); |
59
|
|
|
|
60
|
|
|
// --- COPY test folder files --------------- |
61
|
|
View Code Duplication |
if (count($configurator->copyTestFolders) > 0) { |
|
|
|
|
62
|
|
|
// $file = __DIR__ . '/../testdata/images/'; |
63
|
|
|
foreach (array_keys($configurator->copyTestFolders) as $i) { |
64
|
|
|
$src = $configurator->copyTestFolders[$i][0]; |
65
|
|
|
$dest = $configurator->copyTestFolders[$i][1]; |
66
|
|
|
$utility::xcopy($src, $dest); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
redirect_header('../admin/index.php', 1, AM_RANDOMQUOTE_SAMPLEDATA_SUCCESS); |
70
|
|
|
} |
71
|
|
|
|
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.