From 71c09244f7b554ad68bd12dbf0d09da19fadb7ae Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Thu, 5 Jul 2018 11:58:18 -0400 Subject: [PATCH 1/4] Make sure default DownloadBehavior is stored when initially uploading a document --- code/model/DMSDocument.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/code/model/DMSDocument.php b/code/model/DMSDocument.php index 3a0258f..2044d4b 100644 --- a/code/model/DMSDocument.php +++ b/code/model/DMSDocument.php @@ -235,7 +235,7 @@ class DMSDocument extends DataObject implements DMSDocumentInterface $this->ViewCount = $count; DB::query("UPDATE \"DMSDocument\" SET \"ViewCount\"='$count' WHERE \"ID\"={$this->ID}"); - + $this->extend('trackView'); } @@ -1003,6 +1003,18 @@ class DMSDocument extends DataObject implements DMSDocumentInterface } $this->LastEditedByID = $currentUserID; } + + // make sure default DownloadBehavior is respected when writing since + $defaultDownloadBehaviour = Config::inst()->get('DMSDocument', 'default_download_behaviour'); + if ($this->DownloadBehavior == null && !empty($defaultDownloadBehaviour)) { + $possibleBehaviors = $this->dbObject('DownloadBehavior') + ->enumValues(); + + $behavior =$possibleBehaviors[$defaultDownloadBehaviour]; + if ($behavior) { + $this->DownloadBehavior = $behavior; + } + } } /** From 5561e4a7af2921f63110edcfb93fba12cceec97a Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Thu, 5 Jul 2018 12:04:33 -0400 Subject: [PATCH 2/4] minor formatting fix --- code/model/DMSDocument.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/model/DMSDocument.php b/code/model/DMSDocument.php index 2044d4b..470cdb3 100644 --- a/code/model/DMSDocument.php +++ b/code/model/DMSDocument.php @@ -1010,7 +1010,7 @@ class DMSDocument extends DataObject implements DMSDocumentInterface $possibleBehaviors = $this->dbObject('DownloadBehavior') ->enumValues(); - $behavior =$possibleBehaviors[$defaultDownloadBehaviour]; + $behavior = $possibleBehaviors[$defaultDownloadBehaviour]; if ($behavior) { $this->DownloadBehavior = $behavior; } From 52772ae8791c2b667a3888ac3cea28ee668900db Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Thu, 5 Jul 2018 12:06:14 -0400 Subject: [PATCH 3/4] documentation fix for DownloadBehavior fix --- code/model/DMSDocument.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/code/model/DMSDocument.php b/code/model/DMSDocument.php index 470cdb3..6954160 100644 --- a/code/model/DMSDocument.php +++ b/code/model/DMSDocument.php @@ -1004,7 +1004,8 @@ class DMSDocument extends DataObject implements DMSDocumentInterface $this->LastEditedByID = $currentUserID; } - // make sure default DownloadBehavior is respected when writing since + // make sure default DownloadBehavior is respected when initially writing document + // in case the default in the enum is different than what's set in an outside config $defaultDownloadBehaviour = Config::inst()->get('DMSDocument', 'default_download_behaviour'); if ($this->DownloadBehavior == null && !empty($defaultDownloadBehaviour)) { $possibleBehaviors = $this->dbObject('DownloadBehavior') From cf278fd8e2e00e14628dd52ed61af0948aabfeb3 Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Fri, 6 Jul 2018 08:59:10 -0400 Subject: [PATCH 4/4] Save default DownloadBehaviour on a DMSDocument when initially uploading a new one - array key check for behavior before using --- code/model/DMSDocument.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/code/model/DMSDocument.php b/code/model/DMSDocument.php index 6954160..7176eab 100644 --- a/code/model/DMSDocument.php +++ b/code/model/DMSDocument.php @@ -1011,9 +1011,11 @@ class DMSDocument extends DataObject implements DMSDocumentInterface $possibleBehaviors = $this->dbObject('DownloadBehavior') ->enumValues(); - $behavior = $possibleBehaviors[$defaultDownloadBehaviour]; - if ($behavior) { - $this->DownloadBehavior = $behavior; + if (array_key_exists($defaultDownloadBehaviour, $possibleBehaviors)) { + $behavior = $possibleBehaviors[$defaultDownloadBehaviour]; + if ($behavior) { + $this->DownloadBehavior = $behavior; + } } } }