From 95cc7f627ffb6322a6d3592f1c57cf3815f0dd3a Mon Sep 17 00:00:00 2001 From: William MARTIN Date: Tue, 31 May 2011 13:58:12 +0200 Subject: [PATCH] Process a md5 on the uploaded file, and display it in the per file view. - The uploader can check that the uploaded file is correct - The downloader can check his download too --- src/IDF/Migrations/17DownloadMD5.php | 55 +++++++++++++++++++++++ src/IDF/Upload.php | 7 +++ src/IDF/templates/idf/downloads/view.html | 2 + 3 files changed, 64 insertions(+) create mode 100644 src/IDF/Migrations/17DownloadMD5.php diff --git a/src/IDF/Migrations/17DownloadMD5.php b/src/IDF/Migrations/17DownloadMD5.php new file mode 100644 index 0000000..3e275b5 --- /dev/null +++ b/src/IDF/Migrations/17DownloadMD5.php @@ -0,0 +1,55 @@ +getSqlTable(); + $sql = array(); + $sql['PostgreSQL'] = 'ALTER TABLE '.$table.' ADD COLUMN "md5" TEXT DEFAULT \'\''; + $sql['MySQL'] = 'ALTER TABLE '.$table.' ADD COLUMN `md5` LONGTEXT 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]); +} + +function IDF_Migrations_12DownloadDesc_down($params=null) +{ + $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 @@
{if $deprecated}

{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} +
+{trans 'md5:'} {$file.md5}
{if $file.changelog}

{trans 'Changes'}