Set the SQL type to VARCHAR(32)
Process the md5 of each file during the migrationUpdate all IDF_Upload object to process their md5 during the migration
This commit is contained in:
parent
4d5418a601
commit
06c57f7da6
@ -27,20 +27,29 @@
|
|||||||
|
|
||||||
function IDF_Migrations_17DownloadMD5_up($params=null)
|
function IDF_Migrations_17DownloadMD5_up($params=null)
|
||||||
{
|
{
|
||||||
|
// Add the row
|
||||||
$table = Pluf::factory('IDF_Upload')->getSqlTable();
|
$table = Pluf::factory('IDF_Upload')->getSqlTable();
|
||||||
$sql = array();
|
$sql = array();
|
||||||
$sql['PostgreSQL'] = 'ALTER TABLE '.$table.' ADD COLUMN "md5" TEXT DEFAULT \'\'';
|
$sql['PostgreSQL'] = 'ALTER TABLE '.$table.' ADD COLUMN "md5" VARCHAR(32) DEFAULT \'\'';
|
||||||
$sql['MySQL'] = 'ALTER TABLE '.$table.' ADD COLUMN `md5` LONGTEXT DEFAULT \'\'';
|
$sql['MySQL'] = 'ALTER TABLE '.$table.' ADD COLUMN `md5` VARCHAR(32) DEFAULT \'\'';
|
||||||
$db = Pluf::db();
|
$db = Pluf::db();
|
||||||
$engine = Pluf::f('db_engine');
|
$engine = Pluf::f('db_engine');
|
||||||
if (!isset($sql[$engine])) {
|
if (!isset($sql[$engine])) {
|
||||||
throw new Exception('SQLite complex migration not supported.');
|
throw new Exception('SQLite complex migration not supported.');
|
||||||
}
|
}
|
||||||
$db->execute($sql[$engine]);
|
$db->execute($sql[$engine]);
|
||||||
|
|
||||||
|
// Process md5 of already uploaded file
|
||||||
|
$files = Pluf::factory('IDF_Upload')->getList();
|
||||||
|
foreach ($files as $f) {
|
||||||
|
$f->md5 = md5_file (Pluf::f('upload_path') . '/' . $f->get_project()->shortname . '/files/' . $f->file);
|
||||||
|
$f->update();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function IDF_Migrations_17DownloadMD5_down($params=null)
|
function IDF_Migrations_17DownloadMD5_down($params=null)
|
||||||
{
|
{
|
||||||
|
// Remove the row
|
||||||
$table = Pluf::factory('IDF_Upload')->getSqlTable();
|
$table = Pluf::factory('IDF_Upload')->getSqlTable();
|
||||||
$sql = array();
|
$sql = array();
|
||||||
$sql['PostgreSQL'] = 'ALTER TABLE '.$table.' DROP COLUMN "md5"';
|
$sql['PostgreSQL'] = 'ALTER TABLE '.$table.' DROP COLUMN "md5"';
|
||||||
@ -51,5 +60,4 @@ function IDF_Migrations_17DownloadMD5_down($params=null)
|
|||||||
throw new Exception('SQLite complex migration not supported.');
|
throw new Exception('SQLite complex migration not supported.');
|
||||||
}
|
}
|
||||||
$db->execute($sql[$engine]);
|
$db->execute($sql[$engine]);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user