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); |
|
|
|
|
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')); |
|
|
|
|
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')); |
|
|
|
|
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|