Elgg  Version 4.3
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(!$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
getVersion()
Version of the upgrade.This tells the date when the upgrade was added. It consists of eight digits an...
countItems()
The total number of items to process during the upgrade.If unknown, Batch::UNKNOWN_COUNT should be re...
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
Result of a single BatchUpgrade run.
Definition: Result.php:10
shouldBeSkipped()
Should this upgrade be skipped?If true, the upgrade will not be performed and cannot be accessed late...
static fromTable($table, $alias=null)
{}
Definition: Select.php:13
const ELGG_VALUE_STRING
Definition: constants.php:127
System upgrades are executed synchronously at system upgrade.
_elgg_services()
Get the global service provider.
Definition: elgglib.php:638
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