Installator =& $instance; } /** * Changes table structure, where multilingual fields of TEXT type are present * * @param string $mode when called mode {before, after) */ function Upgrade_4_1_0($mode) { if ($mode == 'before') { // don't user after, because In-Portal calls this method too $this->Installator->SaveConfig(); } if ($mode == 'after') { $ml_helper =& $this->Application->recallObject('kMultiLanguageHelper'); /* @var $ml_helper kMultiLanguageHelper */ $lang_count = $ml_helper->getLanguageCount(); $this->Application->UnitConfigReader->iterateConfigs(Array (&$this, 'updateTextFields'), $lang_count); } } /** * Moves ReplacementTags functionality from EmailMessage to Events table * * @param string $mode when called mode {before, after) */ function Upgrade_4_1_1($mode) { if ($mode == 'after') { $sql = 'SELECT ReplacementTags, EventId FROM '.TABLE_PREFIX.'EmailMessage WHERE (ReplacementTags IS NOT NULL) AND (ReplacementTags <> "") AND (LanguageId = 1)'; $replacement_tags = $this->Conn->GetCol($sql, 'EventId'); foreach ($replacement_tags as $event_id => $replacement_tag) { $sql = 'UPDATE '.TABLE_PREFIX.'Events SET ReplacementTags = '.$this->Conn->qstr($replacement_tag).' WHERE EventId = '.$event_id; $this->Conn->Query($sql); } // drop moved field from source table $sql = 'ALTER TABLE '.TABLE_PREFIX.'EmailMessage DROP `ReplacementTags`'; $this->Conn->Query($sql); } } /** * Callback function, that makes all ml fields of text type null with same default value * * @param string $prefix * @param Array $config_data * @param int $language_count * @return bool */ function updateTextFields($prefix, &$config_data, $language_count) { if (!isset($config_data['TableName']) || !isset($config_data['Fields'])) { // invalid config found or prefix not found return false; } $table_name = $config_data['TableName']; $table_structure = $this->Conn->Query('DESCRIBE '.$table_name, 'Field'); if (!$table_structure) { // table not found return false; } $sqls = Array (); foreach ($config_data['Fields'] as $field => $options) { if (isset($options['formatter']) && $options['formatter'] == 'kMultiLanguage' && !isset($options['master_field'])) { // update all l_ fields (new format) for ($i = 1; $i <= $language_count; $i++) { $ml_field = 'l'.$i.'_'.$field; if ($table_structure[$ml_field]['Type'] == 'text') { $sqls[] = 'CHANGE '.$ml_field.' '.$ml_field.' TEXT NULL DEFAULT NULL'; } } // update if found (old format) if (isset($table_structure[$field]) && $table_structure[$field]['Type'] == 'text') { $sqls[] = 'CHANGE '.$field.' '.$field.' TEXT NULL DEFAULT NULL'; } } } if ($sqls) { $sql = 'ALTER TABLE '.$table_name.' '.implode(', ', $sqls); $this->Conn->Query($sql); } return true; } /** * Replaces In-Portal tags in Forgot Password related email events to K4 ones * * @param string $mode when called mode {before, after) */ function Upgrade_4_2_0($mode) { if ($mode == 'after') { // 1. get event ids based on their name and type combination $event_names = Array ( 'USER.PSWD_'.EVENT_TYPE_ADMIN, 'USER.PSWD_'.EVENT_TYPE_FRONTEND, 'USER.PSWDC_'.EVENT_TYPE_FRONTEND, ); $event_sql = Array (); foreach ($event_names as $mixed_event) { list ($event_name, $event_type) = explode('_', $mixed_event, 2); $event_sql[] = 'Event = "'.$event_name.'" AND Type = '.$event_type; } $sql = 'SELECT EventId FROM '.TABLE_PREFIX.'Events WHERE ('.implode(') OR (', $event_sql).')'; $event_ids = implode(',', $this->Conn->GetCol($sql)); // 2. replace In-Portal tags to K4 tags $replacements = Array ( '' => '', '' => '', ); foreach ($replacements as $old_tag => $new_tag) { $sql = 'UPDATE '.TABLE_PREFIX.'EmailMessage SET Template = REPLACE(Template, '.$this->Conn->qstr($old_tag).', '.$this->Conn->qstr($new_tag).') WHERE EventId IN ('.$event_ids.')'; $this->Conn->Query($sql); } } } /** * Makes admin primary language same as front-end - not needed, done in SQL * * @param string $mode when called mode {before, after) */ function Upgrade_4_2_1($mode) { } function Upgrade_4_2_2($mode) { if ($mode == 'before') { if ($this->Conn->GetOne('SELECT LanguageId FROM '.TABLE_PREFIX.'Language WHERE PrimaryLang = 1')) return ; $this->Conn->Query('UPDATE '.TABLE_PREFIX.'Language SET PrimaryLang = 1 ORDER BY LanguageId LIMIT 1'); } } } ?>