XoopsModules25x /
tdmdownloads
| 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\Tdmdownloads; |
||
| 19 | use XoopsModules\Tdmdownloads\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 = Tdmdownloads\Helper::getInstance(); |
||
| 40 | $utility = new Tdmdownloads\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
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')); |
||
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
| 70 | } |
||
| 71 | |||
| 72 | function saveSampleData() |
||
| 73 | { |
||
| 74 | $moduleDirName = basename(dirname(__DIR__)); |
||
| 75 | $moduleDirNameUpper = 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 = 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
Comprehensibility
Best Practice
introduced
by
|
|||
| 99 | } |
||
| 100 | } |
||
| 101 |