13 private $utf8mb4_tables = [
15 'access_collection_membership',
21 'entity_relationships',
27 'users_remember_me_cookies',
39 private $non_mb4_columns = [
78 'name' =>
'object_class',
83 'name' =>
'object_type',
88 'name' =>
'object_subtype',
98 'name' =>
'river_key',
100 'columns' => [
'object_type',
'object_subtype',
'event']
125 $rows =
elgg()->db->getData(
"SHOW TABLE STATUS FROM `{$config['database']}`");
127 $prefixed_table_names = array_map(
function ($t) use (
$config) {
128 return "{$config['prefix']}{$t}";
129 }, $this->utf8mb4_tables);
131 foreach (
$rows as $row) {
132 if (in_array($row->Name, $prefixed_table_names) && $row->Collation !==
'utf8mb4_general_ci') {
156 $row =
elgg()->db->getDataRow(
"SHOW GLOBAL VARIABLES LIKE 'innodb_large_prefix'");
158 if (empty($row) || $row->Value ===
'OFF') {
160 elgg()->db->updateData(
"SET GLOBAL innodb_large_prefix = 'ON'");
165 $result->
addError(
"Failure to set 'innodb_large_prefix'. Ask your database administrator for more information.");
166 $result->
addError(
"Alternatively ask the database administrator to (temporarily) set 'innodb_large_prefix' to 'ON'.");
167 $result->
addError($e->getMessage());
174 elgg()->db->updateData(
" 176 `{$config['database']}` 177 CHARACTER SET = utf8mb4 178 COLLATE = utf8mb4_unicode_ci 181 foreach ($this->utf8mb4_tables as
$table) {
182 if (!empty($this->non_mb4_columns[$table])) {
183 foreach ($this->non_mb4_columns[$table] as
$column =>
$index) {
186 elgg()->db->updateData(
" 187 ALTER TABLE {$config['prefix']}{$table} 191 elgg()->db->updateData(
" 192 ALTER TABLE {$config['prefix']}{$table} 193 DROP KEY {$index['name']} 200 elgg()->db->updateData(
" 201 ALTER TABLE {$config['prefix']}{$table} 205 elgg()->db->updateData(
" 206 ALTER TABLE {$config['prefix']}{$table} 207 CONVERT TO CHARACTER SET utf8mb4 208 COLLATE utf8mb4_general_ci 211 if (!empty($this->non_mb4_columns[$table])) {
212 foreach ($this->non_mb4_columns[$table] as
$column =>
$index) {
213 if (empty(
$index[
'columns'])) {
215 elgg()->db->updateData(
" 216 ALTER TABLE {$config['prefix']}{$table} 217 MODIFY $column VARCHAR(255) 219 COLLATE utf8_unicode_ci 229 $sql .=
" UNIQUE ({$index['name']})";
230 }
else if (
$index[
'primary']) {
231 $sql .=
" PRIMARY KEY ({$index['name']})";
234 $key_columns = implode(
',', $key_columns);
235 $sql .=
" KEY {$index['name']} ($key_columns)";
238 elgg()->db->updateData(
" 239 ALTER TABLE {$config['prefix']}{$table} 247 $result->
addError($e->getMessage());
Updates database charset to utf8mb4.
Interface to be implement for asynchronous upgrades, i.e.
getVersion()
{Version of the upgrade.This tells the date when the upgrade was added. It consists of eight digits a...
countItems()
{The total number of items to process during the upgrade.If unknown, Batch::UNKNOWN_COUNT should be r...
shouldBeSkipped()
{Should this upgrade be skipped?If true, the upgrade will not be performed and cannot be accessed lat...
addSuccesses($num=1)
Set an item (or items) as successfully upgraded.
$config
Advanced site settings, debugging section.
addFailures($num=1)
Increment failure count.
addError($message)
Add new error message to the batch.
Result of a single BatchUpgrade run.
elgg_extract($key, $array, $default=null, $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
_elgg_services()
Get the global service provider.
needsIncrementOffset()
{Should the run() method receive an offset representing all processed items?If true, run() will receive as $offset the number of items already processed. This is useful if you are only modifying data, and need to use the $offset in a function like elgg_get_entities*() to know how many to skip over.If false, run() will receive as $offset the total number of failures. This should be used if your process deletes or moves data out of the way of the process. E.g. if you delete 50 objects on each run(), you may still use the $offset to skip objects that already failed once.bool}
run(Result $result, $offset)
{Runs upgrade on a single batch of items.If countItems() returns Batch::UNKNOWN_COUNT, this method must call $result->markCompleted() when the upgrade is complete.Result of the batch (this must be returned) Number to skip when processingResult}