File and File_redirection adhoc storage methods updated for urlhash

This commit is contained in:
Mikael Nordfeldth
2015-02-19 18:59:28 +01:00
parent 0dfe39ac87
commit 45dc76de26
7 changed files with 89 additions and 43 deletions

View File

@@ -76,7 +76,6 @@ function updateSchemaCore()
$schema = Schema::get();
$schemaUpdater = new SchemaUpdater($schema);
foreach (tableDefs() as $table => $def) {
preAlterFixes($schemaUpdater, $table);
$schemaUpdater->register($table, $def);
}
$schemaUpdater->checkSchema();
@@ -84,43 +83,6 @@ function updateSchemaCore()
printfnq("DONE.\n");
}
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;
}
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',
);
$schemaUpdater->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;',
$schemaUpdater->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...";
break;
}
}
function updateSchemaPlugins()
{
printfnq("Upgrading plugin schema...");