From 42fa70c3036a42400be626a38b2eec94b19de1e8 Mon Sep 17 00:00:00 2001 From: Jonathan Green Date: Wed, 11 Apr 2018 11:37:29 -0300 Subject: [PATCH 1/2] Prevent Warning Error: Call to a member function getTimestamp() on boolean in islandora_view_datastream_cache_check() --- includes/datastream.inc | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/includes/datastream.inc b/includes/datastream.inc index e7547780..ee0f8cc7 100644 --- a/includes/datastream.inc +++ b/includes/datastream.inc @@ -161,12 +161,14 @@ function islandora_view_datastream_cache_check(AbstractDatastream $datastream) { if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) { $modified_since = DateTime::createFromFormat('D, d M Y H:i:s e', $_SERVER['HTTP_IF_MODIFIED_SINCE']); - if ($datastream->createdDate->getTimestamp() - $modified_since->getTimestamp() > 0) { - // Changed! - return $return; - } - else { - $return = 304; + if ($modified_since !== FALSE) { + if ($datastream->createdDate->getTimestamp() - $modified_since->getTimestamp() > 0) { + // Changed! + return $return; + } + else { + $return = 304; + } } } if ($return === 200 && isset($_SERVER['HTTP_IF_UNMODIFIED_SINCE'])) { From 7d9cdc220b85f91d80a02db626046a488c1acde4 Mon Sep 17 00:00:00 2001 From: Jonathan Green Date: Fri, 13 Apr 2018 15:19:51 -0300 Subject: [PATCH 2/2] Code review feedback Return the current value of $return if we have a bad value. --- includes/datastream.inc | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/includes/datastream.inc b/includes/datastream.inc index ee0f8cc7..8584e53e 100644 --- a/includes/datastream.inc +++ b/includes/datastream.inc @@ -161,7 +161,10 @@ function islandora_view_datastream_cache_check(AbstractDatastream $datastream) { if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) { $modified_since = DateTime::createFromFormat('D, d M Y H:i:s e', $_SERVER['HTTP_IF_MODIFIED_SINCE']); - if ($modified_since !== FALSE) { + if ($modified_since === FALSE) { + return $return; + } + else { if ($datastream->createdDate->getTimestamp() - $modified_since->getTimestamp() > 0) { // Changed! return $return; @@ -173,12 +176,17 @@ function islandora_view_datastream_cache_check(AbstractDatastream $datastream) { } if ($return === 200 && isset($_SERVER['HTTP_IF_UNMODIFIED_SINCE'])) { $unmodified_since = DateTime::createFromFormat('D, d M Y H:i:s e', $_SERVER['HTTP_IF_UNMODIFIED_SINCE']); - if ($datastream->createdDate->getTimestamp() !== $unmodified_since->getTimestamp()) { - // Changed! - $return = 412; + if ($unmodified_since === FALSE) { + return $return; } else { - return $return; + if ($datastream->createdDate->getTimestamp() !== $unmodified_since->getTimestamp()) { + // Changed! + $return = 412; + } + else { + return $return; + } } }