From 7618eb9d08ee9f7be1097468ed938b4713260e90 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Wed, 13 Feb 2019 12:58:33 -0800 Subject: [PATCH] (REF) Clearer docblocks and file names --- CRM/Core/BAO/File.php | 14 ++++++++------ CRM/Core/Page/File.php | 12 ++++++------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/CRM/Core/BAO/File.php b/CRM/Core/BAO/File.php index e33984412f..5e1a32def0 100644 --- a/CRM/Core/BAO/File.php +++ b/CRM/Core/BAO/File.php @@ -768,7 +768,8 @@ AND CEF.entity_id = %2"; } /** - * Generates a MD5 Hash to be appended to file URLS to be checked when trying to download the file. + * Generates an access-token for downloading a specific file. + * * @param int $entityId entity id the file is attached to * @param int $fileId file ID * @return string @@ -794,17 +795,18 @@ AND CEF.entity_id = %2"; } /** - * Validate a file Hash + * Validate a file access token. + * * @param string $hash - * @param int $eid Entity Id the file is attached to - * @param int $fid File Id + * @param int $entityId Entity Id the file is attached to + * @param int $fileId File Id * @return bool */ - public static function validateFileHash($hash, $eid, $fid) { + public static function validateFileHash($hash, $entityId, $fileId) { $input = CRM_Utils_System::explode('_', $hash, 3); $inputTs = CRM_Utils_Array::value(1, $input); $inputLF = CRM_Utils_Array::value(2, $input); - $testHash = CRM_Core_BAO_File::generateFileHash($eid, $fid, $inputTs, $inputLF); + $testHash = CRM_Core_BAO_File::generateFileHash($entityId, $fileId, $inputTs, $inputLF); if (hash_equals($testHash, $hash)) { $now = time(); if ($inputTs + ($inputLF * 60 * 60) >= $now) { diff --git a/CRM/Core/Page/File.php b/CRM/Core/Page/File.php index 87a2e4433e..76d65e0a2f 100644 --- a/CRM/Core/Page/File.php +++ b/CRM/Core/Page/File.php @@ -42,15 +42,15 @@ class CRM_Core_Page_File extends CRM_Core_Page { $download = CRM_Utils_Request::retrieve('download', 'Integer', $this, FALSE, 1); $disposition = $download == 0 ? 'inline' : 'download'; - $eid = CRM_Utils_Request::retrieve('eid', 'Positive', $this, TRUE); // Entity ID (e.g. Contact ID) - $fid = CRM_Utils_Request::retrieve('fid', 'Positive', $this, FALSE); // Field ID - $id = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE); // File ID + $entityId = CRM_Utils_Request::retrieve('eid', 'Positive', $this, TRUE); // Entity ID (e.g. Contact ID) + $fieldId = CRM_Utils_Request::retrieve('fid', 'Positive', $this, FALSE); // Field ID + $fileId = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE); // File ID $hash = CRM_Utils_Request::retrieve('fcs', 'Alphanumeric', $this); - if (!CRM_Core_BAO_File::validateFileHash($hash, $eid, $id)) { + if (!CRM_Core_BAO_File::validateFileHash($hash, $entityId, $fileId)) { CRM_Core_Error::statusBounce('URL for file is not valid'); } - list($path, $mimeType) = CRM_Core_BAO_File::path($id, $eid); + list($path, $mimeType) = CRM_Core_BAO_File::path($fileId, $entityId); $mimeType = CRM_Utils_Request::retrieveValue('mime-type', 'String', $mimeType, FALSE); if (!$path) { @@ -64,7 +64,7 @@ class CRM_Core_Page_File extends CRM_Core_Page { if ($action & CRM_Core_Action::DELETE) { if (CRM_Utils_Request::retrieve('confirmed', 'Boolean')) { - CRM_Core_BAO_File::deleteFileReferences($id, $eid, $fid); + CRM_Core_BAO_File::deleteFileReferences($fileId, $entityId, $fieldId); CRM_Core_Session::setStatus(ts('The attached file has been deleted.'), ts('Complete'), 'success'); $session = CRM_Core_Session::singleton(); -- 2.25.1