Skip to content

Commit 7db2ad5

Browse files
committed
- added save/load group permissions to sample data
1 parent bc5a960 commit 7db2ad5

178 files changed

Lines changed: 10991 additions & 6 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

commonfiles/testdata/index.php

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,18 @@ function loadSampleData()
6767
$language = $xoopsConfig['language'] . '/';
6868
}
6969

70+
// load module tables
7071
foreach ($tables as $table) {
7172
$tabledata = \Xmf\Yaml::readWrapped($language . $table . '.yml');
7273
\Xmf\Database\TableLoad::truncateTable($table);
7374
\Xmf\Database\TableLoad::loadTableFromArray($table, $tabledata);
7475
}
76+
77+
// load permissions
78+
$table = 'group_permission';
79+
$tabledata = \Xmf\Yaml::readWrapped($language . $table . '.yml');
80+
$mid = \Xmf\Module\Helper::getHelper($moduleDirName)->getModule()->getVar('mid');
81+
loadTableFromArrayWithReplace($table, $tabledata, 'gperm_modid', $mid);
7582

7683
// --- COPY test folder files ---------------
7784
if (is_array($configurator->copyTestFolders) && count($configurator->copyTestFolders) > 0) {
@@ -103,9 +110,17 @@ function saveSampleData()
103110
$exportFolder = $languageFolder . '/Exports-' . date('Y-m-d-H-i-s') . '/';
104111
Utility::createFolder($exportFolder);
105112

113+
// save module tables
106114
foreach ($tables as $table) {
107115
\Xmf\Database\TableLoad::saveTableToYamlFile($table, $exportFolder . $table . '.yml');
108116
}
117+
118+
// save permissions
119+
$criteria = new \CriteriaCompo();
120+
$criteria->add(new \Criteria('gperm_modid', \Xmf\Module\Helper::getHelper($moduleDirName)->getModule()->getVar('mid')));
121+
$skipColumns[] = 'gperm_id';
122+
\Xmf\Database\TableLoad::saveTableToYamlFile('group_permission', $exportFolder . 'group_permission.yml', $criteria, $skipColumns);
123+
unset($criteria);
109124

110125
// --- COPY test folder files ---------------
111126
if (is_array($configurator->copyTestFolders) && count($configurator->copyTestFolders) > 0) {
@@ -135,3 +150,58 @@ function exportSchema()
135150
}
136151

137152
}
153+
154+
/**
155+
* loadTableFromArrayWithReplace
156+
*
157+
* @param string $table value with should be used insead of original value of $search
158+
*
159+
* @param array $data array of rows to insert
160+
* Each element of the outer array represents a single table row.
161+
* Each row is an associative array in 'column' => 'value' format.
162+
* @param string $search name of column for which the value should be replaced
163+
* @param $replace
164+
* @return int number of rows inserted
165+
*/
166+
function loadTableFromArrayWithReplace($table, $data, $search, $replace)
167+
{
168+
/** @var \XoopsDatabase */
169+
$db = \XoopsDatabaseFactory::getDatabaseConnection();
170+
171+
$prefixedTable = $db->prefix($table);
172+
$count = 0;
173+
174+
$sql = 'DELETE FROM ' . $prefixedTable . ' WHERE `' . $search . '`=' . $db->quote($replace);
175+
176+
$result = $db->queryF($sql);
177+
178+
foreach ($data as $row) {
179+
$insertInto = 'INSERT INTO ' . $prefixedTable . ' (';
180+
$valueClause = ' VALUES (';
181+
$first = true;
182+
foreach ($row as $column => $value) {
183+
if ($first) {
184+
$first = false;
185+
} else {
186+
$insertInto .= ', ';
187+
$valueClause .= ', ';
188+
}
189+
190+
$insertInto .= $column;
191+
if ($search === $column) {
192+
$valueClause .= $db->quote($replace);
193+
} else {
194+
$valueClause .= $db->quote($value);
195+
}
196+
}
197+
198+
$sql = $insertInto . ') ' . $valueClause . ')';
199+
200+
$result = $db->queryF($sql);
201+
if (false !== $result) {
202+
++$count;
203+
}
204+
}
205+
206+
return $count;
207+
}

docs/changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
- added permissions class and permissions handler (goffy)
1717
- cosmetics (goffy)
1818
- fixed bugs in getXoopsFormSelectFile and getClassGetTableSolenameById (goffy)
19+
- added save/load group permissions to sample data (goffy)
1920

