Fixed GUID duplication issue.

This commit is contained in:
Llewellyn van der Merwe 2020-05-25 02:38:16 +02:00
parent eda4d594d6
commit 5f1d17bfb3
Signed by untrusted user: Llewellyn
GPG Key ID: EFC0C720A240551C
23 changed files with 241 additions and 83 deletions

View File

@ -144,11 +144,11 @@ TODO
+ *Author*: [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com) + *Author*: [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com)
+ *Name*: [Component Builder](https://github.com/vdm-io/Joomla-Component-Builder) + *Name*: [Component Builder](https://github.com/vdm-io/Joomla-Component-Builder)
+ *First Build*: 30th April, 2015 + *First Build*: 30th April, 2015
+ *Last Build*: 22nd May, 2020 + *Last Build*: 25th May, 2020
+ *Version*: 2.11.1 + *Version*: 2.11.1
+ *Copyright*: Copyright (C) 2015 - 2020 Vast Development Method. All rights reserved. + *Copyright*: Copyright (C) 2015 - 2020 Vast Development Method. All rights reserved.
+ *License*: GNU General Public License version 2 or later; see LICENSE.txt + *License*: GNU General Public License version 2 or later; see LICENSE.txt
+ *Line count*: **281750** + *Line count*: **281857**
+ *Field count*: **1522** + *Field count*: **1522**
+ *File count*: **1783** + *File count*: **1783**
+ *Folder count*: **295** + *Folder count*: **295**

View File

@ -144,11 +144,11 @@ TODO
+ *Author*: [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com) + *Author*: [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com)
+ *Name*: [Component Builder](https://github.com/vdm-io/Joomla-Component-Builder) + *Name*: [Component Builder](https://github.com/vdm-io/Joomla-Component-Builder)
+ *First Build*: 30th April, 2015 + *First Build*: 30th April, 2015
+ *Last Build*: 22nd May, 2020 + *Last Build*: 25th May, 2020
+ *Version*: 2.11.1 + *Version*: 2.11.1
+ *Copyright*: Copyright (C) 2015 - 2020 Vast Development Method. All rights reserved. + *Copyright*: Copyright (C) 2015 - 2020 Vast Development Method. All rights reserved.
+ *License*: GNU General Public License version 2 or later; see LICENSE.txt + *License*: GNU General Public License version 2 or later; see LICENSE.txt
+ *Line count*: **281750** + *Line count*: **281857**
+ *Field count*: **1522** + *Field count*: **1522**
+ *File count*: **1783** + *File count*: **1783**
+ *Folder count*: **295** + *Folder count*: **295**

View File

@ -9149,6 +9149,8 @@ class Get
// set some placeholder for this plugin // set some placeholder for this plugin
$this->placeholders[$this->bbb . 'Plugin_name' . $this->ddd] $this->placeholders[$this->bbb . 'Plugin_name' . $this->ddd]
= $plugin->official_name; = $plugin->official_name;
$this->placeholders[$this->hhh . 'PLUGIN_NAME' . $this->hhh]
= $plugin->official_name;
$this->placeholders[$this->bbb . 'Plugin' . $this->ddd] $this->placeholders[$this->bbb . 'Plugin' . $this->ddd]
= ucfirst( = ucfirst(
$plugin->code_name $plugin->code_name
@ -9167,11 +9169,15 @@ class Get
); );
$this->placeholders[$this->bbb . 'plugin.version' . $this->ddd] $this->placeholders[$this->bbb . 'plugin.version' . $this->ddd]
= $plugin->plugin_version; = $plugin->plugin_version;
$this->placeholders[$this->hhh . 'VERSION' . $this->hhh]
= $plugin->plugin_version;
$this->placeholders[$this->bbb . 'plugin_version' . $this->ddd] $this->placeholders[$this->bbb . 'plugin_version' . $this->ddd]
= str_replace( = str_replace(
'.', '_', $plugin->plugin_version '.', '_', $plugin->plugin_version
); );
// set description (TODO) add description field to plugin // set description
$this->placeholders[$this->hhh . 'DESCRIPTION' . $this->hhh]
= '';
if (!isset($plugin->description) if (!isset($plugin->description)
|| !ComponentbuilderHelper::checkString( || !ComponentbuilderHelper::checkString(
$plugin->description $plugin->description
@ -9189,6 +9195,9 @@ class Get
$plugin->key, $plugin->lang_prefix . '_DESCRIPTION', $plugin->key, $plugin->lang_prefix . '_DESCRIPTION',
$plugin->description $plugin->description
); );
// set description
$this->placeholders[$this->hhh . 'DESCRIPTION' . $this->hhh]
= $plugin->description;
$plugin->description = '<p>' . $plugin->description $plugin->description = '<p>' . $plugin->description
. '</p>'; . '</p>';
} }
@ -9672,6 +9681,15 @@ class Get
$this->placeholders[$this->bbb . 'plugin_version' $this->placeholders[$this->bbb . 'plugin_version'
. $this->ddd] . $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; $this->joomlaPlugins[$id] = $plugin;

View File

@ -95,6 +95,13 @@ class Fields extends Structure
*/ */
public $dbUniqueKeys = array(); public $dbUniqueKeys = array();
/**
* unique guid swtich
*
* @var array
*/
public $dbUniqueGuid = array();
/** /**
* keys for database field * keys for database field
* *
@ -3850,6 +3857,7 @@ class Fields extends Structure
$this->queryBuilder[$view_name_single][$name]['null_switch'] $this->queryBuilder[$view_name_single][$name]['null_switch']
= $field['settings']->null_switch; = $field['settings']->null_switch;
// set index types // set index types
$_guid = true;
if ($field['settings']->indexes == 1 if ($field['settings']->indexes == 1
&& !in_array( && !in_array(
$field['settings']->datatype, $textKeys $field['settings']->datatype, $textKeys
@ -3857,6 +3865,11 @@ class Fields extends Structure
{ {
// build unique keys of this view for db // build unique keys of this view for db
$this->dbUniqueKeys[$view_name_single][] = $name; $this->dbUniqueKeys[$view_name_single][] = $name;
// prevent guid from being added twice
if ('guid' === $name)
{
$_guid = false;
}
} }
elseif (($field['settings']->indexes == 2 elseif (($field['settings']->indexes == 2
|| (isset($field['alias']) || (isset($field['alias'])
@ -3868,6 +3881,11 @@ class Fields extends Structure
// build keys of this view for db // build keys of this view for db
$this->dbKeys[$view_name_single][] = $name; $this->dbKeys[$view_name_single][] = $name;
} }
// special treatment for GUID
if ('guid' === $name && $_guid)
{
$this->dbUniqueGuid[$view_name_single] = true;
}
} }
// set list switch // set list switch
$listSwitch = (isset($field['list']) $listSwitch = (isset($field['list'])

View File

@ -17164,9 +17164,24 @@ class Interpretation extends Fields
if (isset($this->dbUniqueKeys[$view]) if (isset($this->dbUniqueKeys[$view])
&& ComponentbuilderHelper::checkArray($this->dbUniqueKeys[$view])) && ComponentbuilderHelper::checkArray($this->dbUniqueKeys[$view]))
{ {
$fields[] = $this->_t(2) . "return array('" . implode( // if guid should also be added
"','", $this->dbUniqueKeys[$view] 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 else
{ {

View File

@ -2019,18 +2019,18 @@ abstract class ComponentbuilderHelper
} }
/** /**
* Returns a GUIDv4 string * Returns a GUIDv4 string
* *
* Thanks to Dave Pearson (and other) * Thanks to Dave Pearson (and other)
* https://www.php.net/manual/en/function.com-create-guid.php#119168 * https://www.php.net/manual/en/function.com-create-guid.php#119168
* *
* Uses the best cryptographically secure method * Uses the best cryptographically secure method
* for all supported platforms with fallback to an older, * for all supported platforms with fallback to an older,
* less secure version. * less secure version.
* *
* @param bool $trim * @param bool $trim
* @return string * @return string
*/ */
public static function GUID ($trim = true) public static function GUID ($trim = true)
{ {
// Windows // Windows
@ -2071,15 +2071,58 @@ abstract class ComponentbuilderHelper
} }
/** /**
* Validate the Globally Unique Identifier * Validate the Globally Unique Identifier ( and check if table already has this identifier)
* *
* Thanks to Lewie * @param string $guid
* https://stackoverflow.com/a/1515456/1429677 * @param string $table
* * @param int $id
* @param string $guid * @return bool
* @return bool */
*/ public static function validGUID ($guid, $table = null, $id = 0)
public static function validGUID ($guid) {
// 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 // check if we have a string
if (self::checkString($guid)) if (self::checkString($guid))

View File

@ -1491,7 +1491,7 @@ class ComponentbuilderModelAdmin_view extends JModelAdmin
} }
// Set the GUID if empty or not valid // 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(); $data['guid'] = (string) ComponentbuilderHelper::GUID();
} }

