Skip to content

Commit 38cd4d8

Browse files
authored
Merge pull request #12 from ggoffy/master
- added possibility to store/restore testdata of created module
2 parents 1b777ea + 0cff9ce commit 38cd4d8

21 files changed

Lines changed: 522 additions & 357 deletions

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Support
44
If you liked the modulebuilder module and thanks to the long process for giving the opportunity to the new module to be created in a moment, consider making a donation to <a href="https://xoops.org/modules/xdonations/" target="_blank" title="Donate to Xoops">Xoops.org</a>
55

6-
# ModuleBuilder version 1.91
6+
# ModuleBuilder version 3.x
77

88
[![Build Status](https://scrutinizer-ci.com/g/txmodxoops/modulebuilder/badges/build.png?b=master)](https://travis-ci.org/txmodxoops/modulebuilder)
99
[![Jenkins coverage](https://img.shields.io/jenkins/c/https/jenkins.qa.ubuntu.com/address-book-service-utopic-i386-ci.svg)](https://github.com/txmodxoops/modulebuilder)
@@ -29,9 +29,9 @@ Screenshot:
2929
Clear version
3030

3131
# Require:
32-
- XOOPS 2.5.8;
32+
- XOOPS 2.5.10;
3333
- XOOPS Admin 1.2;
34-
- PHP 5.3 or high;
34+
- PHP 7.3 or higher;
3535
- MySQL 5.5; -> Minimum Recommended Using InnoDB Version 5.1 or Later
3636

3737
# Adding
@@ -45,20 +45,20 @@ Clear version
4545
# Info
4646
ModuleBuilder is a module that create other basic modules for XOOPS CMS.
4747

48-
Tested with XOOPS 2.5.9, you can not use it with earlier versions, unless because you don't fit some core files in the background and after some tests.
48+
Tested with XOOPS 2.5.11, you can not use it with earlier versions, unless because you don't fit some core files in the background and after some tests.
4949

50-
That is ahead XOOPS versions, and goes to 2.6.0, you should download XOOPS 2.5.7.2 and use with this latest version.
50+
That is ahead XOOPS versions, and goes to 2.6.0, you should download XOOPS 2.5 and use with this latest version.
5151

52-
Therefore recommended not to use modulebuilder 1.91, with previous versions of XOOPS 2.5.7
52+
Therefore recommended not to use modulebuilder 3.x, with previous versions of XOOPS 2.5.10
5353

5454
# System - Tests
55-
PHP = 5.5.15, 5.6.19, 5.7.0
55+
PHP = 7.3, 7.4
5656

5757
MySQL = 5.6.20, 5.7.11
5858

5959
Apache = 2.4.10, 2.4.18
6060

61-
XOOPS = 2.5.7.1, 2.5.7.2, 2.5.8
61+
XOOPS = 2.5.11
6262

6363
Codeception = 2.0.13
6464
Selenium IDE = 2.9.0

admin/building.php

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,17 @@
2323
*
2424
*/
2525

26+
use Xmf\Request;
27+
2628
$templateMain = 'modulebuilder_building.tpl';
2729

2830
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';
3437
if (!is_dir($cachePath)) {
3538
if (!mkdir($cachePath, 0777) && !is_dir($cachePath)) {
3639
throw new \RuntimeException(sprintf('Directory "%s" was not created', $cachePath));
@@ -48,8 +51,30 @@
4851
switch ($op) {
4952
case 'build':
5053
$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();
5157
// Get var module dirname
5258
$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+
5378
// Directories for copy from to
5479
$fromDir = TDMC_UPLOAD_REPOSITORY_PATH . '/' . mb_strtolower($moduleDirname);
5580
$toDir = XOOPS_ROOT_PATH . '/modules/' . mb_strtolower($moduleDirname);
@@ -62,18 +87,16 @@
6287
}
6388
}
6489
// Structure
65-
// include_once TDMC_CLASS_PATH . '/Files/Architecture.php';
66-
$handler = Modulebuilder\Files\CreateArchitecture::getInstance();
6790
// Creation of the structure of folders and files
68-
$baseArchitecture = $handler->setBaseFoldersFiles($moduleObj);
91+
$baseArchitecture = $architecture->setBaseFoldersFiles($moduleObj);
6992
if (false !== $baseArchitecture) {
7093
$GLOBALS['xoopsTpl']->assign('base_architecture', true);
7194
} else {
7295
$GLOBALS['xoopsTpl']->assign('base_architecture', false);
7396
}
7497
// Get files
7598
$build = [];
76-
$files = $handler->setFilesToBuilding($moduleObj);
99+
$files = $architecture->setFilesToBuilding($moduleObj);
77100
foreach ($files as $file) {
78101
if ($file) {
79102
$build['list'] = $file;
@@ -83,18 +106,16 @@
83106
unset($build);
84107

85108
// Get common files
86-
$resCommon = $handler->setCommonFiles($moduleObj);
109+
$resCommon = $architecture->setCommonFiles($moduleObj);
87110
$build['list'] = _AM_MODULEBUILDER_BUILDING_COMMON;
88111
$GLOBALS['xoopsTpl']->append('builds', $build);
89112
unset($build);
90113

91-
92114
// Directory to saved all files
93115
$building_directory = sprintf(_AM_MODULEBUILDER_BUILDING_DIRECTORY, $moduleDirname);
94116

95117
// Copy this module in root modules
96118
if (1 === $inroot_copy) {
97-
$building = Modulebuilder\Building::getInstance();
98119
if (isset($moduleDirname)) {
99120
// Clear this module if it's in root/modules
100121
// Warning: If you have an older operating module with the same name,
@@ -107,7 +128,14 @@
107128
$building->copyDir($fromDir, $toDir);
108129
$building_directory .= sprintf(_AM_MODULEBUILDER_BUILDING_DIRECTORY_INROOT, $toDir);
109130
}
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);
111139
break;
112140
case 'default':
113141
default:
@@ -122,6 +150,7 @@
122150
$building = Modulebuilder\Building::getInstance();
123151
$form = $building->getForm();
124152
$GLOBALS['xoopsTpl']->assign('form', $form->render());
153+
125154
break;
126155
}
127156
include __DIR__ . '/footer.php';

class/Building.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ public function getForm($action = false)
7171
$form->addElement($mod_select, true);
7272

7373
$form->addElement(new \XoopsFormRadioYN(_AM_MODULEBUILDER_MODULE_INROOT_COPY, 'inroot_copy', $helper->getConfig('inroot_copy')));
74-
74+
$form->addElement(new \XoopsFormRadioYN(_AM_MODULEBUILDER_ADMIN_BUILD_TEST . _AM_MODULEBUILDER_ADMIN_BUILD_TEST_DESC, 'testdata_restore', 0));
75+
7576
$form->addElement(new \XoopsFormHidden('op', 'build'));
7677
$form->addElement(new \XoopsFormButton(_REQUIRED . ' <sup class="red bold">*</sup>', 'submit', _SUBMIT, 'submit'));
7778

class/Files/Admin/AdminBroken.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,14 @@ private function getAdminBrokenList($tables, $language, $t = '')
136136
}
137137
}
138138

139-
$ret .= $xc->getXcCriteriaCompo($critName, $t);
140-
$crit = $xc->getXcCriteria('', "'{$fieldSatus}'", 'Constants::STATUS_BROKEN', '', true);
141-
$ret .= $xc->getXcCriteriaAdd($critName, $crit, $t, "\n");
142-
$ret .= $xc->getXcHandlerCountClear($tableName . 'Count', $tableName, '$' . $critName, $t);
143-
$ret .= $xc->getXcXoopsTplAssign($tableName . '_count', "\${$tableName}Count", true, $t);
139+
$ret .= $xc->getXcCriteriaCompo($critName, $t);
140+
$constant = $xc->getXcGetConstants('STATUS_BROKEN');
141+
$crit = $xc->getXcCriteria('', "'{$fieldSatus}'", $constant, '', true);
142+
$ret .= $xc->getXcCriteriaAdd($critName, $crit, $t, "\n");
143+
$ret .= $xc->getXcHandlerCountClear($tableName . 'Count', $tableName, '$' . $critName, $t);
144+
$ret .= $xc->getXcXoopsTplAssign($tableName . '_count', "\${$tableName}Count", true, $t);
144145
$sprintf = $pc->getPhpCodeSprintf($language . 'BROKEN_RESULT', "'{$ucfTableName}'");
145-
$ret .= $xc->getXcXoopsTplAssign($tableName . '_result', $sprintf, true, $t);
146+
$ret .= $xc->getXcXoopsTplAssign($tableName . '_result', $sprintf, true, $t);
146147

147148
$ret .= $xc->getXcCriteriaSetStart($critName,'$start', $t);
148149
$ret .= $xc->getXcCriteriaSetLimit($critName,'$limit', $t);

class/Files/Blocks/BlocksFiles.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ private function getBlocksShow($moduleDirname, $tableName, $tableFieldname, $fie
127127
}
128128
}
129129
if ('' !== $fieldStatus) {
130-
$crit = $xc->getXcCriteria('', "'{$fieldStatus}'", 'Constants::PERM_GLOBAL_VIEW', '', true);
130+
$constant = $xc->getXcGetConstants('PERM_GLOBAL_VIEW');
131+
$crit = $xc->getXcCriteria('', "'{$fieldStatus}'", $constant, '', true);
131132
$critStatus .= $xc->getXcCriteriaAdd($critName, $crit, "\t\t\t");
132133
}
133134

class/Files/Classes/ClassFormElements.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ private function getXoopsFormDhtmlTextArea($language, $fieldName, $required = 'f
128128
$ccFieldName = $tf->getCamelCase($fieldName, false, true);
129129
$ret = $pc->getPhpCodeCommentLine('Form Editor', 'DhtmlTextArea ' . $ccFieldName, "\t\t");
130130
$ret .= $pc->getPhpCodeArray('editorConfigs', null, false, "\t\t");
131-
$getConfig = $xc->getXcGetConfig('editor_' . $rpFieldName);
131+
$getConfig = $xc->getXcGetConfig('editor_default');
132132
$configs = [
133133
'name' => "'{$fieldName}'",
134134
'value' => "\$this->getVar('{$fieldName}', 'e')",
@@ -620,17 +620,18 @@ private function getXoopsFormSelectStatus($language, $moduleDirname, $fieldName,
620620
{
621621
$tf = Modulebuilder\Files\CreateFile::getInstance();
622622
$pc = Modulebuilder\Files\CreatePhpCode::getInstance();
623+
$xc = Modulebuilder\Files\CreateXoopsCode::getInstance();
623624
$cxc = Modulebuilder\Files\Classes\ClassXoopsCode::getInstance();
624625
$ccFieldName = $tf->getCamelCase($fieldName, false, true);
625626
$languageShort = substr($language, 0, 4) . mb_strtoupper($moduleDirname) . '_';
626627
$t = "\t\t";
627628
$ret = $pc->getPhpCodeCommentLine('Form Select', 'Status ' . $ccFieldName, $t);
628629
$ret .= $cxc->getClassXoopsFormSelect($ccFieldName . 'Select', $language, $fieldName, "this->getVar('{$fieldName}')", null, '', false, $t);
629-
$ret .= $cxc->getClassAddOption($ccFieldName . 'Select', "Constants::STATUS_NONE, {$languageShort}STATUS_NONE", $t);
630-
$ret .= $cxc->getClassAddOption($ccFieldName . 'Select', "Constants::STATUS_OFFLINE, {$languageShort}STATUS_OFFLINE", $t);
631-
$ret .= $cxc->getClassAddOption($ccFieldName . 'Select', "Constants::STATUS_SUBMITTED, {$languageShort}STATUS_SUBMITTED", $t);
632-
$ret .= $cxc->getClassAddOption($ccFieldName . 'Select', "Constants::STATUS_APPROVED, {$languageShort}STATUS_APPROVED", $t);
633-
$ret .= $cxc->getClassAddOption($ccFieldName . 'Select', "Constants::STATUS_BROKEN, {$languageShort}STATUS_BROKEN", $t);
630+
$ret .= $cxc->getClassAddOption($ccFieldName . 'Select', $xc->getXcGetConstants('STATUS_NONE') . ", {$languageShort}STATUS_NONE", $t);
631+
$ret .= $cxc->getClassAddOption($ccFieldName . 'Select', $xc->getXcGetConstants('STATUS_OFFLINE') . ", {$languageShort}STATUS_OFFLINE", $t);
632+
$ret .= $cxc->getClassAddOption($ccFieldName . 'Select', $xc->getXcGetConstants('STATUS_SUBMITTED') . ", {$languageShort}STATUS_SUBMITTED", $t);
633+
$ret .= $cxc->getClassAddOption($ccFieldName . 'Select', $xc->getXcGetConstants('STATUS_APPROVED') . ", {$languageShort}STATUS_APPROVED", $t);
634+
$ret .= $cxc->getClassAddOption($ccFieldName . 'Select', $xc->getXcGetConstants('STATUS_BROKEN') . ", {$languageShort}STATUS_BROKEN", $t);
634635
$ret .= $cxc->getClassAddElement('form', "\${$ccFieldName}Select{$required}", $t);
635636

636637
return $ret;

0 commit comments

Comments
 (0)