|
23 | 23 | * |
24 | 24 | */ |
25 | 25 |
|
| 26 | +use Xmf\Request; |
| 27 | + |
26 | 28 | $templateMain = 'modulebuilder_building.tpl'; |
27 | 29 |
|
28 | 30 | include __DIR__ . '/header.php'; |
29 | | -$op = \Xmf\Request::getString('op', 'default'); |
30 | | -$mid = \Xmf\Request::getInt('mod_id'); |
31 | | -$inroot_copy = \Xmf\Request::getInt('inroot_copy'); |
32 | | -$moduleObj = $helper->getHandler('Modules')->get($mid); |
33 | | -$cachePath = XOOPS_VAR_PATH . '/caches/modulebuilder_cache'; |
| 31 | +$op = Request::getString('op', 'default'); |
| 32 | +$mid = Request::getInt('mod_id'); |
| 33 | +$inroot_copy = Request::getInt('inroot_copy'); |
| 34 | +$testdata_restore = Request::getInt('testdata_restore'); |
| 35 | +$moduleObj = $helper->getHandler('Modules')->get($mid); |
| 36 | +$cachePath = XOOPS_VAR_PATH . '/caches/modulebuilder_cache'; |
34 | 37 | if (!is_dir($cachePath)) { |
35 | 38 | if (!mkdir($cachePath, 0777) && !is_dir($cachePath)) { |
36 | 39 | throw new \RuntimeException(sprintf('Directory "%s" was not created', $cachePath)); |
|
48 | 51 | switch ($op) { |
49 | 52 | case 'build': |
50 | 53 | $GLOBALS['xoopsTpl']->assign('navigation', $adminObject->displayNavigation('building.php')); |
| 54 | + $building = Modulebuilder\Building::getInstance(); |
| 55 | + $structure = Modulebuilder\Files\CreateStructure::getInstance(); |
| 56 | + $architecture = Modulebuilder\Files\CreateArchitecture::getInstance(); |
51 | 57 | // Get var module dirname |
52 | 58 | $moduleDirname = $moduleObj->getVar('mod_dirname'); |
| 59 | + if (1 === $testdata_restore) { |
| 60 | + // Directories for copy from |
| 61 | + $fromDir = XOOPS_ROOT_PATH . '/modules/' . mb_strtolower($moduleDirname) . '/testdata'; |
| 62 | + if (is_dir($fromDir)) { |
| 63 | + // Directories for copy to |
| 64 | + $toDir = TDMC_UPLOAD_TEMP_PATH . '/' . mb_strtolower($moduleDirname); |
| 65 | + $structure->isDir($toDir); |
| 66 | + $toDir .= '/testdata'; |
| 67 | + if (is_dir($toDir)) { |
| 68 | + $building->clearDir($toDir); |
| 69 | + } else { |
| 70 | + $structure->isDir($toDir); |
| 71 | + } |
| 72 | + $building->copyDir($fromDir, $toDir); |
| 73 | + } else { |
| 74 | + $testdata_restore = 0; |
| 75 | + } |
| 76 | + } |
| 77 | + |
53 | 78 | // Directories for copy from to |
54 | 79 | $fromDir = TDMC_UPLOAD_REPOSITORY_PATH . '/' . mb_strtolower($moduleDirname); |
55 | 80 | $toDir = XOOPS_ROOT_PATH . '/modules/' . mb_strtolower($moduleDirname); |
|
62 | 87 | } |
63 | 88 | } |
64 | 89 | // Structure |
65 | | - // include_once TDMC_CLASS_PATH . '/Files/Architecture.php'; |
66 | | - $handler = Modulebuilder\Files\CreateArchitecture::getInstance(); |
67 | 90 | // Creation of the structure of folders and files |
68 | | - $baseArchitecture = $handler->setBaseFoldersFiles($moduleObj); |
| 91 | + $baseArchitecture = $architecture->setBaseFoldersFiles($moduleObj); |
69 | 92 | if (false !== $baseArchitecture) { |
70 | 93 | $GLOBALS['xoopsTpl']->assign('base_architecture', true); |
71 | 94 | } else { |
72 | 95 | $GLOBALS['xoopsTpl']->assign('base_architecture', false); |
73 | 96 | } |
74 | 97 | // Get files |
75 | 98 | $build = []; |
76 | | - $files = $handler->setFilesToBuilding($moduleObj); |
| 99 | + $files = $architecture->setFilesToBuilding($moduleObj); |
77 | 100 | foreach ($files as $file) { |
78 | 101 | if ($file) { |
79 | 102 | $build['list'] = $file; |
|
83 | 106 | unset($build); |
84 | 107 |
|
85 | 108 | // Get common files |
86 | | - $resCommon = $handler->setCommonFiles($moduleObj); |
| 109 | + $resCommon = $architecture->setCommonFiles($moduleObj); |
87 | 110 | $build['list'] = _AM_MODULEBUILDER_BUILDING_COMMON; |
88 | 111 | $GLOBALS['xoopsTpl']->append('builds', $build); |
89 | 112 | unset($build); |
90 | 113 |
|
91 | | - |
92 | 114 | // Directory to saved all files |
93 | 115 | $building_directory = sprintf(_AM_MODULEBUILDER_BUILDING_DIRECTORY, $moduleDirname); |
94 | 116 |
|
95 | 117 | // Copy this module in root modules |
96 | 118 | if (1 === $inroot_copy) { |
97 | | - $building = Modulebuilder\Building::getInstance(); |
98 | 119 | if (isset($moduleDirname)) { |
99 | 120 | // Clear this module if it's in root/modules |
100 | 121 | // Warning: If you have an older operating module with the same name, |
|
107 | 128 | $building->copyDir($fromDir, $toDir); |
108 | 129 | $building_directory .= sprintf(_AM_MODULEBUILDER_BUILDING_DIRECTORY_INROOT, $toDir); |
109 | 130 | } |
110 | | - $GLOBALS['xoopsTpl']->assign('building_directory', $building_directory); |
| 131 | + if (1 === $testdata_restore) { |
| 132 | + // Directories for copy from to |
| 133 | + $fromDir = TDMC_UPLOAD_TEMP_PATH . '/' . mb_strtolower($moduleDirname) . '/testdata'; |
| 134 | + $toDir = XOOPS_ROOT_PATH . '/modules/' . mb_strtolower($moduleDirname) . '/testdata'; |
| 135 | + $building->copyDir($fromDir, $toDir); |
| 136 | + } |
| 137 | + |
| 138 | + $GLOBALS['xoopsTpl']->assign('building_directory', $building_directory); |
111 | 139 | break; |
112 | 140 | case 'default': |
113 | 141 | default: |
|
122 | 150 | $building = Modulebuilder\Building::getInstance(); |
123 | 151 | $form = $building->getForm(); |
124 | 152 | $GLOBALS['xoopsTpl']->assign('form', $form->render()); |
| 153 | + |
125 | 154 | break; |
126 | 155 | } |
127 | 156 | include __DIR__ . '/footer.php'; |
0 commit comments