Update 2025-02-15 05:06:14

This commit is contained in:
Robot 2025-02-15 17:06:19 +02:00
parent 77f23fb8c2
commit b87e1f91aa
Signed by: Robot
GPG Key ID: 14DECD44E7E1BB95
157 changed files with 2335 additions and 721 deletions

View File

@ -159,6 +159,9 @@ This repository contains an index (see below) of all the approved powers within
- **class Insert** | [Details](src/a455d916-cfe4-41df-9245-bafb709aacdb) | [Code](src/a455d916-cfe4-41df-9245-bafb709aacdb/code.php) | [Settings](src/a455d916-cfe4-41df-9245-bafb709aacdb/settings.json) | SPK: `Super---a455d916_cfe4_41df_9245_bafb709aacdb---Power`
- **class Load** | [Details](src/008d111c-9d43-427c-8dd4-2653e8b74be8) | [Code](src/008d111c-9d43-427c-8dd4-2653e8b74be8/code.php) | [Settings](src/008d111c-9d43-427c-8dd4-2653e8b74be8/settings.json) | SPK: `Super---008d111c_9d43_427c_8dd4_2653e8b74be8---Power`
- **class Update** | [Details](src/8f83fb79-f92b-4f1f-952b-325f6c22d11e) | [Code](src/8f83fb79-f92b-4f1f-952b-325f6c22d11e/code.php) | [Settings](src/8f83fb79-f92b-4f1f-952b-325f6c22d11e/settings.json) | SPK: `Super---8f83fb79_f92b_4f1f_952b_325f6c22d11e---Power`
- **Namespace**: [VDM\Joomla\Data\Migrator](#vdm-joomla-data-migrator)
- **final class Guid** | [Details](src/0b746305-d34e-4c21-bc20-898c4aeac376) | [Code](src/0b746305-d34e-4c21-bc20-898c4aeac376/code.php) | [Settings](src/0b746305-d34e-4c21-bc20-898c4aeac376/settings.json) | SPK: `Super---0b746305_d34e_4c21_bc20_898c4aeac376---Power`
- **Namespace**: [VDM\Joomla\Interfaces\Data](#vdm-joomla-interfaces-data)
- **interface DeleteInterface** | [Details](src/d8f9ba53-c490-4e8b-8e9f-6757224e069c) | [Code](src/d8f9ba53-c490-4e8b-8e9f-6757224e069c/code.php) | [Settings](src/d8f9ba53-c490-4e8b-8e9f-6757224e069c/settings.json) | SPK: `Super---d8f9ba53_c490_4e8b_8e9f_6757224e069c---Power`
@ -201,6 +204,9 @@ This repository contains an index (see below) of all the approved powers within
- **trait PathCount** | [Details](src/11572d9b-e3d5-4b29-904c-9618d8f2bfd8) | [Code](src/11572d9b-e3d5-4b29-904c-9618d8f2bfd8/code.php) | [Settings](src/11572d9b-e3d5-4b29-904c-9618d8f2bfd8/settings.json) | SPK: `Super---11572d9b_e3d5_4b29_904c_9618d8f2bfd8---Power`
- **trait PathToString** | [Details](src/7d494d91-ab60-43cd-aecf-d50e07f7f30e) | [Code](src/7d494d91-ab60-43cd-aecf-d50e07f7f30e/code.php) | [Settings](src/7d494d91-ab60-43cd-aecf-d50e07f7f30e/settings.json) | SPK: `Super---7d494d91_ab60_43cd_aecf_d50e07f7f30e---Power`
- **trait VarExport** | [Details](src/52a1d14f-304a-431c-8fa4-411179942db5) | [Code](src/52a1d14f-304a-431c-8fa4-411179942db5/code.php) | [Settings](src/52a1d14f-304a-431c-8fa4-411179942db5/settings.json) | SPK: `Super---52a1d14f_304a_431c_8fa4_411179942db5---Power`
- **Namespace**: [VDM\Joomla\Componentbuilder\Data\Migrator](#vdm-joomla-componentbuilder-data-migrator)
- **abstract class Factory** | [Details](src/f04c13b3-e24e-4cb5-b858-c4fe83c6f991) | [Code](src/f04c13b3-e24e-4cb5-b858-c4fe83c6f991/code.php) | [Settings](src/f04c13b3-e24e-4cb5-b858-c4fe83c6f991/settings.json) | SPK: `Super---f04c13b3_e24e_4cb5_b858_c4fe83c6f991---Power`
- **Namespace**: [VDM\Joomla\Componentbuilder\File\Service](#vdm-joomla-componentbuilder-file-service)
- **class File** | [Details](src/202ccd9e-dfcf-4cde-a0ce-bde1fd27f088) | [Code](src/202ccd9e-dfcf-4cde-a0ce-bde1fd27f088/code.php) | [Settings](src/202ccd9e-dfcf-4cde-a0ce-bde1fd27f088/settings.json) | SPK: `Super---202ccd9e_dfcf_4cde_a0ce_bde1fd27f088---Power`

View File

@ -1,6 +1,6 @@
{
"add_head": "0",
"add_licensing_template": "2",
"add_head": 0,
"add_licensing_template": 2,
"extends": "",
"guid": "008d111c-9d43-427c-8dd4-2653e8b74be8",
"implements": [

View File

@ -1,6 +1,6 @@
{
"add_head": "0",
"add_licensing_template": "2",
"add_head": 0,
"add_licensing_template": 2,
"extends": "",
"guid": "03bbc8d5-86e8-4d2f-ae5f-0d44a4f7af13",
"implements": null,

View File

@ -1,6 +1,6 @@
{
"add_head": "0",
"add_licensing_template": "2",
"add_head": 0,
"add_licensing_template": 2,
"extends": "",
"guid": "05744dd3-4030-4cf8-8dda-a93ab809b473",
"implements": null,

View File

@ -1,6 +1,6 @@
{
"add_head": "0",
"add_licensing_template": "2",
"add_head": 0,
"add_licensing_template": 2,
"extends": "7e822c03-1b20-41d1-9427-f5b8d5836af7",
"guid": "05f23281-58e3-482e-be42-2dc1355ef4ea",
"implements": null,

View File

@ -1,6 +1,6 @@
{
"add_head": "0",
"add_licensing_template": "2",
"add_head": 0,
"add_licensing_template": 2,
"extends": "6cbef8f8-4813-48e3-b05a-65e1aea95171",
"guid": "06f8eada-d59b-441c-b287-0aea1793da5a",
"implements": [

View File

@ -1,6 +1,6 @@
{
"add_head": "0",
"add_licensing_template": "2",
"add_head": 0,
"add_licensing_template": 2,
"extends": "",
"guid": "0a59c65c-9daf-4bc9-baf4-e063ff9e6a8a",
"implements": null,

View File

@ -0,0 +1,173 @@
```
██████╗ ██████╗ ██╗ ██╗███████╗██████╗
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
```
# final class Guid (Details)
> namespace: **VDM\Joomla\Data\Migrator**
```uml
@startuml
class Guid << (F,LightGreen) >> #RoyalBlue {
# Items $items
# Load $load
# Update $update
# array $guidCache
# string $table
- array $success
+ __construct(Items $items, Load $load, ...)
+ process(array $config) : array
- processMapping(array $mapping) : void
- processBasicValue(array $mapping) : void
- processSubformValue(array $mapping) : void
- processSubSubformValue(array $mapping) : void
- getItemGuid(string $table, string $column, ...) : ?string
- processJson(string $values, string $linkedTable, ...) : string
- processArray(array $values, string $linkedTable, ...) : array
- updateValue(string $table, string $column, ...) : bool
- setTable(string $table) : void
- getTable() : string
}
note right of Guid::__construct
Constructor.
since: 5.0.4
arguments:
Items $items
Load $load
Update $update
end note
note left of Guid::process
Processes the configuration to migrate IDs to GUIDs.
since: 5.0.4
return: array
end note
note right of Guid::processMapping
Processes a single mapping based on its type.
since: 5.0.4
return: void
end note
note left of Guid::processBasicValue
Processes basic values in a table and replaces IDs with GUIDs.
since: 5.0.4
return: void
end note
note right of Guid::processSubformValue
Processes subform values in a table and replaces IDs with GUIDs.
since: 5.0.4
return: void
end note
note left of Guid::processSubSubformValue
Processes sub-subform values in a table and replaces IDs with GUIDs.
since: 5.0.4
return: void
end note
note right of Guid::getItemGuid
Retrieves or creates a GUID for a given linked table and ID (ITEM).
since: 5.0.4
return: ?string
arguments:
string $table
string $column
mixed $value
end note
note left of Guid::processJson
Processes an json-array of basic values and replaces them with GUIDs.
since: 5.0.4
return: string
arguments:
string $values
string $linkedTable
string $linkedColumn
string $hasUpdate
end note
note right of Guid::processArray
Processes an array values and replaces them with GUIDs.
since: 5.0.4
return: array
arguments:
array $values
string $linkedTable
string $linkedColumn
string $hasUpdate
end note
note left of Guid::updateValue
Updates a value in the database.
since: 5.0.4
return: bool
arguments:
string $table
string $column
string $value
int $id
end note
note right of Guid::setTable
Set the current active table
since: 5.0.4
return: void
end note
note left of Guid::getTable
Get the current active table
since: 5.0.4
return: string
end note
@enduml
```
The Power feature in JCB allows you to write PHP classes and their implementations, making it easy to include them in your Joomla project. JCB handles linking, autoloading, namespacing, and folder structure creation for you.
By using the SPK (Super Power Key) in your custom code (replacing the class name in your code with the SPK), JCB will automatically pull the power from the repository into your project. This makes it available in your JCB instance, allowing you to edit it and include the class in your generated Joomla component.
JCB uses placeholders like [[[`NamespacePrefix`]]] and [[[`ComponentNamespace`]]] in namespacing to prevent collisions and improve reusability across different JCB systems. You can also set the **JCB powers path** globally or per component under the **Dynamic Integration** tab, providing flexibility and easy maintainability.
To add this specific Power to your project in JCB:
> simply use this SPK
```
Super---0b746305_d34e_4c21_bc20_898c4aeac376---Power
```
> remember to replace the `---` with `___` to activate this Power in your code
---
```
██╗ ██████╗██████╗
██║██╔════╝██╔══██╗
██║██║ ██████╔╝
██ ██║██║ ██╔══██╗
╚█████╔╝╚██████╗██████╔╝
╚════╝ ╚═════╝╚═════╝
```
> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)

View File

@ -0,0 +1,548 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 4th September, 2020
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace VDM\Joomla\Data\Migrator;
use Joomla\Registry\Registry;
use VDM\Joomla\Data\Items;
use VDM\Joomla\Database\Load;
use VDM\Joomla\Database\Update;
use VDM\Joomla\Data\Guid as TraitGuid;
/**
* Migrator To Globally Unique Identifier
*
* @since 5.0.4
*/
final class Guid
{
/**
* The Globally Unique Identifier.
*
* @since 5.0.4
*/
use TraitGuid;
/**
* The Items Class.
*
* @var Items
* @since 5.0.4
*/
protected Items $items;
/**
* The Load Class.
*
* @var Load
* @since 5.0.4
*/
protected Load $load;
/**
* The Update Class.
*
* @var Update
* @since 5.0.4
*/
protected Update $update;
/**
* Cache for storing GUIDs to minimize redundant database queries.
*
* @var array
* @since 5.0.4
*/
protected array $guidCache = [];
/**
* Table Name
*
* @var string
* @since 5.0.4
*/
protected string $table;
/**
* Cache all success messages.
*
* @var array
* @since 5.0.4
*/
private array $success = [];
/**
* Constructor.
*
* @param Items $items The Items Class.
* @param Load $load The Load Class.
* @param Update $update The Update Class.
*
* @since 5.0.4
*/
public function __construct(Items $items, Load $load, Update $update)
{
$this->items = $items;
$this->load = $load;
$this->update = $update;
}
/**
* Processes the configuration to migrate IDs to GUIDs.
*
* @param array $config Configuration array defining table and column mappings.
*
* @return array of success messages
* @since 5.0.4
*/
public function process(array $config): array
{
try {
$size = count($config);
$this->success = [
"Success: scan to migrate linked IDs to linked GUIDs has started on {$size} field areas."
];
foreach ($config as $mapping)
{
$this->processMapping($mapping);
}
} catch (\Exception $e) {
throw new \Exception("Error: migrating linked IDs to linked GUIDs. " . $e->getMessage());
}
if (count($this->success) == 1)
{
$this->success[] = "Success: migration completed and all linked IDs are now migrated to linked GUIDs (on previous run).";
}
else
{
$this->success[] = "Success: migration completed and all linked IDs are now migrated to linked GUIDs.";
}
return $this->success;
}
/**
* Processes a single mapping based on its type.
*
* @param array $mapping Configuration for the current table and column.
*
* @return void
* @since 5.0.4
*/
private function processMapping(array $mapping): void
{
if ($mapping['valueType'] == 1)
{
$this->processBasicValue($mapping);
}
elseif ($mapping['valueType'] == 2)
{
$this->processSubformValue($mapping);
}
elseif ($mapping['valueType'] == 3)
{
$this->processSubSubformValue($mapping);
}
// allow for down stream function
elseif ($mapping['valueType'] == 4 &&
isset($mapping['function']) &&
method_exists($this, $mapping['function']))
{
$this->{$mapping['function']}($mapping);
}
}
/**
* Processes basic values in a table and replaces IDs with GUIDs.
*
* @param array $mapping Configuration for the current table and column.
*
* @return void
* @since 5.0.4
*/
private function processBasicValue(array $mapping): void
{
$table = $mapping['table'];
$column = $mapping['column'];
$linkedTable = $mapping['linkedTable'];
$linkedColumn = $mapping['linkedColumn'];
$isArray = $mapping['array'];
$update = false;
$rows = $this->load->rows(["a.{$column}" => $column, 'a.id' => 'id'], ['a' => $table]) ?? [];
foreach ($rows as $row)
{
$parentId = $row['id'];
$value = $row[$column] ?? null;
$hasUpdate = false;
$updatedValue = null;
if (empty($value))
{
continue;
}
if ($isArray)
{
$updatedValue = (is_array($value))
? $this->processArray($value, $linkedTable, $linkedColumn, $hasUpdate)
: $this->processJson($value, $linkedTable, $linkedColumn, $hasUpdate);
}
elseif (is_numeric($value))
{
$guid = $this->getItemGuid($linkedTable, $linkedColumn, $value);
if ($guid !== null)
{
$updatedValue = $guid;
$hasUpdate = true;
}
}
if (!$hasUpdate || $updatedValue === null)
{
continue; // Skip if no GUID updated or returned
}
if ($this->updateValue($table, $column, $updatedValue, $parentId))
{
$update = true;
}
}
if ($update)
{
$this->success[] = "Success: migrated {$column}:field in {$table}:table to GUIDs from {$linkedTable}:table.";
}
}
/**
* Processes subform values in a table and replaces IDs with GUIDs.
*
* @param array $mapping Configuration for the current table and subform column/field.
*
* @return void
* @since 5.0.4
*/
private function processSubformValue(array $mapping): void
{
$table = $mapping['table'];
$column = $mapping['column'];
$field = $mapping['field'];
$linkedTable = $mapping['linkedTable'];
$linkedColumn = $mapping['linkedColumn'];
$isArray = $mapping['array'];
$update = false;
$rows = $this->load->rows(["a.{$column}" => $column, 'a.id' => 'id'], ['a' => $table]) ?? [];
foreach ($rows as $row)
{
$parentId = $row['id'];
$jsonData = $row[$column] ?? null;
if (empty($jsonData))
{
continue;
}
$registry = new Registry($jsonData);
$subformData = $registry->toArray();
$hasUpdate = false;
foreach ($subformData as &$item)
{
if (!empty($item[$field]))
{
if ($isArray)
{
$item[$field] = (is_array($item[$field]))
? $this->processArray($item[$field], $linkedTable, $linkedColumn, $hasUpdate)
: $this->processJson($item[$field], $linkedTable, $linkedColumn, $hasUpdate);
}
elseif (is_numeric($item[$field]))
{
$guid = $this->getItemGuid($linkedTable, $linkedColumn, $item[$field]);
if ($guid !== null)
{
$item[$field] = $guid;
$hasUpdate = true;
}
}
}
}
if (!$hasUpdate)
{
continue; // Skip if no GUID updated
}
$updatedJson = (string) new Registry($subformData);
if ($this->updateValue($table, $column, $updatedJson, $parentId))
{
$update = true;
}
}
if ($update)
{
$this->success[] = "Success: migrated {$column}->{$field}:field in {$table}:table to GUIDs from {$linkedTable}:table.";
}
}
/**
* Processes sub-subform values in a table and replaces IDs with GUIDs.
*
* @param array $mapping Configuration for the current table and subform column/field.
*
* @return void
* @since 5.0.4
*/
private function processSubSubformValue(array $mapping): void
{
$table = $mapping['table'];
$column = $mapping['column'];
$sub = $mapping['sub'];
$field = $mapping['field'];
$linkedTable = $mapping['linkedTable'];
$linkedColumn = $mapping['linkedColumn'];
$isArray = $mapping['array'];
$update = false;
$rows = $this->load->rows(["a.{$column}" => $column, 'a.id' => 'id'], ['a' => $table]) ?? [];
foreach ($rows as $row)
{
$parentId = $row['id'];
$jsonData = $row[$column] ?? null;
if (empty($jsonData))
{
continue;
}
$registry = new Registry($jsonData);
$subformData = $registry->toArray();
$hasUpdate = false;
foreach ($subformData as &$item)
{
if (isset($item[$sub]) && is_array($item[$sub]))
{
foreach ($item[$sub] as &$subItem)
{
if (!empty($subItem[$field]))
{
if ($isArray)
{
$subItem[$field] = (is_array($subItem[$field]))
? $this->processArray($subItem[$field], $linkedTable, $linkedColumn, $hasUpdate)
: $this->processJson($subItem[$field], $linkedTable, $linkedColumn, $hasUpdate);
}
elseif (is_numeric($subItem[$field]))
{
$guid = $this->getItemGuid($linkedTable, $linkedColumn, $subItem[$field]);
if ($guid !== null)
{
$subItem[$field] = $guid;
$hasUpdate = true;
}
}
}
}
}
}
if (!$hasUpdate)
{
continue; // Skip if no GUID updated
}
$updatedJson = (string) new Registry($subformData);
if ($this->updateValue($table, $column, $updatedJson, $parentId))
{
$update = true;
}
}
if ($update)
{
$this->success[] = "Success: migrated {$column}->{$sub}->{$field}:field in {$table}:table to GUIDs from {$linkedTable}:table.";
}
}
/**
* Retrieves or creates a GUID for a given linked table and ID (ITEM).
*
* @param string $table The linked table name.
* @param string $column The column name in the linked table.
* @param mixed $value The value to check or convert.
*
* @return string|null The GUID for the given value, or null if skipped.
* @throws \Exception If the value is invalid.
* @since 5.0.4
*/
private function getItemGuid(string $table, string $column, $value): ?string
{
if (is_numeric($value))
{
// Check if already in cache
$cacheKey = "$table:$column:$value";
if (isset($this->guidCache[$cacheKey]))
{
return $this->guidCache[$cacheKey];
}
// Retrieve GUID from database
$guid = $this->load->value(['a.guid' => 'guid'], ['a' => $table], ["a.{$column}" => $value]);
if (!$this->validateGuid($guid))
{
// Create a new GUID
$this->setTable($table);
$guid = $this->getGuid('guid');
$this->updateValue($table, 'guid', $guid, $value);
}
// Cache the GUID
$this->guidCache[$cacheKey] = $guid;
return $guid;
}
// Check if the value is already a GUID
if ($this->validateGuid($value))
{
return null; // Skip, already a GUID
}
// convert to visible result
$value_printed = var_export($value, true);
// Raise an exception for invalid values
throw new \Exception("Invalid value detected: ({$table}:table)->({$column}:column)->({$value_printed}:value). Must be either an integer or a valid GUID.");
}
/**
* Processes an json-array of basic values and replaces them with GUIDs.
*
* @param string $values JSON string containing the IDs.
* @param string $linkedTable The linked table name.
* @param string $linkedColumn The linked column name.
* @param string $hasUpdate The switch to manage updates.
*
* @return string JSON string with updated GUIDs.
* @since 5.0.4
*/
private function processJson(string $values, string $linkedTable, string $linkedColumn, bool &$hasUpdate): string
{
$array = json_decode($values, true);
$bucket = [];
foreach ($array as $key => $value)
{
if (!empty($value))
{
$val = $this->getItemGuid($linkedTable, $linkedColumn, $value);
if ($val !== null)
{
$bucket[$key] = $val;
$hasUpdate = true;
}
}
}
return json_encode($bucket);
}
/**
* Processes an array values and replaces them with GUIDs.
*
* @param array $values Array of IDs from the subform field.
* @param string $linkedTable The linked table name.
* @param string $linkedColumn The linked column name.
* @param string $hasUpdate The switch to manage updates.
*
* @return array The updated array with GUIDs.
* @since 5.0.4
*/
private function processArray(array $values, string $linkedTable, string $linkedColumn, bool &$hasUpdate): array
{
$bucket = [];
foreach ($values as $key => $value)
{
if (!empty($value))
{
$val = $this->getItemGuid($linkedTable, $linkedColumn, $value);
if ($val !== null)
{
$bucket[$key] = $val;
$hasUpdate = true;
}
}
}
return $bucket;
}
/**
* Updates a value in the database.
*
* @param string $table The table name.
* @param string $column The column to update.
* @param string $value The updated value.
* @param int $id The ID of the row to update.
*
* @return bool
* @since 5.0.4
*/
private function updateValue(string $table, string $column, string $value, int $id): bool
{
return $this->update->row(['id' => $id, $column => $value], 'id', $table);
}
/**
* Set the current active table
*
* @param string $table The table that should be active
*
* @return void
* @since 5.0.4
*/
private function setTable(string $table): void
{
$this->table = $table;
}
/**
* Get the current active table
*
* @return string
* @since 5.0.4
*/
private function getTable(): string
{
return $this->table;
}
}

View File

@ -0,0 +1,518 @@
/**
* The Globally Unique Identifier.
*
* @since 5.0.4
*/
use TraitGuid;
/**
* The Items Class.
*
* @var Items
* @since 5.0.4
*/
protected Items $items;
/**
* The Load Class.
*
* @var Load
* @since 5.0.4
*/
protected Load $load;
/**
* The Update Class.
*
* @var Update
* @since 5.0.4
*/
protected Update $update;
/**
* Cache for storing GUIDs to minimize redundant database queries.
*
* @var array
* @since 5.0.4
*/
protected array $guidCache = [];
/**
* Table Name
*
* @var string
* @since 5.0.4
*/
protected string $table;
/**
* Cache all success messages.
*
* @var array
* @since 5.0.4
*/
private array $success = [];
/**
* Constructor.
*
* @param Items $items The Items Class.
* @param Load $load The Load Class.
* @param Update $update The Update Class.
*
* @since 5.0.4
*/
public function __construct(Items $items, Load $load, Update $update)
{
$this->items = $items;
$this->load = $load;
$this->update = $update;
}
/**
* Processes the configuration to migrate IDs to GUIDs.
*
* @param array $config Configuration array defining table and column mappings.
*
* @return array of success messages
* @since 5.0.4
*/
public function process(array $config): array
{
try {
$size = count($config);
$this->success = [
"Success: scan to migrate linked IDs to linked GUIDs has started on {$size} field areas."
];
foreach ($config as $mapping)
{
$this->processMapping($mapping);
}
} catch (\Exception $e) {
throw new \Exception("Error: migrating linked IDs to linked GUIDs. " . $e->getMessage());
}
if (count($this->success) == 1)
{
$this->success[] = "Success: migration completed and all linked IDs are now migrated to linked GUIDs (on previous run).";
}
else
{
$this->success[] = "Success: migration completed and all linked IDs are now migrated to linked GUIDs.";
}
return $this->success;
}
/**
* Processes a single mapping based on its type.
*
* @param array $mapping Configuration for the current table and column.
*
* @return void
* @since 5.0.4
*/
private function processMapping(array $mapping): void
{
if ($mapping['valueType'] == 1)
{
$this->processBasicValue($mapping);
}
elseif ($mapping['valueType'] == 2)
{
$this->processSubformValue($mapping);
}
elseif ($mapping['valueType'] == 3)
{
$this->processSubSubformValue($mapping);
}
// allow for down stream function
elseif ($mapping['valueType'] == 4 &&
isset($mapping['function']) &&
method_exists($this, $mapping['function']))
{
$this->{$mapping['function']}($mapping);
}
}
/**
* Processes basic values in a table and replaces IDs with GUIDs.
*
* @param array $mapping Configuration for the current table and column.
*
* @return void
* @since 5.0.4
*/
private function processBasicValue(array $mapping): void
{
$table = $mapping['table'];
$column = $mapping['column'];
$linkedTable = $mapping['linkedTable'];
$linkedColumn = $mapping['linkedColumn'];
$isArray = $mapping['array'];
$update = false;
$rows = $this->load->rows(["a.{$column}" => $column, 'a.id' => 'id'], ['a' => $table]) ?? [];
foreach ($rows as $row)
{
$parentId = $row['id'];
$value = $row[$column] ?? null;
$hasUpdate = false;
$updatedValue = null;
if (empty($value))
{
continue;
}
if ($isArray)
{
$updatedValue = (is_array($value))
? $this->processArray($value, $linkedTable, $linkedColumn, $hasUpdate)
: $this->processJson($value, $linkedTable, $linkedColumn, $hasUpdate);
}
elseif (is_numeric($value))
{
$guid = $this->getItemGuid($linkedTable, $linkedColumn, $value);
if ($guid !== null)
{
$updatedValue = $guid;
$hasUpdate = true;
}
}
if (!$hasUpdate || $updatedValue === null)
{
continue; // Skip if no GUID updated or returned
}
if ($this->updateValue($table, $column, $updatedValue, $parentId))
{
$update = true;
}
}
if ($update)
{
$this->success[] = "Success: migrated {$column}:field in {$table}:table to GUIDs from {$linkedTable}:table.";
}
}
/**
* Processes subform values in a table and replaces IDs with GUIDs.
*
* @param array $mapping Configuration for the current table and subform column/field.
*
* @return void
* @since 5.0.4
*/
private function processSubformValue(array $mapping): void
{
$table = $mapping['table'];
$column = $mapping['column'];
$field = $mapping['field'];
$linkedTable = $mapping['linkedTable'];
$linkedColumn = $mapping['linkedColumn'];
$isArray = $mapping['array'];
$update = false;
$rows = $this->load->rows(["a.{$column}" => $column, 'a.id' => 'id'], ['a' => $table]) ?? [];
foreach ($rows as $row)
{
$parentId = $row['id'];
$jsonData = $row[$column] ?? null;
if (empty($jsonData))
{
continue;
}
$registry = new Registry($jsonData);
$subformData = $registry->toArray();
$hasUpdate = false;
foreach ($subformData as &$item)
{
if (!empty($item[$field]))
{
if ($isArray)
{
$item[$field] = (is_array($item[$field]))
? $this->processArray($item[$field], $linkedTable, $linkedColumn, $hasUpdate)
: $this->processJson($item[$field], $linkedTable, $linkedColumn, $hasUpdate);
}
elseif (is_numeric($item[$field]))
{
$guid = $this->getItemGuid($linkedTable, $linkedColumn, $item[$field]);
if ($guid !== null)
{
$item[$field] = $guid;
$hasUpdate = true;
}
}
}
}
if (!$hasUpdate)
{
continue; // Skip if no GUID updated
}
$updatedJson = (string) new Registry($subformData);
if ($this->updateValue($table, $column, $updatedJson, $parentId))
{
$update = true;
}
}
if ($update)
{
$this->success[] = "Success: migrated {$column}->{$field}:field in {$table}:table to GUIDs from {$linkedTable}:table.";
}
}
/**
* Processes sub-subform values in a table and replaces IDs with GUIDs.
*
* @param array $mapping Configuration for the current table and subform column/field.
*
* @return void
* @since 5.0.4
*/
private function processSubSubformValue(array $mapping): void
{
$table = $mapping['table'];
$column = $mapping['column'];
$sub = $mapping['sub'];
$field = $mapping['field'];
$linkedTable = $mapping['linkedTable'];
$linkedColumn = $mapping['linkedColumn'];
$isArray = $mapping['array'];
$update = false;
$rows = $this->load->rows(["a.{$column}" => $column, 'a.id' => 'id'], ['a' => $table]) ?? [];
foreach ($rows as $row)
{
$parentId = $row['id'];
$jsonData = $row[$column] ?? null;
if (empty($jsonData))
{
continue;
}
$registry = new Registry($jsonData);
$subformData = $registry->toArray();
$hasUpdate = false;
foreach ($subformData as &$item)
{
if (isset($item[$sub]) && is_array($item[$sub]))
{
foreach ($item[$sub] as &$subItem)
{
if (!empty($subItem[$field]))
{
if ($isArray)
{
$subItem[$field] = (is_array($subItem[$field]))
? $this->processArray($subItem[$field], $linkedTable, $linkedColumn, $hasUpdate)
: $this->processJson($subItem[$field], $linkedTable, $linkedColumn, $hasUpdate);
}
elseif (is_numeric($subItem[$field]))
{
$guid = $this->getItemGuid($linkedTable, $linkedColumn, $subItem[$field]);
if ($guid !== null)
{
$subItem[$field] = $guid;
$hasUpdate = true;
}
}
}
}
}
}
if (!$hasUpdate)
{
continue; // Skip if no GUID updated
}
$updatedJson = (string) new Registry($subformData);
if ($this->updateValue($table, $column, $updatedJson, $parentId))
{
$update = true;
}
}
if ($update)
{
$this->success[] = "Success: migrated {$column}->{$sub}->{$field}:field in {$table}:table to GUIDs from {$linkedTable}:table.";
}
}
/**
* Retrieves or creates a GUID for a given linked table and ID (ITEM).
*
* @param string $table The linked table name.
* @param string $column The column name in the linked table.
* @param mixed $value The value to check or convert.
*
* @return string|null The GUID for the given value, or null if skipped.
* @throws \Exception If the value is invalid.
* @since 5.0.4
*/
private function getItemGuid(string $table, string $column, $value): ?string
{
if (is_numeric($value))
{
// Check if already in cache
$cacheKey = "$table:$column:$value";
if (isset($this->guidCache[$cacheKey]))
{
return $this->guidCache[$cacheKey];
}
// Retrieve GUID from database
$guid = $this->load->value(['a.guid' => 'guid'], ['a' => $table], ["a.{$column}" => $value]);
if (!$this->validateGuid($guid))
{
// Create a new GUID
$this->setTable($table);
$guid = $this->getGuid('guid');
$this->updateValue($table, 'guid', $guid, $value);
}
// Cache the GUID
$this->guidCache[$cacheKey] = $guid;
return $guid;
}
// Check if the value is already a GUID
if ($this->validateGuid($value))
{
return null; // Skip, already a GUID
}
// convert to visible result
$value_printed = var_export($value, true);
// Raise an exception for invalid values
throw new \Exception("Invalid value detected: ({$table}:table)->({$column}:column)->({$value_printed}:value). Must be either an integer or a valid GUID.");
}
/**
* Processes an json-array of basic values and replaces them with GUIDs.
*
* @param string $values JSON string containing the IDs.
* @param string $linkedTable The linked table name.
* @param string $linkedColumn The linked column name.
* @param string $hasUpdate The switch to manage updates.
*
* @return string JSON string with updated GUIDs.
* @since 5.0.4
*/
private function processJson(string $values, string $linkedTable, string $linkedColumn, bool &$hasUpdate): string
{
$array = json_decode($values, true);
$bucket = [];
foreach ($array as $key => $value)
{
if (!empty($value))
{
$val = $this->getItemGuid($linkedTable, $linkedColumn, $value);
if ($val !== null)
{
$bucket[$key] = $val;
$hasUpdate = true;
}
}
}
return json_encode($bucket);
}
/**
* Processes an array values and replaces them with GUIDs.
*
* @param array $values Array of IDs from the subform field.
* @param string $linkedTable The linked table name.
* @param string $linkedColumn The linked column name.
* @param string $hasUpdate The switch to manage updates.
*
* @return array The updated array with GUIDs.
* @since 5.0.4
*/
private function processArray(array $values, string $linkedTable, string $linkedColumn, bool &$hasUpdate): array
{
$bucket = [];
foreach ($values as $key => $value)
{
if (!empty($value))
{
$val = $this->getItemGuid($linkedTable, $linkedColumn, $value);
if ($val !== null)
{
$bucket[$key] = $val;
$hasUpdate = true;
}
}
}
return $bucket;
}
/**
* Updates a value in the database.
*
* @param string $table The table name.
* @param string $column The column to update.
* @param string $value The updated value.
* @param int $id The ID of the row to update.
*
* @return bool
* @since 5.0.4
*/
private function updateValue(string $table, string $column, string $value, int $id): bool
{
return $this->update->row(['id' => $id, $column => $value], 'id', $table);
}
/**
* Set the current active table
*
* @param string $table The table that should be active
*
* @return void
* @since 5.0.4
*/
private function setTable(string $table): void
{
$this->table = $table;
}
/**
* Get the current active table
*
* @return string
* @since 5.0.4
*/
private function getTable(): string
{
return $this->table;
}

View File

@ -0,0 +1,36 @@
{
"add_head": 1,
"add_licensing_template": 2,
"extends": "",
"guid": "0b746305-d34e-4c21-bc20-898c4aeac376",
"implements": null,
"load_selection": null,
"name": "Guid",
"power_version": "1.0.0",
"system_name": "VDM.Data.Migrator.Guid",
"type": "final class",
"use_selection": {
"use_selection0": {
"use": "21bca8a4-5b28-41c4-843e-8097f0ba7cca",
"as": "default"
},
"use_selection1": {
"use": "06f8eada-d59b-441c-b287-0aea1793da5a",
"as": "default"
},
"use_selection2": {
"use": "cce56585-58b0-4f72-a92c-e2635ea52d83",
"as": "default"
},
"use_selection3": {
"use": "5acded67-0e3d-4c6b-a6ea-b533b076de0c",
"as": "TraitGuid"
}
},
"extendsinterfaces": null,
"namespace": "[[[NamespacePrefix]]]\\Joomla\\Data.Migrator.Guid",
"description": "Migrator To Globally Unique Identifier\r\n\r\n@since 5.0.4",
"licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2020\r\n * @author Llewellyn van der Merwe <https:\/\/dev.vdm.io>\r\n * @git Joomla Component Builder <https:\/\/git.vdm.dev\/joomla\/Component-Builder>\r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n",
"head": "use Joomla\\Registry\\Registry;",
"composer": ""
}

View File

@ -1,6 +1,6 @@
{
"add_head": "0",
"add_licensing_template": "2",
"add_head": 0,
"add_licensing_template": 2,
"extends": "",
"guid": "0e44d149-4863-47ec-8f0f-6a821ab3e77f",
"implements": null,

View File

@ -1,6 +1,6 @@
{
"add_head": "0",
"add_licensing_template": "2",
"add_head": 0,
"add_licensing_template": 2,
"extends": "",
"guid": "0f3f7188-3e0d-4d1a-8dee-7f8026cb65a9",
"implements": null,

View File

@ -1,6 +1,6 @@
{
"add_head": "0",
"add_licensing_template": "2",
"add_head": 0,
"add_licensing_template": 2,
"extends": "",
"guid": "11572d9b-e3d5-4b29-904c-9618d8f2bfd8",
"implements": null,

View File

@ -1,6 +1,6 @@
{
"add_head": "1",
"add_licensing_template": "2",
"add_head": 1,
"add_licensing_template": 2,
"extends": "",
"guid": "1198aecf-84c6-45d2-aea8-d531aa4afdfa",
"implements": null,

View File

@ -1,6 +1,6 @@
{
"add_head": "1",
"add_licensing_template": "2",
"add_head": 1,
"add_licensing_template": 2,
"extends": "",
"guid": "12a2a8de-a893-4dbb-a53d-b52de4f6cb0e",
"implements": null,

View File

@ -1,6 +1,6 @@
{
"add_head": "0",
"add_licensing_template": "2",
"add_head": 0,
"add_licensing_template": 2,
"extends": "",
"guid": "13c2cac1-a70d-42d7-99fc-eb7ac3443069",
"implements": null,

View File

@ -1,6 +1,6 @@
{
"add_head": "1",
"add_licensing_template": "2",
"add_head": 1,
"add_licensing_template": 2,
"extends": "",
"guid": "1401a167-0ce4-4f4a-afee-2d8b02ed339b",
"implements": [

View File

@ -1,6 +1,6 @@
{
"add_head": "0",
"add_licensing_template": "2",
"add_head": 0,
"add_licensing_template": 2,
"extends": "",
"guid": "152c8793-8b75-4715-996a-257b9f65451c",
"implements": null,

View File

@ -1,6 +1,6 @@
{
"add_head": "0",
"add_licensing_template": "2",
"add_head": 0,
"add_licensing_template": 2,
"extends": "",
"guid": "17ed2fec-49d6-4731-92c3-f9cd78fb6273",
"implements": null,

View File

@ -1,6 +1,6 @@
{
"add_head": "1",
"add_licensing_template": "2",
"add_head": 1,
"add_licensing_template": 2,
"extends": "",
"guid": "19a66b48-620c-439b-ab8a-3c0d43e040c3",
"implements": [

View File

@ -1,6 +1,6 @@
{
"add_head": "1",
"add_licensing_template": "2",
"add_head": 1,
"add_licensing_template": 2,
"extends": "",
"guid": "19b2ba92-1655-4384-acfb-979c80de8b6d",
"implements": [

View File

@ -1,6 +1,6 @@
{
"add_head": "0",
"add_licensing_template": "2",
"add_head": 0,
"add_licensing_template": 2,
"extends": "-1",
"guid": "1c10a5f1-204d-4f17-ad9f-0e0684f2030d",
"implements": null,

View File

@ -1,6 +1,6 @@
{
"add_head": "1",
"add_licensing_template": "2",
"add_head": 1,
"add_licensing_template": 2,
"extends": "",
"guid": "1f28cb53-60d9-4db1-b517-3c7dc6b429ef",
"implements": null,

View File

@ -1,6 +1,6 @@
{
"add_head": "1",
"add_licensing_template": "2",
"add_head": 1,
"add_licensing_template": 2,
"extends": "",
"guid": "202ccd9e-dfcf-4cde-a0ce-bde1fd27f088",
"implements": [

View File

@ -1,6 +1,6 @@
{
"add_head": "0",
"add_licensing_template": "2",
"add_head": 0,
"add_licensing_template": 2,
"extends": "",
"guid": "215b35ac-1b26-4838-bbcf-d1fdbbd9353f",
"implements": null,

View File

@ -1,6 +1,6 @@
{
"add_head": "0",
"add_licensing_template": "2",
"add_head": 0,
"add_licensing_template": 2,
"extends": "",
"guid": "217416f6-24cf-41c0-b18e-11086111d447",
"implements": null,

View File

@ -1,6 +1,6 @@
{
"add_head": "1",
"add_licensing_template": "2",
"add_head": 1,
"add_licensing_template": 2,
"extends": "",
"guid": "21754a8b-2323-4a77-8459-378a74c1ec97",
"implements": [

View File

@ -1,6 +1,6 @@
{
"add_head": "0",
"add_licensing_template": "2",
"add_head": 0,
"add_licensing_template": 2,
"extends": "",
"guid": "21bca8a4-5b28-41c4-843e-8097f0ba7cca",
"implements": [

View File

@ -1,6 +1,6 @@
{
"add_head": "0",
"add_licensing_template": "2",
"add_head": 0,
"add_licensing_template": 2,
"extends": "",
"guid": "23ad6e72-1b82-40fb-836c-50da690bb174",
"implements": null,

View File

@ -1,6 +1,6 @@
{
"add_head": "0",
"add_licensing_template": "2",
"add_head": 0,
"add_licensing_template": 2,
"extends": "",
"guid": "250a7272-9ae1-4c63-a058-26bad9ad6f70",
"implements": null,

View File

@ -1,6 +1,6 @@
{
"add_head": "0",
"add_licensing_template": "2",
"add_head": 0,
"add_licensing_template": 2,
"extends": "",
"guid": "2ad31f74-f579-499d-b98b-c4f54fd615dd",
"implements": null,

View File

@ -1,6 +1,6 @@
{
"add_head": "0",
"add_licensing_template": "2",
"add_head": 0,
"add_licensing_template": 2,
"extends": "",
"guid": "2da6d6c4-eb29-4d69-8bc2-36d96e916adf",
"implements": null,

View File

@ -1,6 +1,6 @@
{
"add_head": "1",
"add_licensing_template": "2",
"add_head": 1,
"add_licensing_template": 2,
"extends": "",
"guid": "2dcedd6c-c95b-4a37-9cac-95d28faedca3",
"implements": [

View File

@ -1,6 +1,6 @@
{
"add_head": "1",
"add_licensing_template": "2",
"add_head": 1,
"add_licensing_template": 2,
"extends": "",
"guid": "2e5bf608-de5c-4b00-a20d-47c26aa350d9",
"implements": [

View File

@ -1,6 +1,6 @@
{
"add_head": "0",
"add_licensing_template": "2",
"add_head": 0,
"add_licensing_template": 2,
"extends": "",
"guid": "30c5b4c2-f75f-4d15-869a-f8bfedd87358",
"implements": null,

View File

@ -1,6 +1,6 @@
{
"add_head": "0",
"add_licensing_template": "2",
"add_head": 0,
"add_licensing_template": 2,
"extends": "",
"guid": "34959721-415b-4b5e-8002-3d1fc84b3b2b",
"implements": null,

View File

@ -1,6 +1,6 @@
{
"add_head": "0",
"add_licensing_template": "2",
"add_head": 0,
"add_licensing_template": 2,
"extends": "",
"guid": "3cf76fbf-fd95-4a33-878e-7aff6d36b7f6",
"implements": null,

View File

@ -1,6 +1,6 @@
{
"add_head": "0",
"add_licensing_template": "2",
"add_head": 0,
"add_licensing_template": 2,
"extends": "",
"guid": "3d3ec064-9867-41e6-a48a-964c15d753aa",
"implements": null,

View File

@ -1,6 +1,6 @@
{
"add_head": "0",
"add_licensing_template": "2",
"add_head": 0,
"add_licensing_template": 2,
"extends": "",
"guid": "3fc72954-a303-4cac-b53c-554be38b85e7",
"implements": [

View File

@ -1,6 +1,6 @@
{
"add_head": "0",
"add_licensing_template": "2",
"add_head": 0,
"add_licensing_template": 2,
"extends": "d7600b43-771a-4747-9f5d-952765721799",
"guid": "4144ad3b-2ad5-401f-af0c-a3d856c1e688",
"implements": null,

View File

@ -1,6 +1,6 @@
{
"add_head": "0",
"add_licensing_template": "2",
"add_head": 0,
"add_licensing_template": 2,
"extends": "",
"guid": "43134867-5cb8-4280-9be8-309fd2fd135f",
"implements": [

View File

@ -1,6 +1,6 @@
{
"add_head": "1",
"add_licensing_template": "2",
"add_head": 1,
"add_licensing_template": 2,
"extends": "",
"guid": "46b98346-ec98-42b3-a393-96c7d1282b1c",
"implements": [

View File

@ -1,6 +1,6 @@
{
"add_head": "1",
"add_licensing_template": "2",
"add_head": 1,
"add_licensing_template": 2,
"extends": "",
"guid": "47a63728-cd5d-4d53-99cf-2409bd1c744c",
"implements": null,

View File

@ -1,6 +1,6 @@
{
"add_head": "1",
"add_licensing_template": "2",
"add_head": 1,
"add_licensing_template": 2,
"extends": "",
"guid": "4815e1c7-a433-443d-a112-d1e03d7df84b",
"implements": [

View File

@ -1,6 +1,6 @@
{
"add_head": "0",
"add_licensing_template": "2",
"add_head": 0,
"add_licensing_template": 2,
"extends": "",
"guid": "491dbe41-f26c-4de9-8a95-fcf87b35b56f",
"implements": null,

View File

@ -1,6 +1,6 @@
{
"add_head": "0",
"add_licensing_template": "2",
"add_head": 0,
"add_licensing_template": 2,
"extends": "",
"guid": "4b225c51-d293-48e4-b3f6-5136cf5c3f18",
"implements": null,

View File

@ -1,6 +1,6 @@
{
"add_head": "0",
"add_licensing_template": "2",
"add_head": 0,
"add_licensing_template": 2,
"extends": "900456a2-feb5-48b9-9f05-c5a032a32c59",
"guid": "4b2d6f28-346e-46ec-bf24-d470319cca2d",
"implements": [

View File

@ -1,6 +1,6 @@
{
"add_head": "0",
"add_licensing_template": "2",
"add_head": 0,
"add_licensing_template": 2,
"extends": "",
"guid": "4dd11b9b-3c64-460b-aaa6-62ba467db7aa",
"implements": null,

View File

@ -1,6 +1,6 @@
{
"add_head": "0",
"add_licensing_template": "2",
"add_head": 0,
"add_licensing_template": 2,
"extends": "",
"guid": "51de80f2-2868-4c2c-8198-ef79349e9bd7",
"implements": null,

View File

@ -1,6 +1,6 @@
{
"add_head": "1",
"add_licensing_template": "2",
"add_head": 1,
"add_licensing_template": 2,
"extends": "6cbef8f8-4813-48e3-b05a-65e1aea95171",
"guid": "524eb8f6-38d4-47dc-92ad-98b94e099ac0",
"implements": [

View File

@ -1,6 +1,6 @@
{
"add_head": "0",
"add_licensing_template": "2",
"add_head": 0,
"add_licensing_template": 2,
"extends": "",
"guid": "52a1d14f-304a-431c-8fa4-411179942db5",
"implements": null,

View File

@ -1,6 +1,6 @@
{
"add_head": "0",
"add_licensing_template": "2",
"add_head": 0,
"add_licensing_template": 2,
"extends": "",
"guid": "53f55e5b-63cb-49e7-b1e6-33e7a9f97856",
"implements": null,

View File

@ -1,6 +1,6 @@
{
"add_head": "0",
"add_licensing_template": "2",
"add_head": 0,
"add_licensing_template": 2,
"extends": "",
"guid": "576685fd-263c-46bb-9fdc-1f5eb234cbb6",
"implements": null,

View File

@ -1,6 +1,6 @@
{
"add_head": "0",
"add_licensing_template": "2",
"add_head": 0,
"add_licensing_template": 2,
"extends": "",
"guid": "57c00d53-5581-4fd1-b3ea-080422710243",
"implements": null,

View File

@ -1,6 +1,6 @@
{
"add_head": "0",
"add_licensing_template": "2",
"add_head": 0,
"add_licensing_template": 2,
"extends": "",
"guid": "584747d1-3a86-453d-b7a3-a2219de8d777",
"implements": [

View File

@ -1,6 +1,6 @@
{
"add_head": "0",
"add_licensing_template": "2",
"add_head": 0,
"add_licensing_template": 2,
"extends": "",
"guid": "59b1a2ea-d77e-4040-ac8c-e65cd8743e9b",
"implements": null,

View File

@ -13,6 +13,7 @@
@startuml
class Guid << (T,Orange) >> #Turquoise {
+ getGuid(string $key) : string
+ {static} validateGuid(string $guid) : bool
- fallbackGuid(string $key) : string
- checkGuid(string $guid, string $key) : string
}
@ -26,6 +27,13 @@ available on the platform with a fallback to an older, less secure version.
return: string
end note
note right of Guid::validateGuid
Validate the Globally Unique Identifier
since: 5.0.4
return: bool
end note
note right of Guid::fallbackGuid
Generates a fallback GUIDv4 using less secure methods.

View File

@ -62,6 +62,24 @@ trait Guid
return $this->fallbackGuid($key);
}
/**
* Validate the Globally Unique Identifier
*
* @param string $guid
*
* @return bool
* @since 5.0.4
*/
public static function validateGuid($guid)
{
// check if we have a string
if (!empty($guid) && is_string($guid))
{
return preg_match("/^(\{)?[a-f\d]{8}(-[a-f\d]{4}){4}[a-f\d]{8}(?(1)\})$/i", $guid);
}
return false;
}
/**
* Generates a fallback GUIDv4 using less secure methods.
*

View File

@ -41,6 +41,24 @@
return $this->fallbackGuid($key);
}
/**
* Validate the Globally Unique Identifier
*
* @param string $guid
*
* @return bool
* @since 5.0.4
*/
public static function validateGuid($guid)
{
// check if we have a string
if (!empty($guid) && is_string($guid))
{
return preg_match("/^(\{)?[a-f\d]{8}(-[a-f\d]{4}){4}[a-f\d]{8}(?(1)\})$/i", $guid);
}
return false;
}
/**
* Generates a fallback GUIDv4 using less secure methods.
*

View File

@ -1,6 +1,6 @@
{
"add_head": "0",
"add_licensing_template": "2",
"add_head": 0,
"add_licensing_template": 2,
"extends": "",
"guid": "5acded67-0e3d-4c6b-a6ea-b533b076de0c",
"implements": null,

View File

@ -1,6 +1,6 @@
{
"add_head": "1",
"add_licensing_template": "2",
"add_head": 1,
"add_licensing_template": 2,
"extends": "",
"guid": "5f0205fa-5c43-424a-af7d-abc943c17c8c",
"implements": [

View File

@ -1,6 +1,6 @@
{
"add_head": "0",
"add_licensing_template": "2",
"add_head": 0,
"add_licensing_template": 2,
"extends": "",
"guid": "61d1146f-2c2e-4e42-8492-d076f945cf35",
"implements": null,

View File

@ -1,6 +1,6 @@
{
"add_head": "1",
"add_licensing_template": "2",
"add_head": 1,
"add_licensing_template": 2,
"extends": "",
"guid": "640b5352-fb09-425f-a26e-cd44eda03f15",
"implements": null,

View File

@ -1,6 +1,6 @@
{
"add_head": "0",
"add_licensing_template": "2",
"add_head": 0,
"add_licensing_template": 2,
"extends": "",
"guid": "64a6ff6c-069c-4a11-a76b-db5e36c27690",
"implements": null,

View File

@ -1,6 +1,6 @@
{
"add_head": "0",
"add_licensing_template": "2",
"add_head": 0,
"add_licensing_template": 2,
"extends": "",
"guid": "64e291c2-11f1-423d-a44d-837cc12cc017",
"implements": null,

View File

@ -1,6 +1,6 @@
{
"add_head": "0",
"add_licensing_template": "2",
"add_head": 0,
"add_licensing_template": 2,
"extends": "",
"guid": "65a0f81a-14fc-4870-9382-b8d830b19937",
"implements": null,

View File

@ -1,6 +1,6 @@
{
"add_head": "1",
"add_licensing_template": "2",
"add_head": 1,
"add_licensing_template": 2,
"extends": "",
"guid": "67a5e0ca-0ff0-4979-9b41-da0b09988016",
"implements": null,

View File

@ -1,6 +1,6 @@
{
"add_head": "0",
"add_licensing_template": "2",
"add_head": 0,
"add_licensing_template": 2,
"extends": "",
"guid": "68a0f9af-265a-4db1-bae9-a4e4531f94d7",
"implements": [

View File

@ -1,6 +1,6 @@
{
"add_head": "0",
"add_licensing_template": "2",
"add_head": 0,
"add_licensing_template": 2,
"extends": "",
"guid": "68a41264-64c0-441a-a3d8-8a5e557b1883",
"implements": null,

View File

@ -12,7 +12,8 @@
namespace VDM\Joomla\Abstraction;
use Joomla\CMS\Factory as JoomlaFactory;
use Joomla\CMS\Factory;
use Joomla\Database\DatabaseInterface;
use VDM\Joomla\Utilities\Component\Helper;
@ -54,7 +55,7 @@ abstract class Database
*/
public function __construct()
{
$this->db = JoomlaFactory::getDbo();
$this->db = Factory::getContainer()->get(DatabaseInterface::class);
// set the component table
$this->table = '#__' . Helper::getCode();

View File

@ -29,7 +29,7 @@
*/
public function __construct()
{
$this->db = JoomlaFactory::getDbo();
$this->db = Factory::getContainer()->get(DatabaseInterface::class);
// set the component table
$this->table = '#__' . Helper::getCode();

View File

@ -1,6 +1,6 @@
{
"add_head": "1",
"add_licensing_template": "2",
"add_head": 1,
"add_licensing_template": 2,
"extends": "",
"guid": "6cbef8f8-4813-48e3-b05a-65e1aea95171",
"implements": null,
@ -19,6 +19,6 @@
"namespace": "[[[NamespacePrefix]]]\\Joomla\\Abstraction.Database",
"description": "Database\r\n\r\n@since 3.2.0",
"licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe <https:\/\/dev.vdm.io>\r\n * @git Joomla Component Builder <https:\/\/git.vdm.dev\/joomla\/Component-Builder>\r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n",
"head": "use Joomla\\CMS\\Factory as JoomlaFactory;",
"head": "use Joomla\\CMS\\Factory;\r\nuse Joomla\\Database\\DatabaseInterface;",
"composer": ""
}

View File

@ -1,6 +1,6 @@
{
"add_head": "0",
"add_licensing_template": "2",
"add_head": 0,
"add_licensing_template": 2,
"extends": "5f0205fa-5c43-424a-af7d-abc943c17c8c",
"guid": "709d7294-9a43-46e2-b64e-d16a16f0eab1",
"implements": [

View File

@ -1,6 +1,6 @@
{
"add_head": "0",
"add_licensing_template": "2",
"add_head": 0,
"add_licensing_template": 2,
"extends": "",
"guid": "7179fde6-1e51-4b51-8545-7ca18f74a0f4",
"implements": null,

View File

@ -1,6 +1,6 @@
{
"add_head": "0",
"add_licensing_template": "2",
"add_head": 0,
"add_licensing_template": 2,
"extends": "",
"guid": "7212e4db-371f-4cfd-8122-32e9bb100d83",
"implements": null,

View File

@ -1,6 +1,6 @@
{
"add_head": "0",
"add_licensing_template": "2",
"add_head": 0,
"add_licensing_template": 2,
"extends": "",
"guid": "728ee726-3f0f-4762-899d-f8c9430cee58",
"implements": [

View File

@ -1,6 +1,6 @@
{
"add_head": "1",
"add_licensing_template": "2",
"add_head": 1,
"add_licensing_template": 2,
"extends": "",
"guid": "7832a726-87b6-4e95-887e-7b725d3fab8f",
"implements": null,

View File

@ -1,6 +1,6 @@
{
"add_head": "0",
"add_licensing_template": "2",
"add_head": 0,
"add_licensing_template": 2,
"extends": "",
"guid": "79fd4f39-824d-4ab6-936d-959705ff24ec",
"implements": [

View File

@ -1,6 +1,6 @@
{
"add_head": "0",
"add_licensing_template": "2",
"add_head": 0,
"add_licensing_template": 2,
"extends": "584747d1-3a86-453d-b7a3-a2219de8d777",
"guid": "7c1fb50f-8fb1-4627-8705-6fedf7182ca5",
"implements": [

View File

@ -1,6 +1,6 @@
{
"add_head": "0",
"add_licensing_template": "2",
"add_head": 0,
"add_licensing_template": 2,
"extends": "",
"guid": "7d494d91-ab60-43cd-aecf-d50e07f7f30e",
"implements": null,

View File

@ -1,6 +1,6 @@
{
"add_head": "1",
"add_licensing_template": "2",
"add_head": 1,
"add_licensing_template": 2,
"extends": "43134867-5cb8-4280-9be8-309fd2fd135f",
"guid": "7e822c03-1b20-41d1-9427-f5b8d5836af7",
"implements": [

View File

@ -1,6 +1,6 @@
{
"add_head": "1",
"add_licensing_template": "2",
"add_head": 1,
"add_licensing_template": 2,
"extends": "-1",
"guid": "85321deb-5c3a-401b-9ce1-039a746add51",
"implements": null,

View File

@ -1,6 +1,6 @@
{
"add_head": "0",
"add_licensing_template": "2",
"add_head": 0,
"add_licensing_template": 2,
"extends": "",
"guid": "85785701-07b2-4f81-bc1e-0f423700c254",
"implements": [

View File

@ -1,6 +1,6 @@
{
"add_head": "1",
"add_licensing_template": "2",
"add_head": 1,
"add_licensing_template": 2,
"extends": "2e5bf608-de5c-4b00-a20d-47c26aa350d9",
"guid": "884eca78-281f-4eab-b962-d97e355af16d",
"implements": [

View File

@ -1,6 +1,6 @@
{
"add_head": "0",
"add_licensing_template": "2",
"add_head": 0,
"add_licensing_template": 2,
"extends": "",
"guid": "8aef58c1-3f70-4bd4-b9e4-3f29fcd41cff",
"implements": null,

View File

@ -1,6 +1,6 @@
{
"add_head": "0",
"add_licensing_template": "2",
"add_head": 0,
"add_licensing_template": 2,
"extends": "",
"guid": "8f83fb79-f92b-4f1f-952b-325f6c22d11e",
"implements": [

View File

@ -1,6 +1,6 @@
{
"add_head": "1",
"add_licensing_template": "2",
"add_head": 1,
"add_licensing_template": 2,
"extends": "7e822c03-1b20-41d1-9427-f5b8d5836af7",
"guid": "900456a2-feb5-48b9-9f05-c5a032a32c59",
"implements": [

View File

@ -1,6 +1,6 @@
{
"add_head": "0",
"add_licensing_template": "2",
"add_head": 0,
"add_licensing_template": 2,
"extends": "",
"guid": "90b48ea8-0930-48d1-869a-bce9c901589c",
"implements": [

View File

@ -1,6 +1,6 @@
{
"add_head": "0",
"add_licensing_template": "2",
"add_head": 0,
"add_licensing_template": 2,
"extends": "",
"guid": "91004529-94a9-4590-b842-e7c6b624ecf5",
"implements": null,

View File

@ -1,6 +1,6 @@
{
"add_head": "0",
"add_licensing_template": "2",
"add_head": 0,
"add_licensing_template": 2,
"extends": "",
"guid": "9206082e-a3f7-472e-98b2-de90d06cbdcd",
"implements": [

View File

@ -1,6 +1,6 @@
{
"add_head": "0",
"add_licensing_template": "2",
"add_head": 0,
"add_licensing_template": 2,
"extends": "6cbef8f8-4813-48e3-b05a-65e1aea95171",
"guid": "92291f1f-f248-4ec0-9f2a-3d47c49eeac1",
"implements": [

View File

@ -1,6 +1,6 @@
{
"add_head": "0",
"add_licensing_template": "2",
"add_head": 0,
"add_licensing_template": 2,
"extends": "",
"guid": "95c02df3-fe0a-405b-b506-b7a5b8605b66",
"implements": null,

View File

@ -1,6 +1,6 @@
{
"add_head": "1",
"add_licensing_template": "2",
"add_head": 1,
"add_licensing_template": 2,
"extends": "ffbd4e1f-a342-4080-ab7d-1de3741bf319",
"guid": "9769f3b2-17bf-4f20-b54b-3a4ebe572b36",
"implements": null,

View File

@ -1,6 +1,6 @@
{
"add_head": "0",
"add_licensing_template": "2",
"add_head": 0,
"add_licensing_template": 2,
"extends": "",
"guid": "993fe913-8e36-4800-a5f7-544aa728ee48",
"implements": null,

View File

@ -1,6 +1,6 @@
{
"add_head": "0",
"add_licensing_template": "2",
"add_head": 0,
"add_licensing_template": 2,
"extends": "",
"guid": "9ae018a5-9064-40ed-ad69-9c1ed2a459f5",
"implements": [

View File

@ -1,6 +1,6 @@
{
"add_head": "0",
"add_licensing_template": "2",
"add_head": 0,
"add_licensing_template": 2,
"extends": "",
"guid": "9c3aa650-e536-4eea-a2d4-73cc3e184aa9",
"implements": null,

View File

@ -1,6 +1,6 @@
{
"add_head": "1",
"add_licensing_template": "2",
"add_head": 1,
"add_licensing_template": 2,
"extends": "",
"guid": "9c513baf-b279-43fd-ae29-a585c8cbc4f0",
"implements": null,

View File

@ -1,6 +1,6 @@
{
"add_head": "1",
"add_licensing_template": "2",
"add_head": 1,
"add_licensing_template": 2,
"extends": "2e5bf608-de5c-4b00-a20d-47c26aa350d9",
"guid": "9d76b8dc-3883-4755-b11c-131d19ca8a53",
"implements": [

View File

@ -1,6 +1,6 @@
{
"add_head": "0",
"add_licensing_template": "2",
"add_head": 0,
"add_licensing_template": 2,
"extends": "",
"guid": "9ef0eb24-aae4-4f5a-99af-d724db44808f",
"implements": null,

Some files were not shown because too many files have changed in this diff Show More