2 use wcf\system\package\SplitNodeException
;
4 use wcf\util\StringUtil
;
7 * Adds database columns, each row in the data section
8 * below is executed in a separate request.
10 * @author Alexander Ebert
11 * @copyright 2001-2018 WoltLab GmbH
12 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
13 * @package WoltLabSuite\Core\Conversation
16 ALTER TABLE wcf1_conversation_to_user ADD COLUMN joinedAt INT(10) NOT NULL DEFAULT 0, ADD COLUMN leftAt INT(10) NOT NULL DEFAULT 0, ADD COLUMN lastMessageID INT(10) NULL;
19 $lines = explode("\n", StringUtil
::trim($data));
21 $rebuildData = WCF
::getSession()->getVar('__wcfConversationUpdateAddColumns');
22 if ($rebuildData === null) {
25 'max' => count($lines)
29 // MySQL adds a column by creating a new table in the
30 // background and copying over all the data afterwards.
32 // Using a single `ALTER TABLE` to add multiple columns
33 // results in the same runtime, because copying the table
34 // is what actually takes ages.
35 $statement = WCF
::getDB()->prepareStatement(str_replace('wcf1_', 'wcf'.WCF_N
.'_', $lines[$rebuildData['i']]));
36 $statement->execute();
40 if ($rebuildData['i'] === $rebuildData['max']) {
41 WCF
::getSession()->unregister('__wcfConversationUpdateAddColumns');
44 WCF
::getSession()->register('__wcfConversationUpdateAddColumns', $rebuildData);
46 // call this script again
47 throw new SplitNodeException();