Elgg  Version master
MigrateAdminValidationNotificationPreference.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Upgrades;
4 
7 
9 
13  public function getVersion(): int {
14  return 2024071001;
15  }
16 
20  public function shouldBeSkipped(): bool {
21  return empty($this->countItems());
22  }
23 
27  public function needsIncrementOffset(): bool {
28  return false;
29  }
30 
34  public function countItems(): int {
35  return elgg_count_entities($this->getOptions());
36  }
37 
41  public function run(Result $result, $offset): Result {
42  /* @var $batch \ElggBatch */
44  'offset' => $offset,
45  ]));
46 
48 
49  /* @var $user \ElggUser */
50  foreach ($batch as $user) {
51  // disable for all methods
52  foreach ($methods as $method) {
53  $user->setNotificationSetting($method, false, 'admin_validation_notification');
54  }
55 
56  // migrate preference
57  $user->setNotificationSetting('email', (bool) $user->admin_validation_notification, 'admin_validation_notification');
58  unset($user->admin_validation_notification);
59 
60  $result->addSuccesses();
61  }
62 
63  return $result;
64  }
65 
74  protected function getOptions(array $options = []): array {
75  $defaults = [
76  'type' => 'user',
77  'limit' => 100,
78  'batch' => true,
79  'batch_inc_offset' => $this->needsIncrementOffset(),
80  'batch_size' => 50,
81  'metadata_name' => 'admin_validation_notification',
82  ];
83 
84  return array_merge($defaults, $options);
85  }
86 }
$defaults
Generic entity header upload helper.
Definition: header.php:6
if(empty($count)) $offset
Definition: pagination.php:26
addSuccesses(int $num=1)
Set an item (or items) as successfully upgraded.
Definition: Result.php:73
if($who_can_change_language=== 'nobody') elseif($who_can_change_language=== 'admin_only'&&!elgg_is_admin_logged_in()) $options
Definition: language.php:20
getOptions(array $options=[])
Get the options to fetch orphaned comments.
elgg_get_entities(array $options=[])
Fetches/counts entities or performs a calculation on their properties.
Definition: entities.php:507
elgg_count_entities(array $options=[])
Returns a count of entities.
Definition: entities.php:518
$user
Definition: ban.php:7
Result of a single BatchUpgrade run.
Definition: Result.php:10
elgg_get_notification_methods()
Returns registered delivery methods for notifications [ &#39;email&#39; => &#39;email&#39;, &#39;sms&#39; => &#39;sms&#39;...
Class to extend for asynchronous upgrades, i.e.
$methods
Definition: subscribe.php:8