diff options
Diffstat (limited to 'phpBB/install/database_update.php')
| -rw-r--r-- | phpBB/install/database_update.php | 66 | 
1 files changed, 64 insertions, 2 deletions
diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index 83bbbf4577..019469b061 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -880,7 +880,7 @@ function database_update_info()  					'pm_id'			=> array('pm_id'),  				),  				POSTS_TABLE			=> array( -					'post_username'		=> array('post_username'), +					'post_username'		=> array('post_username:255'),  				),  			),  		), @@ -1749,6 +1749,52 @@ function change_database_data(&$no_updates, $version)  			_sql($sql, $errored, $error_ary);  			// end Bing Bot addition +			// Delete shadow topics pointing to not existing topics +			$batch_size = 500; + +			// Set of affected forums we have to resync +			$sync_forum_ids = array(); + +			do +			{ +				$sql_array = array( +					'SELECT'	=> 't1.topic_id, t1.forum_id', +					'FROM'		=> array( +						TOPICS_TABLE	=> 't1', +					), +					'LEFT_JOIN'	=> array( +						array( +							'FROM'	=> array(TOPICS_TABLE	=> 't2'), +							'ON'	=> 't1.topic_moved_id = t2.topic_id', +						), +					), +					'WHERE'		=> 't1.topic_moved_id <> 0 +								AND t2.topic_id IS NULL', +				); +				$sql = $db->sql_build_query('SELECT', $sql_array); +				$result = $db->sql_query_limit($sql, $batch_size); + +				$topic_ids = array(); +				while ($row = $db->sql_fetchrow($result)) +				{ +					$topic_ids[] = (int) $row['topic_id']; + +					$sync_forum_ids[(int) $row['forum_id']] = (int) $row['forum_id']; +				} +				$db->sql_freeresult($result); + +				if (!empty($topic_ids)) +				{ +					$sql = 'DELETE FROM ' . TOPICS_TABLE . ' +						WHERE ' . $db->sql_in_set('topic_id', $topic_ids); +					$db->sql_query($sql); +				} +			} +			while (sizeof($topic_ids) == $batch_size); + +			// Sync the forums we have deleted shadow topics from. +			sync('forum', 'forum_id', $sync_forum_ids, true, true); +  			$no_updates = false;  		break;  	} @@ -2095,7 +2141,7 @@ class updater_db_tools  	*	drop_columns: Removing/Dropping columns  	*	add_primary_keys: adding primary keys  	*	add_unique_index: adding an unique index -	*	add_index: adding an index +	*	add_index: adding an index (can be column:index_size if you need to provide size)  	*  	* The values are in this format:  	*		{TABLE NAME}		=> array( @@ -3474,6 +3520,12 @@ class updater_db_tools  	{  		$statements = array(); +		// remove index length unless MySQL4 +		if ('mysql_40' != $this->sql_layer) +		{ +			$column = preg_replace('#:.*$#', '', $column); +		} +  		switch ($this->sql_layer)  		{  			case 'firebird': @@ -3484,6 +3536,16 @@ class updater_db_tools  			break;  			case 'mysql_40': +				// add index size to definition as required by MySQL4 +				foreach ($column as $i => $col) +				{ +					if (false !== strpos($col, ':')) +					{ +						list($col, $index_size) = explode(':', $col); +						$column[$i] = "$col($index_size)"; +					} +				} +			// no break  			case 'mysql_41':  				$statements[] = 'CREATE INDEX ' . $index_name . ' ON ' . $table_name . '(' . implode(', ', $column) . ')';  			break;  | 
