Elgg  Version 5.1
ChangeUserNotificationSettingsNamespace.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Upgrades;
4 
9 
16 
20  public function getVersion(): int {
21  return 2021040701;
22  }
23 
27  public function needsIncrementOffset(): bool {
28  return false;
29  }
30 
34  public function shouldBeSkipped(): bool {
35  return empty($this->countItems());
36  }
37 
41  public function countItems(): int {
42  $select = Select::fromTable('metadata', 'md');
43  $entities_table = $select->joinEntitiesTable('md', 'entity_guid');
44 
45  $select->select('count(*) AS total')
46  ->where($select->compare('md.name', 'like', 'notification:method:%', ELGG_VALUE_STRING))
47  ->andWhere($select->compare("{$entities_table}.type", '=', 'user', ELGG_VALUE_STRING));
48 
49  $result = _elgg_services()->db->getDataRow($select);
50 
51  return (int) $result->total;
52  }
53 
57  public function run(Result $result, $offset): Result {
58  $update = Update::table('metadata');
59  $update->set('name', 'REPLACE(name, "notification:method:", "notification:default:")')
60  ->where($update->compare('name', 'like', 'notification:method:%', ELGG_VALUE_STRING));
61 
62  $users = $update->subquery('entities');
63  $users->select('guid')
64  ->where($update->compare('type', '=', 'user', ELGG_VALUE_STRING));
65 
66  $update->andWhere($update->compare('entity_guid', 'in', $users->getSQL()));
67 
68  $num_rows = _elgg_services()->db->updateData($update, true);
69 
70  $result->addSuccesses($num_rows);
71 
72  return $result;
73  }
74 }
if(empty($user_guids)) $users
Definition: ban.php:12
static table($table, $alias=null)
{}
Definition: Update.php:13
if(empty($count)) $offset
Definition: pagination.php:26
Change the metadata name of the user notification settings to be multi-purpose.
addSuccesses(int $num=1)
Set an item (or items) as successfully upgraded.
Definition: Result.php:73
Result of a single BatchUpgrade run.
Definition: Result.php:10
static fromTable($table, $alias=null)
{}
Definition: Select.php:13
const ELGG_VALUE_STRING
Definition: constants.php:112
_elgg_services()
Get the global service provider.
Definition: elgglib.php:346
System upgrades are executed synchronously at system upgrade.