Merge branch '5.2' into 5.3
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / acp / page / RebuildDataPage.class.php
1 <?php
2 namespace wcf\acp\page;
3 use wcf\data\object\type\ObjectTypeCache;
4 use wcf\page\AbstractPage;
5 use wcf\system\WCF;
6
7 /**
8 * Show the list of available rebuild data options.
9 *
10 * @author Marcel Werk
11 * @copyright 2001-2019 WoltLab GmbH
12 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
13 * @package WoltLabSuite\Core\Acp\Page
14 */
15 class RebuildDataPage extends AbstractPage {
16 /**
17 * @inheritDoc
18 */
19 public $activeMenuItem = 'wcf.acp.menu.link.maintenance.rebuildData';
20
21 /**
22 * disallow any rebuild actions unless `wcfN_user_storage` uses `utf8mb4`
23 * @var boolean
24 */
25 public $convertEncoding = false;
26
27 /**
28 * @inheritDoc
29 */
30 public $neededPermissions = ['admin.management.canRebuildData'];
31
32 /**
33 * object types
34 * @var array
35 */
36 public $objectTypes = [];
37
38 /**
39 * @inheritDoc
40 */
41 public function readData() {
42 parent::readData();
43
44 // get object types
45 $this->objectTypes = ObjectTypeCache::getInstance()->getObjectTypes('com.woltlab.wcf.rebuildData');
46
47 // sort object types
48 uasort($this->objectTypes, function ($a, $b) {
49 $niceValueA = ($a->nicevalue ?: 0);
50 $niceValueB = ($b->nicevalue ?: 0);
51
52 if ($niceValueA < $niceValueB) {
53 return -1;
54 }
55 else if ($niceValueA > $niceValueB) {
56 return 1;
57 }
58
59 return 0;
60 });
61
62 // We're disallowing rebuilding any other data unless the
63 // database encoding has been converted to utf8mb4. The
64 // user_storage table is used as a reference, as it is the
65 // last WCF table that holds a varchar column.
66 //
67 // Querying the columns for each table to reliably detect
68 // the need of an encoding conversion isn't an option, as
69 // it turns out to be super slow to retrieve this data.
70 $sql = "SHOW FULL COLUMNS FROM wcf".WCF_N."_user_storage";
71 $statement = WCF::getDB()->prepareStatement($sql);
72 $statement->execute();
73 while ($row = $statement->fetchArray()) {
74 if ($row['Field'] === 'field') {
75 if (preg_match('~^utf8mb4~', $row['Collation'])) {
76 $this->convertEncoding = true;
77 }
78 }
79 }
80 }
81
82 /**
83 * @inheritDoc
84 */
85 public function assignVariables() {
86 parent::assignVariables();
87
88 WCF::getTPL()->assign([
89 'convertEncoding' => $this->convertEncoding,
90 'objectTypes' => $this->objectTypes,
91 ]);
92 }
93 }