19declare(strict_types=1);
35 return 'Migration of files of badge templates 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 image template 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 image template ' .
84 "file $image_path for id $id to the storage service."
88 "IRSS identification for badge image template with id $id: {$identification->serialize()}",
92 }
catch (Throwable
$e) {
93 $this->
error(
"Failed to move badge image template file $image_path for id $id to the storage service with exception: {$e->getMessage()}");
94 $this->
error($e->getTraceAsString());
98 if ($identification ===
null) {
99 $identification =
'-';
101 $identification = $identification->serialize();
104 $this->helper->getDatabase()->update(
114 'Cannot migrate badge image template with id ' .
$id
115 .
' (table: ' . self::TABLE_NAME .
') because no image is set.',
123 $exp = explode(
'.', $image);
124 $suffix = strtolower(array_pop($exp));
140 for ($i = 3; $i > 0; $i--) {
142 if (($tmp = (
int) ($num / $factor)) || $found) {
150 $path_string = (implode(
'/',
$path) .
'/');
153 return $path_string .
'badgetmpl_' .
$id;
158 $res = $this->helper->getDatabase()->query(
159 'SELECT COUNT(id) as amount FROM ' . self::TABLE_NAME .
" WHERE image_rid IS NULL OR image_rid = ''"
161 $row = $this->helper->getDatabase()->fetchObject(
$res);
163 return (
int) ($row->amount ?? 0);
166 private function inform(
string $text,
bool $force =
false): void
168 if ($this->io ===
null || (!$force && !$this->io->isVerbose())) {
172 $this->io->inform($text);
175 private function error(
string $text): void
177 if ($this->io ===
null) {
181 $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...
prepare(Environment $environment)
Prepare the migration by means of some environment.
getImagePath(int $id, string $image)
getPreconditions(Environment $environment)
Objectives the migration depend on.
createLegacyPathSegmentForBadgeTemplateId(int $id)
getRemainingAmountOfSteps()
Count up how many "things" need to be migrated.
step(Environment $environment)
Run one step of the migration.
getDefaultAmountOfStepsPerRun()
Tell the default amount of steps to be executed for one run of the migration.
inform(string $text, bool $force=false)
ilResourceStorageMigrationHelper $helper
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'))