ILIAS  trunk Revision v11.0_alpha-1831-g8615d53dadb
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilBadgeTemplatesFilesMigration Class Reference
+ Inheritance diagram for ilBadgeTemplatesFilesMigration:
+ Collaboration diagram for ilBadgeTemplatesFilesMigration:

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...
 

Private Member Functions

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

Private Attributes

const TABLE_NAME = 'badge_image_template'
 
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.ilBadgeTemplatesFilesMigration.php.

Member Function Documentation

◆ createLegacyPathSegmentForBadgeTemplateId()

ilBadgeTemplatesFilesMigration::createLegacyPathSegmentForBadgeTemplateId ( int  $id)
private

Definition at line 128 of file class.ilBadgeTemplatesFilesMigration.php.

References $id, and $path.

Referenced by getFilePath().

128  : string
129  {
130  $path = [];
131  $found = false;
132  $num = $id;
133  $path_string = '';
134  for ($i = 3; $i > 0; $i--) {
135  $factor = 100 ** $i;
136  if (($tmp = (int) ($num / $factor)) || $found) {
137  $path[] = $tmp;
138  $num %= $factor;
139  $found = true;
140  }
141  }
142 
143  if (count($path)) {
144  $path_string = (implode('/', $path) . '/');
145  }
146 
147  return $path_string . 'badgetmpl_' . $id;
148  }
$path
Definition: ltiservices.php:29
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
+ Here is the caller graph for this function:

◆ error()

ilBadgeTemplatesFilesMigration::error ( string  $text)
private

Definition at line 169 of file class.ilBadgeTemplatesFilesMigration.php.

References null.

Referenced by step().

169  : void
170  {
171  if ($this->io === null) {
172  return;
173  }
174 
175  $this->io->error($text);
176  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
+ Here is the caller graph for this function:

◆ getDefaultAmountOfStepsPerRun()

ilBadgeTemplatesFilesMigration::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.ilBadgeTemplatesFilesMigration.php.

38  : int
39  {
40  return 1000;
41  }

◆ getFilePath()

ilBadgeTemplatesFilesMigration::getFilePath ( int  $a_id)
private

Definition at line 123 of file class.ilBadgeTemplatesFilesMigration.php.

References CLIENT_ID, createLegacyPathSegmentForBadgeTemplateId(), and ILIAS_WEB_DIR.

Referenced by getImagePath().

123  : string
124  {
125  return ILIAS_ABSOLUTE_PATH . '/' . ILIAS_WEB_DIR . '/' . CLIENT_ID . '/sec/ilBadge/' . $this->createLegacyPathSegmentForBadgeTemplateId($a_id);
126  }
const CLIENT_ID
Definition: constants.php:41
const ILIAS_WEB_DIR
Definition: constants.php:45
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getImagePath()

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

Definition at line 115 of file class.ilBadgeTemplatesFilesMigration.php.

References getFilePath().

Referenced by step().

115  : string
116  {
117  $exp = explode('.', $image);
118  $suffix = strtolower(array_pop($exp));
119 
120  return $this->getFilePath($id) . '/img' . $id . '.' . $suffix;
121  }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getLabel()

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

Implements ILIAS\Setup\Migration.

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

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

◆ getPreconditions()

ilBadgeTemplatesFilesMigration::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.ilBadgeTemplatesFilesMigration.php.

References ilResourceStorageMigrationHelper\getPreconditions().

+ Here is the call graph for this function:

◆ getRemainingAmountOfSteps()

ilBadgeTemplatesFilesMigration::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 150 of file class.ilBadgeTemplatesFilesMigration.php.

References $res.

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

◆ inform()

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

Definition at line 160 of file class.ilBadgeTemplatesFilesMigration.php.

References null.

Referenced by step().

160  : void
161  {
162  if ($this->io === null || (!$force && !$this->io->isVerbose())) {
163  return;
164  }
165 
166  $this->io->inform($text);
167  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
+ Here is the caller graph for this function:

◆ prepare()

ilBadgeTemplatesFilesMigration::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.ilBadgeTemplatesFilesMigration.php.

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

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:32
getResource(string $id)
Consumers of this method should check if the result is what they expect, e.g.
+ Here is the call graph for this function:

◆ step()

ilBadgeTemplatesFilesMigration::step ( Environment  $environment)

Run one step of the migration.

Implements ILIAS\Setup\Migration.

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

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

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 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) {
82  $this->error(
83  'IRSS returned NULL as identification when trying to move badge image template ' .
84  "file $image_path for id $id to the storage service."
85  );
86  } else {
87  $this->inform(
88  "IRSS identification for badge image template with id $id: {$identification->serialize()}",
89  true
90  );
91  }
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());
95  throw $e;
96  }
97 
98  if ($identification === null) {
99  $identification = '-';
100  } else {
101  $identification = $identification->serialize();
102  }
103 
104  $this->helper->getDatabase()->update(
105  self::TABLE_NAME,
106  [
107  'image_rid' => [ilDBConstants::T_TEXT, $identification],
108  'image' => [ilDBConstants::T_TEXT, null]
109  ],
110  ['id' => [ilDBConstants::T_INTEGER, $id]]
111  );
112  }
113  }
$res
Definition: ltiservices.php:66
if(!file_exists('../ilias.ini.php'))
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
+ Here is the call graph for this function:

Field Documentation

◆ $helper

ilResourceStorageMigrationHelper ilBadgeTemplatesFilesMigration::$helper
private

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

◆ $io

IOWrapper ilBadgeTemplatesFilesMigration::$io = null
private

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

Referenced by prepare().

◆ TABLE_NAME

const ilBadgeTemplatesFilesMigration::TABLE_NAME = 'badge_image_template'
private

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


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