Skip to content

Commit

Permalink
Merge pull request #160 from ggoffy/master
Browse files Browse the repository at this point in the history
fixed bug in update function
  • Loading branch information
ggoffy authored Oct 1, 2022
2 parents aa6e546 + c0ad364 commit 8a55574
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 94 deletions.
1 change: 1 addition & 0 deletions docs/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
- removed unnecessary sprintf (goffy)
- replace ternary expression by condition (goffy)
- using same param name during inheritance (goffy)
- fixed bug in update function (liomj/goffy)

<h5>3.5.1 Beta 1 [NOT RELEASED]</h5> Dev: XOOPS 2.5.11, PHP 7.4.25, PHP 8.0.12, PHP 8.1.0 Beta 4
- semantic versioning (mamba)
Expand Down
59 changes: 3 additions & 56 deletions files/commonfiles/include/update.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@
function xoops_module_update_modulebuilder($module, $prev_version = null)
{
$ret = null;
/*
if ($prev_version < 10) {
$ret = update_modulebuilder_v10($module);
//enter code or call your function
}

*/
$ret = modulebuilder_check_db($module);

//check upload directory
Expand All @@ -49,60 +50,6 @@ function xoops_module_update_modulebuilder($module, $prev_version = null)
return $ret;
}

// irmtfan bug fix: solve templates duplicate issue
/**
* @param $module
*
* @return bool
*/
function update_modulebuilder_v10($module)
{
global $xoopsDB;
$result = $xoopsDB->query(
'SELECT t1.tpl_id FROM ' . $xoopsDB->prefix('tplfile') . ' t1, ' . $xoopsDB->prefix('tplfile') . ' t2 WHERE t1.tpl_refid = t2.tpl_refid AND t1.tpl_module = t2.tpl_module AND t1.tpl_tplset=t2.tpl_tplset AND t1.tpl_file = t2.tpl_file AND t1.tpl_type = t2.tpl_type AND t1.tpl_id > t2.tpl_id'
);
$tplids = [];
while ([$tplid] = $xoopsDB->fetchRow($result)) {
$tplids[] = $tplid;
}
if (\count($tplids) > 0) {
$tplfileHandler = \xoops_getHandler('tplfile');
$duplicate_files = $tplfileHandler->getObjects(new \Criteria('tpl_id', '(' . \implode(',', $tplids) . ')', 'IN'));

if (\count($duplicate_files) > 0) {
foreach (\array_keys($duplicate_files) as $i) {
$tplfileHandler->delete($duplicate_files[$i]);
}
}
}
$sql = 'SHOW INDEX FROM ' . $xoopsDB->prefix('tplfile') . " WHERE KEY_NAME = 'tpl_refid_module_set_file_type'";
if (!$result = $xoopsDB->queryF($sql)) {
xoops_error($xoopsDB->error() . '<br>' . $sql);

return false;
}
$ret = [];
while (false !== ($myrow = $xoopsDB->fetchArray($result))) {
$ret[] = $myrow;
}
if (!empty($ret)) {
$module->setErrors("'tpl_refid_module_set_file_type' unique index is exist. Note: check 'tplfile' table to be sure this index is UNIQUE because XOOPS CORE need it.");

return true;
}
$sql = 'ALTER TABLE ' . $xoopsDB->prefix('tplfile') . ' ADD UNIQUE tpl_refid_module_set_file_type ( tpl_refid, tpl_module, tpl_tplset, tpl_file, tpl_type )';
if (!$result = $xoopsDB->queryF($sql)) {
xoops_error($xoopsDB->error() . '<br>' . $sql);
$module->setErrors("'tpl_refid_module_set_file_type' unique index is not added to 'tplfile' table. Warning: do not use XOOPS until you add this unique index.");

return false;
}

return true;
}

// irmtfan bug fix: solve templates duplicate issue

