ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
ilPollImagesMigration Class Reference
+ Inheritance diagram for ilPollImagesMigration:
+ Collaboration diagram for ilPollImagesMigration:

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...
 
 getImageFullPath (string $img, int $id)
 
 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...
 

Protected Member Functions

 getThumbnailImagePath (string $img, int $id)
 
 getOrgImagePath (string $img, int $id)
 
 getLegacyPath (int $a_id)
 
 logError (string $text)
 

Protected Attributes

ilDBInterface $db
 
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.ilPollImagesMigration.php.

Member Function Documentation

◆ getDefaultAmountOfStepsPerRun()

ilPollImagesMigration::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 36 of file class.ilPollImagesMigration.php.

36 : int
37 {
38 return 5;
39 }

◆ getImageFullPath()

ilPollImagesMigration::getImageFullPath ( string  $img,
int  $id 
)

Definition at line 119 of file class.ilPollImagesMigration.php.

119 : ?string
120 {
121 return $this->getLegacyPath($id) . '/' . $img;
122 }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23

References $id.

◆ getLabel()

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

Implements ILIAS\Setup\Migration.

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

31 : string
32 {
33 return "PollImagesMigration";
34 }

◆ getLegacyPath()

ilPollImagesMigration::getLegacyPath ( int  $a_id)
protected

Definition at line 134 of file class.ilPollImagesMigration.php.

134 : string
135 {
136 $path = 'sec/ilPoll/' . ilFileSystemAbstractionStorage::createPathFromId($a_id, 'poll');
137 return rtrim(CLIENT_WEB_DIR, '/') . '/' . rtrim($path, '/');
138 }
static createPathFromId(int $a_container_id, string $a_name)
const CLIENT_WEB_DIR
Definition: constants.php:47
$path
Definition: ltiservices.php:30

References $path, CLIENT_WEB_DIR, and ilFileSystemAbstractionStorage\createPathFromId().

+ Here is the call graph for this function:

◆ getOrgImagePath()

ilPollImagesMigration::getOrgImagePath ( string  $img,
int  $id 
)
protected

Definition at line 129 of file class.ilPollImagesMigration.php.

129 : string
130 {
131 return $this->getLegacyPath($id) . "/org_" . $img;
132 }

References $id.

◆ getPreconditions()

ilPollImagesMigration::getPreconditions ( Environment  $environment)

Objectives the migration depend on.

Exceptions
UnachievableExceptionif the objective is not achievable
Returns
Objective[]

Implements ILIAS\Setup\Migration.

Definition at line 41 of file class.ilPollImagesMigration.php.

◆ getRemainingAmountOfSteps()

ilPollImagesMigration::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 110 of file class.ilPollImagesMigration.php.

110 : int
111 {
112 $res = $this->db->query(
113 'SELECT COUNT(*) AS count FROM il_poll WHERE migrated = 0'
114 );
115 $row = $this->db->fetchAssoc($res);
116 return (int) $row['count'];
117 }
$res
Definition: ltiservices.php:69

References $res.

◆ getThumbnailImagePath()

ilPollImagesMigration::getThumbnailImagePath ( string  $img,
int  $id 
)
protected

Definition at line 124 of file class.ilPollImagesMigration.php.

124 : string
125 {
126 return $this->getLegacyPath($id) . "/thb_" . $img;
127 }

References $id.

◆ logError()

ilPollImagesMigration::logError ( string  $text)
protected

Definition at line 140 of file class.ilPollImagesMigration.php.

140 : void
141 {
142 if ($this->io === null) {
143 return;
144 }
145
146 $this->io->error($text);
147 }
$text
Definition: xapiexit.php:21

References $text.

◆ prepare()

ilPollImagesMigration::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 51 of file class.ilPollImagesMigration.php.

53 : void {
54 $this->db = $environment->getResource(Environment::RESOURCE_DATABASE);
55 $io = $environment->getResource(Environment::RESOURCE_ADMIN_INTERACTION);
56 if ($io instanceof IOWrapper) {
57 $this->io = $io;
58 }
59 }
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.

◆ step()

ilPollImagesMigration::step ( Environment  $environment)

Run one step of the migration.

Implements ILIAS\Setup\Migration.

Definition at line 61 of file class.ilPollImagesMigration.php.

63 : void {
64 $res = $this->db->query("SELECT id, image FROM il_poll WHERE migrated = 0 LIMIT 1");
65 $row = $res->fetchAssoc();
66 $image = $row["image"] ?? "";
67 $id = (int) $row["id"];
68
69 if ($image === "") {
70 $this->db->manipulate("UPDATE il_poll SET migrated = 1 WHERE id = " . $this->db->quote($id, ilDBConstants::T_INTEGER));
71 return;
72 }
73
74 $file_path = $this->getImageFullPath($image, $id);
75 $thumbnail_path = $this->getThumbnailImagePath($image, $id);
76 $org_path = $this->getOrgImagePath($image, $id);
77 $stakeholder = (new ilPollImageRepositoryStakeholder())->withUserId(6);
78
79 $irss_helper = new ilResourceStorageMigrationHelper($stakeholder, $environment);
80 $rid = $irss_helper->movePathToStorage($file_path, 6, null, null, false);
81 $rid_thumbnail = $irss_helper->movePathToStorage($thumbnail_path, 6, null, null, false);
82 $org_thumbnail = $irss_helper->movePathToStorage($org_path, 6, null, null, false);
83
84 $res_existing = $this->db->query("SELECT * FROM il_poll_image WHERE object_id = " . $this->db->quote($id, ilDBConstants::T_INTEGER));
85 $row_existing = $res_existing->fetchAssoc();
86 if (!is_null($rid)) {
87 if (is_null($row_existing)) {
88 $this->db->manipulate(
89 "INSERT INTO il_poll_image (object_id, rid) VALUES "
90 . " (" . $this->db->quote($id, ilDBConstants::T_INTEGER)
91 . ", " . $this->db->quote($rid->serialize(), ilDBConstants::T_TEXT) . ")"
92 );
93 } else {
94 $irss_helper->getResourceBuilder()->remove($irss_helper->getResourceBuilder()->get($rid), $stakeholder);
95 }
96 } else {
97 $this->logError('Image ' . $file_path . ' of poll with object ID ' . $id . ' could not be moved to storage.');
98 }
99
100 if (!is_null($rid_thumbnail)) {
101 $irss_helper->getResourceBuilder()->remove($irss_helper->getResourceBuilder()->get($rid_thumbnail), $stakeholder);
102 }
103 if (!is_null($org_thumbnail)) {
104 $irss_helper->getResourceBuilder()->remove($irss_helper->getResourceBuilder()->get($org_thumbnail), $stakeholder);
105 }
106
107 $this->db->manipulate("UPDATE il_poll SET migrated = 1 WHERE id = " . $this->db->quote($id, ilDBConstants::T_INTEGER));
108 }
getImageFullPath(string $img, int $id)
getThumbnailImagePath(string $img, int $id)
getOrgImagePath(string $img, int $id)

References $id, and ilDBConstants\T_INTEGER.

Field Documentation

◆ $db

ilDBInterface ilPollImagesMigration::$db
protected

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

◆ $io

IOWrapper ilPollImagesMigration::$io = null
protected

Definition at line 29 of file class.ilPollImagesMigration.php.


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