19 declare(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);
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()}",
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(
117 $exp = explode(
'.', $image);
118 $suffix = strtolower(array_pop($exp));
120 return $this->
getFilePath($id) .
'/img' . $id .
'.' . $suffix;
134 for ($i = 3; $i > 0; $i--) {
136 if (($tmp = (
int) ($num / $factor)) || $found) {
144 $path_string = (implode(
'/',
$path) .
'/');
147 return $path_string .
'badgetmpl_' .
$id;
152 $res = $this->helper->getDatabase()->query(
153 'SELECT COUNT(id) as amount FROM ' . self::TABLE_NAME .
" WHERE image_rid IS NULL OR image_rid = ''" 155 $row = $this->helper->getDatabase()->fetchObject(
$res);
157 return (
int) ($row->amount ?? 0);
160 private function inform(
string $text,
bool $force =
false): void
162 if ($this->io ===
null || (!$force && !$this->io->isVerbose())) {
166 $this->io->inform($text);
169 private function error(
string $text): void
171 if ($this->io ===
null) {
175 $this->io->error($text);
Wrapper around symfonies input and output facilities to provide just the functionality required for t...
getPreconditions(Environment $environment)
Objectives the migration depend on.
ilResourceStorageMigrationHelper $helper
getDefaultAmountOfStepsPerRun()
Tell the default amount of steps to be executed for one run of the migration.
step(Environment $environment)
Run one step of the migration.
A migration is a potentially long lasting operation that can be broken into discrete steps...
if(!file_exists('../ilias.ini.php'))
getImagePath(int $id, string $image)
prepare(Environment $environment)
Prepare the migration by means of some environment.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
createLegacyPathSegmentForBadgeTemplateId(int $id)
getRemainingAmountOfSteps()
Count up how many "things" need to be migrated.
getResource(string $id)
Consumers of this method should check if the result is what they expect, e.g.
An environment holds resources to be used in the setup process.
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
static getPreconditions()
inform(string $text, bool $force=false)