19 declare(strict_types=1);
29 private \ilDBInterface
$db;
35 return 'Rebuild Missing Thumbnail Images';
46 new \ilDatabaseInitializedObjective()
56 $this->webdir =
"{$ini->readVariable('server', 'absolute_path')}/{$ini->readVariable('clients', 'path')}/{$ini->readVariable('clients', 'default')}";
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
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
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)' 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);
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;
85 if (isset($previous_question_type_id)) {
86 $this->
updateThumbSize($previous_question_id, $previous_question_type_id, $image_width);
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
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
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' 106 $row = $this->db->fetchAssoc($result);
108 return (
int) ($row[
'cnt'] ?? 0);
114 string $image_file_name
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}");
126 copy($filepath, $thumbpath);
127 return $image_info[0];
132 int $question_type_id,
136 match ($question_type_id) {
139 17 =>
'qpl_qst_kprim' 142 'thumb_size' => [
'integer', $image_width],
145 'question_fi' => [
'integer', $question_id]
getRemainingAmountOfSteps()
Count up how many "things" need to be migrated.
step(Environment $environment)
Run one step of the migration.
A migration is a potentially long lasting operation that can be broken into discrete steps...
copyImageToThumb(int $object_id, int $question_id, string $image_file_name)
getDefaultAmountOfStepsPerRun()
Tell the default amount of steps to be executed for one run of the migration.
This defines ways in which objectives may interact with admins during the setup.
getResource(string $id)
Consumers of this method should check if the result is what they expect, e.g.
An environment holds resources to be used in the setup process.
getPreconditions(Environment $environment)
Objectives the migration depend on.
updateThumbSize(int $question_id, int $question_type_id, int $image_width)
const RESOURCE_ADMIN_INTERACTION
prepare(Environment $environment)
Prepare the migration by means of some environment.