aboutsummaryrefslogtreecommitdiff
path: root/classes/File.php
diff options
context:
space:
mode:
authorMikael Nordfeldth <mmn@hethane.se>2015-02-19 18:59:28 +0100
committerMikael Nordfeldth <mmn@hethane.se>2015-02-19 19:05:24 +0100
commit45dc76de268f708bc7bf4e8bd1c6b1f2fd5eb033 (patch)
treeebbef112158f4ee730435af6cb1a9b39d2d80fd7 /classes/File.php
parent0dfe39ac8757c81eb9bf2c6dae7ca409038aa843 (diff)
downloadgnu-social-45dc76de268f708bc7bf4e8bd1c6b1f2fd5eb033.tar
gnu-social-45dc76de268f708bc7bf4e8bd1c6b1f2fd5eb033.zip
File and File_redirection adhoc storage methods updated for urlhash
Diffstat (limited to 'classes/File.php')
-rw-r--r--classes/File.php36
1 files changed, 36 insertions, 0 deletions
diff --git a/classes/File.php b/classes/File.php
index 7d09b74c43..89dcf61cc5 100644
--- a/classes/File.php
+++ b/classes/File.php
@@ -606,4 +606,40 @@ class File extends Managed_DataObject
}
return hash(self::URLHASH_ALG, $url);
}
+
+ static public function beforeSchemaUpdate()
+ {
+ $table = strtolower(get_called_class());
+ $schema = Schema::get();
+ $schemadef = $schema->getTableDef($table);
+
+ // 2015-02-19 We have to upgrade our table definitions to have the urlhash field populated
+ if (isset($schemadef['fields']['urlhash']) && in_array('file_urlhash_key', $schemadef['unique keys'])) {
+ // We already have the urlhash field, so no need to migrate it.
+ return;
+ }
+ 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 (
+ 'type' => 'varchar',
+ 'length' => 64,
+ 'description' => 'sha256 of destination URL after following redirections',
+ );
+ $schema->ensureTable($table, $schemadef);
+ echo "DONE.\n";
+
+ $classname = ucfirst($table);
+ $tablefix = new $classname;
+ // urlhash is hash('sha256', $url) in the File table
+ echo "Updating urlhash fields in $table table...\n";
+ // Maybe very MySQL specific :(
+ $tablefix->query(sprintf('UPDATE %1$s SET %2$s=%3$s;',
+ $schema->quoteIdentifier($table),
+ 'urlhash',
+ // The line below is "result of sha256 on column `url`"
+ 'SHA2(url, 256)'));
+ echo "DONE.\n";
+ echo "Resuming core schema upgrade...";
+ }
}