Skip to content

Commit

Permalink
Dev: Add CintLink tables to install sql
Browse files Browse the repository at this point in the history
  • Loading branch information
olleharstedt committed Aug 22, 2016
1 parent c089597 commit 96dc89b
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 12 deletions.
2 changes: 1 addition & 1 deletion application/config/version.php
Expand Up @@ -13,7 +13,7 @@
*/

$config['versionnumber'] = "2.50+";
$config['dbversionnumber'] = 260;
$config['dbversionnumber'] = 261;
$config['buildnumber'] = '';
$config['updatable'] = true;
$config['assetsversionnumber'] = '31';
Expand Down
31 changes: 24 additions & 7 deletions application/core/plugins/CintLink/CintLink.php
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand All @@ -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.
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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]);
}

}
23 changes: 22 additions & 1 deletion application/helpers/update/updatedb_helper.php
Expand Up @@ -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();
Expand Down
20 changes: 19 additions & 1 deletion installer/sql/create-mssql.sql
Expand Up @@ -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');
19 changes: 18 additions & 1 deletion installer/sql/create-mysql.sql
Expand Up @@ -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');
20 changes: 19 additions & 1 deletion installer/sql/create-pgsql.sql
Expand Up @@ -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');

0 comments on commit 96dc89b

Please sign in to comment.