diff --git a/src/IDF/Migrations/18DownloadMD5.php b/src/IDF/Migrations/18DownloadMD5.php new file mode 100644 index 0000000..159e909 --- /dev/null +++ b/src/IDF/Migrations/18DownloadMD5.php @@ -0,0 +1,63 @@ +getSqlTable(); + $sql = array(); + $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_18DownloadMD5_down($params=null) +{ + // Remove the row + $table = Pluf::factory('IDF_Upload')->getSqlTable(); + $sql = array(); + $sql['PostgreSQL'] = 'ALTER TABLE '.$table.' DROP COLUMN "md5"'; + $sql['MySQL'] = 'ALTER TABLE '.$table.' DROP COLUMN `md5`'; + $db = Pluf::db(); + $engine = Pluf::f('db_engine'); + if (!isset($sql[$engine])) { + throw new Exception('SQLite complex migration not supported.'); + } + $db->execute($sql[$engine]); +} diff --git a/src/IDF/Upload.php b/src/IDF/Upload.php index d4e6094..b4105a2 100644 --- a/src/IDF/Upload.php +++ b/src/IDF/Upload.php @@ -77,6 +77,12 @@ class IDF_Upload extends Pluf_Model 'default' => 0, 'verbose' => __('file size in bytes'), ), + 'md5' => + array( + 'type' => 'Pluf_DB_Field_Text', + 'blank' => true, + 'verbose' => __('MD5'), + ), 'submitter' => array( 'type' => 'Pluf_DB_Field_Foreignkey', @@ -144,6 +150,7 @@ class IDF_Upload extends Pluf_Model if ($this->id == '') { $this->creation_dtime = gmdate('Y-m-d H:i:s'); $this->modif_dtime = gmdate('Y-m-d H:i:s'); + $this->md5 = md5_file (Pluf::f('upload_path') . '/' . $this->get_project()->shortname . '/files/' . $this->file); } } diff --git a/src/IDF/templates/idf/downloads/view.html b/src/IDF/templates/idf/downloads/view.html index 792c0a1..478a0b9 100644 --- a/src/IDF/templates/idf/downloads/view.html +++ b/src/IDF/templates/idf/downloads/view.html @@ -5,6 +5,8 @@
{blocktrans}Attention! This file is marked as deprecated, download it only if you are sure you need this specific version.{/blocktrans}
{/if} {$file} - {$file.filesize|size} +