-
Notifications
You must be signed in to change notification settings - Fork 669
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14561 from jeabakker/features
feat(icons): uniform storage of entity icon cropping coordinates
- Loading branch information
Showing
13 changed files
with
375 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
engine/classes/Elgg/Upgrades/MigrateEntityIconCroppingCoordinates.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php | ||
|
||
namespace Elgg\Upgrades; | ||
|
||
use Elgg\Upgrade\Result; | ||
|
||
class MigrateEntityIconCroppingCoordinates extends \Elgg\Upgrade\SystemUpgrade { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getVersion(): int { | ||
return 2024020101; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function shouldBeSkipped(): bool { | ||
return empty($this->countItems()); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function needsIncrementOffset(): bool { | ||
return false; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function countItems(): int { | ||
return elgg_count_entities($this->getOptions()); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function run(Result $result, $offset): Result { | ||
/* @var $entities \ElggBatch */ | ||
$entities = elgg_get_entities($this->getOptions([ | ||
'offset' => $offset, | ||
])); | ||
/* @var $entity \ElggEntity */ | ||
foreach ($entities as $entity) { | ||
$coords = [ | ||
'x1' => (int) $entity->x1, | ||
'x2' => (int) $entity->x2, | ||
'y1' => (int) $entity->y1, | ||
'y2' => (int) $entity->y2, | ||
]; | ||
|
||
try { | ||
$entity->saveIconCoordinates($coords, 'icon'); | ||
} catch (\Elgg\Exceptions\ExceptionInterface $e) { | ||
// something went wrong with the coords, probably broken | ||
} | ||
|
||
unset($entity->x1); | ||
unset($entity->x2); | ||
unset($entity->y1); | ||
unset($entity->y2); | ||
|
||
$result->addSuccesses(); | ||
} | ||
|
||
return $result; | ||
} | ||
|
||
/** | ||
* Get options for the upgrade | ||
* | ||
* @param array $options additional options | ||
* | ||
* @return array | ||
* @see elgg_get_entities() | ||
*/ | ||
protected function getOptions(array $options = []): array { | ||
$defaults = [ | ||
'limit' => 50, | ||
'batch' => true, | ||
'batch_inc_offset' => $this->needsIncrementOffset(), | ||
'metadata_names' => [ | ||
'x1', | ||
'x2', | ||
'y1', | ||
'y2', | ||
], | ||
]; | ||
|
||
return array_merge($defaults, $options); | ||
} | ||
} |
Oops, something went wrong.