View File

@ -972,7 +972,7 @@ class ComponentbuilderModelClass_method extends JModelAdmin
$data['name'] = ComponentbuilderHelper::safeClassFunctionName($data['name']); $data['name'] = ComponentbuilderHelper::safeClassFunctionName($data['name']);
// Set the GUID if empty or not valid // 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(); $data['guid'] = (string) ComponentbuilderHelper::GUID();
} }

View File

@ -963,7 +963,7 @@ class ComponentbuilderModelClass_property extends JModelAdmin
$data['name'] = ComponentbuilderHelper::safeClassFunctionName($data['name']); $data['name'] = ComponentbuilderHelper::safeClassFunctionName($data['name']);
// Set the GUID if empty or not valid // 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(); $data['guid'] = (string) ComponentbuilderHelper::GUID();
} }

View File

@ -1125,7 +1125,7 @@ class ComponentbuilderModelCustom_admin_view extends JModelAdmin
} }
// Set the GUID if empty or not valid // 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(); $data['guid'] = (string) ComponentbuilderHelper::GUID();
} }

View File

@ -1148,7 +1148,7 @@ class ComponentbuilderModelDynamic_get extends JModelAdmin
// Set the GUID if empty or not valid // 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(); $data['guid'] = (string) ComponentbuilderHelper::GUID();
} }

