From 6135660d0f1b42c0cbc1590214421bb64c017b4a Mon Sep 17 00:00:00 2001 From: Martin Konecny Date: Sun, 6 May 2012 20:05:14 -0400 Subject: [PATCH] CC-3771: year column in cc_files sometimes has values greater than 2^31-1, which causes postgresql to fail when trying to convert this to a year. --- airtime_mvc/application/models/StoredFile.php | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/airtime_mvc/application/models/StoredFile.php b/airtime_mvc/application/models/StoredFile.php index a6044c868..bb3bfed0b 100644 --- a/airtime_mvc/application/models/StoredFile.php +++ b/airtime_mvc/application/models/StoredFile.php @@ -91,6 +91,27 @@ class Application_Model_StoredFile { } else { $dbMd = array(); + + if (isset($p_md["year"])){ + // We need to make sure to clean this value before inserting into database. + // If value is outside of range [-2^31, 2^31-1] then postgresl will throw error + // when trying to retrieve this value. We could make sure number is within these bounds, + // but simplest is to do substring to 4 digits (both values are garbage, but at least our + // new garbage value won't cause errors). If the value is 2012-01-01, then substring to + // 4 digits is an OK result. + // CC-3771 + + $year = $p_md["year"]; + + if (strlen($year) > 4){ + $year = substr($year, 0, 4); + } + if (!is_numeric($year)){ + $year = 0; + } + $p_md["year"] = $year; + } + foreach ($p_md as $mdConst => $mdValue) { $dbMd[constant($mdConst)] = $mdValue; }