]> git.mxchange.org Git - friendica.git/blobdiff - src/Database/DBStructure.php
bump version 2023.12
[friendica.git] / src / Database / DBStructure.php
index c0bd005d1e36c5ca31c52d4c0ac23fffab2e0cac..6291d0ffc4b643a2f32bfbad6f2edb2ca10ff92a 100644 (file)
@@ -57,6 +57,18 @@ class DBStructure
                echo DI::l10n()->t('The database version had been set to %s.', $version);
        }
 
+       /**
+        * Drops a specific table
+        *
+        * @param string $table the table name
+        *
+        * @return bool true if possible, otherwise false
+        */
+       public static function dropTable(string $table): bool
+       {
+               return DBA::isResult(DBA::e('DROP TABLE ' . DBA::quoteIdentifier($table) . ';'));
+       }
+
        /**
         * Drop unused tables
         *
@@ -74,7 +86,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', 'tokens', 'clients', 'profile_check', 'host', 'conversation', 'fcontact', 'config', 'addon'];
+                       'auth_codes', 'tokens', 'clients', 'profile_check', 'host', 'conversation', 'fcontact', 'addon'];
 
                $tables = DBA::selectToArray('INFORMATION_SCHEMA.TABLES', ['TABLE_NAME'],
                        ['TABLE_SCHEMA' => DBA::databaseName(), 'TABLE_TYPE' => 'BASE TABLE']);
@@ -94,8 +106,7 @@ class DBStructure
                                        $sql = 'DROP TABLE ' . DBA::quoteIdentifier($table) . ';';
                                        echo $sql . "\n";
 
-                                       $result = DBA::e($sql);
-                                       if (!DBA::isResult($result)) {
+                                       if (!static::dropTable($table)) {
                                                self::printUpdateError($sql);
                                        }
                                } else {
@@ -783,7 +794,7 @@ class DBStructure
                        }
 
                        if (!DBA::exists('verb', ['id' => 0])) {
-                               DBA::insert('verb', ['name' => '']);
+                               DBA::insert('verb', ['name' => ''], Database::INSERT_IGNORE);
                                $lastid = DBA::lastInsertId();
                                if ($lastid != 0) {
                                        DBA::update('verb', ['id' => 0], ['id' => $lastid]);
@@ -819,7 +830,7 @@ class DBStructure
                }
 
                if (self::existsTable('contact') && !DBA::exists('contact', ['id' => 0])) {
-                       DBA::insert('contact', ['nurl' => '']);
+                       DBA::insert('contact', ['nurl' => ''], Database::INSERT_IGNORE);
                        $lastid = DBA::lastInsertId();
                        if ($lastid != 0) {
                                DBA::update('contact', ['id' => 0], ['id' => $lastid]);
@@ -834,7 +845,7 @@ class DBStructure
                }
 
                if (self::existsTable('tag') && !DBA::exists('tag', ['id' => 0])) {
-                       DBA::insert('tag', ['name' => '']);
+                       DBA::insert('tag', ['name' => ''], Database::INSERT_IGNORE);
                        $lastid = DBA::lastInsertId();
                        if ($lastid != 0) {
                                DBA::update('tag', ['id' => 0], ['id' => $lastid]);
@@ -850,7 +861,7 @@ class DBStructure
 
                if (self::existsTable('permissionset')) {
                        if (!DBA::exists('permissionset', ['id' => 0])) {
-                               DBA::insert('permissionset', ['allow_cid' => '', 'allow_gid' => '', 'deny_cid' => '', 'deny_gid' => '']);
+                               DBA::insert('permissionset', ['allow_cid' => '', 'allow_gid' => '', 'deny_cid' => '', 'deny_gid' => ''], Database::INSERT_IGNORE);
                                $lastid = DBA::lastInsertId();
                                if ($lastid != 0) {
                                        DBA::update('permissionset', ['id' => 0], ['id' => $lastid]);
@@ -878,7 +889,7 @@ class DBStructure
                                        }
                                        $fields = ['id' => $set['psid'], 'uid' => $set['uid'], 'allow_cid' => $permission,
                                                'allow_gid' => '', 'deny_cid' => '', 'deny_gid' => ''];
-                                       DBA::insert('permissionset', $fields);
+                                       DBA::insert('permissionset', $fields, Database::INSERT_IGNORE);
                                }
                                DBA::close($sets);
                        }