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 XOOPS Project (https://xoops.org) |
11
|
|
|
* @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) |
12
|
|
|
* @since 2.5.9 |
13
|
|
|
* @author Michael Beck (aka Mamba) |
14
|
|
|
*/ |
15
|
|
|
|
16
|
|
|
use XoopsModules\Oledrion; |
17
|
|
|
use XoopsModules\Oledrion\Common; |
18
|
|
|
use XoopsModules\Oledrion\Utility; |
19
|
|
|
|
20
|
|
|
require_once dirname(dirname(dirname(__DIR__))) . '/include/cp_header.php'; |
21
|
|
|
require dirname(__DIR__) . '/preloads/autoloader.php'; |
22
|
|
|
|
23
|
|
|
$op = \Xmf\Request::getCmd('op', ''); |
24
|
|
|
|
25
|
|
|
$moduleDirName = basename(dirname(__DIR__)); |
26
|
|
|
$moduleDirNameUpper = mb_strtoupper($moduleDirName); |
27
|
|
|
|
28
|
|
|
$helper = Oledrion\Helper::getInstance(); |
29
|
|
|
// Load language files |
30
|
|
|
$helper->loadLanguage('common'); |
31
|
|
|
|
32
|
|
|
switch ($op) { |
33
|
|
|
case 'load': |
34
|
|
|
if (\Xmf\Request::hasVar('ok', 'REQUEST') && 1 == $_REQUEST['ok']) { |
35
|
|
|
if (!$GLOBALS['xoopsSecurity']->check()) { |
36
|
|
|
redirect_header('../admin/index.php', 3, implode(',', $GLOBALS['xoopsSecurity']->getErrors())); |
37
|
|
|
} |
38
|
|
|
loadSampleData(); |
39
|
|
|
} else { |
40
|
|
|
xoops_cp_header(); |
41
|
|
|
xoops_confirm(['ok' => 1, 'op' => 'load'], 'index.php', sprintf(constant('CO_' . $moduleDirNameUpper . '_' . 'ADD_SAMPLEDATA_OK')), constant('CO_' . $moduleDirNameUpper . '_' . 'CONFIRM'), true); |
42
|
|
|
xoops_cp_footer(); |
43
|
|
|
} |
44
|
|
|
break; |
45
|
|
|
case 'save': |
46
|
|
|
saveSampleData(); |
47
|
|
|
break; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
// XMF TableLoad for SAMPLE data |
51
|
|
|
|
52
|
|
|
function loadSampleData() |
53
|
|
|
{ |
54
|
|
|
global $xoopsConfig; |
55
|
|
|
$moduleDirName = basename(dirname(__DIR__)); |
56
|
|
|
$moduleDirNameUpper = mb_strtoupper($moduleDirName); |
57
|
|
|
|
58
|
|
|
$utility = new Oledrion\Utility(); |
59
|
|
|
$configurator = new Common\Configurator(); |
60
|
|
|
|
61
|
|
|
$tables = \Xmf\Module\Helper::getHelper($moduleDirName)->getModule()->getInfo('tables'); |
62
|
|
|
|
63
|
|
|
$language = 'english/'; |
64
|
|
|
if (is_dir(__DIR__ . '/' . $xoopsConfig['language'])) { |
65
|
|
|
$language = $xoopsConfig['language'] . '/'; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
foreach ($tables as $table) { |
69
|
|
|
$tabledata = \Xmf\Yaml::readWrapped($language . $table . '.yml'); |
70
|
|
|
\Xmf\Database\TableLoad::truncateTable($table); |
71
|
|
|
\Xmf\Database\TableLoad::loadTableFromArray($table, $tabledata); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
// --- COPY test folder files --------------- |
75
|
|
|
if (is_array($configurator->copyTestFolders) && count($configurator->copyTestFolders) > 0) { |
76
|
|
|
// $file = __DIR__ . '/../testdata/images/'; |
77
|
|
|
foreach (array_keys($configurator->copyTestFolders) as $i) { |
78
|
|
|
$src = $configurator->copyTestFolders[$i][0]; |
79
|
|
|
$dest = $configurator->copyTestFolders[$i][1]; |
80
|
|
|
$utility::rcopy($src, $dest); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
redirect_header('../admin/index.php', 1, constant('CO_' . $moduleDirNameUpper . '_' . 'SAMPLEDATA_SUCCESS')); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
function saveSampleData() |
87
|
|
|
{ |
88
|
|
|
global $xoopsConfig; |
89
|
|
|
$moduleDirName = basename(dirname(__DIR__)); |
90
|
|
|
$moduleDirNameUpper = mb_strtoupper($moduleDirName); |
91
|
|
|
|
92
|
|
|
$tables = \Xmf\Module\Helper::getHelper($moduleDirName)->getModule()->getInfo('tables'); |
93
|
|
|
|
94
|
|
|
$languageFolder = __DIR__ . '/' . $xoopsConfig['language']; |
95
|
|
|
if (!file_exists($languageFolder . '/')) { |
96
|
|
|
Utility::createFolder($languageFolder . '/'); |
97
|
|
|
} |
98
|
|
|
$exportFolder = $languageFolder . '/Exports-' . date('Y-m-d-H-i-s') . '/'; |
99
|
|
|
Utility::createFolder($exportFolder); |
100
|
|
|
|
101
|
|
|
foreach ($tables as $table) { |
102
|
|
|
\Xmf\Database\TableLoad::saveTableToYamlFile($table, $exportFolder . $table . '.yml'); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
redirect_header('../admin/index.php', 1, constant('CO_' . $moduleDirNameUpper . '_' . 'SAMPLEDATA_SUCCESS')); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
function exportSchema() |
109
|
|
|
{ |
110
|
|
|
$moduleDirName = basename(dirname(__DIR__)); |
111
|
|
|
$moduleDirNameUpper = mb_strtoupper($moduleDirName); |
|
|
|
|
112
|
|
|
|
113
|
|
|
try { |
114
|
|
|
// TODO set exportSchema |
115
|
|
|
// $migrate = new Oledrion\Migrate($moduleDirName); |
116
|
|
|
// $migrate->saveCurrentSchema(); |
117
|
|
|
// |
118
|
|
|
// redirect_header('../admin/index.php', 1, constant('CO_' . $moduleDirNameUpper . '_' . 'EXPORT_SCHEMA_SUCCESS')); |
119
|
|
|
} |
120
|
|
|
catch (\Exception $e) { |
|
|
|
|
121
|
|
|
exit(constant('CO_' . $moduleDirNameUpper . '_' . 'EXPORT_SCHEMA_ERROR')); |
|
|
|
|
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
} |
125
|
|
|
|