2021
<h5>3.01 Alpha 2 [WORK IN PROGRESS - NOT RELEASED]</h5> Dev: XOOPS 2.5.11, PHP 7.4.2
2122
<hr>

testdata/english/tdmcreate_fields.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,3 +698,28 @@
698698
field_main: '0'
699699
field_search: '0'
700700
field_required: '0'
701+
-
702+
field_id: '29'
703+
field_mid: '1'
704+
field_tid: '3'
705+
field_order: '15'
706+
field_name: tf_selectfile
707+
field_type: '14'
708+
field_value: '100'
709+
field_attribute: '1'
710+
field_null: '2'
711+
field_default: ''
712+
field_key: '1'
713+
field_element: '11'
714+
field_parent: '0'
715+
field_admin: '1'
716+
field_inlist: '1'
717+
field_inform: '1'
718+
field_user: '0'
719+
field_thead: '0'
720+
field_tbody: '0'
721+
field_tfoot: '0'
722+
field_block: '0'
723+
field_main: '0'
724+
field_search: '0'
725+
field_required: '0'

testdata/english/tdmcreate_modules.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
-
22
mod_id: '1'
3-
mod_name: 'My Module'
4-
mod_dirname: mymodule
3+
mod_name: 'My Module 2'
4+
mod_dirname: mymodule2
55
mod_version: '1.0'
66
mod_since: '1.0'
77
mod_min_php: '7.0'

testdata/english/tdmcreate_tables.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
table_name: testfields
6666
table_solename: testfield
6767
table_fieldname: tf
68-
table_nbfields: '14'
68+
table_nbfields: '15'
6969
table_order: '1'
7070
table_image: alert.png
7171
table_autoincrement: '1'

testdata/german/tdmcreate_fields.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,3 +698,28 @@
698698
field_main: '0'
699699
field_search: '0'
700700
field_required: '0'
701+
-
702+
field_id: '29'
703+
field_mid: '1'
704+
field_tid: '3'
705+
field_order: '15'
706+
field_name: tf_selectfile
707+
field_type: '14'
708+
field_value: '100'
709+
field_attribute: '1'
710+
field_null: '2'
711+
field_default: ''
712+
field_key: '1'
713+
field_element: '11'
714+
field_parent: '0'
715+
field_admin: '1'
716+
field_inlist: '1'
717+
field_inform: '1'
718+
field_user: '0'
719+
field_thead: '0'
720+
field_tbody: '0'
721+
field_tfoot: '0'
722+
field_block: '0'
723+
field_main: '0'
724+
field_search: '0'
725+
field_required: '0'

testdata/german/tdmcreate_modules.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
-
22
mod_id: '1'
3-
mod_name: 'My Module'
4-
mod_dirname: mymodule
3+
mod_name: 'My Module 2'
4+
mod_dirname: mymodule2
55
mod_version: '1.0'
66
mod_since: '1.0'
77
mod_min_php: '7.0'

testdata/german/tdmcreate_tables.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
table_name: testfields
6666
table_solename: testfield
6767
table_fieldname: tf
68-
table_nbfields: '14'
68+
table_nbfields: '15'
6969
table_order: '1'
7070
table_image: alert.png
7171
table_autoincrement: '1'

testdata/mymodule2/admin/about.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
/*
3+
You may not change or alter any portion of this comment or credits
4+
of supporting developers from this source code or any supporting source code
5+
which is considered copyrighted (c) material of the original comment or credit authors.
6+
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+
12+
/**
13+
* My Module 2 module for xoops
14+
*
15+
* @copyright 2020 XOOPS Project (https://xooops.org)
16+
* @license GPL 2.0 or later
17+
* @package mymodule2
18+
* @since 1.0
19+
* @min_xoops 2.5.9
20+
* @author TDM XOOPS - Email:<info@email.com> - Website:<http://xoops.org>
21+
*/
22+
require __DIR__ . '/header.php';
23+
$templateMain = 'mymodule2_admin_about.tpl';
24+
$GLOBALS['xoopsTpl']->assign('navigation', $adminObject->displayNavigation('about.php'));
25+
$GLOBALS['xoopsTpl']->assign('about', $adminObject->renderAbout('6KJ7RW5DR3VTJ', false));
26+
require __DIR__ . '/footer.php';

0 commit comments

Comments
 (0)