diff --git a/application/helpers/update/updatedb_helper.php b/application/helpers/update/updatedb_helper.php index be67e7e56e2..86c84d90853 100644 --- a/application/helpers/update/updatedb_helper.php +++ b/application/helpers/update/updatedb_helper.php @@ -316,6 +316,17 @@ function db_upgrade_all($iOldDBVersion, $bSilent=false) { $oDB->createCommand()->update('{{settings_global}}',array('stg_value'=>305),"stg_name='DBVersion'"); } + /** + * Template tables + * @since 2017-07-12 + */ + if ($iOldDBVersion < 305) { + $oTransaction = $oDB->beginTransaction(); + upgradeTemplateTables305($oDB); + $oTransaction->commit(); + $oDB->createCommand()->update('{{settings_global}}',array('stg_value'=>305),"stg_name='DBVersion'"); + } + } catch(Exception $e) { @@ -450,6 +461,48 @@ function createSurveyMenuTable293($oDB) { } } +/** + * @param $oDB + * @return void + */ +function upgradeTemplateTables305($oDB) +{ + // Drop the old survey rights table. + if (tableExists('{surveys_groups}')) { + $oDB->createCommand()->dropTable('{{surveys_groups}}'); + } + + + // Create templates table + $oDB->createCommand()->createTable('{{surveys_groups}}', array( + 'gsid' => 'pk', + 'name' => 'string(45) NOT NULL', + 'title' => 'string(100) DEFAULT NULL', + 'description' => 'text DEFAULT NULL', + 'order' => 'int(11) NOT NULL', + 'owner_uid' => 'int(11) DEFAULT NULL', + 'parent_id' => 'int(11) DEFAULT NULL', + 'created' => 'DATETIME', + 'modified' => 'DATETIME', + 'created_by' => 'int(11) NOT NULL' + )); + + // Add default template + $date = date("Y-m-d H:i:s"); + $oDB->createCommand()->insert('{{surveys_groups}}', array( + 'name' => 'default', + 'title' => 'Default Survey Group', + 'description' => 'LimeSurvey core default survey group', + 'order' => '0', + 'owner_uid' => '1', + 'created' => $date, + 'modified' => $date, + 'created_by' => '1' + )); + + $oDB->createCommand()->addColumn('{{surveys}}','gsid',"int(11) DEFAULT 1"); +} + /** * @param $oDB * @return void diff --git a/installer/sql/create-mysql.sql b/installer/sql/create-mysql.sql index 5c91a05a3d6..52ecf4daaa7 100644 --- a/installer/sql/create-mysql.sql +++ b/installer/sql/create-mysql.sql @@ -463,10 +463,10 @@ CREATE TABLE `prefix_surveys` ( `alloweditaftercompletion` varchar(1) default 'N', `googleanalyticsstyle` varchar(1) DEFAULT NULL, `googleanalyticsapikey` VARCHAR(25) DEFAULT NULL, + `gsid` int(11) DEFAULT '1' PRIMARY KEY (`sid`) ) ENGINE=MYISAM CHARACTER SET utf8mb4 ; - -- -- Table structure for table surveys_languagesettings -- @@ -775,7 +775,33 @@ INSERT INTO `prefix_template_configuration` VALUES (3,'material',NULL,NULL,NULL,'{"add": ["css/template.css", "css/bootstrap-material-design.css", "css/ripples.min.css"]}','{"add": ["scripts/template.js", "scripts/material.js", "scripts/ripples.min.js"]}','{"add":"css/print_template.css",}','{"ajaxmode":"on","brandlogo":"on", "animatebody":"on","bodyanimation":"fadeInRight","animatequestion":"off","questionanimation":"flipInX","animatealert":"off","alertanimation":"shake"}','bootstrap','{"replace": [["css/bootstrap.css","css/bootstrap.css"]]}','','','',''); +-- ----------------------------------------------------- +-- Table `prefix_surveys_groups` +-- ----------------------------------------------------- +CREATE TABLE `prefix_surveys_groups` ( + `gsid` int(11) NOT NULL, + `name` varchar(45) COLLATE utf8mb4_unicode_ci NOT NULL, + `title` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `description` text COLLATE utf8mb4_unicode_ci, + `order` int(11) NOT NULL, + `owner_uid` int(11) DEFAULT NULL, + `parent_id` int(11) DEFAULT NULL, + `created` datetime DEFAULT NULL, + `modified` datetime DEFAULT NULL, + `created_by` int(11) NOT NULL +) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + +ALTER TABLE `prefix_surveys_groups` + ADD PRIMARY KEY (`gsid`); + +ALTER TABLE `prefix_surveys_groups` + MODIFY `gsid` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2; + +INSERT INTO `prefix_surveys_groups` (`gsid`, `name`, `title`, `description`, `order`, `owner_uid`, `parent_id`, `created`, `modified`, `created_by`) VALUES + (1, 'default', 'Default Survey Group', 'LimeSurvey core default survey group', 0, 1, NULL, '2017-07-20 17:09:30', '2017-07-20 17:09:30', 1); + + -- -- Version Info -- -INSERT INTO `prefix_settings_global` VALUES ('DBVersion', '301'); +INSERT INTO `prefix_settings_global` VALUES ('DBVersion', '305');