Elgg  Version master
MigrateEntityIconCroppingCoordinates.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Upgrades;
4 
6 
8 
12  public function getVersion(): int {
13  return 2024020101;
14  }
15 
19  public function shouldBeSkipped(): bool {
20  return empty($this->countItems());
21  }
22 
26  public function needsIncrementOffset(): bool {
27  return false;
28  }
29 
33  public function countItems(): int {
34  return elgg_count_entities($this->getOptions());
35  }
36 
40  public function run(Result $result, $offset): Result {
41  /* @var $entities \ElggBatch */
42  $entities = elgg_get_entities($this->getOptions([
43  'offset' => $offset,
44  ]));
45  /* @var $entity \ElggEntity */
46  foreach ($entities as $entity) {
47  $coords = [
48  'x1' => (int) $entity->x1,
49  'x2' => (int) $entity->x2,
50  'y1' => (int) $entity->y1,
51  'y2' => (int) $entity->y2,
52  ];
53 
54  try {
55  $entity->saveIconCoordinates($coords, 'icon');
56  } catch (\Elgg\Exceptions\ExceptionInterface $e) {
57  // something went wrong with the coords, probably broken
58  }
59 
60  unset($entity->x1);
61  unset($entity->x2);
62  unset($entity->y1);
63  unset($entity->y2);
64 
65  $result->addSuccesses();
66  }
67 
68  return $result;
69  }
70 
79  protected function getOptions(array $options = []): array {
80  $defaults = [
81  'limit' => 50,
82  'batch' => true,
83  'batch_inc_offset' => $this->needsIncrementOffset(),
84  'metadata_names' => [
85  'x1',
86  'x2',
87  'y1',
88  'y2',
89  ],
90  ];
91 
92  return array_merge($defaults, $options);
93  }
94 }
$entity
Definition: reset.php:8
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
Result of a single BatchUpgrade run.
Definition: Result.php:10
System upgrades are executed synchronously at system upgrade.
countItems()
{The total number of items to process during the upgrade.If unknown, Batch::UNKNOWN_COUNT should be r...
shouldBeSkipped()
{Should this upgrade be skipped?If true, the upgrade will not be performed and cannot be accessed lat...
getVersion()
{Version of the upgrade.This tells the date when the upgrade was added. It consists of eight digits a...
needsIncrementOffset()
{Should the run() method receive an offset representing all processed items?If true,...
run(Result $result, $offset)
{Runs upgrade on a single batch of items.If countItems() returns Batch::UNKNOWN_COUNT,...
if($who_can_change_language==='nobody') elseif($who_can_change_language==='admin_only' &&!elgg_is_admin_logged_in()) $options
Definition: language.php:20
elgg_count_entities(array $options=[])
Returns a count of entities.
Definition: entities.php:518
elgg_get_entities(array $options=[])
Fetches/counts entities or performs a calculation on their properties.
Definition: entities.php:507
$defaults
Generic entity header upload helper.
Definition: header.php:6
Generic interface which allows catching of all exceptions thrown in Elgg.
if(empty($count)) $offset
Definition: pagination.php:26