diff --git a/core/upgrade/app_languages.php b/core/upgrade/app_languages.php index 8e383e2b19..d90da0dc78 100644 --- a/core/upgrade/app_languages.php +++ b/core/upgrade/app_languages.php @@ -567,32 +567,32 @@ $text['label-optional_apps']['zh-cn'] = "可选应用程序"; $text['label-optional_apps']['ja-jp'] = "オプションのアプリ"; $text['label-optional_apps']['ko-kr'] = "선택적 앱"; -$text['label-upgrade_schema']['en-us'] = "Schema"; -$text['label-upgrade_schema']['en-gb'] = "Schema"; -$text['label-upgrade_schema']['ar-eg'] = "مخطط"; -$text['label-upgrade_schema']['de-at'] = "Schema"; -$text['label-upgrade_schema']['de-ch'] = "Schema"; -$text['label-upgrade_schema']['de-de'] = "Schema"; -$text['label-upgrade_schema']['el-gr'] = "Σχήμα"; -$text['label-upgrade_schema']['es-cl'] = "Esquema"; -$text['label-upgrade_schema']['es-mx'] = "Esquema"; -$text['label-upgrade_schema']['fr-ca'] = "Schéma"; -$text['label-upgrade_schema']['fr-fr'] = "Schéma"; -$text['label-upgrade_schema']['he-il'] = "סכֵימָה"; -$text['label-upgrade_schema']['it-it'] = "Schema"; -$text['label-upgrade_schema']['ka-ge'] = "სქემა"; -$text['label-upgrade_schema']['nl-nl'] = "Schema"; -$text['label-upgrade_schema']['pl-pl'] = "Schemat"; -$text['label-upgrade_schema']['pt-br'] = "Esquema"; -$text['label-upgrade_schema']['pt-pt'] = "Esquema"; -$text['label-upgrade_schema']['ro-ro'] = "Schemă"; -$text['label-upgrade_schema']['ru-ru'] = "Схема"; -$text['label-upgrade_schema']['sv-se'] = "Schema"; -$text['label-upgrade_schema']['uk-ua'] = "Схема"; -$text['label-upgrade_schema']['tr-tr'] = "Şema"; -$text['label-upgrade_schema']['zh-cn'] = "架构"; -$text['label-upgrade_schema']['ja-jp'] = "スキーマ"; -$text['label-upgrade_schema']['ko-kr'] = "개요"; +$text['label-upgrade_schema']['en-us'] = "Database Schema"; +$text['label-upgrade_schema']['en-gb'] = "Database Schema"; +$text['label-upgrade_schema']['ar-eg'] = "مخطط قاعدة البيانات"; +$text['label-upgrade_schema']['de-at'] = "Datenbankschema"; +$text['label-upgrade_schema']['de-ch'] = "Datenbankschema"; +$text['label-upgrade_schema']['de-de'] = "Datenbankschema"; +$text['label-upgrade_schema']['el-gr'] = "Σχήμα βάσης δεδομένων"; +$text['label-upgrade_schema']['es-cl'] = "Esquema de base de datos"; +$text['label-upgrade_schema']['es-mx'] = "Esquema de base de datos"; +$text['label-upgrade_schema']['fr-ca'] = "Schéma de base de données"; +$text['label-upgrade_schema']['fr-fr'] = "Schéma de base de données"; +$text['label-upgrade_schema']['he-il'] = "схемת מסד הנתונים"; +$text['label-upgrade_schema']['it-it'] = "Schema del database"; +$text['label-upgrade_schema']['ka-ge'] = "მონაცემთა ბაზის სქემა"; +$text['label-upgrade_schema']['nl-nl'] = "Databaseschema"; +$text['label-upgrade_schema']['pl-pl'] = "Schemat bazy danych"; +$text['label-upgrade_schema']['pt-br'] = "Esquema do banco de dados"; +$text['label-upgrade_schema']['pt-pt'] = "Esquema da base de dados"; +$text['label-upgrade_schema']['ro-ro'] = "Schema bazei de date"; +$text['label-upgrade_schema']['ru-ru'] = "Схема базы данных"; +$text['label-upgrade_schema']['sv-se'] = "Databasschema"; +$text['label-upgrade_schema']['uk-ua'] = "Схема бази даних"; +$text['label-upgrade_schema']['tr-tr'] = "Veritabanı şeması"; +$text['label-upgrade_schema']['zh-cn'] = "数据库架构"; +$text['label-upgrade_schema']['ja-jp'] = "データベーススキーマ"; +$text['label-upgrade_schema']['ko-kr'] = "데이터베이스 스키마"; $text['label-upgrade_permissions']['en-us'] = "Group Permissions"; $text['label-upgrade_permissions']['en-gb'] = "Group Permissions"; @@ -1269,32 +1269,32 @@ $text['description-update_all_source_files']['zh-cn'] = "更新所有源文件 $text['description-update_all_source_files']['ja-jp'] = "すべてのソースファイルを更新します。"; $text['description-update_all_source_files']['ko-kr'] = "모든 소스 파일을 업데이트합니다."; -$text['description-upgrade_schema']['en-us'] = "Check the table and field structure."; -$text['description-upgrade_schema']['en-gb'] = "Check the table and field structure."; -$text['description-upgrade_schema']['ar-eg'] = "تحقق من هيكل الجدول والحقول."; -$text['description-upgrade_schema']['de-at'] = "Überprüfen Sie die Tabellen- und Feldstruktur."; -$text['description-upgrade_schema']['de-ch'] = "Überprüfen Sie die Tabellen- und Feldstruktur."; -$text['description-upgrade_schema']['de-de'] = "Überprüfen Sie die Tabellen- und Feldstruktur."; -$text['description-upgrade_schema']['el-gr'] = "Ελέγξτε τη δομή του πίνακα και των πεδίων."; -$text['description-upgrade_schema']['es-cl'] = "Verifique la estructura de la tabla y los campos."; -$text['description-upgrade_schema']['es-mx'] = "Verifique la estructura de la tabla y los campos."; -$text['description-upgrade_schema']['fr-ca'] = "Vérifiez la structure du tableau et des champs."; -$text['description-upgrade_schema']['fr-fr'] = "Vérifiez la structure du tableau et des champs."; -$text['description-upgrade_schema']['he-il'] = "تحقق מבני הטבלה והשדות."; -$text['description-upgrade_schema']['it-it'] = "Controlla la struttura della tabella e dei campi."; -$text['description-upgrade_schema']['ka-ge'] = "შეამოწმეთ ცხრილის და ველების სტрукტურა."; -$text['description-upgrade_schema']['nl-nl'] = "Controleer de tabel- en veldstructuur."; -$text['description-upgrade_schema']['pl-pl'] = "Sprawdź strukturę tabeli i pól."; -$text['description-upgrade_schema']['pt-br'] = "Verifique a estrutura da tabela e dos campos."; -$text['description-upgrade_schema']['pt-pt'] = "Verifique a estrutura da tabela e dos campos."; -$text['description-upgrade_schema']['ro-ro'] = "Verificați structura tabelei și a câmpurilor."; -$text['description-upgrade_schema']['ru-ru'] = "Проверьте структуру таблицы и полей."; -$text['description-upgrade_schema']['sv-se'] = "Kontrollera tabellens och fälten struktur."; -$text['description-upgrade_schema']['uk-ua'] = "Перевірте структуру таблиці та полів."; -$text['description-upgrade_schema']['tr-tr'] = "Tablo ve alan yapısını kontrol edin."; -$text['description-upgrade_schema']['zh-cn'] = "检查表和字段结构。"; -$text['description-upgrade_schema']['ja-jp'] = "テーブルとフィールドの構造を確認してください。"; -$text['description-upgrade_schema']['ko-kr'] = "테이블 및 필드 구조를 확인하세요.";; +$text['description-upgrade_schema']['en-us'] = "Update the tables, columns, and data types."; +$text['description-upgrade_schema']['en-gb'] = "Update the tables, columns, and data types."; +$text['description-upgrade_schema']['ar-eg'] = "تحديث الجداول والأعمدة وأنواع البيانات."; +$text['description-upgrade_schema']['de-at'] = "Aktualisieren Sie die Tabellen, Spalten und Datentypen."; +$text['description-upgrade_schema']['de-ch'] = "Aktualisieren Sie die Tabellen, Spalten und Datentypen."; +$text['description-upgrade_schema']['de-de'] = "Aktualisieren Sie die Tabellen, Spalten und Datentypen."; +$text['description-upgrade_schema']['el-gr'] = "Ενημερώστε τους πίνακες, τις στήλες και τους τύπους δεδομένων."; +$text['description-upgrade_schema']['es-cl'] = "Actualice las tablas, columnas y tipos de datos."; +$text['description-upgrade_schema']['es-mx'] = "Actualice las tablas, columnas y tipos de datos."; +$text['description-upgrade_schema']['fr-ca'] = "Mettez à jour les tables, colonnes et types de données."; +$text['description-upgrade_schema']['fr-fr'] = "Mettez à jour les tables, colonnes et types de données."; +$text['description-upgrade_schema']['he-il'] = "עדכן את הטבלאות והстעורים وأنטייפי данных."; +$text['description-upgrade_schema']['it-it'] = "Aggiorna le tabelle, le colonne e i tipi di dati."; +$text['description-upgrade_schema']['ka-ge'] = "განახლეთ ცხრილებს, ველებს და მონაცემთა ტიპებს."; +$text['description-upgrade_schema']['nl-nl'] = "Update de tabellen, kolommen en gegevenstypen."; +$text['description-upgrade_schema']['pl-pl'] = "Zaktualizuj tabele, kolumny i typy danych."; +$text['description-upgrade_schema']['pt-br'] = "Atualize as tabelas, colunas e tipos de dados."; +$text['description-upgrade_schema']['pt-pt'] = "Atualize as tabelas, colunas e tipos de dados."; +$text['description-upgrade_schema']['ro-ro'] = "Actualizați tabelele, coloanele și tipurile de date."; +$text['description-upgrade_schema']['ru-ru'] = "Обновите таблицы, столбцы и типы данных."; +$text['description-upgrade_schema']['sv-se'] = "Uppdatera tabellerna, kolumnerna och datatyperna."; +$text['description-upgrade_schema']['uk-ua'] = "Оновіть таблиці, стовпці та типи даних."; +$text['description-upgrade_schema']['tr-tr'] = "Tabloları, sütunları ve veri türlerini güncelleyin."; +$text['description-upgrade_schema']['zh-cn'] = "更新表、列和数据类型。"; +$text['description-upgrade_schema']['ja-jp'] = "テーブル、カラム、およびデータ型を更新してください。"; +$text['description-upgrade_schema']['ko-kr'] = "테이블, 열 및 데이터 유형을 업데이트하세요."; $text['description-upgrade_permissions']['en-us'] = "Restore default group permissions."; $text['description-upgrade_permissions']['en-gb'] = "Restore default group permissions."; diff --git a/core/upgrade/index.php b/core/upgrade/index.php index c17c87b1b2..79989632e8 100644 --- a/core/upgrade/index.php +++ b/core/upgrade/index.php @@ -149,9 +149,6 @@ //load an array of the database schema and compare it with the active database if (!empty($action["upgrade_schema"]) && permission_exists("upgrade_schema")) { $obj = new schema(['database' => $database]); - if (isset($action["data_types"]) && $action["data_types"] == 'true') { - $obj->data_types = true; - } $_SESSION["response"]["schema"] = $obj->schema("html"); message::add($text['message-upgrade_schema'], null, $message_timeout); } @@ -369,29 +366,16 @@ if (permission_exists("upgrade_schema")) { echo "\n"; - echo "\n"; + echo "\n"; echo " \n"; echo " \n"; echo "\n"; echo "
\n"; echo "
".$step."
"; echo "
".$text['label-upgrade_schema']."
\n"; echo "
\n"; - echo "  ".$text['description-upgrade_schema']."\n"; + echo "  ".$text['description-upgrade_schema']."\n"; echo "
\n"; - - echo "\n"; $step++; } diff --git a/core/upgrade/upgrade.php b/core/upgrade/upgrade.php index af860bf640..d9ab7cf1f3 100644 --- a/core/upgrade/upgrade.php +++ b/core/upgrade/upgrade.php @@ -204,8 +204,7 @@ echo " -v --version Show the version.\n"; echo " -n --main Update the main application.\n"; echo " -o --optional Update the optional applications.\n"; - echo " -s --schema Check the table and field structure.\n"; - echo " -t --types Updates field data types as needed.\n"; + echo " -s --schema Update the database tables, columns and data types.\n"; echo " -d --defaults Restore application defaults.\n"; echo " -m --menu [default|list] Restore menu default or show the menu list\n"; echo " -p --permissions Restore default file and group permissions.\n"; @@ -222,7 +221,7 @@ echo software::version()."\n"; } -//upgrade schema and/or data_types +//upgrade the schema and data_types if ($upgrade_type == 'schema' or $upgrade_type == '-s' or $upgrade_type == '--schema') { //send a message to the console if ($display_type === 'text') { @@ -230,9 +229,6 @@ } //get the database schema put it into an array then compare and update the database as needed. - if (isset($argv[2]) && $argv[2] == 'data_types') { - $schema->data_types = true; - } $response = $schema->schema($format ?? ''); if ($display_type === 'text') { foreach(explode("\n", $response) as $row) { @@ -241,22 +237,6 @@ } } -//upgrade schema and/or data_types - if ($upgrade_type == 'data_types' or $upgrade_type == '-t' or $upgrade_type == '--types') { - //send a message to the console - if ($display_type === 'text') { - echo "[ Update ] Table, field structure and data types.\n"; - } - - //get the database schema put it into an array then compare and update the database as needed. - $schema->data_types = true; - $response = $schema->schema($format ?? ''); - if ($display_type === 'text') { - foreach(explode("\n", $response) as $row) { - echo " ".trim($row)."\n"; - } - } - } //run all application defaults - add missing defaults if ($upgrade_type == 'defaults' or $upgrade_type == '-d' or $upgrade_type == '--defaults') { diff --git a/core/upgrade/upgrade_menu.php b/core/upgrade/upgrade_menu.php index c6f0ba0b70..f72039ff53 100644 --- a/core/upgrade/upgrade_menu.php +++ b/core/upgrade/upgrade_menu.php @@ -77,9 +77,7 @@ function show_upgrade_menu() { ['1', $text['label-upgrade_source'], $text['description-update_all_source_files']], ['1a', $text['label-main_software'], $text['description-main_software']], ['1b', $text['label-optional_applications'], $text['description-optional_applications']], - ['2', $text['label-database'], $text['description-upgrade_schema']], - ['2a', $text['label-schema'], $text['description-upgrade_schema']], - ['2b', $text['label-upgrade_data_types'], $text['description-upgrade_data_types']], + ['2', $text['label-upgrade_schema'], $text['description-upgrade_schema']], ['3', $text['label-upgrade_apps'], $text['description-upgrade_apps']], ['4', $text['label-upgrade_menu'], $text['description-upgrade_menu']], ['5', $text['label-upgrade_permissions'], $text['description-upgrade_permissions']], @@ -129,14 +127,8 @@ function show_upgrade_menu() { do_upgrade_auto_loader(); break; case 2: - do_upgrade_schema(true); - break; - case '2a': do_upgrade_schema(); break; - case '2b': - do_upgrade_schema(true); - break; case 3: do_upgrade_auto_loader(); do_upgrade_domains(); @@ -163,7 +155,7 @@ function show_upgrade_menu() { case 'a': do_upgrade_code(); do_upgrade_auto_loader(); - do_upgrade_schema(true); + do_upgrade_schema(); do_upgrade_domains(); do_upgrade_menu(); do_upgrade_permissions(); @@ -352,14 +344,11 @@ function do_upgrade_domains() { /** * Upgrades the database schema to the latest version. * - * @param bool $data_types Whether or not to include data types in the upgrade process. Defaults to false. - * * @return void */ -function do_upgrade_schema(bool $data_types = false) { +function do_upgrade_schema() { //get the database schema put it into an array then compare and update the database as needed. $obj = new schema(); - $obj->data_types = $data_types; echo $obj->schema('text'); } diff --git a/core/upgrade/upgrade_schema.php b/core/upgrade/upgrade_schema.php index eb33dcc07b..b91291edb3 100644 --- a/core/upgrade/upgrade_schema.php +++ b/core/upgrade/upgrade_schema.php @@ -60,9 +60,6 @@ //get the database schema put it into an array then compare and update the database as needed. $obj = new schema(['database' => $database]); - if (isset($argv[1]) && $argv[1] == 'data_types') { - $obj->data_types = true; - } echo $obj->schema($format); //formatting for html diff --git a/resources/classes/schema.php b/resources/classes/schema.php index e96debf372..115816c597 100644 --- a/resources/classes/schema.php +++ b/resources/classes/schema.php @@ -610,78 +610,76 @@ } } - //change the data type if it has been changed - //if the data type in the app db array is different than the type in the database then change the data type - if ($this->data_types) { - $db_field_type = $this->column_data_type($table_name, $field_name); - $field_type_array = explode("(", $field_type); - $field_type = $field_type_array[0]; - if (trim($db_field_type) != trim($field_type) && !empty($db_field_type)) { - if ($this->db_type == "pgsql") { - if (strtolower($field_type) == "uuid") { - $sql_update .= "ALTER TABLE " . $table_name . " ALTER COLUMN " . $field_name . " TYPE uuid USING\n"; - $sql_update .= "CAST(regexp_replace(" . $field_name . ", '([A-Z0-9]{4})([A-Z0-9]{12})', E'\\1-\\2')\n"; - $sql_update .= "AS uuid);\n"; - } else { - //field type has not changed - if ($db_field_type == "integer" && strtolower($field_type) == "serial") { + //change the schema data types if needed + //if the data type described in the app_config array is different than the type in the database then update the data type + $db_field_type = $this->column_data_type($table_name, $field_name); + $field_type_array = explode("(", $field_type); + $field_type = $field_type_array[0]; + if (trim($db_field_type) != trim($field_type) && !empty($db_field_type)) { + if ($this->db_type == "pgsql") { + if (strtolower($field_type) == "uuid") { + $sql_update .= "ALTER TABLE " . $table_name . " ALTER COLUMN " . $field_name . " TYPE uuid USING\n"; + $sql_update .= "CAST(regexp_replace(" . $field_name . ", '([A-Z0-9]{4})([A-Z0-9]{12})', E'\\1-\\2')\n"; + $sql_update .= "AS uuid);\n"; + } else { + //field type has not changed + if ($db_field_type == "integer" && strtolower($field_type) == "serial") { - } else if ($db_field_type == "timestamp without time zone" && strtolower($field_type) == "timestamp") { + } else if ($db_field_type == "timestamp without time zone" && strtolower($field_type) == "timestamp") { - } else if ($db_field_type == "timestamp without time zone" && strtolower($field_type) == "datetime") { + } else if ($db_field_type == "timestamp without time zone" && strtolower($field_type) == "datetime") { - } else if ($db_field_type == "timestamp with time zone" && strtolower($field_type) == "timestamptz") { + } else if ($db_field_type == "timestamp with time zone" && strtolower($field_type) == "timestamptz") { - } else if ($db_field_type == "integer" && strtolower($field_type) == "numeric") { + } else if ($db_field_type == "integer" && strtolower($field_type) == "numeric") { - } else if ($db_field_type == "character" && strtolower($field_type) == "char") { + } else if ($db_field_type == "character" && strtolower($field_type) == "char") { - } - //field type has changed - else { - switch ($field_type) { - case 'numeric': - $sql_update .= "ALTER TABLE " . $table_name . " ALTER COLUMN " . $field_name . " TYPE " . $field_type . " USING " . $field_name . "::numeric;\n"; - break; - case 'timestamp': - $sql_update .= "ALTER TABLE " . $table_name . " ALTER COLUMN " . $field_name . " TYPE " . $field_type . " USING " . $field_name . "::timestamp with time zone;\n"; - break; - case 'datetime': - $sql_update .= "ALTER TABLE " . $table_name . " ALTER COLUMN " . $field_name . " TYPE " . $field_type . " USING " . $field_name . "::timestamp without time zone;\n"; - break; - case 'timestamptz': - $sql_update .= "ALTER TABLE " . $table_name . " ALTER COLUMN " . $field_name . " TYPE " . $field_type . " USING " . $field_name . "::timestamp with time zone;\n"; - break; - case 'boolean': - if ($db_field_type == 'numeric') { - $sql_update .= "ALTER TABLE " . $table_name . " ALTER COLUMN " . $field_name . " TYPE text USING " . $field_name . "::text;\n"; - } - if ($db_field_type == 'text') { - $sql_update .= "UPDATE " . $table_name . " set " . $field_name . " = 'false' where " . $field_name . " = '';\n"; - } - $sql_update .= "ALTER TABLE " . $table_name . " ALTER COLUMN " . $field_name . " TYPE " . $field_type . " USING " . $field_name . "::boolean;\n"; - break; - default: unset($using); - $sql_update .= "ALTER TABLE " . $table_name . " ALTER COLUMN " . $field_name . " TYPE " . $field_type . "\n"; - } + } + //field type has changed + else { + switch ($field_type) { + case 'numeric': + $sql_update .= "ALTER TABLE " . $table_name . " ALTER COLUMN " . $field_name . " TYPE " . $field_type . " USING " . $field_name . "::numeric;\n"; + break; + case 'timestamp': + $sql_update .= "ALTER TABLE " . $table_name . " ALTER COLUMN " . $field_name . " TYPE " . $field_type . " USING " . $field_name . "::timestamp with time zone;\n"; + break; + case 'datetime': + $sql_update .= "ALTER TABLE " . $table_name . " ALTER COLUMN " . $field_name . " TYPE " . $field_type . " USING " . $field_name . "::timestamp without time zone;\n"; + break; + case 'timestamptz': + $sql_update .= "ALTER TABLE " . $table_name . " ALTER COLUMN " . $field_name . " TYPE " . $field_type . " USING " . $field_name . "::timestamp with time zone;\n"; + break; + case 'boolean': + if ($db_field_type == 'numeric') { + $sql_update .= "ALTER TABLE " . $table_name . " ALTER COLUMN " . $field_name . " TYPE text USING " . $field_name . "::text;\n"; + } + if ($db_field_type == 'text') { + $sql_update .= "UPDATE " . $table_name . " set " . $field_name . " = 'false' where " . $field_name . " = '';\n"; + } + $sql_update .= "ALTER TABLE " . $table_name . " ALTER COLUMN " . $field_name . " TYPE " . $field_type . " USING " . $field_name . "::boolean;\n"; + break; + default: unset($using); + $sql_update .= "ALTER TABLE " . $table_name . " ALTER COLUMN " . $field_name . " TYPE " . $field_type . "\n"; } } } - if ($this->db_type == "mysql") { - $type = explode("(", $db_field_type); - if ($type[0] == $field_type) { - //do nothing - } else if ($field_type == "numeric" && $type[0] == "decimal") { - //do nothing - } else { - $sql_update .= "ALTER TABLE " . $table_name . " modify " . $field_name . " " . $field_type . ";\n"; - } - unset($type); - } - if ($this->db_type == "sqlite") { - //a change has been made to the field type - $this->applications[$x]['db'][$y]['rebuild'] = 'true'; + } + if ($this->db_type == "mysql") { + $type = explode("(", $db_field_type); + if ($type[0] == $field_type) { + //do nothing + } else if ($field_type == "numeric" && $type[0] == "decimal") { + //do nothing + } else { + $sql_update .= "ALTER TABLE " . $table_name . " modify " . $field_name . " " . $field_type . ";\n"; } + unset($type); + } + if ($this->db_type == "sqlite") { + //a change has been made to the field type + $this->applications[$x]['db'][$y]['rebuild'] = 'true'; } } }