Elgg  Version master
MigrateACLNotificationPreferences.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Upgrades;
4 
8 
16 
20  public function getVersion(): int {
21  return 2021040801;
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 {
43  'type' => 'user',
44  'count' => true,
45  'wheres' => [
46  function(QueryBuilder $qb, $main_alias) {
47  return $qb->compare("{$main_alias}.name", 'like', 'collections_notifications_preferences_%', ELGG_VALUE_STRING);
48  },
49  ],
50  ]);
51  }
52 
56  public function run(Result $result, $offset): Result {
58  'type' => 'user',
59  'limit' => 50,
60  'offset' => $offset,
61  'wheres' => [
62  function(QueryBuilder $qb, $main_alias) {
63  return $qb->compare("{$main_alias}.name", 'like', 'collections_notifications_preferences_%', ELGG_VALUE_STRING);
64  },
65  ],
66  ]);
67 
68  $remove_md = function (\ElggMetadata $md) use (&$result) {
69  if ($md->delete()) {
70  $result->addSuccesses();
71  } else {
72  $result->addFailures();
73  }
74  };
75 
76  /* @var $md \ElggMetadata */
77  foreach ($metadata as $md) {
78  if ($md->value !== -1) {
79  // preference for an access collection which isn't migrated
80  $remove_md($md);
81  continue;
82  }
83 
84  $method = substr($md->name, strlen('collections_notifications_preferences_'));
85  $user = $md->getEntity();
86  if ($user instanceof \ElggUser) {
87  // only truthy values were saved
88  $user->setNotificationSetting($method, true, 'friends');
89  }
90 
91  $remove_md($md);
92  }
93 
94  return $result;
95  }
96 }
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
$user
Definition: ban.php:7
ElggMetadata.
Database abstraction query builder.
Class to extend for asynchronous upgrades, i.e.
Result of a single BatchUpgrade run.
Definition: Result.php:10
Migrate the old access collection notification preferences to the new logic The old settings are from...
shouldBeSkipped()
Should this upgrade be skipped?If true, the upgrade will not be performed and cannot be accessed late...
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,...
getVersion()
Version of the upgrade.This tells the date when the upgrade was added. It consists of eight digits an...
run(Result $result, $offset)
Runs upgrade on a single batch of items.If countItems() returns Batch::UNKNOWN_COUNT,...
const ELGG_VALUE_STRING
Definition: constants.php:112
elgg_get_metadata(array $options=[])
Fetch metadata or perform a calculation on them.
Definition: metadata.php:32
if(empty($count)) $offset
Definition: pagination.php:26
$qb
Definition: queue.php:12
$metadata
Output annotation metadata.
Definition: metadata.php:9