From fc6b04cb5c56bc244606b2555d7d04e2fc673fff Mon Sep 17 00:00:00 2001 From: aB0t Date: Fri, 7 Jun 2024 23:21:05 +0200 Subject: [PATCH] Release of v5.0.1-alpha4 Change the extendsinterfaces field to allow null, #1139. Update the Schema class to also update null mismatching if needed. --- CHANGELOG.md | 10 +- ComponentbuilderInstallerScript.php | 2 +- README.md | 10 +- admin/README.txt | 10 +- admin/sql/install.mysql.utf8.sql | 4 +- componentbuilder.xml | 6 +- componentbuilder_update_server.xml | 6 +- .../VDM.Joomla/src/Abstraction/Schema.php | 91 ++++++++++++++++--- .../Compiler/Builder/Languages.php | 34 +++++++ .../Compiler/Service/BuilderLZ.php | 17 ++++ .../VDM.Joomla/src/Componentbuilder/Table.php | 4 +- 11 files changed, 157 insertions(+), 37 deletions(-) create mode 100644 libraries/vendor_jcb/VDM.Joomla/src/Componentbuilder/Compiler/Builder/Languages.php diff --git a/CHANGELOG.md b/CHANGELOG.md index faa4a33d5..cacbbac48 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,12 +1,14 @@ -# v5.0.1-alpha3 +# v5.0.1-alpha4 -- Add in JCB gitea push feature to help maintain JCB core features. -- Add extending options to interfaces. +- Change the extendsinterfaces field to allow null, #1139 +- Update the Schema class to also update null mismatching if needed # v5.0.1-alpha - Fix auto build from SQL in Joomla 5. -- Fix permission issue for admin views. +- Fix permission issue for admin views. +- Add in JCB gitea push feature to help maintain JCB core features. +- Add extending options to interfaces. # v5.0.0 diff --git a/ComponentbuilderInstallerScript.php b/ComponentbuilderInstallerScript.php index 862a66b78..9b5113b12 100644 --- a/ComponentbuilderInstallerScript.php +++ b/ComponentbuilderInstallerScript.php @@ -3210,7 +3210,7 @@ class Com_ComponentbuilderInstallerScript implements InstallerScriptInterface echo '
-

Upgrade to Version 5.0.1-alpha3 Was Successful! Let us know if anything is not working as expected.

'; +

Upgrade to Version 5.0.1-alpha4 Was Successful! Let us know if anything is not working as expected.