View File

@ -1144,7 +1144,7 @@ class ComponentbuilderModelField extends JModelAdmin
} }
// Set the GUID if empty or not valid // 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(); $data['guid'] = (string) ComponentbuilderHelper::GUID();
} }

View File

@ -1197,7 +1197,7 @@ class ComponentbuilderModelFieldtype extends JModelAdmin
// Set the GUID if empty or not valid // 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(); $data['guid'] = (string) ComponentbuilderHelper::GUID();
} }

View File

@ -1385,7 +1385,7 @@ class ComponentbuilderModelJoomla_component extends JModelAdmin
} }
// Set the GUID if empty or not valid // 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(); $data['guid'] = (string) ComponentbuilderHelper::GUID();
} }

View File

@ -1199,7 +1199,7 @@ class ComponentbuilderModelJoomla_module extends JModelAdmin
} }
// Set the GUID if empty or not valid // 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(); $data['guid'] = (string) ComponentbuilderHelper::GUID();
} }

View File

@ -1162,7 +1162,7 @@ class ComponentbuilderModelJoomla_plugin extends JModelAdmin
} }
// Set the GUID if empty or not valid // 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(); $data['guid'] = (string) ComponentbuilderHelper::GUID();
} }

View File

@ -1048,7 +1048,7 @@ class ComponentbuilderModelLibrary extends JModelAdmin
// Set the GUID if empty or not valid // 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(); $data['guid'] = (string) ComponentbuilderHelper::GUID();
} }

View File

@ -1146,7 +1146,7 @@ class ComponentbuilderModelSite_view extends JModelAdmin
} }
// Set the GUID if empty or not valid // 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(); $data['guid'] = (string) ComponentbuilderHelper::GUID();
} }

View File

@ -852,7 +852,7 @@ class ComponentbuilderModelSnippet extends JModelAdmin
} }
// Set the GUID if empty or not valid // 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(); $data['guid'] = (string) ComponentbuilderHelper::GUID();
} }

View File

