From 906a6b186bb34e52f092750913c265a16b8b0f8e Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Fri, 18 Apr 2014 16:26:26 -0500
Subject: [PATCH] Write new signature on file data loading

---
 setup/cli/modules/file.php | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/setup/cli/modules/file.php b/setup/cli/modules/file.php
index 721ba1d83..ee8316995 100644
--- a/setup/cli/modules/file.php
+++ b/setup/cli/modules/file.php
@@ -104,18 +104,22 @@ class FileManager extends Module {
             }
             catch (Exception $e) {}
 
-            if ($options['backend'])
-                $bk = FileStorageBackend::lookup($options['backend'], $f);
+            if ($options['to'])
+                $bk = FileStorageBackend::lookup($options['to'], $f);
             else
                 // Use the system default
                 $bk = AttachmentFile::getBackendForFile($f);
 
             $type = false;
+            $signature = '';
             $finfo = new finfo(FILEINFO_MIME_TYPE);
             if ($options['file'] && $options['file'] != '-') {
+                if (!file_exists($options['file']))
+                    $this->fail($options['file'].': Cannot open file');
                 if (!$bk->upload($options['file']))
                     $this->fail('Unable to upload file contents to backend');
                 $type = $finfo->file($options['file']);
+                list(, $signature) = AttachmentFile::_getKeyAndHash($options['file'], true);
             }
             else {
                 $stream = fopen('php://stdin', 'rb');
@@ -133,6 +137,7 @@ class FileManager extends Module {
             $sql = 'UPDATE '.FILE_TABLE.' SET bk='.db_input($bk->getBkChar())
                 .', created=CURRENT_TIMESTAMP'
                 .', type='.db_input($type)
+                .', signature='.db_input($signature)
                 .' WHERE id='.db_input($f->getId());
 
             if (!db_query($sql) || db_affected_rows()!=1)
-- 
GitLab