From 3897756e6aca503066ab18881b5784a7f8a8ec9e Mon Sep 17 00:00:00 2001 From: Alexander Walther Date: Tue, 16 Jul 2024 16:28:35 +0200 Subject: [PATCH 1/4] Tabellenschema-Optimierungen --- install.php | 8 +++++++ install/tableset.json | 10 ++++---- lib/neues.php | 53 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 5 deletions(-) diff --git a/install.php b/install.php index 8e94165..31653f5 100644 --- a/install.php +++ b/install.php @@ -14,6 +14,14 @@ /* Tablesets aktualisieren */ if (rex_addon::get('yform') && rex_addon::get('yform')->isAvailable()) { rex_yform_manager_table_api::importTablesets(rex_file::get(__DIR__ . '/install/tableset.json')); + + + // Vorhandene leere UUID-Felder aktualisieren + $sql = rex_sql::factory(); + $sql->setQuery('UPDATE ' . \rex::getTable('neues_entry') . ' SET uuid = uuid() WHERE uuid IS NULL OR uuid = ""'); + + Neues::ensureDbScheme(); + } if (!rex_media::get('neues_entry_fallback_image.png')) { diff --git a/install/tableset.json b/install/tableset.json index 30e88f4..260f17d 100644 --- a/install/tableset.json +++ b/install/tableset.json @@ -352,7 +352,7 @@ "prio": 2, "type_id": "value", "type_name": "choice_status", - "db_type": "text", + "db_type": "int", "list_hidden": 1, "search": 0, "name": "status", @@ -454,7 +454,7 @@ "prio": 8, "type_id": "value", "type_name": "be_manager_relation", - "db_type": "text", + "db_type": "int(10) unsigned", "list_hidden": 1, "search": 0, "name": "lang_id", @@ -733,7 +733,7 @@ "table": { "status": 1, "table_name": "rex_neues_entry_category_rel", - "name": "\ud83d\udcf0 translate:neues_entry_category_rel", + "name": "translate:neues_entry_category_rel", "description": "", "list_amount": 50, "list_sortfield": "id", @@ -757,7 +757,7 @@ "prio": 1, "type_id": "value", "type_name": "be_manager_relation", - "db_type": "text", + "db_type": "int(10) unsigned", "list_hidden": 0, "search": 0, "name": "entry_id", @@ -779,7 +779,7 @@ "prio": 2, "type_id": "value", "type_name": "be_manager_relation", - "db_type": "text", + "db_type": "int(10) unsigned", "list_hidden": 1, "search": 0, "name": "category_id", diff --git a/lib/neues.php b/lib/neues.php index 2c81604..82db745 100644 --- a/lib/neues.php +++ b/lib/neues.php @@ -5,6 +5,10 @@ use rex_fragment; use rex_pager; use rex_sql; +use rex_sql_table; +use rex; +use rex_sql_column; +use rex_sql_index; class Neues { @@ -55,4 +59,53 @@ public static function getEntry(int $postId): string $fragment->setVar('post', $post); return $fragment->parse('neues/entry.php'); } + + public static function ensureDbScheme() + { + rex_sql_table::get(rex::getTable('neues_entry')) + ->ensurePrimaryIdColumn() + ->ensureColumn(new rex_sql_column('status', 'int(11)')) + ->ensureColumn(new rex_sql_column('name', 'varchar(191)', false, '')) + ->ensureColumn(new rex_sql_column('teaser', 'text')) + ->ensureColumn(new rex_sql_column('description', 'text')) + ->ensureColumn(new rex_sql_column('domain_ids', 'text')) + ->ensureColumn(new rex_sql_column('lang_id', 'int(10) unsigned')) + ->ensureColumn(new rex_sql_column('publishdate', 'datetime')) + ->ensureColumn(new rex_sql_column('author_id', 'int(10) unsigned')) + ->ensureColumn(new rex_sql_column('url', 'varchar(191)', false, '')) + ->ensureColumn(new rex_sql_column('image', 'text')) + ->ensureColumn(new rex_sql_column('images', 'text')) + ->ensureColumn(new rex_sql_column('createdate', 'datetime')) + ->ensureColumn(new rex_sql_column('createuser', 'varchar(191)')) + ->ensureColumn(new rex_sql_column('updatedate', 'datetime')) + ->ensureColumn(new rex_sql_column('updateuser', 'varchar(191)')) + ->ensureColumn(new rex_sql_column('uuid', 'varchar(36)')) + ->ensureIndex(new rex_sql_index('uuid', ['uuid'], rex_sql_index::UNIQUE)) + ->ensureIndex(new rex_sql_index('status', ['status'])) + ->ensureIndex(new rex_sql_index('publishdate', ['publishdate'])) + ->ensureIndex(new rex_sql_index('description', ['description'], rex_sql_index::FULLTEXT)) + ->ensure(); + + rex_sql_table::get(rex::getTable('neues_category')) + ->ensurePrimaryIdColumn() + ->ensureColumn(new rex_sql_column('name', 'varchar(191)', false, '')) + ->ensureColumn(new rex_sql_column('image', 'text')) + ->ensureColumn(new rex_sql_column('status', 'text')) + ->ensureColumn(new rex_sql_column('createuser', 'varchar(191)')) + ->ensureColumn(new rex_sql_column('updateuser', 'varchar(191)')) + ->ensureColumn(new rex_sql_column('updatedate', 'datetime')) + ->ensureColumn(new rex_sql_column('createdate', 'datetime')) + ->ensureColumn(new rex_sql_column('uuid', 'varchar(36)')) + ->ensureIndex(new rex_sql_index('uuid', ['uuid'], rex_sql_index::UNIQUE)) + ->ensure(); + rex_sql_table::get(rex::getTable('neues_author')) + ->ensurePrimaryIdColumn() + ->ensureColumn(new rex_sql_column('name', 'varchar(191)', false, '')) + ->ensureColumn(new rex_sql_column('nickname', 'varchar(191)', false, '')) + ->ensureColumn(new rex_sql_column('text', 'text')) + ->ensureColumn(new rex_sql_column('be_user_id', 'text')) + ->ensureColumn(new rex_sql_column('uuid', 'varchar(36)')) + ->ensure(); + + } } From 3864ce7ec3d47a439dce2feabb677cbdff73e5cd Mon Sep 17 00:00:00 2001 From: Alexander Walther Date: Tue, 16 Jul 2024 16:31:08 +0200 Subject: [PATCH 2/4] update uuids on install / update --- install.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/install.php b/install.php index 31653f5..30dbb5e 100644 --- a/install.php +++ b/install.php @@ -18,6 +18,8 @@ // Vorhandene leere UUID-Felder aktualisieren $sql = rex_sql::factory(); + $sql->setQuery('UPDATE ' . \rex::getTable('neues_author') . ' SET uuid = uuid() WHERE uuid IS NULL OR uuid = ""'); + $sql->setQuery('UPDATE ' . \rex::getTable('neues_category') . ' SET uuid = uuid() WHERE uuid IS NULL OR uuid = ""'); $sql->setQuery('UPDATE ' . \rex::getTable('neues_entry') . ' SET uuid = uuid() WHERE uuid IS NULL OR uuid = ""'); Neues::ensureDbScheme(); From e45d6437fb1d25e3d82f3b79c0937c2846cafabc Mon Sep 17 00:00:00 2001 From: Alexander Walther Date: Tue, 16 Jul 2024 16:31:16 +0200 Subject: [PATCH 3/4] ensure neues_entry_category_rel --- lib/neues.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/neues.php b/lib/neues.php index 82db745..1892f37 100644 --- a/lib/neues.php +++ b/lib/neues.php @@ -106,6 +106,12 @@ public static function ensureDbScheme() ->ensureColumn(new rex_sql_column('be_user_id', 'text')) ->ensureColumn(new rex_sql_column('uuid', 'varchar(36)')) ->ensure(); - + + rex_sql_table::get(rex::getTable('neues_entry_category_rel')) + ->ensurePrimaryIdColumn() + ->ensureColumn(new rex_sql_column('entry_id', 'int(10) unsigned')) + ->ensureColumn(new rex_sql_column('category_id', 'int(10) unsigned')) + ->ensureIndex(new rex_sql_index('entry_id_category_id', ['entry_id', 'category_id'], rex_sql_index::UNIQUE)) + ->ensure(); } } From bb3a055f7b0771cb459c4c7007b208265b05e75e Mon Sep 17 00:00:00 2001 From: alxndr-w Date: Tue, 16 Jul 2024 14:31:46 +0000 Subject: [PATCH 4/4] Apply php-cs-fixer changes --- install.php | 9 ++++----- lib/neues.php | 8 ++++---- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/install.php b/install.php index 30dbb5e..930d471 100644 --- a/install.php +++ b/install.php @@ -2,6 +2,7 @@ namespace FriendsOfRedaxo\Neues; +use rex; use rex_addon; use rex_config; use rex_file; @@ -15,15 +16,13 @@ if (rex_addon::get('yform') && rex_addon::get('yform')->isAvailable()) { rex_yform_manager_table_api::importTablesets(rex_file::get(__DIR__ . '/install/tableset.json')); - // Vorhandene leere UUID-Felder aktualisieren $sql = rex_sql::factory(); - $sql->setQuery('UPDATE ' . \rex::getTable('neues_author') . ' SET uuid = uuid() WHERE uuid IS NULL OR uuid = ""'); - $sql->setQuery('UPDATE ' . \rex::getTable('neues_category') . ' SET uuid = uuid() WHERE uuid IS NULL OR uuid = ""'); - $sql->setQuery('UPDATE ' . \rex::getTable('neues_entry') . ' SET uuid = uuid() WHERE uuid IS NULL OR uuid = ""'); + $sql->setQuery('UPDATE ' . rex::getTable('neues_author') . ' SET uuid = uuid() WHERE uuid IS NULL OR uuid = ""'); + $sql->setQuery('UPDATE ' . rex::getTable('neues_category') . ' SET uuid = uuid() WHERE uuid IS NULL OR uuid = ""'); + $sql->setQuery('UPDATE ' . rex::getTable('neues_entry') . ' SET uuid = uuid() WHERE uuid IS NULL OR uuid = ""'); Neues::ensureDbScheme(); - } if (!rex_media::get('neues_entry_fallback_image.png')) { diff --git a/lib/neues.php b/lib/neues.php index 1892f37..b91bfd7 100644 --- a/lib/neues.php +++ b/lib/neues.php @@ -2,13 +2,13 @@ namespace FriendsOfRedaxo\Neues; +use rex; use rex_fragment; use rex_pager; use rex_sql; -use rex_sql_table; -use rex; use rex_sql_column; use rex_sql_index; +use rex_sql_table; class Neues { @@ -85,7 +85,7 @@ public static function ensureDbScheme() ->ensureIndex(new rex_sql_index('publishdate', ['publishdate'])) ->ensureIndex(new rex_sql_index('description', ['description'], rex_sql_index::FULLTEXT)) ->ensure(); - + rex_sql_table::get(rex::getTable('neues_category')) ->ensurePrimaryIdColumn() ->ensureColumn(new rex_sql_column('name', 'varchar(191)', false, '')) @@ -106,7 +106,7 @@ public static function ensureDbScheme() ->ensureColumn(new rex_sql_column('be_user_id', 'text')) ->ensureColumn(new rex_sql_column('uuid', 'varchar(36)')) ->ensure(); - + rex_sql_table::get(rex::getTable('neues_entry_category_rel')) ->ensurePrimaryIdColumn() ->ensureColumn(new rex_sql_column('entry_id', 'int(10) unsigned'))