From 5bc71abccbf0a9c21def2e72877f7d4b9fe97428 Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 15 Jun 2015 12:43:38 +0200 Subject: [PATCH] Dev Several fixes related to upgrade. --- application/components/AssetManager.php | 4 ++++ application/components/MigrationManager.php | 6 +++--- application/core/WebApplication.php | 9 +++++---- .../m150511_124830_group_remove_language.php | 2 +- application/models/QuestionGroup.php | 15 --------------- application/models/Survey.php | 5 ++++- application/views/upgrade/database.php | 2 +- 7 files changed, 18 insertions(+), 25 deletions(-) diff --git a/application/components/AssetManager.php b/application/components/AssetManager.php index 955e2195477..4616b3d3841 100644 --- a/application/components/AssetManager.php +++ b/application/components/AssetManager.php @@ -5,6 +5,10 @@ class AssetManager extends CAssetManager { public function getBaseUrl() { + /** + * @todo Solve this in a more efficient way, for example by storing the result. + * + */ return strtr(parent::getBaseUrl(), ['{baseUrl}' => App()->baseUrl]); } } \ No newline at end of file diff --git a/application/components/MigrationManager.php b/application/components/MigrationManager.php index 85c3f6230f3..ca4bf92d020 100644 --- a/application/components/MigrationManager.php +++ b/application/components/MigrationManager.php @@ -7,7 +7,7 @@ class MigrationManager extends \CApplicationComponent { const BASE_MIGRATION='m000000_000000_base'; - public $migrationTable = 'tbl_migration'; + public $migrationTable = '{{migration}}'; /** * * @var string[] The paths to folders containing migrations. @@ -54,7 +54,7 @@ protected function getMigrationHistory($limit = -1) protected function createMigrationHistoryTable() { - $db=$this->getDbConnection(); + $db = App()->db; echo '
';
 		echo 'Creating migration history table "'.$this->migrationTable.'"...';
         $db->createCommand()->createTable($this->migrationTable,array(
@@ -74,7 +74,7 @@ public function migrateUp($class)
 		if ( $class === self::BASE_MIGRATION) {
 			return;
         }
-        ob_end_flush();
+        @ob_end_flush();
         echo '
';
 		
         echo "*** applying $class\n";
diff --git a/application/core/WebApplication.php b/application/core/WebApplication.php
index b16cf3afb16..1b6b7e92183 100644
--- a/application/core/WebApplication.php
+++ b/application/core/WebApplication.php
@@ -51,17 +51,18 @@ public function setMaintenanceMode($value) {
         @unlink(__DIR__ . '/../config/MAINTENANCE');
     }
     
-    public function onBeginRequest($event) {
-        parent::onBeginRequest($event);
+
+    public function processRequest()
+    {
         /**
          * Add support for maintenance mode.
          */
-        if ($this->maintenanceMode) {
+        if ($this->maintenanceMode && strncmp('upgrade', $this->getUrlManager()->parseUrl($this->getRequest()), 7) != 0) {
             $this->catchAllRequest = [
                 'upgrade'
             ];
         }
-        return true;
+        return parent::processRequest();
     }
     public function setSupportedLanguages($value) {
         foreach($value as $code => $language) {
diff --git a/application/migrations/m150511_124830_group_remove_language.php b/application/migrations/m150511_124830_group_remove_language.php
index 915ea909bd9..6cbbad72eae 100644
--- a/application/migrations/m150511_124830_group_remove_language.php
+++ b/application/migrations/m150511_124830_group_remove_language.php
@@ -31,7 +31,7 @@ public function safeUp()
                 $translation->model = 'Group'; // We have Single Table Inheritance so we use the base class.
                 $translation->model_id = $group->id;
                 foreach ($group->translatableAttributes as $attribute) {
-                    $translation->$attribute = $answer->$attribute;
+                    $translation->$attribute = $group->$attribute;
                 }
                 try {
                     if ($translation->save()) {
diff --git a/application/models/QuestionGroup.php b/application/models/QuestionGroup.php
index 16a35aa3aef..7a1c60da4d1 100644
--- a/application/models/QuestionGroup.php
+++ b/application/models/QuestionGroup.php
@@ -110,21 +110,6 @@ function updateGroupOrder($sid,$lang,$position=0)
             }
         }
 
-        /**
-        * Insert an array into the groups table
-        * Returns false if insertion fails, otherwise the new GID
-        *
-        * @param array $data                           array_merge
-        */
-        public function insertRecords($data)
-        {
-            $group = new self;
-            foreach ($data as $k => $v)
-                $group->$k = $v;
-            if  (!$group->save()) return false;
-            else return $group->gid;
-        }
-
         function getGroups($surveyid) {
             $language = Survey::model()->findByPk($surveyid)->language;
             return Yii::app()->db->createCommand()
diff --git a/application/models/Survey.php b/application/models/Survey.php
index 95434f3e3c2..7b4e201ef7f 100644
--- a/application/models/Survey.php
+++ b/application/models/Survey.php
@@ -23,9 +23,12 @@
  */
 class Survey extends LSActiveRecord
 {
+    const FORMAT_GROUP = 'G';
+    const FORMAT_ALL_IN_ONE = 'A';
+    const FORMAT_QUESTION = 'S';
     private $_fieldMap;
     /* Set some setting not by default database */
-    public $format = 'G';
+    public $format = self::FORMAT_GROUP;
 
     public function attributeLabels() {
         return [
diff --git a/application/views/upgrade/database.php b/application/views/upgrade/database.php
index 02341a40206..5004d2f0f97 100644
--- a/application/views/upgrade/database.php
+++ b/application/views/upgrade/database.php
@@ -19,7 +19,7 @@
             'id' => 'abort', 
             'url' => App()->createUrl('upgrade/database', ['upgrade' => 'abort']),
             'color' => 'danger',
-            'confirm' => 'Are you sure you wisth to exist maintenance mode? Exiting maintenance mode without finishing database upgrades could result in a degraded user experience.'
+            'confirm' => 'Are you sure you wish to exist maintenance mode? Exiting maintenance mode without finishing database upgrades could result in a degraded user experience.'
         ]);
     }
 ?>