]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - scripts/upgrade.php
File_redirection also got urlhash column
[quix0rs-gnu-social.git] / scripts / upgrade.php
index eeddf5559fb25fb362e297897dceafefa3d519b7..07207357e5a1e117076428474bec1de2f1096fc8 100644 (file)
@@ -88,12 +88,13 @@ function preAlterFixes($schemaUpdater, $table)
 {
     switch ($table) {
     case 'file':
+    case 'file_redirection':
         $schemadef = $schemaUpdater->schema->getTableDef($table);
         if (isset($schemadef['fields']['urlhash'])) {
             // We already have the urlhash field, so no need to migrate it.
             break;
         }
-        printfnq("\nFound old $table table, upgrading it to contain 'urlhash' field...\n");
+        echo "\nFound old $table table, upgrading it to contain 'urlhash' field...\n";
         // We have to create a urlhash that is _not_ the primary key,
         // transfer data and THEN run checkSchema
         $schemadef['fields']['urlhash'] = array (
@@ -102,18 +103,20 @@ function preAlterFixes($schemaUpdater, $table)
                                               'description' => 'sha256 of destination URL after following redirections',
                                             );
         $schemaUpdater->schema->ensureTable($table, $schemadef);
-        printfnq("DONE.\n");
+        echo "DONE.\n";
 
-        $filefix = new File();
+        $classname = ucfirst($table);
+        $tablefix = new $classname;
         // urlhash is hash('sha256', $url) in the File table
-        printfnq("Updating urlhash fields in $table table...\n");
-        $filefix->query(sprintf('UPDATE %1$s SET %2$s=%3$s;',
+        echo "Updating urlhash fields in $table table...\n";
+        // Maybe very MySQL specific :(
+        $tablefix->query(sprintf('UPDATE %1$s SET %2$s=%3$s;',
                             $schemaUpdater->schema->quoteIdentifier($table),
                             'urlhash',
                             // The line below is "result of sha256 on column `url`"
                             'SHA2(url, 256)'));
-        printfnq("DONE.\n");
-        printfnq("Resuming core schema upgrade...");
+        echo "DONE.\n";
+        echo "Resuming core schema upgrade...";
         break;
     }
 }