Index: branches/5.2.x/core/install.php =================================================================== diff -u -r16797 -r16813 --- branches/5.2.x/core/install.php (.../install.php) (revision 16797) +++ branches/5.2.x/core/install.php (.../install.php) (revision 16813) @@ -1,6 +1,6 @@ Conn->Query( 'ALTER TABLE ' . TABLE_PREFIX . 'UserSessionData - CHANGE `SessionKey` `SessionId` int unsigned NOT NULL DEFAULT "0"' + CHANGE `SessionKey` `SessionId` bigint unsigned NOT NULL DEFAULT "0"' ); } Index: branches/5.2.x/core/units/helpers/language_import_helper.php =================================================================== diff -u -r16513 -r16813 --- branches/5.2.x/core/units/helpers/language_import_helper.php (.../language_import_helper.php) (revision 16513) +++ branches/5.2.x/core/units/helpers/language_import_helper.php (.../language_import_helper.php) (revision 16813) @@ -1,6 +1,6 @@ Conn->qstrArray($to_insert); - $sql = 'INSERT INTO ' . $this->Application->getUnitOption($prefix, 'TableName') . ' + $sql = 'INSERT INTO `' . $this->Application->getUnitOption($prefix, 'TableName') . '` SELECT * - FROM ' . $this->_tables[$prefix] . ' + FROM `' . $this->_tables[$prefix] . '` WHERE ' . $unique_field . ' IN (' . implode(',', $to_insert) . ')'; $this->Conn->Query($sql); @@ -569,7 +569,7 @@ $sql .= ' live.' . $data_field . ' = ( SELECT temp' . $index . '.' . $data_field . ' - FROM ' . $this->_tables[$prefix] . ' temp' . $index . ' + FROM `' . $this->_tables[$prefix] . '` temp' . $index . ' WHERE temp' . $index . '.' . $unique_field . ' = live.' . $unique_field . ' ),'; } @@ -618,13 +618,13 @@ if ($temp_mode) { // for temp table get only records, that have contents on given language (not empty and isset) $sql = 'SELECT ' . $unique_field . ' - FROM ' . $this->Application->GetTempName($table_name, 'prefix:' . $prefix) . ' + FROM `' . $this->_tables[$prefix] . '` WHERE (' . $data_field . ' <> "") AND (' . $data_field . ' IS NOT NULL)'; } else { // for live table get all records, no matter on what language $sql = 'SELECT ' . $unique_field . ' - FROM ' . $table_name; + FROM `' . $table_name . '`'; } return $this->Conn->GetCol($sql); @@ -679,42 +679,51 @@ */ protected function _prepareTempTable($prefix, $drop_only = false) { - $id_field = $this->Application->getUnitOption($prefix, 'IDField'); - $table = $this->Application->getUnitOption($prefix,'TableName'); - $temp_table = $this->Application->GetTempName($table); + $table = $this->Application->getUnitOption($prefix, 'TableName'); - $sql = 'DROP TABLE IF EXISTS %s'; - $this->Conn->Query( sprintf($sql, $temp_table) ); + if ( $drop_only ) { + // Drop table, that was previously created. + $temp_table = $this->_tables[$prefix]; + } + else { + $temp_table = sprintf($table . '_%s_%s', time(), SecurityGenerator::generateBytes(8)); + } - if (!$drop_only) { - $sql = 'CREATE TABLE ' . $temp_table . ' SELECT * FROM ' . $table . ' WHERE 0'; - $this->Conn->Query($sql); + $sql = 'DROP TABLE IF EXISTS `%s`'; + $this->Conn->Query(sprintf($sql, $temp_table)); - $sql = 'ALTER TABLE %1$s CHANGE %2$s %2$s INT(11) NOT NULL DEFAULT "0"'; - $this->Conn->Query( sprintf($sql, $temp_table, $id_field) ); + if ( $drop_only ) { + return $temp_table; + } - switch ($prefix) { - case 'phrases': - $unique_field = 'PhraseKey'; - break; + $sql = 'CREATE TABLE `' . $temp_table . '` SELECT * FROM `' . $table . '` WHERE 0'; + $this->Conn->Query($sql); - case 'email-template': - $unique_field = 'TemplateId'; - break; + $id_field = $this->Application->getUnitOption($prefix, 'IDField'); + $sql = 'ALTER TABLE `%1$s` CHANGE %2$s %2$s INT(11) NOT NULL DEFAULT "0"'; + $this->Conn->Query(sprintf($sql, $temp_table, $id_field)); - case 'country-state': - $unique_field = 'CountryStateId'; - break; + switch ( $prefix ) { + case 'phrases': + $unique_field = 'PhraseKey'; + break; - default: - throw new Exception('Unknown prefix "' . $prefix . '" during language pack import'); - break; - } + case 'email-template': + $unique_field = 'TemplateId'; + break; - $sql = 'ALTER TABLE ' . $temp_table . ' ADD UNIQUE (' . $unique_field . ')'; - $this->Conn->Query($sql); + case 'country-state': + $unique_field = 'CountryStateId'; + break; + + default: + throw new Exception('Unknown prefix "' . $prefix . '" during language pack import'); + break; } + $sql = 'ALTER TABLE `' . $temp_table . '` ADD UNIQUE (' . $unique_field . ')'; + $this->Conn->Query($sql); + return $temp_table; } Index: branches/5.2.x/core/units/categories/cache_updater.php =================================================================== diff -u -r16513 -r16813 --- branches/5.2.x/core/units/categories/cache_updater.php (.../cache_updater.php) (revision 16513) +++ branches/5.2.x/core/units/categories/cache_updater.php (.../cache_updater.php) (revision 16813) @@ -1,6 +1,6 @@ CatId. ', ' .$perm. ', "' .join(',', $groups). '")'; } } - if (!$values) return ''; - $sql = 'INSERT INTO '.$this->table.' (CategoryId, PermId, ACL) VALUES '.join(',', $values); - return $sql; + + if ( !$values ) { + return ''; + } + + return 'INSERT INTO `' . $this->table . '` (CategoryId, PermId, ACL) VALUES ' . join(',', $values); } } @@ -235,9 +238,22 @@ } $this->iteration = 0; - $this->progressTable = $this->Application->GetTempName('permCacheUpdate'); - $this->permCacheTable = $this->Application->GetTempName(TABLE_PREFIX.'CategoryPermissionsCache'); + if ( PHP_SAPI === 'cli' ) { + // The progress bar isn't used. + $this->progressTable = sprintf('permCacheUpdate_%s_%s', time(), SecurityGenerator::generateBytes(8)); + $this->permCacheTable = sprintf( + TABLE_PREFIX . 'CategoryPermissionsCache_%s_%s', + time(), + SecurityGenerator::generateBytes(8) + ); + } + else { + // Temporary table name must be the same between redirects for progress bar to work. + $this->progressTable = $this->Application->GetTempName('permCacheUpdate'); + $this->permCacheTable = $this->Application->GetTempName(TABLE_PREFIX . 'CategoryPermissionsCache'); + } + if (!isset($continuing) || $continuing == 1) { $this->InitUpdater(); } @@ -262,9 +278,12 @@ function getData() { - $tmp = $this->Conn->GetOne('SELECT data FROM '.$this->progressTable); - if ($tmp) $tmp = unserialize($tmp); + $tmp = $this->Conn->GetOne('SELECT data FROM `' . $this->progressTable . '`'); + if ( $tmp ) { + $tmp = unserialize($tmp); + } + $this->totalCats = isset($tmp['totalCats']) ? $tmp['totalCats'] : 0; $this->doneCats = isset($tmp['doneCats']) ? $tmp['doneCats'] : 0; if (isset($tmp['stack'])) { @@ -283,7 +302,7 @@ 'stack' => $this->Stack, ); - $this->Conn->Query('DELETE FROM '.$this->progressTable); + $this->Conn->Query('DELETE FROM `' . $this->progressTable . '`'); $fields_hash = Array('data' => serialize($tmp)); $this->Conn->doInsert($fields_hash, $this->progressTable); @@ -294,27 +313,34 @@ $this->clearData(); // drop table before starting anyway // 1. create table for rebuilding permissions cache - $this->Conn->Query('CREATE TABLE '.$this->permCacheTable.' LIKE '.TABLE_PREFIX.'CategoryPermissionsCache'); + $this->Conn->Query( + 'CREATE TABLE `' . $this->permCacheTable . '` LIKE `' . TABLE_PREFIX . 'CategoryPermissionsCache`' + ); - if ($this->StrictPath) { - // when using strict path leave all other cache intact - $sql = 'INSERT INTO '.$this->permCacheTable.' + if ( $this->StrictPath ) { + // When using strict path leave all other cache intact. + $sql = 'INSERT INTO `' . $this->permCacheTable . '` SELECT * - FROM '.TABLE_PREFIX.'CategoryPermissionsCache'; + FROM `' . TABLE_PREFIX . 'CategoryPermissionsCache`'; $this->Conn->Query($sql); - // delete only cache related to categories in path - $sql = 'DELETE FROM '.$this->permCacheTable.' - WHERE CategoryId IN ('.implode(',', $this->StrictPath).')'; + // Delete only cache related to categories in path. + $sql = 'DELETE FROM `' . $this->permCacheTable . '` + WHERE CategoryId IN (' . implode(',', $this->StrictPath) . ')'; $this->Conn->Query($sql); } $add_charset = defined(SQL_CHARSET)? ' CHARACTER SET '.SQL_CHARSET.' ' : ''; $add_collation = defined(SQL_COLLATION)? ' COLLATE '.SQL_COLLATION.' ' : ''; - $this->Conn->Query('CREATE TABLE '.$this->progressTable.'(data LONGTEXT'.$add_charset.$add_collation.') '.$add_charset.$add_collation); + $this->Conn->Query(sprintf( + 'CREATE TABLE `%1$s` (data LONGTEXT%2$s%3$s) %2$s%3$s', + $this->progressTable, + $add_charset, + $add_collation + )); - $this->totalCats = (int)$this->Conn->GetOne('SELECT COUNT(*) FROM '.TABLE_PREFIX.'Categories'); + $this->totalCats = (int)$this->Conn->GetOne('SELECT COUNT(*) FROM `' . TABLE_PREFIX . 'Categories`'); $this->doneCats = 0; } @@ -326,9 +352,9 @@ WHERE VariableName = "CategoriesRebuildSerial"'; $this->Conn->Query($sql); - // always drop temporary tables - $this->Conn->Query('DROP TABLE IF EXISTS '.$this->progressTable); - $this->Conn->Query('DROP TABLE IF EXISTS '.$this->permCacheTable); + // Always drop temporary tables. + $this->Conn->Query('DROP TABLE IF EXISTS `' . $this->progressTable . '`'); + $this->Conn->Query('DROP TABLE IF EXISTS `' . $this->permCacheTable . '`'); $this->Application->deleteDBCache('ForcePermCacheUpdate'); } @@ -337,9 +363,9 @@ // copy data from temp permission cache table back to live $this->Conn->Query('TRUNCATE '.TABLE_PREFIX.'CategoryPermissionsCache'); - $sql = 'INSERT INTO '.TABLE_PREFIX.'CategoryPermissionsCache + $sql = 'INSERT INTO `' . TABLE_PREFIX . 'CategoryPermissionsCache` SELECT * - FROM '.$this->permCacheTable; + FROM `' . $this->permCacheTable . '`'; $this->Conn->Query($sql); $this->clearData(); Index: branches/5.2.x/core/kernel/session/session_storage.php =================================================================== diff -u -r16797 -r16813 --- branches/5.2.x/core/kernel/session/session_storage.php (.../session_storage.php) (revision 16797) +++ branches/5.2.x/core/kernel/session/session_storage.php (.../session_storage.php) (revision 16813) @@ -1,7 +1,7 @@ DeleteSessions( Array ($this->GetID()), SESSION_LOG_LOGGED_OUT ); + try { + $this->DeleteSessions(array($this->GetID()), SESSION_LOG_LOGGED_OUT); + } + catch ( RuntimeException $e ) { + // Session is deleted from the database already by the time we attempt to delete it. + } $this->DirectVars = $this->ChangedDirectVars = $this->OriginalData = Array(); }