Skip to content

Commit d71037c

Browse files
committed
- added check quality/inconsistences of module data before building
1 parent 76a8b65 commit d71037c

22 files changed

Lines changed: 614 additions & 160 deletions

_TODO.txt

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,29 @@ TODOs:
1111

1212
new xoops_confirm
1313

14-
catch error when notification selected but no status field exists
15-
16-
Broken files:
17-
Notification for broken files in xoops_version adapt?
18-
add initiate event when click on broken file
1914

2015

2116
Notifications:
22-
there are too much notification, which are not needed/working
23-
- reduce xoops_version.php to needed
24-
- adapt language/modinfo.php (make nice text of e.g.: Global newcategory notify caption)
17+
notification comments
2518

2619

2720
rate.php:
2821
this file currently is not rating
2922

3023

24+
Comment files
25+
are the comment files (CreateArchitecture.php line 533 ff) required?
26+
27+
28+
Permissions:
29+
check handling for different groups
30+
implement autoapprove
31+
32+
33+
Test:
34+
ändern auf testen, nicht bei building ausführen
35+
in user file, but no decision where (header?body?footer?)
36+
keine Doppelverwendung:header?body?footer?
3137

3238

3339
*****************************

admin/building.php

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,14 @@
2828
$templateMain = 'modulebuilder_building.tpl';
2929

