Fix title of data section when editing conversation label
[GitHub/WoltLab/com.woltlab.wcf.conversation.git] / files / acp / update_com.woltlab.wcf.conversation_3.1_addColumn.php
1 <?php
2 use wcf\system\package\SplitNodeException;
3 use wcf\system\WCF;
4 use wcf\util\StringUtil;
5
6 /**
7 * Adds database columns, each row in the data section
8 * below is executed in a separate request.
9 *
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
14 */
15 $data = <<<DATA
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;
17 DATA;
18
19 $lines = explode("\n", StringUtil::trim($data));
20
21 $rebuildData = WCF::getSession()->getVar('__wcfConversationUpdateAddColumns');
22 if ($rebuildData === null) {
23 $rebuildData = [
24 'i' => 0,
25 'max' => count($lines)
26 ];
27 }
28
29 // MySQL adds a column by creating a new table in the
30 // background and copying over all the data afterwards.
31 //
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();
37
38 $rebuildData['i']++;
39
40 if ($rebuildData['i'] === $rebuildData['max']) {
41 WCF::getSession()->unregister('__wcfConversationUpdateAddColumns');
42 }
43 else {
44 WCF::getSession()->register('__wcfConversationUpdateAddColumns', $rebuildData);
45
46 // call this script again
47 throw new SplitNodeException();
48 }