Skip to content

Commit eee9bc8

Browse files
committed
added devtool for removing prefix from table field names
1 parent 8ba8594 commit eee9bc8

File tree

4 files changed

+41
-19
lines changed

4 files changed

+41
-19
lines changed

admin/devtools.php

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -176,16 +176,25 @@
176176
break;
177177
case 'remove_prefix':
178178
$modName = Request::getString('rp_module');
179+
$rpDest = Request::getInt('rp_dest');
179180
if ('' === $modName) {
180181
\redirect_header('devtools.php', 3, \_AM_MODULEBUILDER_DEVTOOLS_INVALID_MOD);
181182
}
182183
$src_path = \XOOPS_ROOT_PATH . '/modules/' . $modName;
183-
$dst_path = TDMC_UPLOAD_PATH . '/devtools/remove_prefix/';
184-
@\mkdir($dst_path);
185-
$dst_path = TDMC_UPLOAD_PATH . '/devtools/remove_prefix/' . $modName;
186-
@\mkdir($dst_path);
187184

188-
Devtools::function_removeprefix($src_path, $src_path, $modName);
185+
if (1 === $rpDest) {
186+
$dst_path = TDMC_UPLOAD_PATH . '/devtools/remove_prefix/';
187+
if (!\mkdir($dst_path) && !\is_dir($dst_path)) {
188+
\redirect_header('devtools.php', 3, \_AM_MODULEBUILDER_DEVTOOLS_RP_ERROR);
189+
}
190+
$dst_path = TDMC_UPLOAD_PATH . '/devtools/remove_prefix/' . $modName;
191+
if (!\mkdir($dst_path) && !\is_dir($dst_path)) {
192+
\redirect_header('devtools.php', 3, \_AM_MODULEBUILDER_DEVTOOLS_RP_ERROR);
193+
}
194+
} else {
195+
$dst_path = $src_path;
196+
}
197+
Devtools::function_removeprefix($src_path, $dst_path, $modName);
189198
\redirect_header('devtools.php', 3, \_AM_MODULEBUILDER_DEVTOOLS_RP_SUCCESS);
190199
break;
191200
case 'list':
@@ -205,8 +214,8 @@
205214
$GLOBALS['xoopsTpl']->assign('tab_form', $tab_form->render());
206215

207216
$dst_path = TDMC_UPLOAD_PATH . '/devtools/remove_prefix/';
208-
$GLOBALS['xoopsTpl']->assign('rp_desc', \str_replace('%s', $dst_path, \_AM_MODULEBUILDER_DEVTOOLS_RP_DESC));
209-
$tab_form = Devtools::getFormModulesRemovePrefix();
217+
$GLOBALS['xoopsTpl']->assign('rp_desc', \_AM_MODULEBUILDER_DEVTOOLS_RP_DESC);
218+
$tab_form = Devtools::getFormModulesRemovePrefix($dst_path);
210219
$GLOBALS['xoopsTpl']->assign('rp_form', $tab_form->render());
211220

212221
$GLOBALS['xoopsTpl']->assign('devtools_list', true);

