19declare(strict_types=1);
35 return 'Migration of files of badges to the resource storage service.';
54 $io = $environment->
getResource(Environment::RESOURCE_ADMIN_INTERACTION);
62 $this->helper->getDatabase()->setLimit(1);
63 $res = $this->helper->getDatabase()->query(
64 'SELECT id, image, image_rid FROM ' . self::TABLE_NAME .
" WHERE image_rid IS NULL OR image_rid = ''"
66 $row = $this->helper->getDatabase()->fetchObject(
$res);
67 if (!($row instanceof stdClass)) {
74 if ($image !==
'' && $image !==
null) {
78 $this->
inform(
"Trying to move badge file $image_path for id $id to the storage service.");
79 $identification = $this->helper->movePathToStorage($image_path, ResourceCollection::NO_SPECIFIC_OWNER);
80 $this->
inform(
'Migration proceeded without error.');
81 if ($identification ===
null) {
83 'IRSS returned NULL as identification when trying to move badge ' .
84 "file $image_path for id $id to the storage service."
87 $this->
inform(
"IRSS identification for badge with id $id: {$identification->serialize()}",
true);
89 }
catch (Throwable
$e) {
90 $this->
error(
"Failed to move badge file {$image_path} for id {$id} to the storage service with exception: {$e->getMessage()}");
91 $this->
error($e->getTraceAsString());
95 if ($identification ===
null) {
96 $identification =
'-';
98 $identification = $identification->serialize();
101 $this->helper->getDatabase()->update(
111 'Cannot migrate badge with id ' .
$id
112 .
' (table: ' . self::TABLE_NAME .
') because no image is set.',
120 $exp = explode(
'.', $image);
121 $suffix = strtolower(array_pop($exp));
137 for ($i = 3; $i > 0; $i--) {
139 if (($tmp = (
int) ($num / $factor)) || $found) {
147 $path_string = (implode(
'/',
$path) .
'/');
150 return $path_string .
'badge_' .
$id;
155 $res = $this->helper->getDatabase()->query(
156 'SELECT COUNT(id) as amount FROM ' . self::TABLE_NAME .
" WHERE image_rid IS NULL OR image_rid = ''"
158 $row = $this->helper->getDatabase()->fetchObject(
$res);
160 return (
int) ($row->amount ?? 0);
168 return static function (
string $file_name):
string {
169 return md5($file_name);
173 private function inform(
string $text,
bool $force =
false): void
175 if ($this->io ===
null || (!$force && !$this->io->isVerbose())) {
179 $this->io->inform($text);
182 private function error(
string $text): void
184 if ($this->io ===
null) {
188 $this->io->error($text);
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Class ResourceCollection.
Wrapper around symfonies input and output facilities to provide just the functionality required for t...
ilResourceStorageMigrationHelper $helper
inform(string $text, bool $force=false)
createLegacyPathSegmentForBadgeId(int $id)
getImagePath(int $id, string $image)
getRemainingAmountOfSteps()
Count up how many "things" need to be migrated.
getRevisionNameCallback()
getPreconditions(Environment $environment)
Objectives the migration depend on.
getDefaultAmountOfStepsPerRun()
Tell the default amount of steps to be executed for one run of the migration.
prepare(Environment $environment)
Prepare the migration by means of some environment.
step(Environment $environment)
Run one step of the migration.
Class ilResourceStorageMigrationHelper.
static getPreconditions()
An environment holds resources to be used in the setup process.
getResource(string $id)
Consumers of this method should check if the result is what they expect, e.g.
A migration is a potentially long lasting operation that can be broken into discrete steps.
if(!file_exists('../ilias.ini.php'))