]> git.mxchange.org Git - friendica.git/blobdiff - src/Database/DBStructure.php
Merge pull request #10318 from annando/issue-9926
[friendica.git] / src / Database / DBStructure.php
index b9e53be045cacf6031303005259f206bd8528b8f..914846590be264ed833d1b683013d997fc813031 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2020, Friendica
+ * @copyright Copyright (C) 2010-2021, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -80,7 +80,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',
-                       'sign', 'spam', 'term', 'user-item'];
+                       'deliverq', 'dsprphotoq', 'ffinder', 'sign', 'spam', 'term', 'user-item', 'thread', 'item'];
 
                $tables = DBA::selectToArray(['INFORMATION_SCHEMA' => 'TABLES'], ['TABLE_NAME'],
                        ['TABLE_SCHEMA' => DBA::databaseName(), 'TABLE_TYPE' => 'BASE TABLE']);
@@ -192,6 +192,9 @@ class DBStructure
        public static function definition($basePath, $with_addons_structure = true)
        {
                if (!self::$definition) {
+                       if (empty($basePath)) {
+                               $basePath = DI::app()->getBasePath();
+                       }
 
                        $filename = $basePath . '/static/dbstructure.config.php';
 
@@ -238,6 +241,12 @@ class DBStructure
                // Assign all field that are present in the table
                foreach ($fieldnames as $field) {
                        if (isset($data[$field])) {
+                               // Limit the length of varchar, varbinary, char and binrary fields
+                               if (is_string($data[$field]) && preg_match("/char\((\d*)\)/", $definition[$table]['fields'][$field]['type'], $result)) {
+                                       $data[$field] = mb_substr($data[$field], 0, $result[1]);
+                               } elseif (is_string($data[$field]) && preg_match("/binary\((\d*)\)/", $definition[$table]['fields'][$field]['type'], $result)) {
+                                       $data[$field] = substr($data[$field], 0, $result[1]);
+                               }
                                $fields[$field] = $data[$field];
                        }
                }
@@ -1232,7 +1241,7 @@ class DBStructure
                        } elseif ($verbose) {
                                echo "Zero permissionset already added\n";
                        }
-                       if (!self::existsForeignKeyForField('item', 'psid')) {
+                       if (self::existsTable('item') && !self::existsForeignKeyForField('item', 'psid')) {
                                $sets = DBA::p("SELECT `psid`, `item`.`uid`, `item`.`private` FROM `item`
                                        LEFT JOIN `permissionset` ON `permissionset`.`id` = `item`.`psid`
                                        WHERE `permissionset`.`id` IS NULL AND NOT `psid` IS NULL");