ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilBadgesFilesMigration Class Reference
+ Inheritance diagram for ilBadgesFilesMigration:
+ Collaboration diagram for ilBadgesFilesMigration:

Public Member Functions

 getLabel ()
 
 getDefaultAmountOfStepsPerRun ()
 Tell the default amount of steps to be executed for one run of the migration. More...
 
 getPreconditions (Environment $environment)
 Objectives the migration depend on. More...
 
 prepare (Environment $environment)
 Prepare the migration by means of some environment. More...
 
 step (Environment $environment)
 Run one step of the migration. More...
 
 getRemainingAmountOfSteps ()
 Count up how many "things" need to be migrated. More...
 
 getRevisionNameCallback ()
 
 getLabel ()
 
 getDefaultAmountOfStepsPerRun ()
 Tell the default amount of steps to be executed for one run of the migration. More...
 
 getPreconditions (Environment $environment)
 Objectives the migration depend on. More...
 
 prepare (Environment $environment)
 Prepare the migration by means of some environment. More...
 
 step (Environment $environment)
 Run one step of the migration. More...
 
 getRemainingAmountOfSteps ()
 Count up how many "things" need to be migrated. More...
 

Private Member Functions

 getImagePath (int $id, string $image)
 
 getFilePath (int $a_id)
 
 createLegacyPathSegmentForBadgeId (int $id)
 
 inform (string $text, bool $force=false)
 
 error (string $text)
 

Private Attributes

const TABLE_NAME = 'badge_badge'
 
ilResourceStorageMigrationHelper $helper
 
IOWrapper $io = null
 

Additional Inherited Members

- Data Fields inherited from ILIAS\Setup\Migration
const INFINITE = -1
 

Detailed Description

Definition at line 26 of file class.ilBadgesFilesMigration.php.

Member Function Documentation

◆ createLegacyPathSegmentForBadgeId()

ilBadgesFilesMigration::createLegacyPathSegmentForBadgeId ( int  $id)
private

Definition at line 131 of file class.ilBadgesFilesMigration.php.

131 : string
132 {
133 $path = [];
134 $found = false;
135 $num = $id;
136 $path_string = '';
137 for ($i = 3; $i > 0; $i--) {
138 $factor = 100 ** $i;
139 if (($tmp = (int) ($num / $factor)) || $found) {
140 $path[] = $tmp;
141 $num %= $factor;
142 $found = true;
143 }
144 }
145
146 if (count($path)) {
147 $path_string = (implode('/', $path) . '/');
148 }
149
150 return $path_string . 'badge_' . $id;
151 }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
$path
Definition: ltiservices.php:30

References $id, and $path.

Referenced by getFilePath().

+ Here is the caller graph for this function:

◆ error()

ilBadgesFilesMigration::error ( string  $text)
private

Definition at line 182 of file class.ilBadgesFilesMigration.php.

182 : void
183 {
184 if ($this->io === null) {
185 return;
186 }
187
188 $this->io->error($text);
189 }

Referenced by step().

+ Here is the caller graph for this function:

◆ getDefaultAmountOfStepsPerRun()

ilBadgesFilesMigration::getDefaultAmountOfStepsPerRun ( )

Tell the default amount of steps to be executed for one run of the migration.

Return Migration::INFINITE if all units should be migrated at once.

Implements ILIAS\Setup\Migration.

Definition at line 38 of file class.ilBadgesFilesMigration.php.

38 : int
39 {
40 return 1000;
41 }

◆ getFilePath()

ilBadgesFilesMigration::getFilePath ( int  $a_id)
private

Definition at line 126 of file class.ilBadgesFilesMigration.php.

126 : string
127 {
128 return ILIAS_ABSOLUTE_PATH . '/' . ILIAS_WEB_DIR . '/' . CLIENT_ID . '/sec/ilBadge/' . $this->createLegacyPathSegmentForBadgeId($a_id);
129 }
const CLIENT_ID
Definition: constants.php:41
const ILIAS_WEB_DIR
Definition: constants.php:45

References CLIENT_ID, createLegacyPathSegmentForBadgeId(), and ILIAS_WEB_DIR.

Referenced by getImagePath().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getImagePath()

ilBadgesFilesMigration::getImagePath ( int  $id,
string  $image 
)
private

Definition at line 118 of file class.ilBadgesFilesMigration.php.

118 : string
119 {
120 $exp = explode('.', $image);
121 $suffix = strtolower(array_pop($exp));
122
123 return $this->getFilePath($id) . '/img' . $id . '.' . $suffix;
124 }

References $id, and getFilePath().

Referenced by step().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getLabel()

ilBadgesFilesMigration::getLabel ( )
Returns
string - a meaningful and concise description for your migration.

Implements ILIAS\Setup\Migration.

Definition at line 33 of file class.ilBadgesFilesMigration.php.

33 : string
34 {
35 return 'Migration of files of badges to the resource storage service.';
36 }

◆ getPreconditions()

ilBadgesFilesMigration::getPreconditions ( Environment  $environment)

Objectives the migration depend on.

Exceptions
UnachievableExceptionif the objective is not achievable
Returns
Objective[]

