diff --git a/application/config/version.php b/application/config/version.php index aab5efe05d0..1a150b19bcc 100644 --- a/application/config/version.php +++ b/application/config/version.php @@ -13,7 +13,7 @@ */ $config['versionnumber'] = "2.50+"; -$config['dbversionnumber'] = 260; +$config['dbversionnumber'] = 261; $config['buildnumber'] = ''; $config['updatable'] = true; $config['assetsversionnumber'] = '31'; diff --git a/application/core/plugins/CintLink/CintLink.php b/application/core/plugins/CintLink/CintLink.php index 903560b237b..9299e4ffdd8 100644 --- a/application/core/plugins/CintLink/CintLink.php +++ b/application/core/plugins/CintLink/CintLink.php @@ -113,6 +113,7 @@ protected function createDatabase() 'modified' => 'datetime', ); $oDB->createCommand()->createTable('{{plugin_cintlink_orders}}', $aFields); + $oDB->createCommand()->createIndex('cint_index','{{plugin_cintlink_orders}}','sid, deleted, status',true); $oTransaction->commit(); } catch(Exception $e) @@ -266,6 +267,7 @@ public function afterQuickMenuLoad() * After survey is completed, user MUST be redirected to * Cint. * This method redirects and dies. + * @todo Survey session on client is not killed? * @return void */ public function afterSurveyComplete() @@ -279,7 +281,8 @@ public function afterSurveyComplete() throw new Exception('Internal error: Can\'t complete survey: surveyId is empty'); } - if (CintLinkOrder::hasAnyOrders($surveyId)) + if (CintLinkOrder::hasAnyOrders($surveyId) && + $this->hasCintParticipantGUID($surveyId)) { // Must update everytime respondent completes survey? // We can never know if it's out-of-date. @@ -307,12 +310,8 @@ public function afterSurveyQuota() $surveyId = $event->get('surveyId'); $matched = $event->get('aMatchedQuotas'); - $ses = Yii::app()->session['survey_' . $surveyId]; - $participantGUIDCode = $this->getParticipantGUIDQuestionCode($surveyId, $ses['fieldarray']); - $hasCintParticipantGUID = !empty($ses[$participantGUIDCode]); - if (!empty($matched) && - $hasCintParticipantGUID && + $this->hasCintParticipantGUID($surveyId) && CintLinkOrder::hasAnyBlockingOrders($surveyId)) { $url = 'http://cds.cintworks.net/survey/screen_out'; @@ -1352,7 +1351,7 @@ protected function hideNaggingNotication($surveyId) /** * Cint need to know how many questions there are in the - * survey. I use base questions + (sub questions / 3). + * survey. I use base questions + (sub questions / 2). * Approx is 3 questions each minute. * @param int $surveyId * @return int @@ -1470,4 +1469,22 @@ protected function getParticipantGUIDQuestionCode($surveyId, array $fieldarray) return false; } + /** + * True if respondent has a Cint participant guid + * @param int $surveyId + * @return boolean + */ + protected function hasCintParticipantGUID($surveyId) + { + $ses = Yii::app()->session['survey_' . $surveyId]; + $participantGUIDCode = $this->getParticipantGUIDQuestionCode($surveyId, $ses['fieldarray']); + + if ($participantGUIDCode === false) + { + return false; + } + + return !empty($ses[$participantGUIDCode]); + } + } diff --git a/application/helpers/update/updatedb_helper.php b/application/helpers/update/updatedb_helper.php index c38387ab660..e3fb2cb7bb8 100644 --- a/application/helpers/update/updatedb_helper.php +++ b/application/helpers/update/updatedb_helper.php @@ -1435,20 +1435,41 @@ function db_upgrade_all($iOldDBVersion, $bSilent=false) { } + /** + * The hash value of a notification is used to calculate uniqueness. + * @since 2016-08-10 + * @author Olle Haerstedt + */ if ($iOldDBVersion < 260) { addColumn('{{notifications}}', 'hash', 'string(64)'); + $oDB->createCommand()->createIndex('notif_hash_index', '{{notifications}}', 'hash', false); $oDB->createCommand()->update('{{settings_global}}',array('stg_value'=>260),"stg_name='DBVersion'"); } + /** + * Cint db version. Cint plugin is activated by default. + * @since 2016-08-22 + * @author Olle Haerstedt + */ + if ($iOldDBVersion < 261) + { + $oDB->createCommand()->insert('{{plugins}}', array( + 'name' => 'CintLink', + 'active' => 1 + )); + + $oDB->createCommand()->update('{{settings_global}}',array('stg_value'=>261),"stg_name='DBVersion'"); + } + // Inform superadmin about update // TODO: DON'T FORGET TO UPDATE THIS $superadmins = User::model()->getSuperAdmins(); Notification::broadcast(array( 'title' => gT('Database update'), - 'message' => sprintf(gT('The database has been updated from version %s to version %s.'), $iOldDBVersion, '260') // <--- UPDATE THIS + 'message' => sprintf(gT('The database has been updated from version %s to version %s.'), $iOldDBVersion, '261') // <--- UPDATE THIS ), $superadmins); $oTransaction->commit(); diff --git a/installer/sql/create-mssql.sql b/installer/sql/create-mssql.sql index 43c1e3d2064..2abcc080b90 100644 --- a/installer/sql/create-mssql.sql +++ b/installer/sql/create-mssql.sql @@ -609,7 +609,25 @@ CREATE TABLE prefix_notifications ( CREATE INDEX [notif_index] ON [prefix_notifications] ([entity_id],[entity],[status]); CREATE INDEX [notif_hash_index] ON [prefix_notifications] ([hash]); +-- +-- Cint plugin, active by default +-- +INSERT INTO prefix_plugins ([name], [active]) VALUES ('CintLInk', 1); +CREATE TABLE IF NOT EXISTS prefix_plugin_cintlink_orders ( + [url] => nvarchar(127) NOT NULL, + [sid] => int NOT NULL, + [raw] => nvarchar(max), + [country] => nvarchar(63), + [status] => nvarchar(15), + [ordered_by] => int NOT NULL, + [deleted] => int DEFAULT 0, + [created] => datetime NOT NULL, + [modified] => datetime DEFAULT NULL, + PRIMARY KEY([url]) +); +CREATE INDEX [cint_index] ON [prefix_plugin_cintlink_orders] ([sid], [deleted], [status]); + -- -- Version Info -- -INSERT INTO [prefix_settings_global] VALUES ('DBVersion', '260'); +INSERT INTO [prefix_settings_global] VALUES ('DBVersion', '261'); diff --git a/installer/sql/create-mysql.sql b/installer/sql/create-mysql.sql index bb64ef5ea12..8a5da53f739 100644 --- a/installer/sql/create-mysql.sql +++ b/installer/sql/create-mysql.sql @@ -615,7 +615,24 @@ CREATE TABLE IF NOT EXISTS `prefix_notifications` ( INDEX(`hash`) ) ENGINE=MYISAM CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; +-- +-- Cint plugin, active by default +-- +INSERT INTO `prefix_plugins` (`name`, `active`) VALUES ('CintLInk', 1); +CREATE TABLE IF NOT EXISTS `prefix_plugin_cintlink_orders` ( + `url` => VARCHAR(127) NOT NULL PRIMARY KEY, + `sid` => INT(11) NOT NULL, + `raw` => TEXT, + `country` => VARCHAR(63), + `status` => VARCHAR(15), + `ordered_by` => INT(11) NOT NULL, + `deleted` => INT DEFAULT 0, + `created` => DATETIME NOT NULL, + `modified` => DATETIME DEFAULT NULL, + INDEX(`sid`, `deleted`, `status`) +) ENGINE=MYISAM CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + -- -- Version Info -- -INSERT INTO `prefix_settings_global` VALUES ('DBVersion', '260'); +INSERT INTO `prefix_settings_global` VALUES ('DBVersion', '261'); diff --git a/installer/sql/create-pgsql.sql b/installer/sql/create-pgsql.sql index ad5c8b9a1ec..024be5e4894 100644 --- a/installer/sql/create-pgsql.sql +++ b/installer/sql/create-pgsql.sql @@ -618,7 +618,25 @@ CREATE TABLE prefix_notifications ( CREATE INDEX prefix_index ON prefix_notifications USING btree (entity, entity_id, status); CREATE INDEX hash_index ON prefix_notifications USING btree (hash); +-- +-- Cint plugin, active by default +-- +INSERT INTO "prefix_plugins" ("name", "active") VALUES ('CintLInk', 1); +CREATE TABLE IF NOT EXISTS "prefix_plugin_cintlink_orders" ( + "url" => CHARACTER VARYING(127) NOT NULL, + "sid" => INTEGER NOT NULL, + "raw" => TEXT, + "country" => CHARACTER VARYING(63), + "status" => CHARACTER VARYING(15), + "ordered_by" => INTEGER NOT NULL, + "deleted" => INTEGER DEFAULT 0, + "created" => TIMESTAMP NOT NULL, + "modified" => TIMESTAMP DEFAULT NULL, + PRIMARY KEY(url) +); +CREATE INDEX cint_index ON prefix_plugin_cintlink_orders USING btree (sid, deleted, status); + -- -- Version Info -- -INSERT INTO prefix_settings_global VALUES ('DBVersion', '260'); +INSERT INTO prefix_settings_global VALUES ('DBVersion', '261');