ILIAS  trunk Revision v11.0_alpha-1749-g1a06bdef097
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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)
 

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.

References getLegacyPath().

Referenced by step().

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

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.

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

Referenced by getImageFullPath(), getOrgImagePath(), and getThumbnailImagePath().

120  : string
121  {
122  $path = 'sec/ilPoll/' . ilFileSystemAbstractionStorage::createPathFromId($a_id, 'poll');
123  return rtrim(CLIENT_WEB_DIR, '/') . '/' . rtrim($path, '/');
124  }
$path
Definition: ltiservices.php:29
static createPathFromId(int $a_container_id, string $a_name)
const CLIENT_WEB_DIR
Definition: constants.php:47
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getOrgImagePath()

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

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

References getLegacyPath().

Referenced by step().

115  : string
116  {
117  return $this->getLegacyPath($id) . "/org_" . $img;
118  }
$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:

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

References $res.

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:66

◆ getThumbnailImagePath()

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

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

References getLegacyPath().

Referenced by step().

110  : string
111  {
112  return $this->getLegacyPath($id) . "/thb_" . $img;
113  }
$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:

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

References ILIAS\Setup\Environment\getResource().

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.
+ Here is the call graph for this function:

◆ step()

ilPollImagesMigration::step ( Environment  $environment)

Run one step of the migration.

Implements ILIAS\Setup\Migration.

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

References $id, $res, getImageFullPath(), getOrgImagePath(), getThumbnailImagePath(), ILIAS\Repository\int(), null, ilDBConstants\T_INTEGER, and ilDBConstants\T_TEXT.

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  }
$res
Definition: ltiservices.php:66
getThumbnailImagePath(string $img, int $id)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
getOrgImagePath(string $img, int $id)
getImageFullPath(string $img, int $id)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
+ Here is the call graph for this function:

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: