From d8fca6b404335087b516792064cda4a9b87b23b4 Mon Sep 17 00:00:00 2001 From: Peter Rotich <peter@enhancesoft.com> Date: Wed, 18 Feb 2015 14:43:20 +0000 Subject: [PATCH] upgrader: Fix upgrade bugs from old versions --- css/filedrop.css | 1 + css/redactor.css | 2 +- include/class.dynamic_forms.php | 36 +++++++++---------- include/class.i18n.php | 2 ++ include/class.organization.php | 2 +- include/class.orm.php | 8 ++--- include/class.staff.php | 4 ++- include/class.thread.php | 5 +-- include/class.upgrader.php | 3 +- .../streams/core/2d590ffa-9143a511.patch.sql | 5 +-- .../streams/core/5cd0a25a-2d590ffa.task.php | 2 +- scp/css/scp.css | 2 +- 12 files changed, 40 insertions(+), 32 deletions(-) diff --git a/css/filedrop.css b/css/filedrop.css index 7c11f8a2a..67512b1cf 100644 --- a/css/filedrop.css +++ b/css/filedrop.css @@ -75,6 +75,7 @@ .tooltip-preview img { max-width: 300px; max-height: 300px; + z-index:11; } /* Bootstrap 3.2 progress-bar */ diff --git a/css/redactor.css b/css/redactor.css index c77113360..dd2b3d91e 100644 --- a/css/redactor.css +++ b/css/redactor.css @@ -61,7 +61,7 @@ } .redactor-toolbar, .redactor-dropdown { - z-index: 5 !important; + z-index: 1 !important; } #redactor-modal-overlay, #redactor-modal-box, diff --git a/include/class.dynamic_forms.php b/include/class.dynamic_forms.php index 833eb318b..8baf336e4 100644 --- a/include/class.dynamic_forms.php +++ b/include/class.dynamic_forms.php @@ -223,23 +223,25 @@ class DynamicForm extends VerySimpleModel { return false; } // New translations (?) - foreach ($vars['trans'] as $lang=>$parts) { - if (!Internationalization::isLanguageInstalled($lang)) - continue; - foreach ($parts as $T => $content) { - $content = trim($content); - if (!$content) + if ($vars['trans'] && is_array($vars['trans'])) { + foreach ($vars['trans'] as $lang=>$parts) { + if (!Internationalization::isLanguageInstalled($lang)) continue; - $t = CustomDataTranslation::create(array( - 'type' => 'phrase', - 'object_hash' => $tags[$T], - 'lang' => $lang, - 'text' => $content, - 'agent_id' => $thisstaff->getId(), - 'updated' => SqlFunction::NOW(), - )); - if (!$t->save()) - return false; + foreach ($parts as $T => $content) { + $content = trim($content); + if (!$content) + continue; + $t = CustomDataTranslation::create(array( + 'type' => 'phrase', + 'object_hash' => $tags[$T], + 'lang' => $lang, + 'text' => $content, + 'agent_id' => $thisstaff->getId(), + 'updated' => SqlFunction::NOW(), + )); + if (!$t->save()) + return false; + } } } return true; @@ -790,8 +792,6 @@ class DynamicFormEntry extends VerySimpleModel { 'ordering' => array('sort'), 'pk' => array('id'), 'select_related' => array('form'), - 'fields' => array('id', 'form_id', 'object_type', 'object_id', - 'sort', 'extra', 'updated', 'created'), 'joins' => array( 'form' => array( 'null' => true, diff --git a/include/class.i18n.php b/include/class.i18n.php index 4b764717a..e0fcd9e11 100644 --- a/include/class.i18n.php +++ b/include/class.i18n.php @@ -382,6 +382,8 @@ class Internationalization { static function getCurrentLocale() { global $thisstaff, $cfg; + // FIXME: Move this majic elsewhere - see upgrade bug note in + // class.staff.php if ($thisstaff) { return $thisstaff->getLocale() ?: self::getCurrentLanguage(); diff --git a/include/class.organization.php b/include/class.organization.php index 05b23ca12..e13329507 100644 --- a/include/class.organization.php +++ b/include/class.organization.php @@ -370,7 +370,7 @@ class Organization extends OrganizationModel { $org->addDynamicData($vars); } - Signal::send('organization.created', $user); + Signal::send('organization.created', $org); return $org; } diff --git a/include/class.orm.php b/include/class.orm.php index 0e0568e44..c004ab455 100644 --- a/include/class.orm.php +++ b/include/class.orm.php @@ -484,9 +484,6 @@ class AnnotatedModel { function __call($what, $how) { return call_user_func_array(array($this->model, $what), $how); } - static function __callStatic($what, $how) { - return call_user_func_array(array($this->model, $what), $how); - } } class SqlFunction { @@ -1783,6 +1780,9 @@ class MySqlCompiler extends SqlCompiler { elseif ($what instanceof SqlFunction) { return $what->toSql($this); } + elseif (!isset($what)) { + return 'NULL'; + } else { switch ($slot) { case self::SLOT_JOINS: @@ -2076,7 +2076,7 @@ class MySqlCompiler extends SqlCompiler { $set = implode(', ', $set); list($where, $having) = $this->getWhereHavingClause($queryset); $joins = $this->getJoins($queryset); - $sql = 'UPDATE '.$this->quote($table).' SET '.$set.$joins.$where; + $sql = 'UPDATE '.$this->quote($table).$joins.' SET '.$set.$where; return new MysqlExecutor($sql, $this->params); } diff --git a/include/class.staff.php b/include/class.staff.php index 57e0ee30b..955785bd8 100644 --- a/include/class.staff.php +++ b/include/class.staff.php @@ -302,7 +302,9 @@ implements AuthenticatedUser, EmailContact { } function getLocale() { - return $this->locale; + //XXX: isset is required here to avoid possible crash when upgrading + // installation where locale column doesn't exist yet. + return isset($this->locale) ? $this->locale : 0; } function getRole($dept=null) { diff --git a/include/class.thread.php b/include/class.thread.php index de87e5819..e90fc095f 100644 --- a/include/class.thread.php +++ b/include/class.thread.php @@ -609,7 +609,7 @@ class ThreadEntry extends VerySimpleModel { if(!$file['error'] && ($F=AttachmentFile::upload($file)) && $this->saveAttachment($F)) - $uploaded[]=$id; + $uploaded[]= $F->getId(); else { if(!$file['error']) $error = sprintf(__('Unable to upload file - %s'),$file['name']); @@ -1099,7 +1099,8 @@ class ThreadEntry extends VerySimpleModel { // Inline images (attached to the draft) $entry->saveAttachments(Draft::getAttachmentIds($body)); - Signal::send('threadentry.created', $this); + Signal::send('threadentry.created', $entry); + return $entry; } diff --git a/include/class.upgrader.php b/include/class.upgrader.php index 6246e542d..63fba34d8 100644 --- a/include/class.upgrader.php +++ b/include/class.upgrader.php @@ -348,7 +348,8 @@ class StreamUpgrader extends SetupWizard { if (!isset($this->task)) { $class = (include $task_file); if (!is_string($class) || !class_exists($class)) - return $ost->logError("Bogus migration task", "{$this->phash}:{$class}") ; + return $ost->logError("Bogus migration task", + "{$this->phash}:{$class}"); //FIXME: This can cause crash $this->task = new $class(); if (isset($_SESSION['ost_upgrader']['task'][$this->phash])) $this->task->wakeup($_SESSION['ost_upgrader']['task'][$this->phash]); diff --git a/include/upgrader/streams/core/2d590ffa-9143a511.patch.sql b/include/upgrader/streams/core/2d590ffa-9143a511.patch.sql index f52e0bb25..2ef827545 100644 --- a/include/upgrader/streams/core/2d590ffa-9143a511.patch.sql +++ b/include/upgrader/streams/core/2d590ffa-9143a511.patch.sql @@ -34,8 +34,9 @@ ALTER TABLE `%TABLE_PREFIX%thread_entry` ADD `flags` int(11) unsigned NOT NULL default '0' AFTER `type`; -- Set the ORIGINAL_MESSAGE flag to all the first messages of each thread -CREATE TABLE `%TABLE_PREFIX%_orig_msg_ids` AS -SELECT min(id) AS id FROM `%TABLE_PREFIX%thread_entry` +CREATE TABLE `%TABLE_PREFIX%_orig_msg_ids` + (id INT NOT NULL, PRIMARY KEY (id)) + SELECT min(id) as id FROM `%TABLE_PREFIX%thread_entry` WHERE type = 'M' GROUP BY thread_id; diff --git a/include/upgrader/streams/core/5cd0a25a-2d590ffa.task.php b/include/upgrader/streams/core/5cd0a25a-2d590ffa.task.php index 0379bd4be..f18c0cab9 100644 --- a/include/upgrader/streams/core/5cd0a25a-2d590ffa.task.php +++ b/include/upgrader/streams/core/5cd0a25a-2d590ffa.task.php @@ -1,6 +1,6 @@ <?php -class InstructionPorter extends MigrationTask { +class InstructionsPorter extends MigrationTask { var $description = "Converting custom form instructions to HTML"; function run($max_time) { diff --git a/scp/css/scp.css b/scp/css/scp.css index f9296da91..e687b82be 100644 --- a/scp/css/scp.css +++ b/scp/css/scp.css @@ -1440,7 +1440,7 @@ time { bottom:0; left:0; right:0; - z-index:1; + z-index:11; } .redactor-editor { -- GitLab