Fixed GUID duplication issue.
This commit is contained in:
@@ -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 = '<p>' . $plugin->description
|
||||
. '</p>';
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
|
@@ -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'])
|
||||
|
@@ -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
|
||||
{
|
||||
|
@@ -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))
|
||||
|
Reference in New Issue
Block a user