@ -100,7 +100,6 @@ CREATE TABLE IF NOT EXISTS `#__componentbuilder_joomla_component` (
`metadesc` TEXT NOT NULL, `metadesc` TEXT NOT NULL,
`metadata` TEXT NOT NULL, `metadata` TEXT NOT NULL,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
UNIQUE KEY `idx_guid` (`guid`),
KEY `idx_system_name` (`system_name`), KEY `idx_system_name` (`system_name`),
KEY `idx_name_code` (`name_code`), KEY `idx_name_code` (`name_code`),
KEY `idx_add_php_helper_admin` (`add_php_helper_admin`), 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_update_server_target` (`update_server_target`),
KEY `idx_creatuserhelper` (`creatuserhelper`), KEY `idx_creatuserhelper` (`creatuserhelper`),
KEY `idx_adduikit` (`adduikit`), KEY `idx_adduikit` (`adduikit`),
KEY `idx_guid` (`guid`),
KEY `idx_access` (`access`), KEY `idx_access` (`access`),
KEY `idx_checkout` (`checked_out`), KEY `idx_checkout` (`checked_out`),
KEY `idx_createdby` (`created_by`), 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, `access` INT(10) unsigned NOT NULL DEFAULT 0,
`ordering` INT(11) NOT NULL DEFAULT 0, `ordering` INT(11) NOT NULL DEFAULT 0,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
UNIQUE KEY `idx_guid` (`guid`),
KEY `idx_system_name` (`system_name`), KEY `idx_system_name` (`system_name`),
KEY `idx_add_php_method_uninstall` (`add_php_method_uninstall`), KEY `idx_add_php_method_uninstall` (`add_php_method_uninstall`),
KEY `idx_add_php_postflight_update` (`add_php_postflight_update`), 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_php_preflight_install` (`add_php_preflight_install`),
KEY `idx_add_sales_server` (`add_sales_server`), KEY `idx_add_sales_server` (`add_sales_server`),
KEY `idx_add_php_preflight_update` (`add_php_preflight_update`), KEY `idx_add_php_preflight_update` (`add_php_preflight_update`),
KEY `idx_guid` (`guid`),
KEY `idx_name` (`name`), KEY `idx_name` (`name`),
KEY `idx_access` (`access`), KEY `idx_access` (`access`),
KEY `idx_checkout` (`checked_out`), 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, `access` INT(10) unsigned NOT NULL DEFAULT 0,
`ordering` INT(11) NOT NULL DEFAULT 0, `ordering` INT(11) NOT NULL DEFAULT 0,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
UNIQUE KEY `idx_guid` (`guid`),
KEY `idx_system_name` (`system_name`), KEY `idx_system_name` (`system_name`),
KEY `idx_class_extends` (`class_extends`), KEY `idx_class_extends` (`class_extends`),
KEY `idx_joomla_plugin_group` (`joomla_plugin_group`), 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_update` (`add_php_preflight_update`),
KEY `idx_add_php_preflight_uninstall` (`add_php_preflight_uninstall`), KEY `idx_add_php_preflight_uninstall` (`add_php_preflight_uninstall`),
KEY `idx_add_sales_server` (`add_sales_server`), KEY `idx_add_sales_server` (`add_sales_server`),
KEY `idx_guid` (`guid`),
KEY `idx_name` (`name`), KEY `idx_name` (`name`),
KEY `idx_access` (`access`), KEY `idx_access` (`access`),
KEY `idx_checkout` (`checked_out`), 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, `access` INT(10) unsigned NOT NULL DEFAULT 0,
`ordering` INT(11) NOT NULL DEFAULT 0, `ordering` INT(11) NOT NULL DEFAULT 0,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
UNIQUE KEY `idx_guid` (`guid`),
KEY `idx_name_single` (`name_single`), KEY `idx_name_single` (`name_single`),
KEY `idx_name_list` (`name_list`), KEY `idx_name_list` (`name_list`),
KEY `idx_add_fadein` (`add_fadein`), 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_custom_import` (`add_custom_import`),
KEY `idx_add_php_getitems` (`add_php_getitems`), KEY `idx_add_php_getitems` (`add_php_getitems`),
KEY `idx_add_php_getitems_after_all` (`add_php_getitems_after_all`), KEY `idx_add_php_getitems_after_all` (`add_php_getitems_after_all`),
KEY `idx_guid` (`guid`),
KEY `idx_access` (`access`), KEY `idx_access` (`access`),
KEY `idx_checkout` (`checked_out`), KEY `idx_checkout` (`checked_out`),
KEY `idx_createdby` (`created_by`), 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, `access` INT(10) unsigned NOT NULL DEFAULT 0,
`ordering` INT(11) NOT NULL DEFAULT 0, `ordering` INT(11) NOT NULL DEFAULT 0,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
UNIQUE KEY `idx_guid` (`guid`),
KEY `idx_name` (`name`), KEY `idx_name` (`name`),
KEY `idx_main_get` (`main_get`), KEY `idx_main_get` (`main_get`),
KEY `idx_add_php_jview_display` (`add_php_jview_display`), 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_add_php_ajax` (`add_php_ajax`),
KEY `idx_dynamic_get` (`dynamic_get`), KEY `idx_dynamic_get` (`dynamic_get`),
KEY `idx_add_custom_button` (`add_custom_button`), KEY `idx_add_custom_button` (`add_custom_button`),
KEY `idx_guid` (`guid`),
KEY `idx_access` (`access`), KEY `idx_access` (`access`),
KEY `idx_checkout` (`checked_out`), KEY `idx_checkout` (`checked_out`),
KEY `idx_createdby` (`created_by`), 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, `access` INT(10) unsigned NOT NULL DEFAULT 0,
`ordering` INT(11) NOT NULL DEFAULT 0, `ordering` INT(11) NOT NULL DEFAULT 0,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
UNIQUE KEY `idx_guid` (`guid`),
KEY `idx_name` (`name`), KEY `idx_name` (`name`),
KEY `idx_main_get` (`main_get`), KEY `idx_main_get` (`main_get`),
KEY `idx_add_php_jview_display` (`add_php_jview_display`), 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_php_ajax` (`add_php_ajax`),
KEY `idx_add_custom_button` (`add_custom_button`), KEY `idx_add_custom_button` (`add_custom_button`),
KEY `idx_button_position` (`button_position`), KEY `idx_button_position` (`button_position`),
KEY `idx_guid` (`guid`),
KEY `idx_access` (`access`), KEY `idx_access` (`access`),
KEY `idx_checkout` (`checked_out`), KEY `idx_checkout` (`checked_out`),
KEY `idx_createdby` (`created_by`), 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, `access` INT(10) unsigned NOT NULL DEFAULT 0,
`ordering` INT(11) NOT NULL DEFAULT 0, `ordering` INT(11) NOT NULL DEFAULT 0,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
UNIQUE KEY `idx_guid` (`guid`),
KEY `idx_name` (`name`), KEY `idx_name` (`name`),
KEY `idx_main_source` (`main_source`), KEY `idx_main_source` (`main_source`),
KEY `idx_gettype` (`gettype`), 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_before_getitems` (`add_php_before_getitems`),
KEY `idx_add_php_after_getitems` (`add_php_after_getitems`), KEY `idx_add_php_after_getitems` (`add_php_after_getitems`),
KEY `idx_add_php_router_parse` (`add_php_router_parse`), KEY `idx_add_php_router_parse` (`add_php_router_parse`),
KEY `idx_guid` (`guid`),
KEY `idx_access` (`access`), KEY `idx_access` (`access`),
KEY `idx_checkout` (`checked_out`), KEY `idx_checkout` (`checked_out`),
KEY `idx_createdby` (`created_by`), 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, `access` INT(10) unsigned NOT NULL DEFAULT 0,
`ordering` INT(11) NOT NULL DEFAULT 0, `ordering` INT(11) NOT NULL DEFAULT 0,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
UNIQUE KEY `idx_guid` (`guid`),
KEY `idx_name` (`name`), KEY `idx_name` (`name`),
KEY `idx_visibility` (`visibility`), KEY `idx_visibility` (`visibility`),
KEY `idx_guid` (`guid`),
KEY `idx_joomla_plugin_group` (`joomla_plugin_group`), KEY `idx_joomla_plugin_group` (`joomla_plugin_group`),
KEY `idx_access` (`access`), KEY `idx_access` (`access`),
KEY `idx_checkout` (`checked_out`), 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, `access` INT(10) unsigned NOT NULL DEFAULT 0,
`ordering` INT(11) NOT NULL DEFAULT 0, `ordering` INT(11) NOT NULL DEFAULT 0,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
UNIQUE KEY `idx_guid` (`guid`),
KEY `idx_name` (`name`), KEY `idx_name` (`name`),
KEY `idx_visibility` (`visibility`), KEY `idx_visibility` (`visibility`),
KEY `idx_guid` (`guid`),
KEY `idx_joomla_plugin_group` (`joomla_plugin_group`), KEY `idx_joomla_plugin_group` (`joomla_plugin_group`),
KEY `idx_access` (`access`), KEY `idx_access` (`access`),
KEY `idx_checkout` (`checked_out`), KEY `idx_checkout` (`checked_out`),
@ -910,9 +910,9 @@ CREATE TABLE IF NOT EXISTS `#__componentbuilder_library` (
`access` INT(10) unsigned NOT NULL DEFAULT 0, `access` INT(10) unsigned NOT NULL DEFAULT 0,
`ordering` INT(11) NOT NULL DEFAULT 0, `ordering` INT(11) NOT NULL DEFAULT 0,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
UNIQUE KEY `idx_guid` (`guid`),
KEY `idx_name` (`name`), KEY `idx_name` (`name`),
KEY `idx_how` (`how`), KEY `idx_how` (`how`),
KEY `idx_guid` (`guid`),
KEY `idx_access` (`access`), KEY `idx_access` (`access`),
KEY `idx_checkout` (`checked_out`), KEY `idx_checkout` (`checked_out`),
KEY `idx_createdby` (`created_by`), KEY `idx_createdby` (`created_by`),
@ -949,10 +949,10 @@ CREATE TABLE IF NOT EXISTS `#__componentbuilder_snippet` (
`access` INT(10) unsigned NOT NULL DEFAULT 0, `access` INT(10) unsigned NOT NULL DEFAULT 0,
`ordering` INT(11) NOT NULL DEFAULT 0, `ordering` INT(11) NOT NULL DEFAULT 0,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
UNIQUE KEY `idx_guid` (`guid`),
KEY `idx_name` (`name`), KEY `idx_name` (`name`),
KEY `idx_type` (`type`), KEY `idx_type` (`type`),
KEY `idx_library` (`library`), KEY `idx_library` (`library`),
KEY `idx_guid` (`guid`),
KEY `idx_access` (`access`), KEY `idx_access` (`access`),
KEY `idx_checkout` (`checked_out`), KEY `idx_checkout` (`checked_out`),
KEY `idx_createdby` (`created_by`), KEY `idx_createdby` (`created_by`),
@ -1029,7 +1029,6 @@ CREATE TABLE IF NOT EXISTS `#__componentbuilder_field` (
`access` INT(10) unsigned NOT NULL DEFAULT 0, `access` INT(10) unsigned NOT NULL DEFAULT 0,
`ordering` INT(11) NOT NULL DEFAULT 0, `ordering` INT(11) NOT NULL DEFAULT 0,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
UNIQUE KEY `idx_guid` (`guid`),
KEY `idx_name` (`name`), KEY `idx_name` (`name`),
KEY `idx_fieldtype` (`fieldtype`), KEY `idx_fieldtype` (`fieldtype`),
KEY `idx_datatype` (`datatype`), 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_css_views` (`add_css_views`),
KEY `idx_add_javascript_view_footer` (`add_javascript_view_footer`), KEY `idx_add_javascript_view_footer` (`add_javascript_view_footer`),
KEY `idx_add_javascript_views_footer` (`add_javascript_views_footer`), KEY `idx_add_javascript_views_footer` (`add_javascript_views_footer`),
KEY `idx_guid` (`guid`),
KEY `idx_access` (`access`), KEY `idx_access` (`access`),
KEY `idx_checkout` (`checked_out`), KEY `idx_checkout` (`checked_out`),
KEY `idx_createdby` (`created_by`), KEY `idx_createdby` (`created_by`),
@ -1082,7 +1082,6 @@ CREATE TABLE IF NOT EXISTS `#__componentbuilder_fieldtype` (
`access` INT(10) unsigned NOT NULL DEFAULT 0, `access` INT(10) unsigned NOT NULL DEFAULT 0,
`ordering` INT(11) NOT NULL DEFAULT 0, `ordering` INT(11) NOT NULL DEFAULT 0,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
UNIQUE KEY `idx_guid` (`guid`),
KEY `idx_name` (`name`), KEY `idx_name` (`name`),
KEY `idx_null_switch` (`null_switch`), KEY `idx_null_switch` (`null_switch`),
KEY `idx_indexes` (`indexes`), KEY `idx_indexes` (`indexes`),
@ -1092,6 +1091,7 @@ CREATE TABLE IF NOT EXISTS `#__componentbuilder_fieldtype` (
KEY `idx_datatype` (`datatype`), KEY `idx_datatype` (`datatype`),
KEY `idx_has_defaults` (`has_defaults`), KEY `idx_has_defaults` (`has_defaults`),
KEY `idx_datalenght` (`datalenght`), KEY `idx_datalenght` (`datalenght`),
KEY `idx_guid` (`guid`),
KEY `idx_catid` (`catid`), KEY `idx_catid` (`catid`),
KEY `idx_access` (`access`), KEY `idx_access` (`access`),
KEY `idx_checkout` (`checked_out`), KEY `idx_checkout` (`checked_out`),

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<extension type="component" version="3.2" method="upgrade"> <extension type="component" version="3.2" method="upgrade">
<name>COM_COMPONENTBUILDER</name> <name>COM_COMPONENTBUILDER</name>
<creationDate>22nd May, 2020</creationDate> <creationDate>25th May, 2020</creationDate>
<author>Llewellyn van der Merwe</author> <author>Llewellyn van der Merwe</author>
<authorEmail>llewellyn@joomlacomponentbuilder.com</authorEmail> <authorEmail>llewellyn@joomlacomponentbuilder.com</authorEmail>
<authorUrl>http://www.joomlacomponentbuilder.com</authorUrl> <authorUrl>http://www.joomlacomponentbuilder.com</authorUrl>

View File

@ -8973,9 +8973,11 @@ class com_componentbuilderInstallerScript
} }
} }
} }
// target version less then 2.11.0 // target version less then or equal to 2.11.1
if (count($this->JCBversion) == 3 && $this->JCBversion[0] <= 2 && $this->JCBversion[1] < 11) 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 * Returns a GUIDv4 string
* *
@ -9037,7 +9039,7 @@ class com_componentbuilderInstallerScript
* @param string $guid * @param string $guid
* @return bool * @return bool
*/ */
function validGUID ($guid) function validateGUID ($guid)
{ {
// check if we have a string // check if we have a string
if (ComponentbuilderHelper::checkString($guid)) if (ComponentbuilderHelper::checkString($guid))
@ -9047,6 +9049,23 @@ class com_componentbuilderInstallerScript
return false; 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 :) // we must update all GUID's for future use :)
$guid_tables = array( $guid_tables = array(
'joomla_component', 'joomla_component',
@ -9077,10 +9096,14 @@ class com_componentbuilderInstallerScript
$db->execute(); $db->execute();
if ($db->getNumRows()) if ($db->getNumRows())
{ {
// keep track of used
$usedGUID = array();
// get the rows
$rows = $db->loadObjectList(); $rows = $db->loadObjectList();
foreach ($rows as $row) 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. // Create a new query object.
$query = $db->getQuery(true); $query = $db->getQuery(true);
@ -9100,8 +9123,6 @@ class com_componentbuilderInstallerScript
} }
} }
} }
// set a notice that this was done
$app->enqueueMessage('<p>Globally Unique Identifier <b>GUID</b> was added to <b>various tables</b> in JCB, thanks to <strong><a href="https://vdm.bz/get-jcb-pro-membership" target="_blank">PRO members</a></strong> contribution!</p>', 'Notice');
} }
// check if this install has the libraries in the helper folder, if so remove it // check if this install has the libraries in the helper folder, if so remove it
$vendorPath = JPATH_ADMINISTRATOR . '/components/com_componentbuilder/helpers/vendor'; $vendorPath = JPATH_ADMINISTRATOR . '/components/com_componentbuilder/helpers/vendor';

