Passed
Push — master ( be4646...73e318 )
by Michael
03:39
created

saveSampleData()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 6
nc 2
nop 0
dl 0
loc 12
rs 10
c 1
b 0
f 0
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
 * 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
 * @copyright       The XOOPS Project http://sourceforge.net/projects/xoops/
12
 * @license         GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
13
 * @package
14
 * @since           2.5.9
15
 * @author          Michael Beck (aka Mamba)
16
 */
17
18
use XoopsModules\Extgallery;
19
use XoopsModules\Extgallery\Common;
20
21
require dirname(dirname(dirname(__DIR__))) . '/mainfile.php';
22
include dirname(__DIR__) . '/preloads/autoloader.php';
23
$op = \Xmf\Request::getCmd('op', '');
24
25
switch ($op) {
26
    case 'load':
27
        loadSampleData();
28
        break;
29
    case 'save':
30
        saveSampleData();
31
        break;
32
}
33
34
// XMF TableLoad for SAMPLE data
35
36
function loadSampleData()
37
{
38
    $moduleDirName = basename(dirname(__DIR__));
39
    $helper        = Extgallery\Helper::getInstance();
40
    $utility       = new Extgallery\Utility();
41
    $configurator  = new Common\Configurator();
42
    // Load language files
43
    $helper->loadLanguage('admin');
44
    $helper->loadLanguage('modinfo');
45
    $helper->loadLanguage('common');
46
47
//    $items = \Xmf\Yaml::readWrapped('quotes_data.yml');
48
//    \Xmf\Database\TableLoad::truncateTable($moduleDirName . '_quotes');
49
//    \Xmf\Database\TableLoad::loadTableFromArray($moduleDirName . '_quotes', $items);
50
51
    $tables = \Xmf\Module\Helper::getHelper($moduleDirName)->getModule()->getInfo('tables');
52
53
    foreach ($tables as $table) {
54
        $tabledata = \Xmf\Yaml::readWrapped($table . '.yml');
55
        \Xmf\Database\TableLoad::truncateTable($table);
56
        \Xmf\Database\TableLoad::loadTableFromArray($table, $tabledata);
0 ignored issues
show
Bug introduced by
It seems like $tabledata can also be of type boolean; however, parameter $data of Xmf\Database\TableLoad::loadTableFromArray() 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

56
        \Xmf\Database\TableLoad::loadTableFromArray($table, /** @scrutinizer ignore-type */ $tabledata);
Loading history...
57
    }
58
59
60
    //  ---  COPY test folder files ---------------
61
    if (is_array ($configurator->copyTestFolders) && 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::rcopy($src, $dest);
67
        }
68
    }
69
70
    redirect_header('../admin/index.php', 1, constant('CO_' . $moduleDirNameUpper . '_' . 'SAMPLEDATA_SUCCESS'));
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $moduleDirNameUpper does not exist. Did you maybe mean $moduleDirName?
Loading history...
71
}
72
73
function saveSampleData()
74
{
75
    $moduleDirName      = basename(dirname(__DIR__));
76
    $moduleDirNameUpper = strtoupper($moduleDirName);
77
78
    $tables = \Xmf\Module\Helper::getHelper($moduleDirName)->getModule()->getInfo('tables');
79
80
    foreach ($tables as $table) {
81
        \Xmf\Database\TableLoad::saveTableToYamlFile($table, $table . '_' . date("Y-m-d H-i-s") . '.yml');
82
    }
83
84
    redirect_header('../admin/index.php', 1, constant('CO_' . $moduleDirNameUpper . '_' . 'SAMPLEDATA_SUCCESS'));
85
}
86
87
function exportSchema()
88
{
89
    try {
90
        $moduleDirName      = basename(dirname(__DIR__));
91
        $moduleDirNameUpper = strtoupper($moduleDirName);
92
93
        $migrate = new  \Xmf\Database\Migrate($moduleDirName);
94
        $migrate->saveCurrentSchema();
95
96
        redirect_header('../admin/index.php', 1, constant('CO_' . $moduleDirNameUpper . '_' . 'EXPORT_SCHEMA_SUCCESS'));
97
    } catch (\Exception $e) {
98
        exit(constant('CO_' . $moduleDirNameUpper . '_' . 'EXPORT_SCHEMA_ERROR'));
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
Comprehensibility Best Practice introduced by
The variable $moduleDirNameUpper does not seem to be defined for all execution paths leading up to this point.
Loading history...
99
    }
100
}
101