From cb0593370a34550b51c8a3e93147f7b713669d07 Mon Sep 17 00:00:00 2001 From: Duncan Sommerville Date: Sat, 4 Jul 2015 00:38:53 -0400 Subject: [PATCH 1/2] Quick fix --- airtime_mvc/application/Bootstrap.php | 8 ++--- airtime_mvc/application/models/Preference.php | 36 +++++++++++++++---- 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/airtime_mvc/application/Bootstrap.php b/airtime_mvc/application/Bootstrap.php index 0c1911d55..2519b303c 100644 --- a/airtime_mvc/application/Bootstrap.php +++ b/airtime_mvc/application/Bootstrap.php @@ -144,10 +144,10 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap $baseUrl = Application_Common_OsPath::getBaseDir(); - $view->headLink(array('rel' => 'icon', - 'href' => $baseUrl . 'favicon.ico?' . $CC_CONFIG['airtime_version'], - 'type' => 'image/x-icon'), 'PREPEND') - ->appendStylesheet($baseUrl . 'css/bootstrap.css?' . $CC_CONFIG['airtime_version']) + /* + * array('rel' => 'icon', 'href' => $baseUrl . 'favicon.ico?' . $CC_CONFIG['airtime_version'], 'type' => 'image/x-icon'), 'PREPEND' + */ + $view->headLink()->appendStylesheet($baseUrl . 'css/bootstrap.css?' . $CC_CONFIG['airtime_version']) ->appendStylesheet($baseUrl . 'css/redmond/jquery-ui-1.8.8.custom.css?' . $CC_CONFIG['airtime_version']) ->appendStylesheet($baseUrl . 'css/pro_dropdown_3.css?' . $CC_CONFIG['airtime_version']) ->appendStylesheet($baseUrl . 'css/qtip/jquery.qtip.min.css?' . $CC_CONFIG['airtime_version']) diff --git a/airtime_mvc/application/models/Preference.php b/airtime_mvc/application/models/Preference.php index e8d116246..ec8b49a3c 100644 --- a/airtime_mvc/application/models/Preference.php +++ b/airtime_mvc/application/models/Preference.php @@ -27,17 +27,17 @@ class Application_Model_Preference private static function setValue($key, $value, $isUserValue = false) { $cache = new Cache(); - - try { - - $con = Propel::getConnection(CcPrefPeer::DATABASE_NAME); - $con->beginTransaction(); + $con = Propel::getConnection(CcPrefPeer::DATABASE_NAME); + $con->beginTransaction(); + try { + static::_lock($con); $userId = self::getUserId(); - if ($isUserValue && is_null($userId)) + if ($isUserValue && is_null($userId)) { throw new Exception("User id can't be null for a user preference {$key}."); - + } + //Check if key already exists $sql = "SELECT COUNT(*) FROM cc_pref" ." WHERE keystr = :key"; @@ -113,6 +113,28 @@ class Application_Model_Preference $cache->store($key, $value, $isUserValue, $userId); } + /** + * Given a PDO connection, lock the cc_pref table for the current transaction + * + * Creates a table level lock, which defaults to ACCESS EXCLUSIVE mode; + * see http://www.postgresql.org/docs/9.1/static/explicit-locking.html + * + * @param PDO $con + */ + private static function _lock($con) { + // If we're not in a transaction, a lock is pointless + if (!$con->inTransaction()) { + return; + } + // Don't specify NOWAIT here; we should block on obtaining this lock + // in case we're handling simultaneous requests. + // Locks only last until the end of the transaction, so we shouldn't have to + // worry about this causing any noticeable difference in request processing speed + $sql = "LOCK TABLE cc_pref"; + $st = $con->prepare($sql); + $st->execute(); + } + private static function getValue($key, $isUserValue = false) { $cache = new Cache(); From db7e4086ba0db45cd338096c33e417288b4524be Mon Sep 17 00:00:00 2001 From: Duncan Sommerville Date: Sat, 4 Jul 2015 01:16:58 -0400 Subject: [PATCH 2/2] Re-add favicon headlink --- airtime_mvc/application/Bootstrap.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/airtime_mvc/application/Bootstrap.php b/airtime_mvc/application/Bootstrap.php index 2519b303c..919b365bd 100644 --- a/airtime_mvc/application/Bootstrap.php +++ b/airtime_mvc/application/Bootstrap.php @@ -144,10 +144,8 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap $baseUrl = Application_Common_OsPath::getBaseDir(); - /* - * array('rel' => 'icon', 'href' => $baseUrl . 'favicon.ico?' . $CC_CONFIG['airtime_version'], 'type' => 'image/x-icon'), 'PREPEND' - */ - $view->headLink()->appendStylesheet($baseUrl . 'css/bootstrap.css?' . $CC_CONFIG['airtime_version']) + $view->headLink(array('rel' => 'icon', 'href' => $baseUrl . 'favicon.ico?' . $CC_CONFIG['airtime_version'], 'type' => 'image/x-icon'), 'PREPEND') + ->appendStylesheet($baseUrl . 'css/bootstrap.css?' . $CC_CONFIG['airtime_version']) ->appendStylesheet($baseUrl . 'css/redmond/jquery-ui-1.8.8.custom.css?' . $CC_CONFIG['airtime_version']) ->appendStylesheet($baseUrl . 'css/pro_dropdown_3.css?' . $CC_CONFIG['airtime_version']) ->appendStylesheet($baseUrl . 'css/qtip/jquery.qtip.min.css?' . $CC_CONFIG['airtime_version'])