View File

@ -2016,18 +2016,18 @@ abstract class ComponentbuilderHelper
} }
/** /**
* Returns a GUIDv4 string * Returns a GUIDv4 string
* *
* Thanks to Dave Pearson (and other) * Thanks to Dave Pearson (and other)
* https://www.php.net/manual/en/function.com-create-guid.php#119168 * https://www.php.net/manual/en/function.com-create-guid.php#119168
* *
* Uses the best cryptographically secure method * Uses the best cryptographically secure method
* for all supported platforms with fallback to an older, * for all supported platforms with fallback to an older,
* less secure version. * less secure version.
* *
* @param bool $trim * @param bool $trim
* @return string * @return string
*/ */
public static function GUID ($trim = true) public static function GUID ($trim = true)
{ {
// Windows // Windows
@ -2068,15 +2068,58 @@ abstract class ComponentbuilderHelper
} }
/** /**
* Validate the Globally Unique Identifier * Validate the Globally Unique Identifier ( and check if table already has this identifier)
* *
* Thanks to Lewie * @param string $guid
* https://stackoverflow.com/a/1515456/1429677 * @param string $table
* * @param int $id
* @param string $guid * @return bool
* @return bool */
*/ public static function validGUID ($guid, $table = null, $id = 0)
public static function validGUID ($guid) {
// 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 // check if we have a string
if (self::checkString($guid)) if (self::checkString($guid))