Elgg  Version 6.1
ChangeUserNotificationSettingsNamespace.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Upgrades;
4 
11 
18 
22  public function getVersion(): int {
23  return 2021040701;
24  }
25 
29  public function needsIncrementOffset(): bool {
30  return false;
31  }
32 
36  public function shouldBeSkipped(): bool {
37  return empty($this->countItems());
38  }
39 
43  public function countItems(): int {
45  $entities_table = $select->joinEntitiesTable($select->getTableAlias(), 'entity_guid');
46 
47  $select->select('count(*) AS total')
48  ->where($select->compare("{$select->getTableAlias()}.name", 'like', 'notification:method:%', ELGG_VALUE_STRING))
49  ->andWhere($select->compare("{$entities_table}.type", '=', 'user', ELGG_VALUE_STRING));
50 
51  $result = _elgg_services()->db->getDataRow($select);
52 
53  return (int) $result->total;
54  }
55 
59  public function run(Result $result, $offset): Result {
61  $update->set('name', 'REPLACE(name, "notification:method:", "notification:default:")')
62  ->where($update->compare('name', 'like', 'notification:method:%', ELGG_VALUE_STRING));
63 
64  $users = $update->subquery(EntityTable::TABLE_NAME);
65  $users->select('guid')
66  ->where($update->compare('type', '=', 'user', ELGG_VALUE_STRING));
67 
68  $update->andWhere($update->compare('entity_guid', 'in', $users->getSQL()));
69 
70  $num_rows = _elgg_services()->db->updateData($update, true);
71 
72  $result->addSuccesses($num_rows);
73 
74  return $result;
75  }
76 }
static table(string $table)
Returns a QueryBuilder for updating data in a given table.
Definition: Update.php:17
if(empty($user_guids)) $users
Definition: ban.php:12
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
const ELGG_VALUE_STRING
Definition: constants.php:112
static fromTable(string $table, string $alias=null)
Returns a QueryBuilder for selecting data from a given table.
Definition: Select.php:18
_elgg_services()
Get the global service provider.
Definition: elgglib.php:353
System upgrades are executed synchronously at system upgrade.