From f58656b96fc42f10f7c3e3f120d0c1b2d7f40961 Mon Sep 17 00:00:00 2001 From: markusfluer Date: Fri, 11 Aug 2017 14:13:11 +0200 Subject: [PATCH] Fixed error: Dbupgrade not correctly working on upgrading from 2.6X --- application/config/version.php | 3 +- .../controllers/admin/authentication.php | 18 +++ .../helpers/update/updatedb_helper.php | 146 ++++++++++++++++++ 3 files changed, 166 insertions(+), 1 deletion(-) diff --git a/application/config/version.php b/application/config/version.php index a80f0ecd8ee..6bd0b0fb1c3 100644 --- a/application/config/version.php +++ b/application/config/version.php @@ -11,9 +11,10 @@ * See COPYRIGHT.php for copyright notices and details. */ + $config['versionnumber'] = '3.0.0-beta.2'; //The current version of this branch $config['masterversion'] = '2.67.2'; //The current masters version merged into this branch -$config['dbversionnumber'] = 309; +$config['dbversionnumber'] = 310; $config['buildnumber'] = ''; $config['updatable'] = true; $config['assetsversionnumber'] = '2902'; diff --git a/application/controllers/admin/authentication.php b/application/controllers/admin/authentication.php index 4a90eedb18a..4732e26bf09 100644 --- a/application/controllers/admin/authentication.php +++ b/application/controllers/admin/authentication.php @@ -250,6 +250,22 @@ public function forgotpassword() } } + public static function runDbUpgrade(){ + // Check if the DB is up to date + if (Yii::app()->db->schema->getTable('{{surveys}}') ) + { + $sDBVersion = getGlobalSetting('DBVersion'); + } + if ((int) $sDBVersion < Yii::app()->getConfig('dbversionnumber') && $action != 'databaseupdate') + { + // Try a silent update first + Yii::app()->loadHelper('update/updatedb'); + if (!db_upgrade_all(intval($sDBVersion),true)){ + $this->redirect(array('/admin/databaseupdate/sa/db')); + } + } + } + /** * Send the forgot password email * @@ -329,6 +345,7 @@ private function _redirectIfLoggedIn() { if (!Yii::app()->user->getIsGuest()) { + $this->runDbUpgrade(); $this->getController()->redirect(array('/admin')); } } @@ -358,6 +375,7 @@ private function _userCanLogin() */ private static function doRedirect() { + self::runDbUpgrade(); $returnUrl = App()->user->getReturnUrl(array('/admin')); Yii::app()->getController()->redirect($returnUrl); } diff --git a/application/helpers/update/updatedb_helper.php b/application/helpers/update/updatedb_helper.php index 8c32ed8db24..562b79c1e99 100644 --- a/application/helpers/update/updatedb_helper.php +++ b/application/helpers/update/updatedb_helper.php @@ -366,6 +366,16 @@ function db_upgrade_all($iOldDBVersion, $bSilent=false) { SurveymenuEntries::reorderMenu(1); } + /* + * Reset all surveymenu tables, because there were too many errors + */ + if ($iOldDBVersion < 310) { + $oTransaction = $oDB->beginTransaction(); + reCreateSurveyMenuTable310($oDB); + $oDB->createCommand()->update('{{settings_global}}',array('stg_value'=>310),"stg_name='DBVersion'"); + $oTransaction->commit(); + } + } catch(Exception $e) @@ -500,7 +510,143 @@ function createSurveyMenuTable293($oDB) { $oDB->createCommand()->insert('{{surveymenu_entries}}', array_combine($colsToAdd,$row)); } } +function reCreateSurveyMenuTable310(&$oDB) +{ + +// Drop the old surveymenu table. +if (tableExists('{surveymenu}')) { + $oDB->createCommand()->dropTable('{{surveymenu}}'); +} +// Drop the old surveymenu_entries table. +if (tableExists('{surveymenu_entries}')) { + $oDB->createCommand()->dropTable('{{surveymenu_entries}}'); +} + +$oDB->createCommand()->createTable('{{surveymenu}}', array( + "id" => "int(11) NOT NULL AUTO_INCREMENT", + "parent_id" => "int(11) DEFAULT NULL", + "survey_id" => "int(11) DEFAULT NULL", + "user_id" => "int(11) DEFAULT NULL", + "ordering" => "int(11) DEFAULT '0'", + "level" => "int(11) DEFAULT '0'", + "title" => "varchar(255) NOT NULL DEFAULT ''", + "position" => "varchar(255) NOT NULL DEFAULT 'side'", + "description" => "text ", + "changed_at" => "timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP", + "changed_by" => "int(11) NOT NULL DEFAULT '0'", + "created_at" => "datetime DEFAULT NULL", + "created_by" => "int(11) NOT NULL DEFAULT '0'", + "PRIMARY KEY (`id`)", + "KEY `ordering` (`ordering`)", + "KEY `title` (`title`(250))" +)); +$oDB->createCommand()->insert( + '{{surveymenu}}', + array( + "id" =>1, + "parent_id" =>NULL, + "survey_id" =>NULL, + "user_id" =>NULL, + "ordering" =>1, + "level" =>0, + "title" =>'surveymenu', + "position" =>'side', + "description" =>'Main survey menu', + "changed_at" => date('Y-m-d H:i:s'), + "changed_by" =>0, + "created_at" =>date('Y-m-d H:i:s'), + "created_by" => 0 + )); +$oDB->createCommand()->insert( + '{{surveymenu}}', + array( + "id" =>2, + "parent_id" =>NULL, + "survey_id" =>NULL, + "user_id" =>NULL, + "ordering" =>1, + "level" =>0, + "title" =>'quickmenue', + "position" =>'collapsed', + "description" =>'Quickmenu', + "changed_at" => date('Y-m-d H:i:s'), + "changed_by" =>0, + "created_at" =>date('Y-m-d H:i:s'), + "created_by" => 0 + )); + + + $oDB->createCommand()->createTable('{{surveymenu_entries}}', array( + "id" => "int(11) NOT NULL AUTO_INCREMENT", + "menu_id" => "int(11) DEFAULT NULL", + "user_id" => "int(11) DEFAULT NULL", + "ordering" => "int(11) DEFAULT '0'", + "name" => "varchar(255) NOT NULL DEFAULT ''", + "title" => "varchar(255) NOT NULL DEFAULT ''", + "menu_title" => "varchar(255) NOT NULL DEFAULT ''", + "menu_description" => "text ", + "menu_icon" => "varchar(255) NOT NULL DEFAULT ''", + "menu_icon_type" => "varchar(255) NOT NULL DEFAULT ''", + "menu_class" => "varchar(255) NOT NULL DEFAULT ''", + "menu_link" => "varchar(255) NOT NULL DEFAULT ''", + "action" => "varchar(255) NOT NULL DEFAULT ''", + "template" => "varchar(255) NOT NULL DEFAULT ''", + "partial" => "varchar(255) NOT NULL DEFAULT ''", + "classes" => "varchar(255) NOT NULL DEFAULT ''", + "permission" => "varchar(255) NOT NULL DEFAULT ''", + "permission_grade" => "varchar(255) DEFAULT NULL", + "data" => "text ", + "getdatamethod" => "varchar(255) NOT NULL DEFAULT ''", + "language" => "varchar(255) NOT NULL DEFAULT 'en-GB'", + "changed_at" => "timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP", + "changed_by" => "int(11) NOT NULL DEFAULT '0'", + "created_at" => "datetime DEFAULT NULL", + "created_by" => "int(11) NOT NULL DEFAULT '0'", + "PRIMARY KEY (`id`)", + "KEY `menu_id` (`menu_id`)", + "KEY `ordering` (`ordering`)", + "KEY `title` (`title`(191))", + "KEY `menu_title` (`menu_title`(191))" + )); + $colsToAdd = array("id","menu_id","user_id","ordering","name","title","menu_title","menu_description","menu_icon","menu_icon_type","menu_class","menu_link","action","template","partial","classes","permission","permission_grade","data","getdatamethod","language","changed_at","changed_by","created_at","created_by"); + $rowsToAdd = array( + array(1,1,NULL,1,'overview','Survey overview','Overview','Open general survey overview and quick action','list','fontawesome','','admin/survey/sa/view','','','','','','','{\"render\": { \"link\": {\"data\": {\"surveyid\": [\"survey\",\"sid\"]}}}}','','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0), + array(2,1,NULL,2,'generalsettings','Edit survey general settings','General settings','Open general survey settings','gears','fontawesome','','','updatesurveylocalesettings','editLocalSettings_main_view','/admin/survey/subview/accordion/_generaloptions_panel','','surveysettings','read',NULL,'_generalTabEditSurvey','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0), + array(3,1,NULL,3,'surveytexts','Edit survey text elements','Survey texts','Edit survey text elements','file-text-o','fontawesome','','','updatesurveylocalesettings','editLocalSettings_main_view','/admin/survey/subview/tab_edit_view','','surveylocale','read',NULL,'_getTextEditData','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0), + array(4,1,NULL,4,'template_options','Template options','Template options','Edit Template options for this survey','paint-brush','fontawesome','','admin/templateoptions/sa/updatesurvey','','','','','templates','read','{"render": {"link": { "pjaxed": false, "data": {"surveyid": ["survey","sid"], "gsid":["survey","gsid"]}}}}','','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0), + array(5,1,NULL,5,'participants','Survey participants','Survey participants','Go to survey participant and token settings','user','fontawesome','','admin/tokens/sa/index/','','','','','surveysettings','update','{\"render\": { \"link\": {\"data\": {\"surveyid\": [\"survey\",\"sid\"]}}}}','','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0), + array(6,1,NULL,6,'presentation','Presentation & navigation settings','Presentation','Edit presentation and navigation settings','eye-slash','fontawesome','','','updatesurveylocalesettings','editLocalSettings_main_view','/admin/survey/subview/accordion/_presentation_panel','','surveylocale','read',NULL,'_tabPresentationNavigation','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0), + array(7,1,NULL,7,'publication','Publication and access control settings','Publication & access','Edit settings for publicationa and access control','key','fontawesome','','','updatesurveylocalesettings','editLocalSettings_main_view','/admin/survey/subview/accordion/_publication_panel','','surveylocale','read',NULL,'_tabPublicationAccess','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0), + array(8,1,NULL,8,'surveypermissions','Edit surveypermissions','Survey permissions','Edit permissions for this survey','lock','fontawesome','','admin/surveypermission/sa/view/','','','','','surveysecurity','read','{\"render\": { \"link\": {\"data\": {\"surveyid\": [\"survey\",\"sid\"]}}}}','','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0), + array(9,1,NULL,9,'tokens','Token handling','Participant tokens','Define how tokens should be treated or generated','users','fontawesome','','','updatesurveylocalesettings','editLocalSettings_main_view','/admin/survey/subview/accordion/_tokens_panel','','surveylocale','read',NULL,'_tabTokens','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0), + array(10,1,NULL,10,'quotas','Edit quotas','Survey quotas','Edit quotas for this survey.','tasks','fontawesome','','admin/quotas/sa/index/','','','','','quotas','read','{\"render\": { \"link\": {\"data\": {\"surveyid\": [\"survey\",\"sid\"]}}}}','','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0), + array(11,1,NULL,11,'assessments','Edit assessments','Assessments','Edit and look at the asessements for this survey.','comment-o','fontawesome','','admin/assessments/sa/index/','','','','','assessments','read','{\"render\": { \"link\": {\"data\": {\"surveyid\": [\"survey\",\"sid\"]}}}}','','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0), + array(12,1,NULL,12,'notification','Notification and data management settings','Data management','Edit settings for notification and data management','feed','fontawesome','','','updatesurveylocalesettings','editLocalSettings_main_view','/admin/survey/subview/accordion/_notification_panel','','surveylocale','read',NULL,'_tabNotificationDataManagement','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0), + array(13,1,NULL,13,'emailtemplates','Email templates','Email templates','Edit the templates for invitation, reminder and registration emails','envelope-square','fontawesome','','admin/emailtemplates/sa/index/','','','','','assessments','read','{\"render\": { \"link\": {\"data\": {\"surveyid\": [\"survey\",\"sid\"]}}}}','','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0), + array(14,1,NULL,14,'panelintegration','Edit survey panel integration','Panel integration','Define panel integrations for your survey','link','fontawesome','','','updatesurveylocalesettings','editLocalSettings_main_view','/admin/survey/subview/accordion/_integration_panel','','surveylocale','read',NULL,'_tabPanelIntegration','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0), + array(15,1,NULL,15,'ressources','Add/Edit ressources to the survey','Ressources','Add/Edit ressources to the survey','file','fontawesome','','','updatesurveylocalesettings','editLocalSettings_main_view','/admin/survey/subview/accordion/_resources_panel','','surveylocale','read',NULL,'_tabResourceManagement','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0), + array(16,2,NULL,1,'activateSurvey','Activate survey','Activate survey','Activate survey','play','fontawesome','','admin/survey/sa/activate','','','','','surveyactivation','update','{\"render\": {\"isActive\": false, \"link\": {\"data\": {\"surveyid\": [\"survey\",\"sid\"]}}}}','','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0), + array(17,2,NULL,2,'deactivateSurvey','Stop this survey','Stop this survey','Stop this survey','stop','fontawesome','','admin/survey/sa/deactivate','','','','','surveyactivation','update','{\"render\": {\"isActive\": true, \"link\": {\"data\": {\"surveyid\": [\"survey\",\"sid\"]}}}}','','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0), + array(18,2,NULL,3,'testSurvey','Go to survey','Go to survey','Go to survey','cog','fontawesome','','survey/index/','','','','','','','{\"render\"\: {\"link\"\: {\"external\"\: true, \"data\"\: {\"sid\"\: [\"survey\",\"sid\"], \"newtest\"\: \"Y\", \"lang\"\: [\"survey\",\"language\"]}}}}','','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0), + array(19,2,NULL,4,'listQuestions','List questions','List questions','List questions','list','fontawesome','','admin/survey/sa/listquestions','','','','','surveycontent','read','{\"render\": { \"link\": {\"data\": {\"surveyid\": [\"survey\",\"sid\"]}}}}','','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0), + array(20,2,NULL,5,'listQuestionGroups','List question groups','List question groups','List question groups','th-list','fontawesome','','admin/survey/sa/listquestiongroups','','','','','surveycontent','read','{\"render\": { \"link\": {\"data\": {\"surveyid\": [\"survey\",\"sid\"]}}}}','','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0), + array(21,2,NULL,6,'generalsettings','Edit survey general settings','General settings','Open general survey settings','gears','fontawesome','','','updatesurveylocalesettings','editLocalSettings_main_view','/admin/survey/subview/accordion/_generaloptions_panel','','surveysettings','read',NULL,'_generalTabEditSurvey','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0), + array(22,2,NULL,7,'surveypermissions','Edit surveypermissions','Survey permissions','Edit permissions for this survey','lock','fontawesome','','admin/surveypermission/sa/view/','','','','','surveysecurity','read','{\"render\": { \"link\": {\"data\": {\"surveyid\": [\"survey\",\"sid\"]}}}}','','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0), + array(23,2,NULL,8,'quotas','Edit quotas','Survey quotas','Edit quotas for this survey.','tasks','fontawesome','','admin/quotas/sa/index/','','','','','quotas','read','{\"render\": { \"link\": {\"data\": {\"surveyid\": [\"survey\",\"sid\"]}}}}','','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0), + array(24,2,NULL,9,'assessments','Edit assessments','Assessments','Edit and look at the asessements for this survey.','comment-o','fontawesome','','admin/assessments/sa/index/','','','','','assessments','read','{\"render\": { \"link\": {\"data\": {\"surveyid\": [\"survey\",\"sid\"]}}}}','','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0), + array(25,2,NULL,10,'emailtemplates','Email templates','Email templates','Edit the templates for invitation, reminder and registration emails','envelope-square','fontawesome','','admin/emailtemplates/sa/index/','','','','','surveylocale','read','{\"render\": { \"link\": {\"data\": {\"surveyid\": [\"survey\",\"sid\"]}}}}','','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0), + array(26,2,NULL,11,'surveyLogicFile','Survey logic file','Survey logic file','Survey logic file','sitemap','fontawesome','','admin/expressions/sa/survey_logic_file/','','','','','surveycontent','read','{\"render\": { \"link\": {\"data\": {\"surveyid\": [\"survey\",\"sid\"]}}}}','','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0), + array(27,2,NULL,12,'tokens','Token handling','Participant tokens','Define how tokens should be treated or generated','user','fontawesome','','','updatesurveylocalesettings','editLocalSettings_main_view','/admin/survey/subview/accordion/_tokens_panel','','surveylocale','read','{\"render\": { \"link\": {\"data\": {\"surveyid\": [\"survey\",\"sid\"]}}}}','_tabTokens','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0), + array(28,2,NULL,13,'cpdb','Central participant database','Central participant database','Central participant database','users','fontawesome','','admin/participants/sa/displayParticipants','','','','','tokens','read','{render\: {\"link\"\: {}}','','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0), + array(29,2,NULL,14,'responses','Responses','Responses','Responses','icon-browse','iconclass','','admin/responses/sa/browse/','','','','','responses','read','{\"render\"\: {\"isActive\"\: true}}','','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0), + array(30,2,NULL,15,'statistics','Statistics','Statistics','Statistics','bar-chart','fontawesome','','admin/statistics/sa/index/','','','','','statistics','read','{\"render\"\: {\"isActive\"\: true}}','','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0), + array(31,2,NULL,16,'reorder','Reorder questions/question groups','Reorder questions/question groups','Reorder questions/question groups','icon-organize','iconclass','','admin/survey/sa/organize/','','','','','surveycontent','update','{\"render\": {\"isActive\": false, \"link\": {\"data\": {\"surveyid\": [\"survey\",\"sid\"]}}}}','','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0) + ); + foreach($rowsToAdd as $row){ + $oDB->createCommand()->insert('{{surveymenu_entries}}', array_combine($colsToAdd,$row)); + } +} /** * @param $oDB * @return void