diff --git a/src/IDF/Migrations/17DownloadMD5.php b/src/IDF/Migrations/17DownloadMD5.php index 34e030f..3b86bc2 100644 --- a/src/IDF/Migrations/17DownloadMD5.php +++ b/src/IDF/Migrations/17DownloadMD5.php @@ -27,20 +27,29 @@ function IDF_Migrations_17DownloadMD5_up($params=null) { + // Add the row $table = Pluf::factory('IDF_Upload')->getSqlTable(); $sql = array(); - $sql['PostgreSQL'] = 'ALTER TABLE '.$table.' ADD COLUMN "md5" TEXT DEFAULT \'\''; - $sql['MySQL'] = 'ALTER TABLE '.$table.' ADD COLUMN `md5` LONGTEXT DEFAULT \'\''; + $sql['PostgreSQL'] = 'ALTER TABLE '.$table.' ADD COLUMN "md5" VARCHAR(32) DEFAULT \'\''; + $sql['MySQL'] = 'ALTER TABLE '.$table.' ADD COLUMN `md5` VARCHAR(32) DEFAULT \'\''; $db = Pluf::db(); $engine = Pluf::f('db_engine'); if (!isset($sql[$engine])) { throw new Exception('SQLite complex migration not supported.'); } $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) { + // Remove the row $table = Pluf::factory('IDF_Upload')->getSqlTable(); $sql = array(); $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.'); } $db->execute($sql[$engine]); - }