Skip to content

Commit

Permalink
Merge pull request #75 from FriendsOfREDAXO/table-scheme-optimization
Browse files Browse the repository at this point in the history
Tabellen-Schema-Optimierungen: Korrekte und neu unterstützte Datentypen für Relationen
  • Loading branch information
alxndr-w authored Jul 16, 2024
2 parents 73e93d3 + bb3a055 commit 0421982
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 5 deletions.
9 changes: 9 additions & 0 deletions install.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace FriendsOfRedaxo\Neues;

use rex;
use rex_addon;
use rex_config;
use rex_file;
Expand All @@ -14,6 +15,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_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')) {
Expand Down
10 changes: 5 additions & 5 deletions install/tableset.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions lang/de_de.lang
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ neues_category_name_validate_unique = Dieser Name ist bereits vergeben.
neues_category_title = Kategorie
neues_category_title_notice = Name der Kategorie, Schlagwort oder Name einer Beitragsreihe.
neues_category_image = Titelbild
neues_category_uuid = UUID
neues_teaser = Teaser
neues_teaser_notice = Ein kurzer Anreißer-Text oder eine Zusammenfassung, die in der Terminübersicht ausgegeben werden kann.
neues_description = Inhalt
Expand All @@ -42,6 +43,7 @@ neues_updateuser = Zuletzt geändert von...
neues_publishdate = Veröffentlicht am...
neues_publishdate_validate_compare_value = Das Veröffentlichungsdatum darf nicht leer sein.
neues_publishuser = Veröffentlicht von...
neues_entry_uuid = UUID

neues_category_ids = Kategorie(n)
neues_prio = Reihenfolge
Expand Down Expand Up @@ -73,6 +75,7 @@ neues_author_name = Name
neues_author_nickname = Spitzname
neues_author_text = Beschreibung
neues_author_be_user_id = REDAXO-Benutzer:in
neues_author_uuid = UUID

# Settings

Expand Down
59 changes: 59 additions & 0 deletions lib/neues.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

namespace FriendsOfRedaxo\Neues;

use rex;
use rex_fragment;
use rex_pager;
use rex_sql;
use rex_sql_column;
use rex_sql_index;
use rex_sql_table;

class Neues
{
Expand Down Expand Up @@ -55,4 +59,59 @@ 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();

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();
}
}

0 comments on commit 0421982

Please sign in to comment.