'; // Add/Update component in the action logs extensions table. $this->setActionLogsExtensions(); diff --git a/README.md b/README.md index a453d5fce..2f82cc05d 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ The Component Builder for [Joomla](https://extensions.joomla.org/extension/compo Whether you're a seasoned [Joomla](https://extensions.joomla.org/extension/component-builder/) developer, or have just started, Component Builder will save you lots of time and money. A real must have! -You can install it quite easily and with no limitations. On [gitea](https://git.vdm.dev/joomla/Component-Builder/tags) is the latest release (5.0.1-alpha3) with **ALL** its features and **ALL** concepts totally open-source and free! +You can install it quite easily and with no limitations. On [gitea](https://git.vdm.dev/joomla/Component-Builder/tags) is the latest release (5.0.1-alpha4) with **ALL** its features and **ALL** concepts totally open-source and free! > Watch Quick Build of a Hello World component in [JCB on Youtube](https://www.youtube.com/watch?v=IQfsLYIeblk&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&index=45) @@ -144,13 +144,13 @@ TODO + *Author*: [Llewellyn van der Merwe](mailto:joomla@vdm.io) + *Name*: [Component Builder](https://git.vdm.dev/joomla/Component-Builder) + *First Build*: 30th April, 2015 -+ *Last Build*: 5th June, 2024 -+ *Version*: 5.0.1-alpha3 ++ *Last Build*: 7th June, 2024 ++ *Version*: 5.0.1-alpha4 + *Copyright*: Copyright (C) 2015 Vast Development Method. All rights reserved. + *License*: GNU General Public License version 2 or later; see LICENSE.txt -+ *Line count*: **750039** ++ *Line count*: **750452** + *Field count*: **2106** -+ *File count*: **5314** ++ *File count*: **5319** + *Folder count*: **540** > This **component** was build with a [Joomla](https://extensions.joomla.org/extension/component-builder/) [Automated Component Builder](https://www.joomlacomponentbuilder.com). diff --git a/admin/README.txt b/admin/README.txt index a453d5fce..2f82cc05d 100644 --- a/admin/README.txt +++ b/admin/README.txt @@ -9,7 +9,7 @@ The Component Builder for [Joomla](https://extensions.joomla.org/extension/compo Whether you're a seasoned [Joomla](https://extensions.joomla.org/extension/component-builder/) developer, or have just started, Component Builder will save you lots of time and money. A real must have! -You can install it quite easily and with no limitations. On [gitea](https://git.vdm.dev/joomla/Component-Builder/tags) is the latest release (5.0.1-alpha3) with **ALL** its features and **ALL** concepts totally open-source and free! +You can install it quite easily and with no limitations. On [gitea](https://git.vdm.dev/joomla/Component-Builder/tags) is the latest release (5.0.1-alpha4) with **ALL** its features and **ALL** concepts totally open-source and free! > Watch Quick Build of a Hello World component in [JCB on Youtube](https://www.youtube.com/watch?v=IQfsLYIeblk&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&index=45) @@ -144,13 +144,13 @@ TODO + *Author*: [Llewellyn van der Merwe](mailto:joomla@vdm.io) + *Name*: [Component Builder](https://git.vdm.dev/joomla/Component-Builder) + *First Build*: 30th April, 2015 -+ *Last Build*: 5th June, 2024 -+ *Version*: 5.0.1-alpha3 ++ *Last Build*: 7th June, 2024 ++ *Version*: 5.0.1-alpha4 + *Copyright*: Copyright (C) 2015 Vast Development Method. All rights reserved. + *License*: GNU General Public License version 2 or later; see LICENSE.txt -+ *Line count*: **750039** ++ *Line count*: **750452** + *Field count*: **2106** -+ *File count*: **5314** ++ *File count*: **5319** + *Folder count*: **540** > This **component** was build with a [Joomla](https://extensions.joomla.org/extension/component-builder/) [Automated Component Builder](https://www.joomlacomponentbuilder.com). diff --git a/admin/sql/install.mysql.utf8.sql b/admin/sql/install.mysql.utf8.sql index b9765d827..d2f83146e 100644 --- a/admin/sql/install.mysql.utf8.sql +++ b/admin/sql/install.mysql.utf8.sql @@ -367,9 +367,9 @@ CREATE TABLE IF NOT EXISTS `#__componentbuilder_power` ( `approved_paths` TEXT NULL, `composer` TEXT NULL, `description` TEXT NULL, - `extends` VARCHAR(36) NOT NULL DEFAULT '', + `extends` VARCHAR(36) NULL DEFAULT '', `extends_custom` VARCHAR(64) NULL DEFAULT '', - `extendsinterfaces` TEXT NOT NULL, + `extendsinterfaces` TEXT NULL, `extendsinterfaces_custom` TEXT NULL, `guid` VARCHAR(36) NOT NULL DEFAULT '', `head` TEXT NULL, diff --git a/componentbuilder.xml b/componentbuilder.xml index 72876c173..f9073c44b 100644 --- a/componentbuilder.xml +++ b/componentbuilder.xml @@ -1,15 +1,15 @@ COM_COMPONENTBUILDER - 5th June, 2024 + 7th June, 2024 Llewellyn van der Merwe joomla@vdm.io https://dev.vdm.io Copyright (C) 2015 Vast Development Method. All rights reserved. GNU General Public License version 2 or later; see LICENSE.txt - 5.0.1-alpha3 + 5.0.1-alpha4 Component Builder (v.5.0.1-alpha3) +

Component Builder (v.5.0.1-alpha4)

The Component Builder for [Joomla](https://extensions.joomla.org/extension/component-builder/) is highly advanced tool that is truly able to build extremely complex components in a fraction of the time. diff --git a/componentbuilder_update_server.xml b/componentbuilder_update_server.xml index b436c98e7..ab56ff299 100644 --- a/componentbuilder_update_server.xml +++ b/componentbuilder_update_server.xml @@ -62,7 +62,7 @@ 5.0.1-alpha https://dev.vdm.io - https://git.vdm.dev/api/v1/repos/joomla/pkg-component-builder/archive/v5.0.1-alpha3.zip + https://git.vdm.dev/api/v1/repos/joomla/pkg-component-builder/archive/v5.0.1-alpha4.zip alpha @@ -77,10 +77,10 @@ pkg_component_builder package site - 5.0.1-alpha3 + 5.0.1-alpha4 https://dev.vdm.io - https://git.vdm.dev/api/v1/repos/joomla/pkg-component-builder/archive/v5.0.1-alpha3.zip + https://git.vdm.dev/api/v1/repos/joomla/pkg-component-builder/archive/v5.0.1-alpha4.zip alpha diff --git a/libraries/vendor_jcb/VDM.Joomla/src/Abstraction/Schema.php b/libraries/vendor_jcb/VDM.Joomla/src/Abstraction/Schema.php index 694bbc927..a41d27bae 100644 --- a/libraries/vendor_jcb/VDM.Joomla/src/Abstraction/Schema.php +++ b/libraries/vendor_jcb/VDM.Joomla/src/Abstraction/Schema.php @@ -343,9 +343,17 @@ abstract class Schema implements SchemaInterface 'expected' => $expected['type'] ]; } - // check if update of default values is needed - if ($this->checkDefault($table, $column) && !isset($requireUpdate[$column])) + elseif ($this->checkDefault($table, $column)) + { + $requireUpdate[$column] = [ + 'column' => $column, + 'current' => $current->Type, + 'expected' => $expected['type'] + ]; + } + // check if update of null is needed + elseif ($this->checkNull($table, $column)) { $requireUpdate[$column] = [ 'column' => $column, @@ -391,13 +399,21 @@ abstract class Schema implements SchemaInterface $default = $this->getDefaultValue($type, $db_default); // Prepare the null switch, and auto increment statement - $null_switch = !empty($db['null_switch']) ? " " . $db['null_switch'] : ''; + $null_switch = !empty($db['null_switch']) ? ' ' . $db['null_switch'] : ''; + + // Prepare the auto increment statement $auto_increment = !empty($db['auto_increment']) ? " AUTO_INCREMENT" : ''; + // If there's a default value, the column should not be nullable + if ($default !== '') + { + $null_switch = ''; + } + $this->setKeys($db); // Assemble the SQL snippet for the column definition - return "{$column_name} {$type}{$null_switch}{$default}{$auto_increment}"; + return "{$column_name} {$type}{$null_switch}{$auto_increment}{$default}"; } catch (\Exception $e) { throw new \Exception("Error: failed to generate column definition for ($table.$field). " . $e->getMessage()); } @@ -448,6 +464,61 @@ abstract class Schema implements SchemaInterface return false; } + /** + * Check and Update the null value if needed, including existing data adjustments + * + * @param string $table The table to update. + * @param string $column The column/field to check. + * + * @return bool + * @since 3.2.2 + */ + protected function checkNull(string $table, string $column): bool + { + // Retrieve the expected column configuration + $expected = $this->table->get($table, $column, 'db'); + + // Skip updates if the null_switch is not set + if (!isset($expected['null_switch'])) + { + return false; + } + + // Retrieve the current column configuration + $current = $this->columns[$column]; + + // Skip updates if the Null is not set + if (!isset($current->Null)) + { + return false; + } + + // set the expected NULL + $expected_null = 'NO'; + if ($expected['null_switch'] === "NULL") + { + $expected_null = 'YES'; + } + + // set the current NULL + $current_null = $current->Null; + + // Prepare the type and default value SQL statement + $type = $expected['type'] ?? 'TEXT'; + $db_default = isset($expected['default']) ? $expected['default'] : null; + $default = $this->getDefaultValue($type, $db_default, true); + + // check the null values if they match + if ($current_null !== $expected_null && $current_null === 'NO' && empty($default)) + { + $this->success[] = "Success: updated the ($column) null state in $table table."; + + return true; + } + + return false; + } + /** * Update the data type of the given fields. * @@ -679,8 +750,8 @@ abstract class Schema implements SchemaInterface * Adjusts the default value SQL fragment for a database field based on its type and specific rules. * * If the field is of type DATETIME and the Joomla version is not 3, it sets the default to CURRENT_TIMESTAMP - * if not explicitly specified otherwise. For all other types, or when a 'EMPTY' default is specified, it handles - * defaults by either leaving them unset or applying the provided default, properly quoted for SQL safety. + * if not explicitly specified otherwise. For all other types it handles defaults by either leaving them unset or applying + * the provided default, properly quoted for SQL safety. When a 'EMPTY' default is specified, it returns no default at all. (:) * * @param string $type The type of the database field (e.g., 'DATETIME'). * @param string|null $defaultValue Optional default value for the field, null if not provided. @@ -691,7 +762,7 @@ abstract class Schema implements SchemaInterface */ protected function getDefaultValue(string $type, ?string $defaultValue, bool $pure = false): string { - if ($defaultValue === null) + if ($defaultValue === null || strtoupper($defaultValue) === 'EMPTY') { return ''; } @@ -722,11 +793,7 @@ abstract class Schema implements SchemaInterface return 'NULL'; } - if (is_string($value) && strtoupper($value) === 'EMPTY') - { - return "''"; - } - elseif (is_numeric($value)) + if (is_numeric($value)) { if (filter_var($value, FILTER_VALIDATE_INT)) { diff --git a/libraries/vendor_jcb/VDM.Joomla/src/Componentbuilder/Compiler/Builder/Languages.php b/libraries/vendor_jcb/VDM.Joomla/src/Componentbuilder/Compiler/Builder/Languages.php new file mode 100644 index 000000000..a03171f23 --- /dev/null +++ b/libraries/vendor_jcb/VDM.Joomla/src/Componentbuilder/Compiler/Builder/Languages.php @@ -0,0 +1,34 @@ + + * @git 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\Componentbuilder\Compiler\Builder; + + +use VDM\Joomla\Abstraction\Registry\Traits\IsArray; +use VDM\Joomla\Interfaces\Registryinterface; +use VDM\Joomla\Abstraction\Registry; + + +/** + * Languages Builder Class + * + * @since 3.2.2 + */ +final class Languages extends Registry implements Registryinterface +{ + /** + * Is an Array + * + * @since 3.2.2 + */ + use IsArray; +} + diff --git a/libraries/vendor_jcb/VDM.Joomla/src/Componentbuilder/Compiler/Service/BuilderLZ.php b/libraries/vendor_jcb/VDM.Joomla/src/Componentbuilder/Compiler/Service/BuilderLZ.php index b6421dd92..6a8a6a6e8 100644 --- a/libraries/vendor_jcb/VDM.Joomla/src/Componentbuilder/Compiler/Service/BuilderLZ.php +++ b/libraries/vendor_jcb/VDM.Joomla/src/Componentbuilder/Compiler/Service/BuilderLZ.php @@ -14,6 +14,7 @@ namespace VDM\Joomla\Componentbuilder\Compiler\Service; use Joomla\DI\Container; use Joomla\DI\ServiceProviderInterface; +use VDM\Joomla\Componentbuilder\Compiler\Builder\Languages; use VDM\Joomla\Componentbuilder\Compiler\Builder\LanguageMessages; use VDM\Joomla\Componentbuilder\Compiler\Builder\Layout; use VDM\Joomla\Componentbuilder\Compiler\Builder\LayoutData; @@ -86,6 +87,9 @@ class BuilderLZ implements ServiceProviderInterface */ public function register(Container $container) { + $container->alias(Languages::class, 'Compiler.Builder.Languages') + ->share('Compiler.Builder.Languages', [$this, 'getLanguages'], true); + $container->alias(LanguageMessages::class, 'Compiler.Builder.Language.Messages') ->share('Compiler.Builder.Language.Messages', [$this, 'getLanguageMessages'], true); @@ -246,6 +250,19 @@ class BuilderLZ implements ServiceProviderInterface ->share('Compiler.Builder.Views.Default.Ordering', [$this, 'getViewsDefaultOrdering'], true); } + /** + * Get The Languages Class. + * + * @param Container $container The DI container. + * + * @return Languages + * @since 3.2.0 + */ + public function getLanguages(Container $container): Languages + { + return new Languages(); + } + /** * Get The LanguageMessages Class. * diff --git a/libraries/vendor_jcb/VDM.Joomla/src/Componentbuilder/Table.php b/libraries/vendor_jcb/VDM.Joomla/src/Componentbuilder/Table.php index 3d8d66197..4cbee85c3 100644 --- a/libraries/vendor_jcb/VDM.Joomla/src/Componentbuilder/Table.php +++ b/libraries/vendor_jcb/VDM.Joomla/src/Componentbuilder/Table.php @@ -3262,7 +3262,7 @@ class Table extends BaseTable implements Tableinterface 'db' => [ 'type' => 'VARCHAR(36)', 'default' => '', - 'null_switch' => 'NOT NULL', + 'null_switch' => 'NULL', 'unique_key' => false, 'key' => false, ], @@ -3342,7 +3342,7 @@ class Table extends BaseTable implements Tableinterface 'db' => [ 'type' => 'TEXT', 'default' => 'EMPTY', - 'null_switch' => 'NOT NULL', + 'null_switch' => 'NULL', 'unique_key' => false, 'key' => false, ],