3030
include __DIR__ . '/header.php';
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';
31+
$op = Request::getString('op', 'default');
32+
$mid = Request::getInt('mod_id');
33+
$inrootCopy = Request::getInt('inroot_copy');
34+
$testdataRestore = Request::getInt('testdata_restore');
35+
$checkData = Request::hasVar('check_data');
36+
$moduleObj = $helper->getHandler('Modules')->get($mid);
37+
38+
$cachePath = XOOPS_VAR_PATH . '/caches/modulebuilder_cache_';
3739
if (!is_dir($cachePath)) {
3840
if (!mkdir($cachePath, 0777) && !is_dir($cachePath)) {
3941
throw new \RuntimeException(sprintf('Directory "%s" was not created', $cachePath));
@@ -47,16 +49,40 @@
4749
if (!file_exists($indexFile = $cachePath . '/index.html')) {
4850
copy('index.html', $indexFile);
4951
}
52+
53+
if ($checkData > 0) {
54+
$op = 'check_data';
55+
}
5056
// Switch option
5157
switch ($op) {
58+
case 'check_data':
59+
$GLOBALS['xoopsTpl']->assign('navigation', $adminObject->displayNavigation('building.php'));
60+
$GLOBALS['xoopsTpl']->assign('modPathIcon16', TDMC_URL . '/' . $modPathIcon16);
61+
$checkdata = Modulebuilder\Files\CheckData::getInstance();
62+
63+
// check data for inconsistences
64+
$checkResults = [];
65+
$checkResults = $checkdata->getCheckPreBuilding($moduleObj);
66+
67+
if (count($checkResults) > 0) {
68+
//$GLOBALS['xoopsTpl']->assign('navigation', $adminObject->displayNavigation('building.php'));
69+
$GLOBALS['xoopsTpl']->assign('checkResults', $checkResults);
70+
} else {
71+
$GLOBALS['xoopsTpl']->assign('checkResultsNice', true);
72+
}
73+
74+
break;
5275
case 'build':
5376
$GLOBALS['xoopsTpl']->assign('navigation', $adminObject->displayNavigation('building.php'));
5477
$building = Modulebuilder\Building::getInstance();
5578
$structure = Modulebuilder\Files\CreateStructure::getInstance();
5679
$architecture = Modulebuilder\Files\CreateArchitecture::getInstance();
80+
$checkdata = Modulebuilder\Files\CheckData::getInstance();
5781
// Get var module dirname
5882
$moduleDirname = $moduleObj->getVar('mod_dirname');
59-
if (1 === $testdata_restore) {
83+
84+
//save test data of selected module before building new version
85+
if (1 === $testdataRestore) {
6086
// Directories for copy from
6187
$fromDir = XOOPS_ROOT_PATH . '/modules/' . mb_strtolower($moduleDirname) . '/testdata';
6288
if (is_dir($fromDir)) {
@@ -71,7 +97,7 @@
7197
}
7298
$building->copyDir($fromDir, $toDir);
7399
} else {
74-
$testdata_restore = 0;
100+
$testdataRestore = 0;
75101
}
76102
}
77103

@@ -115,7 +141,7 @@
115141
$building_directory = sprintf(_AM_MODULEBUILDER_BUILDING_DIRECTORY, $moduleDirname);
116142

117143
// Copy this module in root modules
118-
if (1 === $inroot_copy) {
144+
if (1 === $inrootCopy) {
119145
if (isset($moduleDirname)) {
120146
// Clear this module if it's in root/modules
121147
// Warning: If you have an older operating module with the same name,
@@ -128,11 +154,16 @@
128154
$building->copyDir($fromDir, $toDir);
129155
$building_directory .= sprintf(_AM_MODULEBUILDER_BUILDING_DIRECTORY_INROOT, $toDir);
130156
}
131-
if (1 === $testdata_restore) {
157+
if (1 === $testdataRestore) {
132158
// Directories for copy from to
133159
$fromDir = TDMC_UPLOAD_TEMP_PATH . '/' . mb_strtolower($moduleDirname) . '/testdata';
134160
$toDir = XOOPS_ROOT_PATH . '/modules/' . mb_strtolower($moduleDirname) . '/testdata';
135-
$building->copyDir($fromDir, $toDir);
161+
if (is_dir($toDir)) {
162+
$building->clearDir($toDir);
163+
}
164+
if (is_dir($fromDir)) {
165+
$building->copyDir($fromDir, $toDir);
166+
}
136167
}
137168

138169
$GLOBALS['xoopsTpl']->assign('building_directory', $building_directory);

assets/images/icons/16/error.png

821 Bytes
Loading

assets/images/icons/16/warning.png

543 Bytes
Loading

class/Building.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,15 @@ public function getForm($action = false)
6969
$mod_select->addOption($mod->getVar('mod_id'), $mod->getVar('mod_name'));
7070
}
7171
$form->addElement($mod_select, true);
72-
72+
7373
$form->addElement(new \XoopsFormRadioYN(_AM_MODULEBUILDER_MODULE_INROOT_COPY, 'inroot_copy', $helper->getConfig('inroot_copy')));
7474
$form->addElement(new \XoopsFormRadioYN(_AM_MODULEBUILDER_ADMIN_BUILD_TEST . _AM_MODULEBUILDER_ADMIN_BUILD_TEST_DESC, 'testdata_restore', 0));
7575

7676
$form->addElement(new \XoopsFormHidden('op', 'build'));
77-
$form->addElement(new \XoopsFormButton(_REQUIRED . ' <sup class="red bold">*</sup>', 'submit', _SUBMIT, 'submit'));
77+
$btnTray = new \XoopsFormElementTray(_REQUIRED . ' <sup class="red bold">*</sup>', '&nbsp;');
78+
$btnTray->addElement(new \XoopsFormButton('', 'submit', _SUBMIT, 'submit'));
79+
$btnTray->addElement(new \XoopsFormButton('', 'check_data', _AM_MODULEBUILDER_ADMIN_BUILD_CHECK, 'submit'));
80+
$form->addElement($btnTray);
7881

7982
return $form;
8083
}

class/Files/CheckData.php

Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
<?php
2+
3+
namespace XoopsModules\Modulebuilder\Files;
4+
5+
use XoopsModules\Modulebuilder;
6+
7+
/*
8+
You may not change or alter any portion of this comment or credits
9+
of supporting developers from this source code or any supporting source code
10+
which is considered copyrighted (c) material of the original comment or credit authors.
11+
12+
This program is distributed in the hope that it will be useful,
13+
but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15+
*/
16+
/**
17+
* modulebuilder module.
18+
*
19+
* @copyright XOOPS Project (https://xoops.org)
20+
* @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
21+
*
22+
* @since 2.5.0
23+
*
24+
* @author Txmod Xoops http://www.txmodxoops.org
25+
*
26+
*/
27+
28+
//include dirname(__DIR__) . '/autoload.php';
29+
30+
/**
31+
* Class CheckData.
32+
*/
33+
class CheckData
34+
{
35+
/**
36+
* @public function constructor class
37+
*
38+
* @param null
39+
*/
40+
public function __construct()
41+
{
42+
//parent::__construct();
43+
}
44+
45+
/**
46+
* @static function getInstance
47+
*
48+
* @param null
49+
*
50+
* @return Modulebuilder\Files\CreateArchitecture
51+
*/
52+
public static function getInstance()
53+
{
54+
static $instance = false;
55+
if (!$instance) {
56+
$instance = new self();
57+
}
58+
59+
return $instance;
60+
}
61+
62+
/**
63+
* @public function getCheckResult
64+
*
65+
* @param $module
66+
*/
67+
public function getCheckPreBuilding($module)
68+
{
69+
$cf = Modulebuilder\Files\CreateFile::getInstance();
70+
71+
$modId = $module->getVar('mod_id');
72+
$tables = $cf->getTableTables($modId);
73+
$errors = [];
74+
75+
foreach (array_keys($tables) as $t) {
76+
if (1 == $tables[$t]->getVar('table_broken')) {
77+
$tableId = $tables[$t]->getVar('table_id');
78+
$tableName = $tables[$t]->getVar('table_name');
79+
$fields = $cf->getTableFields($modId, $tableId);
80+
$fieldSatus = '';
81+
82+
foreach (array_keys($fields) as $f) {
83+
$fieldName = $fields[$f]->getVar('field_name');
84+
if (16 == $fields[$f]->getVar('field_element')) {
85+
$fieldSatus = $fieldName;
86+
}
87+
}
88+
// check whether each table with handling "broken" has also a field "status"
89+
if ('' == $fieldSatus) {
90+
$error = str_replace('%t', $tableName, _AM_MODULEBUILDER_CHECKPREBUILD_BROKEN1);
91+
$errors[] = ['tableName' => $tableName, 'icon' => 'error', 'info' => $error];
92+
}
93+
}
94+
}
95+
foreach (array_keys($tables) as $t) {
96+
$tableId = $tables[$t]->getVar('table_id');
97+
$tableName = $tables[$t]->getVar('table_name');
98+
$fields = $cf->getTableFields($modId, $tableId);
99+
100+
foreach (array_keys($fields) as $f) {
101+
$fieldName = $fields[$f]->getVar('field_name');
102+
// check fields for parameters
103+
if ($f > 0) {
104+
$fieldParams = (int)$fields[$f]->getVar('field_parent') + (int)$fields[$f]->getVar('field_admin') + (int)$fields[$f]->getVar('field_inlist') + (int)$fields[$f]->getVar('field_inform')
105+
+ (int)$fields[$f]->getVar('field_user') + (int)$fields[$f]->getVar('field_ihead') + (int)$fields[$f]->getVar('field_ibody') + (int)$fields[$f]->getVar('field_ifoot')
106+
+ (int)$fields[$f]->getVar('field_thead') + (int)$fields[$f]->getVar('field_tbody') + (int)$fields[$f]->getVar('field_tfoot') + (int)$fields[$f]->getVar('field_block')
107+
+ (int)$fields[$f]->getVar('field_main') + (int)$fields[$f]->getVar('field_search') + (int)$fields[$f]->getVar('field_required');
108+
if (0 == $fieldParams) {
109+
$error = str_replace(['%f', '%t'], [$fieldName, $tableName], _AM_MODULEBUILDER_CHECKPREBUILD_FIELDS1);
110+
$errors[] = ['tableName' => $tableName, 'icon' => 'error', 'info' => $error];
111+
}
112+
}
113+
}
114+
}
115+
116+
//check user file no usage in index or item
117+
foreach (array_keys($tables) as $t) {
118+
$tableId = $tables[$t]->getVar('table_id');
119+
$tableName = $tables[$t]->getVar('table_name');
120+
$fields = $cf->getTableFields($modId, $tableId);
121+
122+
foreach (array_keys($fields) as $f) {
123+
$fieldName = $fields[$f]->getVar('field_name');
124+
if (1 == $fields[$f]->getVar('field_user')) {
125+
// check fields for parameters
126+
if ($f > 0) {
127+
$fieldParams = (int)$fields[$f]->getVar('field_ihead') + (int)$fields[$f]->getVar('field_ibody') + (int)$fields[$f]->getVar('field_ifoot')
128+
+ (int)$fields[$f]->getVar('field_thead') + (int)$fields[$f]->getVar('field_tbody') + (int)$fields[$f]->getVar('field_tfoot');
129+
if (0 == $fieldParams) {
130+
$error = str_replace(['%f', '%t'], [$fieldName, $tableName], _AM_MODULEBUILDER_CHECKPREBUILD_FIELDS2);
131+
$errors[] = ['tableName' => $tableName, 'icon' => 'warning', 'info' => $error];
132+
}
133+
}
134+
}
135+
}
136+
}
137+
//check user file index multiple usage
138+
//check user file item multiple usage
139+
foreach (array_keys($tables) as $t) {
140+
$tableId = $tables[$t]->getVar('table_id');
141+
$tableName = $tables[$t]->getVar('table_name');
142+
$fields = $cf->getTableFields($modId, $tableId);
143+
144+
foreach (array_keys($fields) as $f) {
145+
$fieldName = $fields[$f]->getVar('field_name');
146+
if (1 == $fields[$f]->getVar('field_user')) {
147+
// check fields for parameters
148+
if ($f > 0) {
149+
$fieldParams = (int)$fields[$f]->getVar('field_ihead') + (int)$fields[$f]->getVar('field_ibody') + (int)$fields[$f]->getVar('field_ifoot');
150+
if ($fieldParams > 1) {
151+
$error = str_replace(['%f', '%t'], [$fieldName, $tableName], _AM_MODULEBUILDER_CHECKPREBUILD_FIELDS3);
152+
$errors[] = ['tableName' => $tableName, 'icon' => 'warning', 'info' => $error];
153+
}
154+
$fieldParams = (int)$fields[$f]->getVar('field_thead') + (int)$fields[$f]->getVar('field_tbody') + (int)$fields[$f]->getVar('field_tfoot');
155+
if ($fieldParams > 1) {
156+
$error = str_replace(['%f', '%t'], [$fieldName, $tableName], _AM_MODULEBUILDER_CHECKPREBUILD_FIELDS3);
157+
$errors[] = ['tableName' => $tableName, 'icon' => 'warning', 'info' => $error];
158+
}
159+
}
160+
}
161+
}
162+
}
163+
164+
//use in block but not field selected
165+
foreach (array_keys($tables) as $t) {
166+
$tableId = $tables[$t]->getVar('table_id');
167+
$tableName = $tables[$t]->getVar('table_name');
168+
$fields = $cf->getTableFields($modId, $tableId);
169+
$count = 0;
170+
if (1 == $tables[$t]->getVar('table_blocks')) {
171+
foreach (array_keys($fields) as $f) {
172+
$fieldName = $fields[$f]->getVar('field_name');
173+
if (1 == $fields[$f]->getVar('field_block')) {
174+
$count++;
175+
}
176+
}
177+
if (0 == $count) {
178+
$error = str_replace(['%f', '%t'], [$fieldName, $tableName], _AM_MODULEBUILDER_CHECKPREBUILD_BLOCK1);
179+
$errors[] = ['tableName' => $tableName, 'icon' => 'warning', 'info' => $error];
180+
}
181+
}
182+
}
183+
//use in block but not field date
184+
foreach (array_keys($tables) as $t) {
185+
$tableId = $tables[$t]->getVar('table_id');
186+
$tableName = $tables[$t]->getVar('table_name');
187+
$fields = $cf->getTableFields($modId, $tableId);
188+
$count = 0;
189+
if (1 == $tables[$t]->getVar('table_blocks')) {
190+
foreach (array_keys($fields) as $f) {
191+
$fieldName = $fields[$f]->getVar('field_name');
192+
if (15 == $fields[$f]->getVar('field_element') || 21 == $fields[$f]->getVar('field_element')) {
193+
$count++;
194+
}
195+
}
196+
if (0 == $count) {
197+
$error = str_replace(['%f', '%t'], [$fieldName, $tableName], _AM_MODULEBUILDER_CHECKPREBUILD_BLOCK2);
198+
$errors[] = ['tableName' => $tableName, 'icon' => 'warning', 'info' => $error];
199+
}
200+
}
201+
}
202+
203+
return $errors;
204+
}
205+
}

class/Files/CreateArchitecture.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,9 +339,6 @@ public function setFilesToBuilding($module)
339339
// Creation of notifications files
340340
if (1 === (int)$tables[$t]->getVar('table_notifications')) {
341341
$languageMailTpl = Modulebuilder\Files\Language\LanguageMailTpl::getInstance();
342-
// Language Mail Template New File
343-
$languageMailTpl->write($module, $table, $tableSoleName . '_new_notify.tpl');
344-
$ret[] = $languageMailTpl->render();
345342
// Language Mail Template Modify File
346343
$languageMailTpl->write($module, $table, $tableSoleName . '_modify_notify.tpl');
347344
$ret[] = $languageMailTpl->render();

class/Files/CreateXoopsCode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1787,7 +1787,7 @@ public function getXcCommonPagesDelete($language, $tableName, $tableSoleName, $f
17871787
if (!$admin && 1 == $tableNotifications) {
17881788
$contInsert .= $pc->getPhpCodeCommentLine('Event delete notification', null, $t . "\t\t");
17891789
$contInsert .= $pc->getPhpCodeArray('tags', [], false, $t . "\t\t");
1790-
$contInsert .= $xc->getXcEqualsOperator("\$tags['{$stuFieldMain}']", "\${$ccFieldMain}", '', $t . "\t\t");
1790+
$contInsert .= $xc->getXcEqualsOperator("\$tags['ITEM_NAME']", "\${$ccFieldMain}", '', $t . "\t\t");
17911791
$contInsert .= $xc->getXcXoopsHandler('notification', $t . "\t\t");
17921792
$contInsert .= $cf->getSimpleString("\$notificationHandler->triggerEvent('global', 0, 'global_delete', \$tags);", $t . "\t\t");
17931793
$contInsert .= $cf->getSimpleString("\$notificationHandler->triggerEvent('{$tableName}', \${$ccFieldId}, '{$tableSoleName}_delete', \$tags);", $t . "\t\t");

0 commit comments

Comments
 (0)