19 declare(strict_types=1);
44 private ?IOWrapper
$io = null;
53 return self::NUMBER_OF_STEPS;
67 $this->stakeholder =
new ilCertificateTemplateStakeholder();
69 if ($io instanceof IOWrapper) {
80 $remaining_paths = $this->
stepCertificates(self::NUMBER_OF_PATHS_PER_STEP, self::TABLE_TEMPLATE_CERTIFICATES);
81 if ($remaining_paths > 0) {
88 $this->db->setLimit($remaining_paths);
92 SELECT id, background_image_path AS path FROM ' . $this->db->quoteIdentifier($table) .
' 93 WHERE background_image_ident IS NULL OR background_image_ident = \'\' 95 SELECT id, thumbnail_image_path AS path FROM ' . $this->db->quoteIdentifier($table) .
' 96 WHERE thumbnail_image_ident IS NULL OR thumbnail_image_ident = \'\' 99 HAVING path IS NOT NULL AND path != \'\' 101 $result = $this->db->query($query);
102 $paths = $this->db->numRows($result);
104 while ($row = $this->db->fetchAssoc($result)) {
107 $remaining_paths -= self::NUMBER_OF_PATHS_PER_STEP - $paths;
110 return $remaining_paths;
115 $result = $this->db->queryF(
116 'SELECT value FROM settings WHERE module = %s AND keyword = %s',
118 [
'certificate',
'cert_bg_image']
120 $row = $this->db->fetchAssoc($result);
122 if (!isset($row[
'value']) || $row[
'value'] ===
'') {
126 $path_to_file = ILIAS_ABSOLUTE_PATH .
'/' .
ILIAS_WEB_DIR .
'/' .
CLIENT_ID .
'/certificates/default/' . $row[
'value'];
127 if (!is_file($path_to_file)) {
135 $this->
inform(
"Migrating global default certificate background image: $path_to_file");
136 $resource_id = $this->helper->movePathToStorage(
138 $this->stakeholder->getOwnerOfNewResources(),
146 $image_ident = $resource_id->serialize();
148 "IRSS identification for global default certificate background image: $image_ident",
153 'IRSS returned NULL as identification when trying to move global default background image ' .
154 "file $path_to_file to the storage service." 159 '/certificates/default/' . $row[
'value'],
166 WHERE module = %s AND keyword = %s';
167 $this->db->manipulateF(
170 [$image_ident,
'certificate',
'cert_bg_image']
182 $sanitized_filepath = ltrim($filepath);
183 if (str_starts_with($filepath,
'/')) {
184 $sanitized_filepath = substr($sanitized_filepath, 1);
188 $resource_id = $this->helper->movePathToStorage(
190 $this->stakeholder->getOwnerOfNewResources(),
198 $image_ident = $resource_id->serialize();
200 "IRSS identification for image path $full_path when migrating table $table: $image_ident" .
201 ($table === self::TABLE_TEMPLATE_CERTIFICATES ?
"\n" . self::TABLE_USER_CERTIFICATES .
": $image_ident" :
''),
206 'IRSS returned NULL as identification when trying to move ' .
207 "file $full_path to the storage service for table $table." .
208 ($table === self::TABLE_TEMPLATE_CERTIFICATES ?
"\n" . self::TABLE_USER_CERTIFICATES .
": $image_ident" :
'')
213 UPDATE {$this->db->quoteIdentifier($table)} 214 SET background_image_ident = %s WHERE background_image_path = %s;";
215 $this->db->manipulateF(
218 [$image_ident, $filepath]
221 UPDATE {$this->db->quoteIdentifier($table)} 222 SET thumbnail_image_ident = %s WHERE thumbnail_image_path = %s;";
223 $this->db->manipulateF(
226 [$image_ident, $filepath]
228 if ($table === self::TABLE_TEMPLATE_CERTIFICATES) {
230 UPDATE {$this->db->quoteIdentifier(self::TABLE_USER_CERTIFICATES)} 231 SET background_image_ident = %s WHERE background_image_path = %s;";
232 $this->db->manipulateF(
235 [$image_ident, $filepath]
238 UPDATE {$this->db->quoteIdentifier(self::TABLE_USER_CERTIFICATES)} 239 SET thumbnail_image_ident = %s WHERE thumbnail_image_path = %s;";
240 $this->db->manipulateF(
243 [$image_ident, $filepath]
247 if ($image_ident !==
'-') {
249 UPDATE {$this->db->quoteIdentifier($table)} 250 SET background_image_path = NULL WHERE background_image_path = %s;";
251 $this->db->manipulateF(
257 UPDATE {$this->db->quoteIdentifier($table)} 258 SET thumbnail_image_path = NULL WHERE thumbnail_image_path = %s;";
259 $this->db->manipulateF(
264 if ($table === self::TABLE_TEMPLATE_CERTIFICATES) {
266 UPDATE {$this->db->quoteIdentifier(self::TABLE_USER_CERTIFICATES)} 267 SET background_image_path = NULL WHERE background_image_path = %s;";
268 $this->db->manipulateF(
274 UPDATE {$this->db->quoteIdentifier(self::TABLE_USER_CERTIFICATES)} 275 SET thumbnail_image_path = NULL WHERE thumbnail_image_path = %s;";
276 $this->db->manipulateF(
289 $result = $this->db->query(
291 SELECT COUNT(*) AS count 295 SELECT background_image_path AS path FROM il_cert_user_cert 296 WHERE background_image_ident IS NULL OR background_image_ident = \'\' 298 SELECT thumbnail_image_path AS path FROM il_cert_user_cert 299 WHERE thumbnail_image_ident IS NULL OR thumbnail_image_ident = \'\' 301 SELECT background_image_path AS path FROM il_cert_template 302 WHERE background_image_ident IS NULL OR background_image_ident = \'\' 304 SELECT thumbnail_image_path AS path FROM il_cert_template 305 WHERE thumbnail_image_ident IS NULL OR thumbnail_image_ident = \'\' 308 HAVING path IS NOT NULL AND path != \'\' 312 $row = $this->db->fetchAssoc($result);
314 $paths += (
int) ($row[
'count'] ?? 0);
315 $num_steps = (
int) ceil($paths / self::NUMBER_OF_STEPS);
318 "Remaining certificate background image/tile image paths: $paths / Number of steps: $num_steps",
327 $this->db->manipulateF(
329 UPDATE il_cert_template SET background_image_ident = %s 330 WHERE currently_active = 1 AND (background_image_path = %s OR background_image_path = %s ) 331 AND background_image_ident IS NULL OR background_image_ident = \'\'',
340 '/certificates/default/background.jpg' 344 $this->db->manipulateF(
346 UPDATE il_cert_user_cert SET background_image_ident = %s 347 WHERE currently_active = 1 AND (background_image_path = %s OR background_image_path = %s ) 348 AND background_image_ident IS NULL OR background_image_ident = \'\'',
357 '/certificates/default/background.jpg' 364 if ($this->io === null || (!$force && !$this->io->isVerbose())) {
368 $this->io->inform($text);
373 if ($this->io === null) {
377 $this->io->error($text);
A migration is a potentially long lasting operation that can be broken into discrete steps...
Class ResourceIdentification.
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.
const RESOURCE_ADMIN_INTERACTION