]> git.mxchange.org Git - friendica.git/blobdiff - src/Database/DBStructure.php
Issue 11508: Sanitizing date fields for events and polls
[friendica.git] / src / Database / DBStructure.php
index 02a29b404d8b59863c2e0cc75d1568d8b6eba670..2638bafab767f825d56932ba1bc82697af0b0872 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2010-2021, the Friendica project
+ * @copyright Copyright (C) 2010-2022, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -82,7 +82,7 @@ class DBStructure
                $old_tables = ['fserver', 'gcign', 'gcontact', 'gcontact-relation', 'gfollower' ,'glink', 'item-delivery-data',
                        'item-activity', 'item-content', 'item_id', 'participation', 'poll', 'poll_result', 'queue', 'retriever_rule',
                        'deliverq', 'dsprphotoq', 'ffinder', 'sign', 'spam', 'term', 'user-item', 'thread', 'item', 'challenge',
-                       'auth_codes', 'clients', 'tokens', 'profile_check'];
+                       'auth_codes', 'tokens', 'clients', 'profile_check', 'host'];
 
                $tables = DBA::selectToArray(['INFORMATION_SCHEMA' => 'TABLES'], ['TABLE_NAME'],
                        ['TABLE_SCHEMA' => DBA::databaseName(), 'TABLE_TYPE' => 'BASE TABLE']);
@@ -96,10 +96,10 @@ class DBStructure
                        echo DI::l10n()->t('These tables are not used for friendica and will be deleted when you execute "dbstructure drop -e":') . "\n\n";
                }
 
-               foreach ($tables as $table) {
-                       if (in_array($table['TABLE_NAME'], $old_tables)) {
+               foreach ($old_tables as $table) {
+                       if (in_array($table, array_column($tables, 'TABLE_NAME'))) {
                                if ($execute) {
-                                       $sql = 'DROP TABLE ' . DBA::quoteIdentifier($table['TABLE_NAME']) . ';';
+                                       $sql = 'DROP TABLE ' . DBA::quoteIdentifier($table) . ';';
                                        echo $sql . "\n";
 
                                        $result = DBA::e($sql);
@@ -107,7 +107,7 @@ class DBStructure
                                                self::printUpdateError($sql);
                                        }
                                } else {
-                                       echo $table['TABLE_NAME'] . "\n";
+                                       echo $table . "\n";
                                }
                        }
                }
@@ -135,7 +135,7 @@ class DBStructure
                        return;
                }
 
-               foreach ($tables AS $table) {
+               foreach ($tables as $table) {
                        $sql = "ALTER TABLE " . DBA::quoteIdentifier($table['table_name']) . " ENGINE=InnoDB ROW_FORMAT=DYNAMIC;";
                        echo $sql . "\n";
 
@@ -271,7 +271,7 @@ class DBStructure
                echo "-- " . FRIENDICA_PLATFORM . " " . FRIENDICA_VERSION . " (" . FRIENDICA_CODENAME, ")\n";
                echo "-- DB_UPDATE_VERSION " . DB_UPDATE_VERSION . "\n";
                echo "-- ------------------------------------------\n\n\n";
-               foreach ($database AS $name => $structure) {
+               foreach ($database as $name => $structure) {
                        echo "--\n";
                        echo "-- TABLE $name\n";
                        echo "--\n";
@@ -368,7 +368,7 @@ class DBStructure
                $primary_keys = [];
                $foreign_keys = [];
 
-               foreach ($structure["fields"] AS $fieldname => $field) {
+               foreach ($structure["fields"] as $fieldname => $field) {
                        $sql_rows[] = "`" . DBA::escape($fieldname) . "` " . self::FieldCommand($field);
                        if (!empty($field['primary'])) {
                                $primary_keys[] = $fieldname;
@@ -379,7 +379,7 @@ class DBStructure
                }
 
                if (!empty($structure["indexes"])) {
-                       foreach ($structure["indexes"] AS $indexname => $fieldnames) {
+                       foreach ($structure["indexes"] as $indexname => $fieldnames) {
                                $sql_index = self::createIndex($indexname, $fieldnames, "");
                                if (!is_null($sql_index)) {
                                        $sql_rows[] = $sql_index;
@@ -387,7 +387,7 @@ class DBStructure
                        }
                }
 
-               foreach ($foreign_keys AS $fieldname => $parameters) {
+               foreach ($foreign_keys as $fieldname => $parameters) {
                        $sql_rows[] = self::foreignCommand($name, $fieldname, $parameters);
                }
 
@@ -460,7 +460,7 @@ class DBStructure
                }
 
                $names = "";
-               foreach ($fieldnames AS $fieldname) {
+               foreach ($fieldnames as $fieldname) {
                        if ($names != "") {
                                $names .= ",";
                        }
@@ -569,7 +569,7 @@ class DBStructure
                }
 
                if (DBA::isResult($tables)) {
-                       foreach ($tables AS $table) {
+                       foreach ($tables as $table) {
                                $table = current($table);
 
                                Logger::info('updating structure', ['table' => $table]);
@@ -591,7 +591,7 @@ class DBStructure
                }
 
                // Compare it
-               foreach ($definition AS $name => $structure) {
+               foreach ($definition as $name => $structure) {
                        $is_new_table = false;
                        $sql3 = "";
                        if (!isset($database[$name])) {
@@ -623,7 +623,7 @@ class DBStructure
                                        }
                                }
                                // Compare the field structure field by field
-                               foreach ($structure["fields"] AS $fieldname => $parameters) {
+                               foreach ($structure["fields"] as $fieldname => $parameters) {
                                        if (!isset($database[$name]["fields"][$fieldname])) {
                                                $sql2 = self::addTableField($fieldname, $parameters);
                                                if ($sql3 == "") {
@@ -670,7 +670,7 @@ class DBStructure
                         * Don't create keys if table is new
                         */
                        if (!$is_new_table) {
-                               foreach ($structure["indexes"] AS $indexname => $fieldnames) {
+                               foreach ($structure["indexes"] as $indexname => $fieldnames) {
                                        if (isset($database[$name]["indexes"][$indexname])) {
                                                $current_index_definition = implode(",", $database[$name]["indexes"][$indexname]);
                                        } else {
@@ -694,7 +694,7 @@ class DBStructure
 
                                // Foreign keys
                                // Compare the field structure field by field
-                               foreach ($structure["fields"] AS $fieldname => $parameters) {
+                               foreach ($structure["fields"] as $fieldname => $parameters) {
                                        if (empty($parameters['foreign'])) {
                                                continue;
                                        }
@@ -767,7 +767,7 @@ class DBStructure
 
                                // Now have a look at the field collations
                                // Compare the field structure field by field
-                               foreach ($structure["fields"] AS $fieldname => $parameters) {
+                               foreach ($structure["fields"] as $fieldname => $parameters) {
                                        // Compare the field definition
                                        $field_definition = ($database[$name]["fields"][$fieldname] ?? '') ?: ['Collation' => ''];
 
@@ -860,7 +860,7 @@ class DBStructure
                }
 
                if (DBA::isResult($indexes)) {
-                       foreach ($indexes AS $index) {
+                       foreach ($indexes as $index) {
                                if ($index["Key_name"] != "PRIMARY" && $index["Non_unique"] == "0" && !isset($indexdata[$index["Key_name"]])) {
                                        $indexdata[$index["Key_name"]] = ["UNIQUE"];
                                }
@@ -881,7 +881,7 @@ class DBStructure
 
                $fielddata = [];
                if (DBA::isResult($fields)) {
-                       foreach ($fields AS $field) {
+                       foreach ($fields as $field) {
                                $search = ['tinyint(1)', 'tinyint(3) unsigned', 'tinyint(4)', 'smallint(5) unsigned', 'smallint(6)', 'mediumint(8) unsigned', 'mediumint(9)', 'bigint(20)', 'int(10) unsigned', 'int(11)'];
                                $replace = ['boolean', 'tinyint unsigned', 'tinyint', 'smallint unsigned', 'smallint', 'mediumint unsigned', 'mediumint', 'bigint', 'int unsigned', 'int'];
                                $field['COLUMN_TYPE'] = str_replace($search, $replace, $field['COLUMN_TYPE']);
@@ -1055,7 +1055,7 @@ class DBStructure
 
                $table = DBA::escape($table);
 
-               foreach ($columns AS $column) {
+               foreach ($columns as $column) {
                        $sql = "SHOW COLUMNS FROM `" . $table . "` LIKE '" . $column . "';";
 
                        $stmt = DBA::p($sql);