ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ILIAS\TestQuestionPool\Setup\RebuildMissingThumbnailMigration Class Reference
+ Inheritance diagram for ILIAS\TestQuestionPool\Setup\RebuildMissingThumbnailMigration:
+ Collaboration diagram for ILIAS\TestQuestionPool\Setup\RebuildMissingThumbnailMigration:

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

 copyImageToThumb (int $object_id, int $question_id, string $image_file_name)
 
 updateThumbSize (int $question_id, int $question_type_id, int $image_width)
 

Private Attributes

ilDBInterface $db
 
AdminInteraction $io
 
string $webdir
 

Additional Inherited Members

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

Detailed Description

Definition at line 27 of file RebuildMissingThumbnailMigration.php.

Member Function Documentation

◆ copyImageToThumb()

ILIAS\TestQuestionPool\Setup\RebuildMissingThumbnailMigration::copyImageToThumb ( int  $object_id,
int  $question_id,
string  $image_file_name 
)
private

Definition at line 111 of file RebuildMissingThumbnailMigration.php.

Referenced by ILIAS\TestQuestionPool\Setup\RebuildMissingThumbnailMigration\step().

115  : ?int {
116  $filepath = "{$this->webdir}/assessment/{$object_id}/{$question_id}/images/{$image_file_name}";
117  $thumbpath = "{$this->webdir}/assessment/{$object_id}/{$question_id}/images/thumb.{$image_file_name}";
118  if (!file_exists($filepath)
119  || filesize($filepath) <= 0
120  || !($image_info = getimagesize($filepath))
121  || !is_writable(dirname($thumbpath))) {
122  $this->io->inform("\nWARNING: Could not create thumbnail for image {$filepath} of question {$question_id}");
123  return 0;
124  }
125 
126  copy($filepath, $thumbpath);
127  return $image_info[0];
128  }
+ Here is the caller graph for this function:

◆ getDefaultAmountOfStepsPerRun()

ILIAS\TestQuestionPool\Setup\RebuildMissingThumbnailMigration::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 RebuildMissingThumbnailMigration.php.

38  : int
39  {
40  return 100;
41  }

◆ getLabel()

ILIAS\TestQuestionPool\Setup\RebuildMissingThumbnailMigration::getLabel ( )
Returns
string - a meaningful and concise description for your migration.

Implements ILIAS\Setup\Migration.

Definition at line 33 of file RebuildMissingThumbnailMigration.php.

33  : string
34  {
35  return 'Rebuild Missing Thumbnail Images';
36  }

◆ getPreconditions()

ILIAS\TestQuestionPool\Setup\RebuildMissingThumbnailMigration::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 RebuildMissingThumbnailMigration.php.

43  : array
44  {
45  return [
46  new \ilDatabaseInitializedObjective()
47  ];
48  }

◆ getRemainingAmountOfSteps()

ILIAS\TestQuestionPool\Setup\RebuildMissingThumbnailMigration::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 90 of file RebuildMissingThumbnailMigration.php.

90  : int
91  {
92  $result = $this->db->query(
93  'SELECT COUNT(*) cnt FROM' . PHP_EOL
94  . '(SELECT q.question_id' . PHP_EOL
95  . 'FROM qpl_questions q JOIN qpl_qst_sc s on q.question_id = s.question_fi JOIN qpl_a_sc sa on q.question_id = sa.question_fi' . PHP_EOL
96  . 'WHERE q.question_type_fi = 1 AND s.thumb_size IS NULL AND NOT q.obj_fi = 0 and not sa.imagefile = "" AND NOT ISNULL(sa.imagefile)' . PHP_EOL
97  . 'UNION' . PHP_EOL
98  . 'SELECT q.question_id' . PHP_EOL
99  . 'FROM qpl_questions q JOIN qpl_qst_mc m on q.question_id = m.question_fi JOIN qpl_a_mc ma on q.question_id = ma.question_fi' . PHP_EOL
100  . 'WHERE q.question_type_fi = 2 AND m.thumb_size IS NULL AND NOT q.obj_fi = 0 AND NOT ma.imagefile = "" AND NOT ISNULL(ma.imagefile)' . PHP_EOL
101  . 'UNION' . PHP_EOL
102  . 'SELECT q.question_id' . PHP_EOL
103  . 'FROM qpl_questions q JOIN qpl_qst_kprim k on q.question_id = k.question_fi JOIN qpl_a_kprim ka on q.question_id = ka.question_fi' . PHP_EOL
104  . 'WHERE q.question_type_fi = 17 AND k.thumb_size IS NULL AND NOT q.obj_fi = 0 AND NOT ka.imagefile = "" AND NOT ISNULL(ka.imagefile)) cnt'
105  );
106  $row = $this->db->fetchAssoc($result);
107 
108  return (int) ($row['cnt'] ?? 0);
109  }

◆ prepare()

ILIAS\TestQuestionPool\Setup\RebuildMissingThumbnailMigration::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 50 of file RebuildMissingThumbnailMigration.php.

References ILIAS\$ini, ILIAS\Setup\Environment\getResource(), ILIAS\Setup\Environment\RESOURCE_ADMIN_INTERACTION, ILIAS\Setup\Environment\RESOURCE_DATABASE, and ILIAS\Setup\Environment\RESOURCE_ILIAS_INI.

