From 5f1d17bfb3bc6e74529f1b28bb1dd85be231c4a2 Mon Sep 17 00:00:00 2001 From: Llewellyn van der Merwe Date: Mon, 25 May 2020 02:38:16 +0200 Subject: [PATCH] Fixed GUID duplication issue. --- README.md | 4 +- admin/README.txt | 4 +- admin/helpers/compiler/a_Get.php | 20 ++++- admin/helpers/compiler/c_Fields.php | 18 +++++ admin/helpers/compiler/e_Interpretation.php | 21 ++++- admin/helpers/componentbuilder.php | 85 ++++++++++++++++----- admin/models/admin_view.php | 2 +- admin/models/class_method.php | 2 +- admin/models/class_property.php | 2 +- admin/models/custom_admin_view.php | 2 +- admin/models/dynamic_get.php | 2 +- admin/models/field.php | 2 +- admin/models/fieldtype.php | 2 +- admin/models/joomla_component.php | 2 +- admin/models/joomla_module.php | 2 +- admin/models/joomla_plugin.php | 2 +- admin/models/library.php | 2 +- admin/models/site_view.php | 2 +- admin/models/snippet.php | 2 +- admin/sql/install.mysql.utf8.sql | 26 +++---- componentbuilder.xml | 2 +- script.php | 33 ++++++-- site/helpers/componentbuilder.php | 85 ++++++++++++++++----- 23 files changed, 241 insertions(+), 83 deletions(-) diff --git a/README.md b/README.md index 5d53944d4..6be109f46 100644 --- a/README.md +++ b/README.md @@ -144,11 +144,11 @@ TODO + *Author*: [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com) + *Name*: [Component Builder](https://github.com/vdm-io/Joomla-Component-Builder) + *First Build*: 30th April, 2015 -+ *Last Build*: 22nd May, 2020 ++ *Last Build*: 25th May, 2020 + *Version*: 2.11.1 + *Copyright*: Copyright (C) 2015 - 2020 Vast Development Method. All rights reserved. + *License*: GNU General Public License version 2 or later; see LICENSE.txt -+ *Line count*: **281750** ++ *Line count*: **281857** + *Field count*: **1522** + *File count*: **1783** + *Folder count*: **295** diff --git a/admin/README.txt b/admin/README.txt index 5d53944d4..6be109f46 100644 --- a/admin/README.txt +++ b/admin/README.txt @@ -144,11 +144,11 @@ TODO + *Author*: [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com) + *Name*: [Component Builder](https://github.com/vdm-io/Joomla-Component-Builder) + *First Build*: 30th April, 2015 -+ *Last Build*: 22nd May, 2020 ++ *Last Build*: 25th May, 2020 + *Version*: 2.11.1 + *Copyright*: Copyright (C) 2015 - 2020 Vast Development Method. All rights reserved. + *License*: GNU General Public License version 2 or later; see LICENSE.txt -+ *Line count*: **281750** ++ *Line count*: **281857** + *Field count*: **1522** + *File count*: **1783** + *Folder count*: **295** diff --git a/admin/helpers/compiler/a_Get.php b/admin/helpers/compiler/a_Get.php index 95c6cfe7c..7b0690610 100644 --- a/admin/helpers/compiler/a_Get.php +++ b/admin/helpers/compiler/a_Get.php @@ -9149,6 +9149,8 @@ class Get // set some placeholder for this plugin $this->placeholders[$this->bbb . 'Plugin_name' . $this->ddd] = $plugin->official_name; + $this->placeholders[$this->hhh . 'PLUGIN_NAME' . $this->hhh] + = $plugin->official_name; $this->placeholders[$this->bbb . 'Plugin' . $this->ddd] = ucfirst( $plugin->code_name @@ -9167,11 +9169,15 @@ class Get ); $this->placeholders[$this->bbb . 'plugin.version' . $this->ddd] = $plugin->plugin_version; + $this->placeholders[$this->hhh . 'VERSION' . $this->hhh] + = $plugin->plugin_version; $this->placeholders[$this->bbb . 'plugin_version' . $this->ddd] = str_replace( '.', '_', $plugin->plugin_version ); - // set description (TODO) add description field to plugin + // set description + $this->placeholders[$this->hhh . 'DESCRIPTION' . $this->hhh] + = ''; if (!isset($plugin->description) || !ComponentbuilderHelper::checkString( $plugin->description @@ -9189,6 +9195,9 @@ class Get $plugin->key, $plugin->lang_prefix . '_DESCRIPTION', $plugin->description ); + // set description + $this->placeholders[$this->hhh . 'DESCRIPTION' . $this->hhh] + = $plugin->description; $plugin->description = '

' . $plugin->description . '

'; } @@ -9672,6 +9681,15 @@ class Get $this->placeholders[$this->bbb . 'plugin_version' . $this->ddd] ); + unset( + $this->placeholders[$this->hhh . 'VERSION' + . $this->hhh]); + unset( + $this->placeholders[$this->hhh . 'DESCRIPTION' + . $this->hhh]); + unset( + $this->placeholders[$this->hhh . 'PLUGIN_NAME' + . $this->hhh]); $this->joomlaPlugins[$id] = $plugin; diff --git a/admin/helpers/compiler/c_Fields.php b/admin/helpers/compiler/c_Fields.php index 1dc6f27d2..a6f365590 100644 --- a/admin/helpers/compiler/c_Fields.php +++ b/admin/helpers/compiler/c_Fields.php @@ -95,6 +95,13 @@ class Fields extends Structure */ public $dbUniqueKeys = array(); + /** + * unique guid swtich + * + * @var array + */ + public $dbUniqueGuid = array(); + /** * keys for database field * @@ -3850,6 +3857,7 @@ class Fields extends Structure $this->queryBuilder[$view_name_single][$name]['null_switch'] = $field['settings']->null_switch; // set index types + $_guid = true; if ($field['settings']->indexes == 1 && !in_array( $field['settings']->datatype, $textKeys @@ -3857,6 +3865,11 @@ class Fields extends Structure { // build unique keys of this view for db $this->dbUniqueKeys[$view_name_single][] = $name; + // prevent guid from being added twice + if ('guid' === $name) + { + $_guid = false; + } } elseif (($field['settings']->indexes == 2 || (isset($field['alias']) @@ -3868,6 +3881,11 @@ class Fields extends Structure // build keys of this view for db $this->dbKeys[$view_name_single][] = $name; } + // special treatment for GUID + if ('guid' === $name && $_guid) + { + $this->dbUniqueGuid[$view_name_single] = true; + } } // set list switch $listSwitch = (isset($field['list']) diff --git a/admin/helpers/compiler/e_Interpretation.php b/admin/helpers/compiler/e_Interpretation.php index 1182eb8c8..36a1a8d82 100644 --- a/admin/helpers/compiler/e_Interpretation.php +++ b/admin/helpers/compiler/e_Interpretation.php @@ -17164,9 +17164,24 @@ class Interpretation extends Fields if (isset($this->dbUniqueKeys[$view]) && ComponentbuilderHelper::checkArray($this->dbUniqueKeys[$view])) { - $fields[] = $this->_t(2) . "return array('" . implode( - "','", $this->dbUniqueKeys[$view] - ) . "');"; + // if guid should also be added + if (isset($this->dbUniqueGuid[$view])) + { + $fields[] = $this->_t(2) . "return array('" . implode( + "','", $this->dbUniqueKeys[$view] + ) . "', 'guid');"; + } + else + { + $fields[] = $this->_t(2) . "return array('" . implode( + "','", $this->dbUniqueKeys[$view] + ) . "');"; + } + } + // if only GUID is found + elseif (isset($this->dbUniqueGuid[$view])) + { + $fields[] = $this->_t(2) . "return array('guid');"; } else { diff --git a/admin/helpers/componentbuilder.php b/admin/helpers/componentbuilder.php index cd10f0cca..cf7d9cd02 100644 --- a/admin/helpers/componentbuilder.php +++ b/admin/helpers/componentbuilder.php @@ -2019,18 +2019,18 @@ abstract class ComponentbuilderHelper } /** - * Returns a GUIDv4 string - * - * Thanks to Dave Pearson (and other) - * https://www.php.net/manual/en/function.com-create-guid.php#119168 - * - * Uses the best cryptographically secure method - * for all supported platforms with fallback to an older, - * less secure version. - * - * @param bool $trim - * @return string - */ + * Returns a GUIDv4 string + * + * Thanks to Dave Pearson (and other) + * https://www.php.net/manual/en/function.com-create-guid.php#119168 + * + * Uses the best cryptographically secure method + * for all supported platforms with fallback to an older, + * less secure version. + * + * @param bool $trim + * @return string + */ public static function GUID ($trim = true) { // Windows @@ -2071,15 +2071,58 @@ abstract class ComponentbuilderHelper } /** - * Validate the Globally Unique Identifier - * - * Thanks to Lewie - * https://stackoverflow.com/a/1515456/1429677 - * - * @param string $guid - * @return bool - */ - public static function validGUID ($guid) + * Validate the Globally Unique Identifier ( and check if table already has this identifier) + * + * @param string $guid + * @param string $table + * @param int $id + * @return bool + */ + public static function validGUID ($guid, $table = null, $id = 0) + { + // check if we have a string + if (self::validateGUID($guid)) + { + // check if table already has this identifier + if (self::checkString($table)) + { + // Get the database object and a new query object. + $db = \JFactory::getDbo(); + $query = $db->getQuery(true); + $query->select('COUNT(*)') + ->from('#__componentbuilder_' . (string) $table) + ->where($db->quoteName('guid') . ' = ' . $db->quote($guid)); + + // remove this item from the list + if ($id > 0) + { + $query->where($db->quoteName('id') . ' <> ' . (int) $id); + } + + // Set and query the database. + $db->setQuery($query); + $duplicate = (bool) $db->loadResult(); + + if ($duplicate) + { + return false; + } + } + return true; + } + return false; + } + + /** + * Validate the Globally Unique Identifier + * + * Thanks to Lewie + * https://stackoverflow.com/a/1515456/1429677 + * + * @param string $guid + * @return bool + */ + protected static function validateGUID ($guid) { // check if we have a string if (self::checkString($guid)) diff --git a/admin/models/admin_view.php b/admin/models/admin_view.php index eabebb88d..0f469f420 100644 --- a/admin/models/admin_view.php +++ b/admin/models/admin_view.php @@ -1491,7 +1491,7 @@ class ComponentbuilderModelAdmin_view extends JModelAdmin } // Set the GUID if empty or not valid - if (isset($data['guid']) && !ComponentbuilderHelper::validGUID($data['guid'])) + if (isset($data['guid']) && !ComponentbuilderHelper::validGUID($data['guid'], "admin_view", $data['id'])) { $data['guid'] = (string) ComponentbuilderHelper::GUID(); } diff --git a/admin/models/class_method.php b/admin/models/class_method.php index a4efca20f..004874715 100644 --- a/admin/models/class_method.php +++ b/admin/models/class_method.php @@ -972,7 +972,7 @@ class ComponentbuilderModelClass_method extends JModelAdmin $data['name'] = ComponentbuilderHelper::safeClassFunctionName($data['name']); // Set the GUID if empty or not valid - if (isset($data['guid']) && !ComponentbuilderHelper::validGUID($data['guid'])) + if (isset($data['guid']) && !ComponentbuilderHelper::validGUID($data['guid'], "class_method", $data['id'])) { $data['guid'] = (string) ComponentbuilderHelper::GUID(); } diff --git a/admin/models/class_property.php b/admin/models/class_property.php index d3cc588c0..6a6af7baf 100644 --- a/admin/models/class_property.php +++ b/admin/models/class_property.php @@ -963,7 +963,7 @@ class ComponentbuilderModelClass_property extends JModelAdmin $data['name'] = ComponentbuilderHelper::safeClassFunctionName($data['name']); // Set the GUID if empty or not valid - if (isset($data['guid']) && !ComponentbuilderHelper::validGUID($data['guid'])) + if (isset($data['guid']) && !ComponentbuilderHelper::validGUID($data['guid'], "class_property", $data['id'])) { $data['guid'] = (string) ComponentbuilderHelper::GUID(); } diff --git a/admin/models/custom_admin_view.php b/admin/models/custom_admin_view.php index 38a47565b..a21f8c5c7 100644 --- a/admin/models/custom_admin_view.php +++ b/admin/models/custom_admin_view.php @@ -1125,7 +1125,7 @@ class ComponentbuilderModelCustom_admin_view extends JModelAdmin } // Set the GUID if empty or not valid - if (isset($data['guid']) && !ComponentbuilderHelper::validGUID($data['guid'])) + if (isset($data['guid']) && !ComponentbuilderHelper::validGUID($data['guid'], "custom_admin_view", $data['id'])) { $data['guid'] = (string) ComponentbuilderHelper::GUID(); } diff --git a/admin/models/dynamic_get.php b/admin/models/dynamic_get.php index 7212d02f1..d897a4af4 100644 --- a/admin/models/dynamic_get.php +++ b/admin/models/dynamic_get.php @@ -1148,7 +1148,7 @@ class ComponentbuilderModelDynamic_get extends JModelAdmin // Set the GUID if empty or not valid - if (isset($data['guid']) && !ComponentbuilderHelper::validGUID($data['guid'])) + if (isset($data['guid']) && !ComponentbuilderHelper::validGUID($data['guid'], "dynamic_get", $data['id'])) { $data['guid'] = (string) ComponentbuilderHelper::GUID(); } diff --git a/admin/models/field.php b/admin/models/field.php index a100c9e6d..5cc2eafb8 100644 --- a/admin/models/field.php +++ b/admin/models/field.php @@ -1144,7 +1144,7 @@ class ComponentbuilderModelField extends JModelAdmin } // Set the GUID if empty or not valid - if (isset($data['guid']) && !ComponentbuilderHelper::validGUID($data['guid'])) + if (isset($data['guid']) && !ComponentbuilderHelper::validGUID($data['guid'], "field", $data['id'])) { $data['guid'] = (string) ComponentbuilderHelper::GUID(); } diff --git a/admin/models/fieldtype.php b/admin/models/fieldtype.php index b3405fc28..bc916c4f3 100644 --- a/admin/models/fieldtype.php +++ b/admin/models/fieldtype.php @@ -1197,7 +1197,7 @@ class ComponentbuilderModelFieldtype extends JModelAdmin // Set the GUID if empty or not valid - if (isset($data['guid']) && !ComponentbuilderHelper::validGUID($data['guid'])) + if (isset($data['guid']) && !ComponentbuilderHelper::validGUID($data['guid'], "fieldtype", $data['id'])) { $data['guid'] = (string) ComponentbuilderHelper::GUID(); } diff --git a/admin/models/joomla_component.php b/admin/models/joomla_component.php index 18ea494ae..d4063eb70 100644 --- a/admin/models/joomla_component.php +++ b/admin/models/joomla_component.php @@ -1385,7 +1385,7 @@ class ComponentbuilderModelJoomla_component extends JModelAdmin } // Set the GUID if empty or not valid - if (isset($data['guid']) && !ComponentbuilderHelper::validGUID($data['guid'])) + if (isset($data['guid']) && !ComponentbuilderHelper::validGUID($data['guid'], "joomla_component", $data['id'])) { $data['guid'] = (string) ComponentbuilderHelper::GUID(); } diff --git a/admin/models/joomla_module.php b/admin/models/joomla_module.php index 9940fa9d2..313d937bd 100644 --- a/admin/models/joomla_module.php +++ b/admin/models/joomla_module.php @@ -1199,7 +1199,7 @@ class ComponentbuilderModelJoomla_module extends JModelAdmin } // Set the GUID if empty or not valid - if (isset($data['guid']) && !ComponentbuilderHelper::validGUID($data['guid'])) + if (isset($data['guid']) && !ComponentbuilderHelper::validGUID($data['guid'], "joomla_module", $data['id'])) { $data['guid'] = (string) ComponentbuilderHelper::GUID(); } diff --git a/admin/models/joomla_plugin.php b/admin/models/joomla_plugin.php index 108086112..4fac186d9 100644 --- a/admin/models/joomla_plugin.php +++ b/admin/models/joomla_plugin.php @@ -1162,7 +1162,7 @@ class ComponentbuilderModelJoomla_plugin extends JModelAdmin } // Set the GUID if empty or not valid - if (isset($data['guid']) && !ComponentbuilderHelper::validGUID($data['guid'])) + if (isset($data['guid']) && !ComponentbuilderHelper::validGUID($data['guid'], "joomla_plugin", $data['id'])) { $data['guid'] = (string) ComponentbuilderHelper::GUID(); } diff --git a/admin/models/library.php b/admin/models/library.php index 101ec89f2..7d3ce5578 100644 --- a/admin/models/library.php +++ b/admin/models/library.php @@ -1048,7 +1048,7 @@ class ComponentbuilderModelLibrary extends JModelAdmin // Set the GUID if empty or not valid - if (isset($data['guid']) && !ComponentbuilderHelper::validGUID($data['guid'])) + if (isset($data['guid']) && !ComponentbuilderHelper::validGUID($data['guid'], "library", $data['id'])) { $data['guid'] = (string) ComponentbuilderHelper::GUID(); } diff --git a/admin/models/site_view.php b/admin/models/site_view.php index d24886a70..a826d76dd 100644 --- a/admin/models/site_view.php +++ b/admin/models/site_view.php @@ -1146,7 +1146,7 @@ class ComponentbuilderModelSite_view extends JModelAdmin } // Set the GUID if empty or not valid - if (isset($data['guid']) && !ComponentbuilderHelper::validGUID($data['guid'])) + if (isset($data['guid']) && !ComponentbuilderHelper::validGUID($data['guid'], "site_view", $data['id'])) { $data['guid'] = (string) ComponentbuilderHelper::GUID(); } diff --git a/admin/models/snippet.php b/admin/models/snippet.php index 55a0fd39b..4439466cb 100644 --- a/admin/models/snippet.php +++ b/admin/models/snippet.php @@ -852,7 +852,7 @@ class ComponentbuilderModelSnippet extends JModelAdmin } // Set the GUID if empty or not valid - if (isset($data['guid']) && !ComponentbuilderHelper::validGUID($data['guid'])) + if (isset($data['guid']) && !ComponentbuilderHelper::validGUID($data['guid'], "snippet", $data['id'])) { $data['guid'] = (string) ComponentbuilderHelper::GUID(); } diff --git a/admin/sql/install.mysql.utf8.sql b/admin/sql/install.mysql.utf8.sql index 77fb71bfc..2feb16036 100644 --- a/admin/sql/install.mysql.utf8.sql +++ b/admin/sql/install.mysql.utf8.sql @@ -100,7 +100,6 @@ CREATE TABLE IF NOT EXISTS `#__componentbuilder_joomla_component` ( `metadesc` TEXT NOT NULL, `metadata` TEXT NOT NULL, PRIMARY KEY (`id`), - UNIQUE KEY `idx_guid` (`guid`), KEY `idx_system_name` (`system_name`), KEY `idx_name_code` (`name_code`), KEY `idx_add_php_helper_admin` (`add_php_helper_admin`), @@ -135,6 +134,7 @@ CREATE TABLE IF NOT EXISTS `#__componentbuilder_joomla_component` ( KEY `idx_update_server_target` (`update_server_target`), KEY `idx_creatuserhelper` (`creatuserhelper`), KEY `idx_adduikit` (`adduikit`), + KEY `idx_guid` (`guid`), KEY `idx_access` (`access`), KEY `idx_checkout` (`checked_out`), KEY `idx_createdby` (`created_by`), @@ -200,7 +200,6 @@ CREATE TABLE IF NOT EXISTS `#__componentbuilder_joomla_module` ( `access` INT(10) unsigned NOT NULL DEFAULT 0, `ordering` INT(11) NOT NULL DEFAULT 0, PRIMARY KEY (`id`), - UNIQUE KEY `idx_guid` (`guid`), KEY `idx_system_name` (`system_name`), KEY `idx_add_php_method_uninstall` (`add_php_method_uninstall`), KEY `idx_add_php_postflight_update` (`add_php_postflight_update`), @@ -215,6 +214,7 @@ CREATE TABLE IF NOT EXISTS `#__componentbuilder_joomla_module` ( KEY `idx_add_php_preflight_install` (`add_php_preflight_install`), KEY `idx_add_sales_server` (`add_sales_server`), KEY `idx_add_php_preflight_update` (`add_php_preflight_update`), + KEY `idx_guid` (`guid`), KEY `idx_name` (`name`), KEY `idx_access` (`access`), KEY `idx_checkout` (`checked_out`), @@ -278,7 +278,6 @@ CREATE TABLE IF NOT EXISTS `#__componentbuilder_joomla_plugin` ( `access` INT(10) unsigned NOT NULL DEFAULT 0, `ordering` INT(11) NOT NULL DEFAULT 0, PRIMARY KEY (`id`), - UNIQUE KEY `idx_guid` (`guid`), KEY `idx_system_name` (`system_name`), KEY `idx_class_extends` (`class_extends`), KEY `idx_joomla_plugin_group` (`joomla_plugin_group`), @@ -295,6 +294,7 @@ CREATE TABLE IF NOT EXISTS `#__componentbuilder_joomla_plugin` ( KEY `idx_add_php_preflight_update` (`add_php_preflight_update`), KEY `idx_add_php_preflight_uninstall` (`add_php_preflight_uninstall`), KEY `idx_add_sales_server` (`add_sales_server`), + KEY `idx_guid` (`guid`), KEY `idx_name` (`name`), KEY `idx_access` (`access`), KEY `idx_checkout` (`checked_out`), @@ -410,7 +410,6 @@ CREATE TABLE IF NOT EXISTS `#__componentbuilder_admin_view` ( `access` INT(10) unsigned NOT NULL DEFAULT 0, `ordering` INT(11) NOT NULL DEFAULT 0, PRIMARY KEY (`id`), - UNIQUE KEY `idx_guid` (`guid`), KEY `idx_name_single` (`name_single`), KEY `idx_name_list` (`name_list`), KEY `idx_add_fadein` (`add_fadein`), @@ -449,6 +448,7 @@ CREATE TABLE IF NOT EXISTS `#__componentbuilder_admin_view` ( KEY `idx_add_custom_import` (`add_custom_import`), KEY `idx_add_php_getitems` (`add_php_getitems`), KEY `idx_add_php_getitems_after_all` (`add_php_getitems_after_all`), + KEY `idx_guid` (`guid`), KEY `idx_access` (`access`), KEY `idx_checkout` (`checked_out`), KEY `idx_createdby` (`created_by`), @@ -508,7 +508,6 @@ CREATE TABLE IF NOT EXISTS `#__componentbuilder_custom_admin_view` ( `access` INT(10) unsigned NOT NULL DEFAULT 0, `ordering` INT(11) NOT NULL DEFAULT 0, PRIMARY KEY (`id`), - UNIQUE KEY `idx_guid` (`guid`), KEY `idx_name` (`name`), KEY `idx_main_get` (`main_get`), KEY `idx_add_php_jview_display` (`add_php_jview_display`), @@ -524,6 +523,7 @@ CREATE TABLE IF NOT EXISTS `#__componentbuilder_custom_admin_view` ( KEY `idx_add_php_ajax` (`add_php_ajax`), KEY `idx_dynamic_get` (`dynamic_get`), KEY `idx_add_custom_button` (`add_custom_button`), + KEY `idx_guid` (`guid`), KEY `idx_access` (`access`), KEY `idx_checkout` (`checked_out`), KEY `idx_createdby` (`created_by`), @@ -583,7 +583,6 @@ CREATE TABLE IF NOT EXISTS `#__componentbuilder_site_view` ( `access` INT(10) unsigned NOT NULL DEFAULT 0, `ordering` INT(11) NOT NULL DEFAULT 0, PRIMARY KEY (`id`), - UNIQUE KEY `idx_guid` (`guid`), KEY `idx_name` (`name`), KEY `idx_main_get` (`main_get`), KEY `idx_add_php_jview_display` (`add_php_jview_display`), @@ -600,6 +599,7 @@ CREATE TABLE IF NOT EXISTS `#__componentbuilder_site_view` ( KEY `idx_add_php_ajax` (`add_php_ajax`), KEY `idx_add_custom_button` (`add_custom_button`), KEY `idx_button_position` (`button_position`), + KEY `idx_guid` (`guid`), KEY `idx_access` (`access`), KEY `idx_checkout` (`checked_out`), KEY `idx_createdby` (`created_by`), @@ -729,7 +729,6 @@ CREATE TABLE IF NOT EXISTS `#__componentbuilder_dynamic_get` ( `access` INT(10) unsigned NOT NULL DEFAULT 0, `ordering` INT(11) NOT NULL DEFAULT 0, PRIMARY KEY (`id`), - UNIQUE KEY `idx_guid` (`guid`), KEY `idx_name` (`name`), KEY `idx_main_source` (`main_source`), KEY `idx_gettype` (`gettype`), @@ -742,6 +741,7 @@ CREATE TABLE IF NOT EXISTS `#__componentbuilder_dynamic_get` ( KEY `idx_add_php_before_getitems` (`add_php_before_getitems`), KEY `idx_add_php_after_getitems` (`add_php_after_getitems`), KEY `idx_add_php_router_parse` (`add_php_router_parse`), + KEY `idx_guid` (`guid`), KEY `idx_access` (`access`), KEY `idx_checkout` (`checked_out`), KEY `idx_createdby` (`created_by`), @@ -813,9 +813,9 @@ CREATE TABLE IF NOT EXISTS `#__componentbuilder_class_property` ( `access` INT(10) unsigned NOT NULL DEFAULT 0, `ordering` INT(11) NOT NULL DEFAULT 0, PRIMARY KEY (`id`), - UNIQUE KEY `idx_guid` (`guid`), KEY `idx_name` (`name`), KEY `idx_visibility` (`visibility`), + KEY `idx_guid` (`guid`), KEY `idx_joomla_plugin_group` (`joomla_plugin_group`), KEY `idx_access` (`access`), KEY `idx_checkout` (`checked_out`), @@ -848,9 +848,9 @@ CREATE TABLE IF NOT EXISTS `#__componentbuilder_class_method` ( `access` INT(10) unsigned NOT NULL DEFAULT 0, `ordering` INT(11) NOT NULL DEFAULT 0, PRIMARY KEY (`id`), - UNIQUE KEY `idx_guid` (`guid`), KEY `idx_name` (`name`), KEY `idx_visibility` (`visibility`), + KEY `idx_guid` (`guid`), KEY `idx_joomla_plugin_group` (`joomla_plugin_group`), KEY `idx_access` (`access`), KEY `idx_checkout` (`checked_out`), @@ -910,9 +910,9 @@ CREATE TABLE IF NOT EXISTS `#__componentbuilder_library` ( `access` INT(10) unsigned NOT NULL DEFAULT 0, `ordering` INT(11) NOT NULL DEFAULT 0, PRIMARY KEY (`id`), - UNIQUE KEY `idx_guid` (`guid`), KEY `idx_name` (`name`), KEY `idx_how` (`how`), + KEY `idx_guid` (`guid`), KEY `idx_access` (`access`), KEY `idx_checkout` (`checked_out`), KEY `idx_createdby` (`created_by`), @@ -949,10 +949,10 @@ CREATE TABLE IF NOT EXISTS `#__componentbuilder_snippet` ( `access` INT(10) unsigned NOT NULL DEFAULT 0, `ordering` INT(11) NOT NULL DEFAULT 0, PRIMARY KEY (`id`), - UNIQUE KEY `idx_guid` (`guid`), KEY `idx_name` (`name`), KEY `idx_type` (`type`), KEY `idx_library` (`library`), + KEY `idx_guid` (`guid`), KEY `idx_access` (`access`), KEY `idx_checkout` (`checked_out`), KEY `idx_createdby` (`created_by`), @@ -1029,7 +1029,6 @@ CREATE TABLE IF NOT EXISTS `#__componentbuilder_field` ( `access` INT(10) unsigned NOT NULL DEFAULT 0, `ordering` INT(11) NOT NULL DEFAULT 0, PRIMARY KEY (`id`), - UNIQUE KEY `idx_guid` (`guid`), KEY `idx_name` (`name`), KEY `idx_fieldtype` (`fieldtype`), KEY `idx_datatype` (`datatype`), @@ -1044,6 +1043,7 @@ CREATE TABLE IF NOT EXISTS `#__componentbuilder_field` ( KEY `idx_add_css_views` (`add_css_views`), KEY `idx_add_javascript_view_footer` (`add_javascript_view_footer`), KEY `idx_add_javascript_views_footer` (`add_javascript_views_footer`), + KEY `idx_guid` (`guid`), KEY `idx_access` (`access`), KEY `idx_checkout` (`checked_out`), KEY `idx_createdby` (`created_by`), @@ -1082,7 +1082,6 @@ CREATE TABLE IF NOT EXISTS `#__componentbuilder_fieldtype` ( `access` INT(10) unsigned NOT NULL DEFAULT 0, `ordering` INT(11) NOT NULL DEFAULT 0, PRIMARY KEY (`id`), - UNIQUE KEY `idx_guid` (`guid`), KEY `idx_name` (`name`), KEY `idx_null_switch` (`null_switch`), KEY `idx_indexes` (`indexes`), @@ -1092,6 +1091,7 @@ CREATE TABLE IF NOT EXISTS `#__componentbuilder_fieldtype` ( KEY `idx_datatype` (`datatype`), KEY `idx_has_defaults` (`has_defaults`), KEY `idx_datalenght` (`datalenght`), + KEY `idx_guid` (`guid`), KEY `idx_catid` (`catid`), KEY `idx_access` (`access`), KEY `idx_checkout` (`checked_out`), diff --git a/componentbuilder.xml b/componentbuilder.xml index 366966b47..c06e3bf01 100644 --- a/componentbuilder.xml +++ b/componentbuilder.xml @@ -1,7 +1,7 @@ COM_COMPONENTBUILDER - 22nd May, 2020 + 25th May, 2020 Llewellyn van der Merwe llewellyn@joomlacomponentbuilder.com http://www.joomlacomponentbuilder.com diff --git a/script.php b/script.php index 2edb47d4b..5b07e82a0 100644 --- a/script.php +++ b/script.php @@ -8973,9 +8973,11 @@ class com_componentbuilderInstallerScript } } } - // target version less then 2.11.0 - if (count($this->JCBversion) == 3 && $this->JCBversion[0] <= 2 && $this->JCBversion[1] < 11) + // target version less then or equal to 2.11.1 + if (count($this->JCBversion) == 3 && $this->JCBversion[0] <= 2 && ($this->JCBversion[1] < 11 || ($this->JCBversion[1] == 11 && $this->JCBversion[2] <= 1))) { + // keep track of used + $usedGUID = array(); /** * Returns a GUIDv4 string * @@ -9037,7 +9039,7 @@ class com_componentbuilderInstallerScript * @param string $guid * @return bool */ - function validGUID ($guid) + function validateGUID ($guid) { // check if we have a string if (ComponentbuilderHelper::checkString($guid)) @@ -9047,6 +9049,23 @@ class com_componentbuilderInstallerScript return false; } + /** + * Validate the Globally Unique Identifier + * + * @param string $guid + * @return bool + */ + function validGUID ($guid, &$usedGUID) + { + // check if we have a string + if (validateGUID($guid) && !isset($usedGUID[$guid])) + { + $usedGUID[$guid] = true; + return true; + } + return false; + } + // we must update all GUID's for future use :) $guid_tables = array( 'joomla_component', @@ -9077,10 +9096,14 @@ class com_componentbuilderInstallerScript $db->execute(); if ($db->getNumRows()) { + // keep track of used + $usedGUID = array(); + // get the rows $rows = $db->loadObjectList(); foreach ($rows as $row) { - if (!validGUID($row->guid)) + // load value not to use it again + if (!validGUID($row->guid, $usedGUID)) { // Create a new query object. $query = $db->getQuery(true); @@ -9100,8 +9123,6 @@ class com_componentbuilderInstallerScript } } } - // set a notice that this was done - $app->enqueueMessage('

Globally Unique Identifier GUID was added to various tables in JCB, thanks to PRO members contribution!

', 'Notice'); } // check if this install has the libraries in the helper folder, if so remove it $vendorPath = JPATH_ADMINISTRATOR . '/components/com_componentbuilder/helpers/vendor'; diff --git a/site/helpers/componentbuilder.php b/site/helpers/componentbuilder.php index b271e523d..4f30b3419 100644 --- a/site/helpers/componentbuilder.php +++ b/site/helpers/componentbuilder.php @@ -2016,18 +2016,18 @@ abstract class ComponentbuilderHelper } /** - * Returns a GUIDv4 string - * - * Thanks to Dave Pearson (and other) - * https://www.php.net/manual/en/function.com-create-guid.php#119168 - * - * Uses the best cryptographically secure method - * for all supported platforms with fallback to an older, - * less secure version. - * - * @param bool $trim - * @return string - */ + * Returns a GUIDv4 string + * + * Thanks to Dave Pearson (and other) + * https://www.php.net/manual/en/function.com-create-guid.php#119168 + * + * Uses the best cryptographically secure method + * for all supported platforms with fallback to an older, + * less secure version. + * + * @param bool $trim + * @return string + */ public static function GUID ($trim = true) { // Windows @@ -2068,15 +2068,58 @@ abstract class ComponentbuilderHelper } /** - * Validate the Globally Unique Identifier - * - * Thanks to Lewie - * https://stackoverflow.com/a/1515456/1429677 - * - * @param string $guid - * @return bool - */ - public static function validGUID ($guid) + * Validate the Globally Unique Identifier ( and check if table already has this identifier) + * + * @param string $guid + * @param string $table + * @param int $id + * @return bool + */ + public static function validGUID ($guid, $table = null, $id = 0) + { + // check if we have a string + if (self::validateGUID($guid)) + { + // check if table already has this identifier + if (self::checkString($table)) + { + // Get the database object and a new query object. + $db = \JFactory::getDbo(); + $query = $db->getQuery(true); + $query->select('COUNT(*)') + ->from('#__componentbuilder_' . (string) $table) + ->where($db->quoteName('guid') . ' = ' . $db->quote($guid)); + + // remove this item from the list + if ($id > 0) + { + $query->where($db->quoteName('id') . ' <> ' . (int) $id); + } + + // Set and query the database. + $db->setQuery($query); + $duplicate = (bool) $db->loadResult(); + + if ($duplicate) + { + return false; + } + } + return true; + } + return false; + } + + /** + * Validate the Globally Unique Identifier + * + * Thanks to Lewie + * https://stackoverflow.com/a/1515456/1429677 + * + * @param string $guid + * @return bool + */ + protected static function validateGUID ($guid) { // check if we have a string if (self::checkString($guid))