exportSchema()   A
last analyzed

Complexity

Conditions 2
Paths 6

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 8
nc 6
nop 0
dl 0
loc 13
rs 10
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
 * This program is distributed in the hope that it will be useful,
7
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9
 *
10
 * @copyright       The XOOPS Project http://sourceforge.net/projects/xoops/
11
 * @license         GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
12
 * @package
13
 * @since           2.5.9
14
 * @author          Michael Beck (aka Mamba)
15
 */
16
17
use XoopsModules\Soapbox;
18
use XoopsModules\Soapbox\Common;
19
20
require dirname(dirname(dirname(__DIR__))) . '/mainfile.php';
21
include dirname(__DIR__) . '/preloads/autoloader.php';
22
$op = \Xmf\Request::getCmd('op', '');
23
24
switch ($op) {
25
    case 'load':
26
        loadSampleData();
27
        break;
28
    case 'save':
29
        saveSampleData();
30
        break;
31
}
32
33
// XMF TableLoad for SAMPLE data
34
35
function loadSampleData()
36
{
37
    $moduleDirName      = basename(dirname(__DIR__));
38
    $moduleDirNameUpper = mb_strtoupper($moduleDirName);
39
    $helper             = Soapbox\Helper::getInstance();
40
    $utility            = new Soapbox\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
    //  ---  COPY test folder files ---------------
60
    if (is_array($configurator->copyTestFolders) && count($configurator->copyTestFolders) > 0) {
61
        //        $file = __DIR__ . '/../testdata/images/';
62
        foreach (array_keys($configurator->copyTestFolders) as $i) {
63
            $src  = $configurator->copyTestFolders[$i][0];
64
            $dest = $configurator->copyTestFolders[$i][1];
65
            $utility::rcopy($src, $dest);
66
        }
67
    }
68
69
    redirect_header('../admin/index.php', 1, constant('CO_' . $moduleDirNameUpper . '_' . 'SAMPLEDATA_SUCCESS'));
70
}
71
72
function saveSampleData()
73
{
74
    $moduleDirName      = basename(dirname(__DIR__));
75
    $moduleDirNameUpper = mb_strtoupper($moduleDirName);
76
77
    $tables = \Xmf\Module\Helper::getHelper($moduleDirName)->getModule()->getInfo('tables');
78
79
    foreach ($tables as $table) {
80
        \Xmf\Database\TableLoad::saveTableToYamlFile($table, $table . '_' . date('Y-m-d H-i-s') . '.yml');
81
    }
82
83
    redirect_header('../admin/index.php', 1, constant('CO_' . $moduleDirNameUpper . '_' . 'SAMPLEDATA_SUCCESS'));
84
}
85
86
function exportSchema()
87
{
88
    try {
89
        $moduleDirName      = basename(dirname(__DIR__));
90
        $moduleDirNameUpper = mb_strtoupper($moduleDirName);
91
92
        $migrate = new  \Xmf\Database\Migrate($moduleDirName);
93
        $migrate->saveCurrentSchema();
94
95
        redirect_header('../admin/index.php', 1, constant('CO_' . $moduleDirNameUpper . '_' . 'EXPORT_SCHEMA_SUCCESS'));
96
    }
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