50  : void
51  {
52  $this->db = $environment->getResource(Environment::RESOURCE_DATABASE);
53  $this->io = $environment->getResource(Environment::RESOURCE_ADMIN_INTERACTION);
54 
55  $ini = $environment->getResource(Environment::RESOURCE_ILIAS_INI);
56  $this->webdir = "{$ini->readVariable('server', 'absolute_path')}/{$ini->readVariable('clients', 'path')}/{$ini->readVariable('clients', 'default')}";
57  }
+ Here is the call graph for this function:

◆ step()

ILIAS\TestQuestionPool\Setup\RebuildMissingThumbnailMigration::step ( Environment  $environment)

Run one step of the migration.

Implements ILIAS\Setup\Migration.

Definition at line 59 of file RebuildMissingThumbnailMigration.php.

References ILIAS\TestQuestionPool\Setup\RebuildMissingThumbnailMigration\copyImageToThumb(), and ILIAS\TestQuestionPool\Setup\RebuildMissingThumbnailMigration\updateThumbSize().

59  : void
60  {
61  $result = $this->db->query(
62  '(SELECT sa.imagefile, q.obj_fi, q.question_type_fi, q.question_id' . PHP_EOL
63  . 'FROM qpl_questions q JOIN qpl_qst_sc s on q.question_id = s.question_fi JOIN qpl_a_sc sa on q.question_id = sa.question_fi' . PHP_EOL
64  . 'WHERE q.question_type_fi = 1 AND s.thumb_size IS NULL AND NOT q.obj_fi = 0 and not sa.imagefile = "" AND NOT ISNULL(sa.imagefile) ORDER BY q.question_id)' . PHP_EOL
65  . 'UNION' . PHP_EOL
66  . '(SELECT ma.imagefile, q.obj_fi, q.question_type_fi, q.question_id ' . PHP_EOL
67  . 'FROM qpl_questions q JOIN qpl_qst_mc m on q.question_id = m.question_fi JOIN qpl_a_mc ma on q.question_id = ma.question_fi' . PHP_EOL
68  . 'WHERE q.question_type_fi = 2 AND m.thumb_size IS NULL AND NOT q.obj_fi = 0 AND NOT ma.imagefile = "" AND NOT ISNULL(ma.imagefile) ORDER BY q.question_id)' . PHP_EOL
69  . 'UNION' . PHP_EOL
70  . '(SELECT ka.imagefile, q.obj_fi, q.question_type_fi, q.question_id' . PHP_EOL
71  . 'FROM qpl_questions q JOIN qpl_qst_kprim k on q.question_id = k.question_fi JOIN qpl_a_kprim ka on q.question_id = ka.question_fi' . PHP_EOL
72  . 'WHERE q.question_type_fi = 17 AND k.thumb_size IS NULL AND NOT q.obj_fi = 0 AND NOT ka.imagefile = "" AND NOT ISNULL(ka.imagefile) ORDER BY q.question_id)'
73  );
74 
75  $previous_question_id = null;
76  while (($row = $this->db->fetchObject($result)) !== null) {
77  if ($previous_question_id !== null && $previous_question_id !== $row->question_id) {
78  $this->updateThumbSize($row->question_id, $row->question_type_fi, $image_width);
79  }
80  $image_width = $this->copyImageToThumb($row->obj_fi, $row->question_id, $row->imagefile);
81  $previous_question_id = $row->question_id;
82  $previous_question_type_id = $row->question_type_fi;
83  }
84 
85  if (isset($previous_question_type_id)) {
86  $this->updateThumbSize($previous_question_id, $previous_question_type_id, $image_width);
87  }
88  }
copyImageToThumb(int $object_id, int $question_id, string $image_file_name)
updateThumbSize(int $question_id, int $question_type_id, int $image_width)
+ Here is the call graph for this function:

◆ updateThumbSize()

ILIAS\TestQuestionPool\Setup\RebuildMissingThumbnailMigration::updateThumbSize ( int  $question_id,
int  $question_type_id,
int  $image_width 
)
private

Definition at line 130 of file RebuildMissingThumbnailMigration.php.

Referenced by ILIAS\TestQuestionPool\Setup\RebuildMissingThumbnailMigration\step().

134  : void {
135  $this->db->replace(
136  match ($question_type_id) {
137  1 => 'qpl_qst_sc',
138  2 => 'qpl_qst_mc',
139  17 => 'qpl_qst_kprim'
140  },
141  [
142  'thumb_size' => ['integer', $image_width],
143  ],
144  [
145  'question_fi' => ['integer', $question_id]
146  ]
147  );
148  }
+ Here is the caller graph for this function:

Field Documentation

◆ $db

ilDBInterface ILIAS\TestQuestionPool\Setup\RebuildMissingThumbnailMigration::$db
private

Definition at line 29 of file RebuildMissingThumbnailMigration.php.

◆ $io

AdminInteraction ILIAS\TestQuestionPool\Setup\RebuildMissingThumbnailMigration::$io
private

Definition at line 30 of file RebuildMissingThumbnailMigration.php.

◆ $webdir

string ILIAS\TestQuestionPool\Setup\RebuildMissingThumbnailMigration::$webdir
private

Definition at line 31 of file RebuildMissingThumbnailMigration.php.


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