From cb0593370a34550b51c8a3e93147f7b713669d07 Mon Sep 17 00:00:00 2001 From: Duncan Sommerville Date: Sat, 4 Jul 2015 00:38:53 -0400 Subject: [PATCH 1/3] 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/3] 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']) From 5cb396e512ef3caefde48a4ff8805091312bd5e3 Mon Sep 17 00:00:00 2001 From: Duncan Sommerville Date: Mon, 6 Jul 2015 18:03:44 -0400 Subject: [PATCH 3/3] SAAS-923 - 2.5.14 schema upgrade to add partial unique index on cc_pref's keystr column (when subjid is null) --- airtime_mvc/application/configs/constants.php | 3 ++- .../upgrade_sql/airtime_2.5.14/upgrade.sql | 4 ++++ airtime_mvc/application/models/Preference.php | 3 ++- airtime_mvc/application/upgrade/Upgrades.php | 18 ++++++++++++++++++ airtime_mvc/build/sql/defaultdata.sql | 8 ++++++++ 5 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 airtime_mvc/application/controllers/upgrade_sql/airtime_2.5.14/upgrade.sql diff --git a/airtime_mvc/application/configs/constants.php b/airtime_mvc/application/configs/constants.php index 4360cd9e7..aaed5d901 100644 --- a/airtime_mvc/application/configs/constants.php +++ b/airtime_mvc/application/configs/constants.php @@ -24,7 +24,8 @@ define('LICENSE_URL' , 'http://www.gnu.org/licenses/agpl-3.0-standalone.h define('AIRTIME_COPYRIGHT_DATE' , '2010-2015'); define('AIRTIME_REST_VERSION' , '1.1'); define('AIRTIME_API_VERSION' , '1.1'); -define('AIRTIME_CODE_VERSION' , '2.5.13'); +// XXX: it's important that we upgrade this every time we add an upgrade! +define('AIRTIME_CODE_VERSION' , '2.5.14'); // Defaults define('DEFAULT_LOGO_PLACEHOLDER', 1); diff --git a/airtime_mvc/application/controllers/upgrade_sql/airtime_2.5.14/upgrade.sql b/airtime_mvc/application/controllers/upgrade_sql/airtime_2.5.14/upgrade.sql new file mode 100644 index 000000000..3a5362ca1 --- /dev/null +++ b/airtime_mvc/application/controllers/upgrade_sql/airtime_2.5.14/upgrade.sql @@ -0,0 +1,4 @@ +ALTER TABLE cc_pref ALTER COLUMN subjid SET NULL; +ALTER TABLE cc_pref ALTER COLUMN subjid SET DEFAULT NULL; +CREATE UNIQUE INDEX cc_pref_key_idx ON cc_pref (keystr) WHERE subjid IS NULL; +ANALYZE cc_pref; \ No newline at end of file diff --git a/airtime_mvc/application/models/Preference.php b/airtime_mvc/application/models/Preference.php index ec8b49a3c..736dbef98 100644 --- a/airtime_mvc/application/models/Preference.php +++ b/airtime_mvc/application/models/Preference.php @@ -31,7 +31,8 @@ class Application_Model_Preference $con->beginTransaction(); try { - static::_lock($con); + /* Comment this out while we reevaluate it in favor of a unique constraint + static::_lock($con); */ $userId = self::getUserId(); if ($isUserValue && is_null($userId)) { diff --git a/airtime_mvc/application/upgrade/Upgrades.php b/airtime_mvc/application/upgrade/Upgrades.php index aa012eca6..bcd9c5093 100644 --- a/airtime_mvc/application/upgrade/Upgrades.php +++ b/airtime_mvc/application/upgrade/Upgrades.php @@ -455,3 +455,21 @@ class AirtimeUpgrader2513 extends AirtimeUpgrader return '2.5.13'; } } + +/** + * Class AirtimeUpgrader2514 + * + * SAAS-923 - Add a partial constraint to cc_pref so that keystrings must be unique + */ +class AirtimeUpgrader2514 extends AirtimeUpgrader +{ + protected function getSupportedSchemaVersions() { + return array ( + '2.5.13' + ); + } + + public function getNewVersion() { + return '2.5.14'; + } +} diff --git a/airtime_mvc/build/sql/defaultdata.sql b/airtime_mvc/build/sql/defaultdata.sql index 49bf3ff29..30fd8d765 100644 --- a/airtime_mvc/build/sql/defaultdata.sql +++ b/airtime_mvc/build/sql/defaultdata.sql @@ -376,3 +376,11 @@ INSERT INTO cc_stream_setting ("keyname", "value", "type") VALUES ('s4_descripti INSERT INTO cc_stream_setting ("keyname", "value", "type") VALUES ('s4_genre', '', 'string'); INSERT INTO cc_stream_setting (keyname, value, type) VALUES ('s4_channels', 'stereo', 'string'); +-- added in 2.5.14 - this can't be set up in Propel's XML schema, so we need to do it here -- Duncan + +ALTER TABLE cc_pref ALTER COLUMN subjid SET NULL; +ALTER TABLE cc_pref ALTER COLUMN subjid SET DEFAULT NULL; +CREATE UNIQUE INDEX cc_pref_key_idx ON cc_pref (keystr) WHERE subjid IS NULL; +ANALYZE cc_pref; -- this validates the new partial index + +--end added in 2.5.14