ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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)
 

Protected Attributes

ilDBInterface $db
 

Additional Inherited Members

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

Detailed Description

Definition at line 25 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 34 of file class.ilPollImagesMigration.php.

34 : int
35 {
36 return 5;
37 }

◆ getImageFullPath()

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

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

105 : ?string
106 {
107 return $this->getLegacyPath($id) . '/' . $img;
108 }
$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 29 of file class.ilPollImagesMigration.php.

29 : string
30 {
31 return "PollImagesMigration";
32 }

◆ getLegacyPath()

ilPollImagesMigration::getLegacyPath ( int  $a_id)
protected

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

120 : string
121 {
122 $path = 'sec/ilPoll/' . ilFileSystemAbstractionStorage::createPathFromId($a_id, 'poll');
123 return rtrim(CLIENT_WEB_DIR, '/') . '/' . rtrim($path, '/');
124 }
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 115 of file class.ilPollImagesMigration.php.

115 : string
116 {
117 return $this->getLegacyPath($id) . "/org_" . $img;
118 }

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 39 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 96 of file class.ilPollImagesMigration.php.

96 : int
97 {
98 $res = $this->db->query(
99 'SELECT COUNT(*) AS count FROM il_poll WHERE migrated = 0'
100 );
101 $row = $this->db->fetchAssoc($res);
102 return (int) $row['count'];
103 }
$res
Definition: ltiservices.php:69

References $res.

◆ getThumbnailImagePath()

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

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

110 : string
111 {
112 return $this->getLegacyPath($id) . "/thb_" . $img;
113 }

References $id.

◆ 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 49 of file class.ilPollImagesMigration.php.

51 : void {
52 $this->db = $environment->getResource(Environment::RESOURCE_DATABASE);
53 }
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 55 of file class.ilPollImagesMigration.php.

57 : void {
58 $res = $this->db->query("SELECT id, image FROM il_poll WHERE migrated = 0 LIMIT 1");
59 $row = $res->fetchAssoc();
60 $image = $row["image"] ?? "";
61 $id = (int) $row["id"];
62
63 if ($image === "") {
64 $this->db->manipulate("UPDATE il_poll SET migrated = 1 WHERE id = " . $this->db->quote($id, ilDBConstants::T_INTEGER));
65 return;
66 }
67
68 $file_path = $this->getImageFullPath($image, $id);
69 $thumbnail_path = $this->getThumbnailImagePath($image, $id);
70 $org_path = $this->getOrgImagePath($image, $id);
71 $stakeholder = (new ilPollImageRepositoryStakeholder())->withUserId(6);
72 $irss_helper = new ilResourceStorageMigrationHelper($stakeholder, $environment);
73 $rid = $irss_helper->movePathToStorage($file_path, 6, null, null, false);
74 $rid_thumbnail = $irss_helper->movePathToStorage($thumbnail_path, 6, null, null, false);
75 $org_thumbnail = $irss_helper->movePathToStorage($org_path, 6, null, null, false);
76
77 $res_existing = $this->db->query("SELECT * FROM il_poll_image WHERE object_id = " . $this->db->quote($id, ilDBConstants::T_INTEGER));
78 $row_existing = $res_existing->fetchAssoc();
79 if (is_null($row_existing)) {
80 $this->db->manipulate(
81 "INSERT INTO il_poll_image (object_id, rid) VALUES "
82 . " (" . $this->db->quote($id, ilDBConstants::T_INTEGER)
83 . ", " . $this->db->quote($rid->serialize(), ilDBConstants::T_TEXT) . ")"
84 );
85 }
86
87 if (!is_null($row_existing)) {
88 $irss_helper->getResourceBuilder()->remove($irss_helper->getResourceBuilder()->get($rid), $stakeholder);
89 }
90 $irss_helper->getResourceBuilder()->remove($irss_helper->getResourceBuilder()->get($rid_thumbnail), $stakeholder);
91 $irss_helper->getResourceBuilder()->remove($irss_helper->getResourceBuilder()->get($org_thumbnail), $stakeholder);
92
93 $this->db->manipulate("UPDATE il_poll SET migrated = 1 WHERE id = " . $this->db->quote($id, ilDBConstants::T_INTEGER));
94 }
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 27 of file class.ilPollImagesMigration.php.


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