/**
* @param $module
*
Expand Down
76 changes: 38 additions & 38 deletions sql/mysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,34 @@

CREATE TABLE `modulebuilder_settings` (
`set_id` INT(5) UNSIGNED NOT NULL AUTO_INCREMENT,
`set_name` VARCHAR(255) NOT NULL DEFAULT 'My Module',
`set_dirname` VARCHAR(100) NOT NULL DEFAULT 'mymoduledirname',
`set_version` VARCHAR(10) NOT NULL DEFAULT '1.0.0',
`set_since` VARCHAR(5) NOT NULL DEFAULT '1.0.0',
`set_min_php` VARCHAR(5) NOT NULL DEFAULT '7.0',
`set_min_xoops` VARCHAR(15) NOT NULL DEFAULT '2.5.10',
`set_min_admin` VARCHAR(8) NOT NULL DEFAULT '1.2',
`set_min_mysql` VARCHAR(8) NOT NULL DEFAULT '5.5',
`set_description` VARCHAR(255) NOT NULL DEFAULT 'This module is for doing following...',
`set_author` VARCHAR(255) NOT NULL DEFAULT 'TDM XOOPS',
`set_author_mail` VARCHAR(255) NOT NULL DEFAULT '[email protected]',
`set_author_website_url` VARCHAR(255) NOT NULL DEFAULT 'http://xoops.org',
`set_author_website_name` VARCHAR(255) NOT NULL DEFAULT 'XOOPS Project',
`set_credits` VARCHAR(255) NOT NULL DEFAULT 'XOOPS Development Team',
`set_license` VARCHAR(255) NOT NULL DEFAULT 'GPL 2.0 or later',
`set_release_info` VARCHAR(255) NOT NULL DEFAULT 'release_info',
`set_release_file` VARCHAR(255) NOT NULL DEFAULT 'release_info file',
`set_manual` VARCHAR(255) NOT NULL DEFAULT 'link to manual file',
`set_manual_file` VARCHAR(255) NOT NULL DEFAULT 'install.txt',
`set_image` VARCHAR(255) NOT NULL DEFAULT 'empty.png',
`set_demo_site_url` VARCHAR(255) NOT NULL DEFAULT 'https://xoops.org',
`set_demo_site_name` VARCHAR(255) NOT NULL DEFAULT 'XOOPS Demo Site',
`set_support_url` VARCHAR(255) NOT NULL DEFAULT 'http://xoops.org/modules/newbb',
`set_support_name` VARCHAR(255) NOT NULL DEFAULT 'Support Forum',
`set_website_url` VARCHAR(255) NOT NULL DEFAULT 'www.xoops.org',
`set_website_name` VARCHAR(255) NOT NULL DEFAULT 'XOOPS Project',
`set_release` VARCHAR(11) NOT NULL DEFAULT '2015-05-02',
`set_status` VARCHAR(150) NOT NULL DEFAULT 'Beta 1',
`set_name` VARCHAR(255) NOT NULL DEFAULT '',
`set_dirname` VARCHAR(100) NOT NULL DEFAULT '',
`set_version` VARCHAR(15) NOT NULL DEFAULT '',
`set_since` VARCHAR(15) NOT NULL DEFAULT '',
`set_min_php` VARCHAR(15) NOT NULL DEFAULT '',
`set_min_xoops` VARCHAR(15) NOT NULL DEFAULT '',
`set_min_admin` VARCHAR(15) NOT NULL DEFAULT '',
`set_min_mysql` VARCHAR(15) NOT NULL DEFAULT '',
`set_description` VARCHAR(255) NOT NULL DEFAULT '',
`set_author` VARCHAR(255) NOT NULL DEFAULT '',
`set_author_mail` VARCHAR(255) NOT NULL DEFAULT '',
`set_author_website_url` VARCHAR(255) NOT NULL DEFAULT '',
`set_author_website_name` VARCHAR(255) NOT NULL DEFAULT '',
`set_credits` VARCHAR(255) NOT NULL DEFAULT '',
`set_license` VARCHAR(255) NOT NULL DEFAULT '',
`set_release_info` VARCHAR(255) NOT NULL DEFAULT '',
`set_release_file` VARCHAR(255) NOT NULL DEFAULT '',
`set_manual` VARCHAR(255) NOT NULL DEFAULT '',
`set_manual_file` VARCHAR(255) NOT NULL DEFAULT '',
`set_image` VARCHAR(255) NOT NULL DEFAULT '',
`set_demo_site_url` VARCHAR(255) NOT NULL DEFAULT '',
`set_demo_site_name` VARCHAR(255) NOT NULL DEFAULT '',
`set_support_url` VARCHAR(255) NOT NULL DEFAULT '',
`set_support_name` VARCHAR(255) NOT NULL DEFAULT '',
`set_website_url` VARCHAR(255) NOT NULL DEFAULT '',
`set_website_name` VARCHAR(255) NOT NULL DEFAULT '',
`set_release` VARCHAR(11) NOT NULL DEFAULT '',
`set_status` VARCHAR(150) NOT NULL DEFAULT '',
`set_admin` TINYINT(1) UNSIGNED NOT NULL DEFAULT '1',
`set_user` TINYINT(1) UNSIGNED NOT NULL DEFAULT '1',
`set_blocks` TINYINT(1) UNSIGNED NOT NULL DEFAULT '1',
Expand All @@ -49,8 +49,8 @@ CREATE TABLE `modulebuilder_settings` (
`set_notifications` TINYINT(1) UNSIGNED NOT NULL DEFAULT '0',
`set_permissions` TINYINT(1) UNSIGNED NOT NULL DEFAULT '0',
`set_inroot_copy` TINYINT(1) UNSIGNED NOT NULL DEFAULT '0',
`set_donations` VARCHAR(50) NOT NULL DEFAULT '6KJ7RW5DR3VTJ',
`set_subversion` VARCHAR(10) NOT NULL DEFAULT '13070',
`set_donations` VARCHAR(50) NOT NULL DEFAULT '',
`set_subversion` VARCHAR(10) NOT NULL DEFAULT '',
`set_type` TINYINT(3) UNSIGNED NOT NULL DEFAULT '1',
PRIMARY KEY (`set_id`)
)
Expand All @@ -60,7 +60,7 @@ CREATE TABLE `modulebuilder_settings` (

INSERT INTO `modulebuilder_settings` (`set_id`, `set_name`, `set_dirname`, `set_version`, `set_since`, `set_min_php`, `set_min_xoops`, `set_min_admin`, `set_min_mysql`, `set_description`, `set_author`, `set_author_mail`, `set_author_website_url`, `set_author_website_name`, `set_credits`, `set_license`, `set_release_info`, `set_release_file`, `set_manual`, `set_manual_file`, `set_image`, `set_demo_site_url`, `set_demo_site_name`, `set_support_url`, `set_support_name`, `set_website_url`, `set_website_name`, `set_release`, `set_status`, `set_admin`, `set_user`, `set_blocks`, `set_search`, `set_comments`, `set_notifications`, `set_permissions`, `set_inroot_copy`, `set_donations`, `set_subversion`, `set_type`)
VALUES
(1, 'My Module', 'mymoduledirname', '1.0.0', '1.0.0', '7.0', '2.5.10', '1.2', '5.6', 'This module is for doing following...', 'TDM XOOPS', '[email protected]', 'http://xoops.org', 'XOOPS Project', 'XOOPS Development Team', 'GPL 2.0 or later', 'release_info', 'release_info file', 'link to manual file',
(1, 'My Module', 'mymoduledirname', '1.0.0', '1.0.0', '7.0', '2.5.10', '1.2', '5.6', 'This module is for doing following...', 'TDM XOOPS', '[email protected]', 'https://xoops.org', 'XOOPS Project', 'XOOPS Development Team', 'GPL 2.0 or later', 'release_info', 'release_info file', 'link to manual file',
'install.txt', 'empty.png', 'https://xoops.org', 'XOOPS Demo Site', 'https://xoops.org/modules/newbb', 'Support Forum', 'www.xoops.org', 'XOOPS Project',
'2017-12-02', 'Beta 1', '1', '1', '1', '0', '0', '0', '0', '0', '6KJ7RW5DR3VTJ', '13070', 1);

Expand All @@ -72,12 +72,12 @@ CREATE TABLE `modulebuilder_modules` (
`mod_id` INT(5) UNSIGNED NOT NULL AUTO_INCREMENT,
`mod_name` VARCHAR(200) NOT NULL DEFAULT '',
`mod_dirname` VARCHAR(100) NOT NULL DEFAULT '',
`mod_version` VARCHAR(10) NOT NULL DEFAULT '1.0.0',
`mod_since` VARCHAR(10) NOT NULL DEFAULT '1.0.0',
`mod_min_php` VARCHAR(4) NOT NULL DEFAULT '5.5',
`mod_version` VARCHAR(15) NOT NULL DEFAULT '1.0.0',
`mod_since` VARCHAR(15) NOT NULL DEFAULT '1.0.0',
`mod_min_php` VARCHAR(15) NOT NULL DEFAULT '5.5',
`mod_min_xoops` VARCHAR(15) NOT NULL DEFAULT '2.5.11',
`mod_min_admin` VARCHAR(4) NOT NULL DEFAULT '1.2',
`mod_min_mysql` VARCHAR(6) NOT NULL DEFAULT '5.5',
`mod_min_admin` VARCHAR(15) NOT NULL DEFAULT '1.2',
`mod_min_mysql` VARCHAR(15) NOT NULL DEFAULT '5.5',
`mod_description` TEXT,
`mod_author` VARCHAR(200) NOT NULL DEFAULT 'TDM XOOPS',
`mod_author_mail` VARCHAR(200) NOT NULL DEFAULT '[email protected]',
Expand Down Expand Up @@ -106,8 +106,8 @@ CREATE TABLE `modulebuilder_modules` (
`mod_notifications` TINYINT(1) UNSIGNED NOT NULL DEFAULT '0',
`mod_permissions` TINYINT(1) UNSIGNED NOT NULL DEFAULT '0',
`mod_inroot_copy` TINYINT(1) UNSIGNED NOT NULL DEFAULT '1',
`mod_donations` VARCHAR(50) NOT NULL DEFAULT '6KJ7RW5DR3VTJ',
`mod_subversion` VARCHAR(10) NOT NULL DEFAULT '12550',
`mod_donations` VARCHAR(50) NOT NULL DEFAULT '',
`mod_subversion` VARCHAR(10) NOT NULL DEFAULT '',
PRIMARY KEY (`mod_id`),
KEY `mod_name` (`mod_name`),
UNIQUE KEY `mod_dirname` (`mod_dirname`)
Expand Down

0 comments on commit 8a55574

Please sign in to comment.