class/Devtools.php

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,28 +71,32 @@ public static function function_removeprefix($src_path, $dst_path, $moduleDirNam
7171
$crFields->add(new \Criteria('field_tid', $tid));
7272
$fieldsAll = $helper->getHandler('Fields')->getAll($crFields);
7373
foreach (\array_keys($fieldsAll) as $k) {
74-
$fieldName = $fieldsAll[$k]->getVar('field_name');
74+
$fieldName = $fieldsAll[$k]->getVar('field_name');
75+
$rpFieldName = '';
7576
if (\mb_strpos($fieldName, '_')) {
7677
$str = \mb_strpos($fieldName, '_');
7778
if (false !== $str) {
7879
$rpFieldName = \mb_substr($fieldName, $str + 1, \mb_strlen($fieldName));
7980
}
8081
}
81-
// for getVar, setVar,....
82-
$patKeys[] = "'" . $fieldName . "'";
82+
// for getVar, setVar, forms, ....
83+
$patKeys[] = "'" . $fieldName . "'";
8384
$patValues[] = "'" . $rpFieldName . "'";
84-
$patKeys[] = 'showImgSelected(\"imglabel_' . $fieldName . '\",';
85+
$patKeys[] = 'showImgSelected(\"imglabel_' . $fieldName . '\",';
8586
$patValues[] = 'showImgSelected(\"imglabel_' . $rpFieldName . '\",';
86-
$patKeys[] = '\"' . $fieldName . '\",';
87+
$patKeys[] = '\"' . $fieldName . '\",';
8788
$patValues[] = '\"' . $rpFieldName . '\",';
88-
$patKeys[] = "id='imglabel_" . $fieldName . "' alt=";
89+
$patKeys[] = "id='imglabel_" . $fieldName . "' alt=";
8990
$patValues[] = "id='imglabel_" . $rpFieldName . "' alt=";
90-
$patKeys[] = "sort = '" . $fieldName . ' ASC,';
91+
$patKeys[] = "sort = '" . $fieldName . ' ASC,';
9192
$patValues[] = "sort = '" . $rpFieldName . ' ASC,';
92-
$patKeys[] = 'ASC, ' . $fieldName . "', \$order";
93+
$patKeys[] = 'ASC, ' . $fieldName . "', \$order";
9394
$patValues[] = 'ASC, ' . $rpFieldName . "', \$order";
95+
//clone feature
96+
$patKeys[] = "'" . $fieldName . "_source'";
97+
$patValues[] = "'" . $rpFieldName . "_source'";
9498
// for tpl files
95-
if ($rpFieldName=='id') {
99+
if ($rpFieldName === 'id') {
96100
$patKeys[] = 'op=edit&' . $fieldName . '=';
97101
$patValues[] = 'op=edit&' . $rpFieldName . '=';
98102
$patKeys[] = 'op=show&' . $fieldName . '=';
@@ -582,7 +586,7 @@ public static function getFormModulesTab($action = false)
582586
* @param bool $action
583587
* @return \XoopsSimpleForm
584588
*/
585-
public static function getFormModulesRemovePrefix($action = false)
589+
public static function getFormModulesRemovePrefix($dst_path, $action = false)
586590
{
587591
if (!$action) {
588592
$action = $_SERVER['REQUEST_URI'];
@@ -599,6 +603,10 @@ public static function getFormModulesRemovePrefix($action = false)
599603
$modulesSelect->addOption($mod, $mod);
600604
}
601605
$form->addElement($modulesSelect, true);
606+
$destradioSelect = new \XoopsFormRadio(\_AM_MODULEBUILDER_DEVTOOLS_RP_DEST, 'rp_dest', 1);
607+
$destradioSelect->addOption('1', \str_replace('%s', $dst_path, \_AM_MODULEBUILDER_DEVTOOLS_RP_DEST1));
608+
$destradioSelect->addOption('2', \_AM_MODULEBUILDER_DEVTOOLS_RP_DEST2);
609+
$form->addElement($destradioSelect);
602610
// To Save
603611
$form->addElement(new \XoopsFormHidden('op', 'remove_prefix'));
604612
$form->addElement(new \XoopsFormButtonTray('', \_SUBMIT, 'submit', '', false));

docs/changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
- create nicer mysql.sql (goffy)
55
- added trailing '_text' for output of prepared text (goffy)
66
- fixed bugs with foreach in tpl caused by singular table names (goffy)
7+
- added devtool for removing prefix from table field names (mamba/goffy)
78

89
<h5>3.7.0 Alpha [2023-07-06]</h5> Dev: XOOPS 2.5.11 RC2, PHP 8.0
910
- implemented smarty 3 (zivXP/goffy)

language/english/admin.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,8 +466,12 @@
466466
\define('_AM_MODULEBUILDER_DEVTOOLS_TAB_SUCCESS', 'Function replace tabs successfully added to copy of module');
467467
\define('_AM_MODULEBUILDER_DEVTOOLS_RP', 'Remove prefix from table field names');
468468
\define('_AM_MODULEBUILDER_DEVTOOLS_RP_MODULE', 'Select module to remove prefix');
469-
\define('_AM_MODULEBUILDER_DEVTOOLS_RP_DESC', 'This tool creates a copy of selected module in %s and remove prefix from table field names');
470-
\define('_AM_MODULEBUILDER_DEVTOOLS_RP_SUCCESS', 'Function remove prefix tabs successfully added to copy of module');
469+
\define('_AM_MODULEBUILDER_DEVTOOLS_RP_DESC', 'This tool removes prefix from table field names');
470+
\define('_AM_MODULEBUILDER_DEVTOOLS_RP_DEST', 'Destination');
471+
\define('_AM_MODULEBUILDER_DEVTOOLS_RP_DEST1', 'Create a copy of selected module in %s');
472+
\define('_AM_MODULEBUILDER_DEVTOOLS_RP_DEST2', 'Overwrite original files');
473+
\define('_AM_MODULEBUILDER_DEVTOOLS_RP_SUCCESS', 'Function remove prefix from table field names successfully added to copy of module');
474+
\define('_AM_MODULEBUILDER_DEVTOOLS_RP_ERROR', 'Error occured when removing prefix from table field names');
471475
// -------------------- IMPORT MODULE -----------------------------------
472476

473477
\define('_AM_MODULEBUILDER_MODULES_IMPORT', 'Import Module');

0 commit comments

Comments
 (0)