Passed
Push — master ( 762245...66eec6 )
by Michael
02:15
created

loadSampleData()   A

Complexity

Conditions 5
Paths 4

Size

Total Lines 35
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
dl 0
loc 35
rs 9.3554
c 1
b 0
f 0
cc 5
nc 4
nop 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\Extcal;
19
use XoopsModules\Extcal\Common;
20
21
require dirname(dirname(dirname(__DIR__))) . '/mainfile.php';
22
include dirname(__DIR__) . '/preloads/autoloader.php';
23
$op = \Xmf\Request::getCmd('op', '');
0 ignored issues
show
Bug introduced by
The type Xmf\Request was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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        = Extcal\Helper::getInstance();
40
    $utility       = new Extcal\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');
0 ignored issues
show
Bug introduced by
The type Xmf\Module\Helper was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
52
53
    foreach ($tables as $table) {
54
        $tabledata = \Xmf\Yaml::readWrapped($table . '.yml');
0 ignored issues
show
Bug introduced by
The type Xmf\Yaml was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
55
        \Xmf\Database\TableLoad::truncateTable($table);
0 ignored issues
show
Bug introduced by
The type Xmf\Database\TableLoad was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
56
        \Xmf\Database\TableLoad::loadTableFromArray($table, $tabledata);
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
Bug introduced by
The function redirect_header was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

70
    /** @scrutinizer ignore-call */ 
71
    redirect_header('../admin/index.php', 1, constant('CO_' . $moduleDirNameUpper . '_' . 'SAMPLEDATA_SUCCESS'));
Loading history...
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'));
0 ignored issues
show
Bug introduced by
The function redirect_header was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

84
    /** @scrutinizer ignore-call */ 
85
    redirect_header('../admin/index.php', 1, constant('CO_' . $moduleDirNameUpper . '_' . 'SAMPLEDATA_SUCCESS'));
Loading history...
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);
0 ignored issues
show
Bug introduced by
The type Xmf\Database\Migrate was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
94
        $migrate->saveCurrentSchema();
95
96
        redirect_header('../admin/index.php', 1, constant('CO_' . $moduleDirNameUpper . '_' . 'EXPORT_SCHEMA_SUCCESS'));
0 ignored issues
show
Bug introduced by
The function redirect_header was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

96
        /** @scrutinizer ignore-call */ 
97
        redirect_header('../admin/index.php', 1, constant('CO_' . $moduleDirNameUpper . '_' . 'EXPORT_SCHEMA_SUCCESS'));
Loading history...
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