Elgg  Version master
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 {
44  $select = Select::fromTable(MetadataTable::TABLE_NAME, MetadataTable::DEFAULT_JOIN_ALIAS);
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 {
60  $update = Update::table(MetadataTable::TABLE_NAME);
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 }
return[ 'admin/delete_admin_notices'=>['access'=> 'admin'], 'admin/menu/save'=>['access'=> 'admin'], 'admin/plugins/activate'=>['access'=> 'admin'], 'admin/plugins/activate_all'=>['access'=> 'admin'], 'admin/plugins/deactivate'=>['access'=> 'admin'], 'admin/plugins/deactivate_all'=>['access'=> 'admin'], 'admin/plugins/set_priority'=>['access'=> 'admin'], 'admin/security/security_txt'=>['access'=> 'admin'], 'admin/security/settings'=>['access'=> 'admin'], 'admin/security/regenerate_site_secret'=>['access'=> 'admin'], 'admin/site/cache/invalidate'=>['access'=> 'admin'], 'admin/site/flush_cache'=>['access'=> 'admin'], 'admin/site/icons'=>['access'=> 'admin'], 'admin/site/set_maintenance_mode'=>['access'=> 'admin'], 'admin/site/set_robots'=>['access'=> 'admin'], 'admin/site/theme'=>['access'=> 'admin'], 'admin/site/unlock_upgrade'=>['access'=> 'admin'], 'admin/site/settings'=>['access'=> 'admin'], 'admin/upgrade'=>['access'=> 'admin'], 'admin/upgrade/reset'=>['access'=> 'admin'], 'admin/user/ban'=>['access'=> 'admin'], 'admin/user/bulk/ban'=>['access'=> 'admin'], 'admin/user/bulk/delete'=>['access'=> 'admin'], 'admin/user/bulk/unban'=>['access'=> 'admin'], 'admin/user/bulk/validate'=>['access'=> 'admin'], 'admin/user/change_email'=>['access'=> 'admin'], 'admin/user/delete'=>['access'=> 'admin'], 'admin/user/login_as'=>['access'=> 'admin'], 'admin/user/logout_as'=>[], 'admin/user/makeadmin'=>['access'=> 'admin'], 'admin/user/resetpassword'=>['access'=> 'admin'], 'admin/user/removeadmin'=>['access'=> 'admin'], 'admin/user/unban'=>['access'=> 'admin'], 'admin/user/validate'=>['access'=> 'admin'], 'annotation/delete'=>[], 'avatar/upload'=>[], 'comment/save'=>[], 'diagnostics/download'=>['access'=> 'admin'], 'entity/chooserestoredestination'=>[], 'entity/delete'=>[], 'entity/mute'=>[], 'entity/restore'=>[], 'entity/subscribe'=>[], 'entity/trash'=>[], 'entity/unmute'=>[], 'entity/unsubscribe'=>[], 'login'=>['access'=> 'logged_out'], 'logout'=>[], 'notifications/mute'=>['access'=> 'public'], 'plugins/settings/remove'=>['access'=> 'admin'], 'plugins/settings/save'=>['access'=> 'admin'], 'plugins/usersettings/save'=>[], 'register'=>['access'=> 'logged_out', 'middleware'=>[\Elgg\Router\Middleware\RegistrationAllowedGatekeeper::class,],], 'river/delete'=>[], 'settings/notifications'=>[], 'settings/notifications/subscriptions'=>[], 'user/changepassword'=>['access'=> 'public'], 'user/requestnewpassword'=>['access'=> 'public'], 'useradd'=>['access'=> 'admin'], 'usersettings/save'=>[], 'widgets/add'=>[], 'widgets/delete'=>[], 'widgets/move'=>[], 'widgets/save'=>[],]
Definition: actions.php:73
if(empty($user_guids)) $users
Definition: ban.php:12
Entity table database service.
Definition: EntityTable.php:24
This class interfaces with the database to perform CRUD operations on metadata.
joinEntitiesTable(string $from_alias='', string $from_column='guid', ?string $join_type='inner', ?string $joined_alias=null)
Join entity table from alias and return joined table alias.
Query builder for fetching data from the database.
Definition: Select.php:8
Query builder for updating data in the database.
Definition: Update.php:8
Result of a single BatchUpgrade run.
Definition: Result.php:10
System upgrades are executed synchronously at system upgrade.
Change the metadata name of the user notification settings to be multi-purpose.
countItems()
The total number of items to process during the upgrade.If unknown, Batch::UNKNOWN_COUNT should be re...
getVersion()
Version of the upgrade.This tells the date when the upgrade was added. It consists of eight digits an...
shouldBeSkipped()
Should this upgrade be skipped?If true, the upgrade will not be performed and cannot be accessed late...
run(Result $result, $offset)
Runs upgrade on a single batch of items.If countItems() returns Batch::UNKNOWN_COUNT,...
needsIncrementOffset()
Should the run() method receive an offset representing all processed items?If true,...
const ELGG_VALUE_STRING
Definition: constants.php:112
_elgg_services()
Get the global service provider.
Definition: elgglib.php:353
if(empty($count)) $offset
Definition: pagination.php:26