]> git.mxchange.org Git - friendica.git/blobdiff - src/Database/DBStructure.php
NL translation update THX casperrutten33
[friendica.git] / src / Database / DBStructure.php
index 9f225cbb93c3ec5bcef55d4ffebcc460f3cdde8f..bf76eccacb50edd3b6f19dcea3360477d3fc4e3c 100644 (file)
@@ -291,13 +291,11 @@ class DBStructure
         */
        public static function update($basePath, $verbose, $action, $install = false, array $tables = null, array $definition = null)
        {
-               if (!$install) {
+               if ($action && !$install) {
                        if (self::isUpdating()) {
                                return DI::l10n()->t('Another database update is currently running.');
                        }
-               }
 
-               if ($action && !$install) {
                        DI::config()->set('system', 'maintenance', 1);
                        DI::config()->set('system', 'maintenance_reason', DI::l10n()->t('%s: Database update', DateTimeFormat::utcNow() . ' ' . date('e')));
                }
@@ -485,8 +483,8 @@ class DBStructure
                                        }
                                }
 
-                               foreach ($existing_foreign_keys as $constraint => $param) {
-                                       $sql2 = self::dropForeignKey($constraint);
+                               foreach ($existing_foreign_keys as $param) {
+                                       $sql2 = self::dropForeignKey($param['CONSTRAINT_NAME']);
 
                                        if ($sql3 == "") {
                                                $sql3 = "ALTER" . $ignore . " TABLE `" . $temp_name . "` " . $sql2;
@@ -695,8 +693,8 @@ class DBStructure
 
                if (DBA::isResult($foreign_keys)) {
                        foreach ($foreign_keys as $foreign_key) {
-                               $constraint = $foreign_key['CONSTRAINT_NAME'];
-                               unset($foreign_key['CONSTRAINT_NAME']); 
+                               $parameters = ['foreign' => [$foreign_key['REFERENCED_TABLE_NAME'] => $foreign_key['REFERENCED_COLUMN_NAME']]];
+                               $constraint = self::getConstraintName($table, $foreign_key['COLUMN_NAME'], $parameters);
                                $foreigndata[$constraint] = $foreign_key;
                        }
                }
@@ -734,8 +732,8 @@ class DBStructure
                                        $fielddata[$field['COLUMN_NAME']]['not null'] = true;
                                }
 
-                               if (isset($field['COLUMN_DEFAULT'])) {
-                                       $fielddata[$field['COLUMN_NAME']]['default'] = $field['COLUMN_DEFAULT'];
+                               if (isset($field['COLUMN_DEFAULT']) && ($field['COLUMN_DEFAULT'] != 'NULL')) {
+                                       $fielddata[$field['COLUMN_NAME']]['default'] = trim($field['COLUMN_DEFAULT'], "'");
                                }
 
                                if (!empty($field['EXTRA'])) {
@@ -785,10 +783,7 @@ class DBStructure
                $foreign_table = array_keys($parameters['foreign'])[0];
                $foreign_field = array_values($parameters['foreign'])[0];
 
-               $constraint = self::getConstraintName($tablename, $fieldname, $parameters);
-
-               $sql = "CONSTRAINT `" . $constraint . "` FOREIGN KEY (`" . $fieldname . "`)" .
-                       " REFERENCES `" . $foreign_table . "` (`" . $foreign_field . "`)";
+               $sql = "FOREIGN KEY (`" . $fieldname . "`) REFERENCES `" . $foreign_table . "` (`" . $foreign_field . "`)";
 
                if (!empty($parameters['foreign']['on update'])) {
                        $sql .= " ON UPDATE " . strtoupper($parameters['foreign']['on update']);
@@ -1009,6 +1004,12 @@ class DBStructure
         */
        public static function checkInitialValues()
        {
+               if (self::existsTable('verb') && !DBA::exists('verb', ['id' => 1])) {
+                       foreach (Item::ACTIVITIES as $index => $activity) {
+                               DBA::insert('verb', ['id' => $index + 1, 'name' => $activity], true);
+                       }
+               }
+
                if (self::existsTable('contact') && !DBA::exists('contact', ['id' => 0])) {
                        DBA::insert('contact', ['nurl' => '']);
                        $lastid = DBA::lastInsertId();
@@ -1074,21 +1075,18 @@ class DBStructure
         */
        private static function isUpdating()
        {
-               $processes = DBA::select(['information_schema' => 'processlist'],
-                       ['command', 'info'], ['db' => DBA::databaseName()]);
-
                $isUpdate = false;
 
+               $processes = DBA::select(['information_schema' => 'processlist'], ['info'],
+                       ['db' => DBA::databaseName(), 'command' => ['Query', 'Execute']]);
+
                while ($process = DBA::fetch($processes)) {
-                       if (empty($process['info'])) {
-                               continue;
-                       }
                        $parts = explode(' ', $process['info']);
-                       $command = strtolower(array_shift($parts));
-                       if ($command == 'alter') {
+                       if (in_array(strtolower(array_shift($parts)), ['alter', 'create', 'drop', 'rename'])) {
                                $isUpdate = true;
                        }
                }
+
                DBA::close($processes);
 
                return $isUpdate;