Implements ILIAS\Setup\Migration.

Definition at line 43 of file class.ilBadgesFilesMigration.php.

References ilResourceStorageMigrationHelper\getPreconditions().

+ Here is the call graph for this function:

◆ getRemainingAmountOfSteps()

ilBadgesFilesMigration::getRemainingAmountOfSteps ( )

Count up how many "things" need to be migrated.

This helps the admin to decide how big he can create the steps and also how long a migration takes

Implements ILIAS\Setup\Migration.

Definition at line 153 of file class.ilBadgesFilesMigration.php.

153 : int
154 {
155 $res = $this->helper->getDatabase()->query(
156 'SELECT COUNT(id) as amount FROM ' . self::TABLE_NAME . " WHERE image_rid IS NULL OR image_rid = ''"
157 );
158 $row = $this->helper->getDatabase()->fetchObject($res);
159
160 return (int) ($row->amount ?? 0);
161 }
$res
Definition: ltiservices.php:69

References $res.

◆ getRevisionNameCallback()

ilBadgesFilesMigration::getRevisionNameCallback ( )
Returns
Closure(string): string

Definition at line 166 of file class.ilBadgesFilesMigration.php.

166 : Closure
167 {
168 return static function (string $file_name): string {
169 return md5($file_name);
170 };
171 }

◆ inform()

ilBadgesFilesMigration::inform ( string  $text,
bool  $force = false 
)
private

Definition at line 173 of file class.ilBadgesFilesMigration.php.

173 : void
174 {
175 if ($this->io === null || (!$force && !$this->io->isVerbose())) {
176 return;
177 }
178
179 $this->io->inform($text);
180 }

Referenced by step().

+ Here is the caller graph for this function:

◆ prepare()

ilBadgesFilesMigration::prepare ( Environment  $environment)

Prepare the migration by means of some environment.

This is not supposed to modify the environment, but will be run to prime the migration object to run step and getRemainingAmountOfSteps afterwards.

Implements ILIAS\Setup\Migration.

Definition at line 48 of file class.ilBadgesFilesMigration.php.

48 : void
49 {
50 $this->helper = new ilResourceStorageMigrationHelper(
52 $environment
53 );
54 $io = $environment->getResource(Environment::RESOURCE_ADMIN_INTERACTION);
55 if ($io instanceof IOWrapper) {
56 $this->io = $io;
57 }
58 }
Wrapper around symfonies input and output facilities to provide just the functionality required for t...
Definition: IOWrapper.php:33
getResource(string $id)
Consumers of this method should check if the result is what they expect, e.g.

References $io, and ILIAS\Setup\Environment\getResource().

+ Here is the call graph for this function:

◆ step()

ilBadgesFilesMigration::step ( Environment  $environment)

Run one step of the migration.

Implements ILIAS\Setup\Migration.

Definition at line 60 of file class.ilBadgesFilesMigration.php.

60 : void
61 {
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 = ''"
65 );
66 $row = $this->helper->getDatabase()->fetchObject($res);
67 if (!($row instanceof stdClass)) {
68 return;
69 }
70
71 $id = (int) $row->id;
72 $image = $row->image;
73
74 if ($image !== '' && $image !== null) {
75 $image_path = $this->getImagePath($id, $image);
76
77 try {
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) {
82 $this->error(
83 'IRSS returned NULL as identification when trying to move badge ' .
84 "file $image_path for id $id to the storage service."
85 );
86 } else {
87 $this->inform("IRSS identification for badge with id $id: {$identification->serialize()}", true);
88 }
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());
92 throw $e;
93 }
94
95 if ($identification === null) {
96 $identification = '-';
97 } else {
98 $identification = $identification->serialize();
99 }
100
101 $this->helper->getDatabase()->update(
102 self::TABLE_NAME,
103 [
104 'image_rid' => [ilDBConstants::T_TEXT, $identification],
105 'image' => [ilDBConstants::T_TEXT, null]
106 ],
107 ['id' => [ilDBConstants::T_INTEGER, $id]]
108 );
109 } else {
110 $this->inform(
111 'Cannot migrate badge with id ' . $id
112 . ' (table: ' . self::TABLE_NAME . ') because no image is set.',
113 true
114 );
115 }
116 }
inform(string $text, bool $force=false)
getImagePath(int $id, string $image)
if(!file_exists('../ilias.ini.php'))

References Vendor\Package\$e, $id, $res, error(), getImagePath(), if, inform(), ILIAS\Repository\int(), ilDBConstants\T_INTEGER, and ilDBConstants\T_TEXT.

+ Here is the call graph for this function:

Field Documentation

◆ $helper

ilResourceStorageMigrationHelper ilBadgesFilesMigration::$helper
private

Definition at line 30 of file class.ilBadgesFilesMigration.php.

◆ $io

IOWrapper ilBadgesFilesMigration::$io = null
private

Definition at line 31 of file class.ilBadgesFilesMigration.php.

Referenced by prepare().

◆ TABLE_NAME

const ilBadgesFilesMigration::TABLE_NAME = 'badge_badge'
private

Definition at line 28 of file class.ilBadgesFilesMigration.php.


The documentation for this class was generated from the following file: