ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS Class Reference

Migrates mail attachments to the IRSS, the attachments of the most recently sent mails first, because these are the ones users access most (e.g. More...

+ Inheritance diagram for ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS:
+ Collaboration diagram for ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS:

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

 migrateSentAttachmentDirectories ()
 Sent and received mails share one directory per sending process. More...
 
 copyDirectoryToCollection (string $absolute_path, array $filenames, int $owner_id)
 Files stay on disk until the collection is stored and the mail rows point at it. More...
 
 discardResources (array $resource_ids)
 Copies of a directory that could not be migrated completely are removed, the next run copies it again. More...
 
 listDirectoryFiles (string $absolute_path)
 
 deleteMigratedDirectory (string $absolute_path)
 
 nextUnmigratedPaths ()
 
 skipPath (string $relative_path, string $reason)
 
 mailIdsOfPath (string $relative_path)
 
 migrateSerializedMailAttachments ()
 Drafts and scheduled mails reference files of the user's attachment pool. More...
 
 migrateSerializedMail (int $mail_id, int $user_id, string $raw_attachments, string $mail_path, bool $references_pool)
 
 migratePoolFilenamesToCollection (array $filenames, int $user_id, string $mail_path, int $mail_id)
 Pool files are copied, not moved: The same pool file may be referenced by several drafts and stays available in the user's pool, where it is migrated when it is used the next time. More...
 
 markConfidential (ResourceIdentification $identification)
 
 markCollectionResourcesConfidential (ResourceCollectionIdentification $rcid)
 
 clearMailAttachmentsColumn (int $mail_id)
 
 resolveOwnerIdForPath (string $relative_path)
 
 assignRcidToPath (string $relative_path, ResourceCollectionIdentification $rcid)
 
 updateMailAttachmentFields (string $relative_path, ResourceCollectionIdentification $rcid)
 
 markPathAsSkipped (string $relative_path)
 
 resolveAdminInteraction (Environment $environment)
 
 count (string $key, int $amount=1)
 
 info (string $message, array $context=[])
 
 warning (string $message, array $context=[])
 
 error (string $message, array $context=[], ?Throwable $exception=null)
 
 report (string $level, string $message, array $context)
 

Private Attributes

const int PATHS_PER_STEP = 25
 
const int MAILS_PER_STEP = 50
 
const string SKIPPED_MARKER = '-'
 
ilResourceStorageMigrationHelper $helper = null
 
AdminInteraction $io = null
 
int $step_number = 0
 
array $statistics = []
 

Additional Inherited Members

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

Detailed Description

Migrates mail attachments to the IRSS, the attachments of the most recently sent mails first, because these are the ones users access most (e.g.

the first page of their inbox).

Definition at line 41 of file MigrateMailAttachmentsToIRSS.php.

Member Function Documentation

◆ assignRcidToPath()

ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS::assignRcidToPath ( string  $relative_path,
ResourceCollectionIdentification  $rcid 
)
private

Definition at line 518 of file MigrateMailAttachmentsToIRSS.php.

518 : void
519 {
520 $this->helper->getDatabase()->manipulateF(
521 'UPDATE mail_attachment SET rcid = %s WHERE path = %s',
523 [$rcid->serialize(), $relative_path]
524 );
525 }

References ILIAS\ResourceStorage\Identification\AbstractIdentification\serialize(), and ilDBConstants\T_TEXT.

Referenced by ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS\migrateSentAttachmentDirectories().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ clearMailAttachmentsColumn()

ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS::clearMailAttachmentsColumn ( int  $mail_id)
private

Definition at line 449 of file MigrateMailAttachmentsToIRSS.php.

449 : void
450 {
451 $this->helper->getDatabase()->update(
452 'mail',
453 [
454 'attachments' => [ilDBConstants::T_CLOB, ''],
455 ],
456 [
457 'mail_id' => [ilDBConstants::T_INTEGER, $mail_id],
458 ]
459 );
460 }

References ilDBConstants\T_CLOB, and ilDBConstants\T_INTEGER.

◆ copyDirectoryToCollection()

ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS::copyDirectoryToCollection ( string  $absolute_path,
array  $filenames,
int  $owner_id 
)
private

Files stay on disk until the collection is stored and the mail rows point at it.

A rerun can therefore still read them when this step stops in between.

Parameters
list<string>$filenames

Definition at line 163 of file MigrateMailAttachmentsToIRSS.php.

168 $collection = $this->helper->getCollectionBuilder()->new($owner_id);
169 $copies = [];
170 foreach ($filenames as $file_name) {
171 $resource_id = $this->helper->movePathToStorage(
172 $absolute_path . '/' . $file_name,
173 $owner_id,
174 null,
175 static fn(string $name): string => md5($name),
176 true
177 );
178 if (!$resource_id instanceof ResourceIdentification) {
179 $this->discardResources($copies);
180
181 return null;
182 }
183 $copies[] = $resource_id;
184 $collection->add($resource_id);
185 }
186
187 if ($collection->count() !== count($filenames)
188 || !$this->helper->getCollectionBuilder()->store($collection)) {
189 $this->discardResources($copies);
190
191 return null;
192 }
193
194 return $collection->getIdentification();
195 }
discardResources(array $resource_ids)
Copies of a directory that could not be migrated completely are removed, the next run copies it again...

References ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS\discardResources().

Referenced by ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS\migrateSentAttachmentDirectories().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ count()

ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS::count ( string  $key,
int  $amount = 1 
)
private

Definition at line 558 of file MigrateMailAttachmentsToIRSS.php.

558 : void
559 {
560 $this->statistics[$key] = ($this->statistics[$key] ?? 0) + $amount;
561 }

Referenced by ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS\migrateSentAttachmentDirectories().

+ Here is the caller graph for this function:

◆ deleteMigratedDirectory()

ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS::deleteMigratedDirectory ( string  $absolute_path)
private

Definition at line 226 of file MigrateMailAttachmentsToIRSS.php.

226 : void
227 {
228 foreach ($this->listDirectoryFiles($absolute_path) as $file_name) {
229 unlink($absolute_path . '/' . $file_name);
230 }
231 rmdir($absolute_path);
232 }

Referenced by ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS\migrateSentAttachmentDirectories().

+ Here is the caller graph for this function:

◆ discardResources()

ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS::discardResources ( array  $resource_ids)
private

Copies of a directory that could not be migrated completely are removed, the next run copies it again.

Parameters
list<ResourceIdentification>$resource_ids

Definition at line 202 of file MigrateMailAttachmentsToIRSS.php.

202 : void
203 {
204 foreach ($resource_ids as $resource_id) {
205 $this->helper->getManager()->remove($resource_id, $this->helper->getStakeholder());
206 }
207 }

Referenced by ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS\copyDirectoryToCollection().

+ Here is the caller graph for this function:

◆ error()

ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS::error ( string  $message,
array  $context = [],
?Throwable  $exception = null 
)
private
Parameters
array<string,mixed>$context

Definition at line 582 of file MigrateMailAttachmentsToIRSS.php.

582 : void
583 {
584 if ($exception !== null) {
585 $context['exception'] = $exception::class . ': ' . $exception->getMessage() .
586 ' (' . $exception->getFile() . ':' . $exception->getLine() . ')';
587 }
588
589 $this->report('ERROR', $message, $context);
590 }
report(string $level, string $message, array $context)

References $message.

Referenced by ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS\step().

+ Here is the caller graph for this function:

◆ getDefaultAmountOfStepsPerRun()

ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS::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 59 of file MigrateMailAttachmentsToIRSS.php.

59 : int
60 {
61 return 10;
62 }

◆ getLabel()

ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS::getLabel ( )
Returns
string - a meaningful and concise description for your migration.

Implements ILIAS\Setup\Migration.

Definition at line 54 of file MigrateMailAttachmentsToIRSS.php.

54 : string
55 {
56 return 'Migrate Mail Attachments to IRSS';
57 }

◆ getPreconditions()

ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS::getPreconditions ( Environment  $environment)

Objectives the migration depend on.

Exceptions
UnachievableExceptionif the objective is not achievable
Returns
Objective[]

Implements ILIAS\Setup\Migration.

Definition at line 64 of file MigrateMailAttachmentsToIRSS.php.

64 : array
65 {
66 return array_merge(
68 [new ilDatabaseUpdateStepsExecutedObjective(new MailDBUpdateSteps12())]
69 );
70 }
This class attempt to achieve a set of database update steps.

References ilResourceStorageMigrationHelper\getPreconditions().

+ Here is the call graph for this function:

◆ getRemainingAmountOfSteps()

ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS::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 462 of file MigrateMailAttachmentsToIRSS.php.

462 : int
463 {
464 $db = $this->helper->getDatabase();
465
466 $path_count = (int) $db->fetchAssoc(
467 $db->query(
468 'SELECT COUNT(DISTINCT path) cnt FROM mail_attachment
469 WHERE (rcid IS NULL OR rcid = "")
470 AND path IS NOT NULL AND path != ""'
471 )
472 )['cnt'];
473
474 $mail_count = (int) $db->fetchAssoc(
475 $db->query(
476 'SELECT COUNT(m.mail_id) cnt FROM mail m
477 LEFT JOIN mail_attachment ma ON ma.mail_id = m.mail_id
478 WHERE ma.mail_id IS NULL
479 AND m.attachments LIKE ' . $db->quote('a:%', ilDBConstants::T_TEXT)
480 )
481 )['cnt'];
482
483 $remaining = max(
484 (int) ceil($path_count / self::PATHS_PER_STEP),
485 (int) ceil($mail_count / self::MAILS_PER_STEP)
486 );
487
488 $this->info('Remaining', [
489 'directories' => $path_count,
490 'drafts' => $mail_count,
491 'steps' => $remaining,
492 ]);
493
494 return $remaining;
495 }

References ILIAS\UI\examples\MessageBox\Info\info(), ILIAS\Repository\int(), and ilDBConstants\T_TEXT.

+ Here is the call graph for this function:

◆ info()

ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS::info ( string  $message,
array  $context = [] 
)
private
Parameters
array<string,mixed>$context

Definition at line 566 of file MigrateMailAttachmentsToIRSS.php.

566 : void
567 {
568 $this->report('INFO', $message, $context);
569 }

References $message.

Referenced by ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS\step().

+ Here is the caller graph for this function:

◆ listDirectoryFiles()

ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS::listDirectoryFiles ( string  $absolute_path)
private
Returns
list<string>

Definition at line 212 of file MigrateMailAttachmentsToIRSS.php.

212 : array
213 {
214 $filenames = [];
215 foreach (new \DirectoryIterator($absolute_path) as $file_info) {
216 if (!$file_info->isFile()) {
217 continue;
218 }
219 $filenames[] = $file_info->getFilename();
220 }
221 sort($filenames);
222
223 return $filenames;
224 }

References ILIAS\UI\examples\Symbol\Glyph\Sort\sort().

Referenced by ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS\migrateSentAttachmentDirectories().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mailIdsOfPath()

ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS::mailIdsOfPath ( string  $relative_path)
private
Returns
list<int>

Definition at line 274 of file MigrateMailAttachmentsToIRSS.php.

274 : array
275 {
276 $db = $this->helper->getDatabase();
277 $res = $db->queryF(
278 'SELECT mail_id FROM mail_attachment WHERE path = %s',
280 [$relative_path]
281 );
282
283 $mail_ids = [];
284 while ($row = $db->fetchAssoc($res)) {
285 $mail_ids[] = (int) $row['mail_id'];
286 }
287
288 return $mail_ids;
289 }
foreach($_POST as $key=> $value) $res

References ILIAS\$db, $res, ILIAS\Repository\int(), and ilDBConstants\T_TEXT.

+ Here is the call graph for this function:

◆ markCollectionResourcesConfidential()

ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS::markCollectionResourcesConfidential ( ResourceCollectionIdentification  $rcid)
private

Definition at line 442 of file MigrateMailAttachmentsToIRSS.php.

442 : void
443 {
444 foreach ($this->helper->getCollectionBuilder()->get($rcid)->getResourceIdentifications() as $identification) {
445 $this->markConfidential($identification);
446 }
447 }

Referenced by ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS\migrateSentAttachmentDirectories().

+ Here is the caller graph for this function:

◆ markConfidential()

ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS::markConfidential ( ResourceIdentification  $identification)
private

Definition at line 437 of file MigrateMailAttachmentsToIRSS.php.

437 : void
438 {
439 $this->helper->getManager()->setConfidential($identification, true);
440 }

◆ markPathAsSkipped()

ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS::markPathAsSkipped ( string  $relative_path)
private

Definition at line 542 of file MigrateMailAttachmentsToIRSS.php.

542 : void
543 {
544 $this->helper->getDatabase()->manipulateF(
545 'UPDATE mail_attachment SET rcid = %s WHERE path = %s',
547 [self::SKIPPED_MARKER, $relative_path]
548 );
549 }

References ilDBConstants\T_TEXT.

◆ migratePoolFilenamesToCollection()

ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS::migratePoolFilenamesToCollection ( array  $filenames,
int  $user_id,
string  $mail_path,
int  $mail_id 
)
private

Pool files are copied, not moved: The same pool file may be referenced by several drafts and stays available in the user's pool, where it is migrated when it is used the next time.

Parameters
list<string>$filenames

Definition at line 390 of file MigrateMailAttachmentsToIRSS.php.

396 $collection = $this->helper->getCollectionBuilder()->new($user_id);
397
398 foreach ($filenames as $filename) {
399 $absolute_path = $mail_path . '/' . $user_id . '_' . $filename;
400 if ($filename === '' || str_contains($filename, '/') || str_contains($filename, '\\') || !is_file($absolute_path)) {
401 $this->warning('Pool file referenced by the mail does not exist', [
402 'mail_id' => $mail_id,
403 'file' => $filename,
404 ]);
405
406 continue;
407 }
408
409 // Pool files are stored as "<user_id>_<name>" on disk, the users only know the name
410 $resource_id = $this->helper->movePathToStorage(
411 $absolute_path,
412 $user_id,
413 static fn(): string => $filename,
414 static fn(): string => md5($filename),
415 true
416 );
417
418 if ($resource_id instanceof ResourceIdentification) {
419 $this->markConfidential($resource_id);
420 $collection->add($resource_id);
421 }
422 }
423
424 if ($collection->count() === 0) {
425 return null;
426 }
427
428 if (!$this->helper->getCollectionBuilder()->store($collection)) {
429 $this->discardResources(array_values($collection->getResourceIdentifications()));
430
431 return null;
432 }
433
434 return $collection->getIdentification();
435 }
$filename
Definition: buildRTE.php:78

References $filename, and $user_id.

◆ migrateSentAttachmentDirectories()

ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS::migrateSentAttachmentDirectories ( )
private

Sent and received mails share one directory per sending process.

All mails referencing a directory get the same collection, the mail_attachment rows are used for reference counting.

Definition at line 113 of file MigrateMailAttachmentsToIRSS.php.

113 : void
114 {
115 $mail_path = rtrim($this->helper->getClientDataDir(), '/') . '/mail';
116
117 foreach ($this->nextUnmigratedPaths() as $relative_path) {
118 $absolute_path = $mail_path . '/' . $relative_path;
119 if (trim($relative_path, '/. ') === '' || str_contains($relative_path, '..')) {
120 $this->skipPath($relative_path, 'Invalid directory name');
121
122 continue;
123 }
124
125 if (!is_dir($absolute_path)) {
126 $this->skipPath($relative_path, 'Directory does not exist');
127
128 continue;
129 }
130
131 $filenames = $this->listDirectoryFiles($absolute_path);
132 if ($filenames === []) {
133 $this->skipPath($relative_path, 'No file of the directory could be stored');
134
135 continue;
136 }
137
138 $owner_id = $this->resolveOwnerIdForPath($relative_path);
139 $rcid = $this->copyDirectoryToCollection($absolute_path, $filenames, $owner_id);
140 if ($rcid === null) {
141 $this->warning('Directory was not migrated because not every file could be stored', [
142 'path' => $relative_path,
143 'files' => count($filenames),
144 ]);
145
146 continue;
147 }
148
150 $this->assignRcidToPath($relative_path, $rcid);
151 $this->updateMailAttachmentFields($relative_path, $rcid);
152 $this->deleteMigratedDirectory($absolute_path);
153 $this->count('directories_migrated');
154 }
155 }
updateMailAttachmentFields(string $relative_path, ResourceCollectionIdentification $rcid)
copyDirectoryToCollection(string $absolute_path, array $filenames, int $owner_id)
Files stay on disk until the collection is stored and the mail rows point at it.
markCollectionResourcesConfidential(ResourceCollectionIdentification $rcid)
assignRcidToPath(string $relative_path, ResourceCollectionIdentification $rcid)

References ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS\assignRcidToPath(), ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS\copyDirectoryToCollection(), ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS\count(), ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS\deleteMigratedDirectory(), ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS\listDirectoryFiles(), ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS\markCollectionResourcesConfidential(), ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS\nextUnmigratedPaths(), ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS\resolveOwnerIdForPath(), ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS\skipPath(), ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS\updateMailAttachmentFields(), and ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS\warning().

Referenced by ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS\step().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ migrateSerializedMail()

ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS::migrateSerializedMail ( int  $mail_id,
int  $user_id,
string  $raw_attachments,
string  $mail_path,
bool  $references_pool 
)
private

Definition at line 328 of file MigrateMailAttachmentsToIRSS.php.

334 : void {
335 $attachments = MailAttachments::fromDb($raw_attachments);
336 if ($attachments === null || !$attachments->isLegacy()) {
337 if ($attachments === null) {
338 $this->warning('Attachments of mail could not be read and have been removed', [
339 'mail_id' => $mail_id,
340 'value' => substr($raw_attachments, 0, 200),
341 ]);
342 }
343 $this->clearMailAttachmentsColumn($mail_id);
344
345 return;
346 }
347
348 // Sent and received mails reference a directory. Without one, files of the owner's pool must not be attached.
349 if (!$references_pool) {
350 $this->warning('Mail outside drafts and outbox has no attachment directory, its attachments have been removed', [
351 'mail_id' => $mail_id,
352 'files' => $attachments->legacyFilenames(),
353 ]);
354 $this->clearMailAttachmentsColumn($mail_id);
355
356 return;
357 }
358
359 $rcid = $this->migratePoolFilenamesToCollection($attachments->legacyFilenames(), $user_id, $mail_path, $mail_id);
360 if ($rcid === null) {
361 $this->warning('None of the pool files referenced by the mail exists, its attachments have been removed', [
362 'mail_id' => $mail_id,
363 'files' => $attachments->legacyFilenames(),
364 ]);
365 $this->clearMailAttachmentsColumn($mail_id);
366
367 return;
368 }
369
370 $db = $this->helper->getDatabase();
371 $db->manipulateF(
372 'INSERT INTO mail_attachment (mail_id, path, rcid) VALUES (%s, %s, %s)',
374 [$mail_id, '', $rcid->serialize()]
375 );
376 $db->update(
377 'mail',
378 ['attachments' => [ilDBConstants::T_CLOB, $rcid->serialize()]],
379 ['mail_id' => [ilDBConstants::T_INTEGER, $mail_id]]
380 );
381 $this->count('drafts_migrated');
382 }
migratePoolFilenamesToCollection(array $filenames, int $user_id, string $mail_path, int $mail_id)
Pool files are copied, not moved: The same pool file may be referenced by several drafts and stays av...

◆ migrateSerializedMailAttachments()

ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS::migrateSerializedMailAttachments ( )
private

Drafts and scheduled mails reference files of the user's attachment pool.

Mails referencing a directory are handled by migrateSentAttachmentDirectories() and must never be treated as pool references.

Definition at line 299 of file MigrateMailAttachmentsToIRSS.php.

299 : void
300 {
301 $db = $this->helper->getDatabase();
302 $db->setLimit(self::MAILS_PER_STEP);
303 $res = $db->query(
304 'SELECT m.mail_id, m.user_id, m.attachments, fo.m_type FROM mail m
305 LEFT JOIN mail_attachment ma ON ma.mail_id = m.mail_id
306 LEFT JOIN mail_obj_data fo ON fo.obj_id = m.folder_id
307 WHERE ma.mail_id IS NULL
308 AND m.attachments LIKE ' . $db->quote('a:%', ilDBConstants::T_TEXT) . '
309 ORDER BY m.send_time DESC, m.mail_id DESC'
310 );
311
312 $mail_path = rtrim($this->helper->getClientDataDir(), '/') . '/mail';
313 while ($row = $db->fetchAssoc($res)) {
315 (int) $row['mail_id'],
316 (int) $row['user_id'],
317 (string) $row['attachments'],
318 $mail_path,
319 in_array(
320 $row['m_type'] ?? null,
321 [MailFolderType::DRAFTS->value, MailFolderType::OUTBOX->value],
322 true
323 )
324 );
325 }
326 }
migrateSerializedMail(int $mail_id, int $user_id, string $raw_attachments, string $mail_path, bool $references_pool)

References ILIAS\$db, $res, ILIAS\Mail\Folder\OUTBOX, and ilDBConstants\T_TEXT.

Referenced by ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS\step().

+ Here is the caller graph for this function:

◆ nextUnmigratedPaths()

ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS::nextUnmigratedPaths ( )
private
Returns
list<string> Paths of the most recently sent mails first

Definition at line 237 of file MigrateMailAttachmentsToIRSS.php.

237 : array
238 {
239 $db = $this->helper->getDatabase();
240 $db->setLimit(self::PATHS_PER_STEP);
241 $res = $db->query(
242 'SELECT ma.path FROM mail_attachment ma
243 LEFT JOIN mail m ON m.mail_id = ma.mail_id
244 WHERE (ma.rcid IS NULL OR ma.rcid = "")
245 AND ma.path IS NOT NULL AND ma.path != ""
246 GROUP BY ma.path
247 ORDER BY MAX(m.send_time) DESC'
248 );
249
250 $paths = [];
251 while ($row = $db->fetchAssoc($res)) {
252 $paths[] = (string) $row['path'];
253 }
254
255 return $paths;
256 }

References ILIAS\$db, and $res.

Referenced by ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS\migrateSentAttachmentDirectories().

+ Here is the caller graph for this function:

◆ prepare()

ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS::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 72 of file MigrateMailAttachmentsToIRSS.php.

72 : void
73 {
74 $this->io = $this->resolveAdminInteraction($environment);
75 $this->helper = new ilResourceStorageMigrationHelper(
77 $environment
78 );
79 }

References ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS\resolveAdminInteraction().

+ Here is the call graph for this function:

◆ report()

ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS::report ( string  $level,
string  $message,
array  $context 
)
private
Parameters
array<string,mixed>$context

Definition at line 595 of file MigrateMailAttachmentsToIRSS.php.

595 : void
596 {
597 $this->io?->inform(sprintf(
598 '[%s] Mail attachment migration %s: %s%s',
599 date('Y-m-d H:i:s'),
600 $level,
601 $message,
602 $context !== []
603 ? ' ' . json_encode($context, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PARTIAL_OUTPUT_ON_ERROR)
604 : ''
605 ));
606 }

References $message, and ILIAS\UI\examples\Symbol\Glyph\Date\date().

+ Here is the call graph for this function:

◆ resolveAdminInteraction()

ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS::resolveAdminInteraction ( Environment  $environment)
private

Definition at line 551 of file MigrateMailAttachmentsToIRSS.php.

552 {
554
555 return $io instanceof AdminInteraction ? $io : null;
556 }
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.

References ILIAS\Setup\Environment\getResource().

Referenced by ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS\prepare(), and ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS\step().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ resolveOwnerIdForPath()

ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS::resolveOwnerIdForPath ( string  $relative_path)
private

Definition at line 497 of file MigrateMailAttachmentsToIRSS.php.

497 : int
498 {
499 $db = $this->helper->getDatabase();
500 $db->setLimit(1, 0);
501 $res = $db->queryF(
502 'SELECT m.sender_id FROM mail_attachment ma
503 INNER JOIN mail m ON m.mail_id = ma.mail_id
504 WHERE ma.path = %s
505 ORDER BY m.send_time ASC',
507 [$relative_path]
508 );
509
510 $row = $db->fetchAssoc($res);
511 if (is_array($row) && (int) $row['sender_id'] > 0) {
512 return (int) $row['sender_id'];
513 }
514
515 return defined('SYSTEM_USER_ID') ? (int) SYSTEM_USER_ID : 6;
516 }
const SYSTEM_USER_ID
This file contains constants for PHPStan analyis, see: https://phpstan.org/config-reference#constants...
Definition: constants.php:26

References $res, ILIAS\Repository\int(), SYSTEM_USER_ID, and ilDBConstants\T_TEXT.

Referenced by ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS\migrateSentAttachmentDirectories().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ skipPath()

ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS::skipPath ( string  $relative_path,
string  $reason 
)
private

Definition at line 258 of file MigrateMailAttachmentsToIRSS.php.

258 : void
259 {
260 $mail_ids = $this->mailIdsOfPath($relative_path);
261 $this->markPathAsSkipped($relative_path);
262 $this->count('directories_skipped');
263
264 $this->warning('Directory skipped: ' . $reason, [
265 'path' => $relative_path,
266 'mails' => count($mail_ids),
267 'mail_ids' => array_slice($mail_ids, 0, 20),
268 ]);
269 }

Referenced by ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS\migrateSentAttachmentDirectories().

+ Here is the caller graph for this function:

◆ step()

ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS::step ( Environment  $environment)

Run one step of the migration.

Implements ILIAS\Setup\Migration.

Definition at line 81 of file MigrateMailAttachmentsToIRSS.php.

81 : void
82 {
83 $this->io ??= $this->resolveAdminInteraction($environment);
84 $this->step_number++;
85 $this->statistics = [];
86 $started = microtime(true);
87
88 try {
91 } catch (Throwable $e) {
92 $this->error('Migration aborted', ['step' => $this->step_number], $e);
93
94 throw $e;
95 }
96
97 if ($this->statistics !== []) {
98 $this->info('Step finished', array_merge(
99 ['step' => $this->step_number, 'seconds' => round(microtime(true) - $started, 2)],
100 $this->statistics
101 ));
102 }
103 }
migrateSentAttachmentDirectories()
Sent and received mails share one directory per sending process.
error(string $message, array $context=[], ?Throwable $exception=null)
migrateSerializedMailAttachments()
Drafts and scheduled mails reference files of the user's attachment pool.

References Vendor\Package\$e, ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS\error(), ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS\info(), ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS\migrateSentAttachmentDirectories(), ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS\migrateSerializedMailAttachments(), and ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS\resolveAdminInteraction().

+ Here is the call graph for this function:

◆ updateMailAttachmentFields()

ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS::updateMailAttachmentFields ( string  $relative_path,
ResourceCollectionIdentification  $rcid 
)
private

Definition at line 527 of file MigrateMailAttachmentsToIRSS.php.

527 : void
528 {
529 $mail_ids = $this->mailIdsOfPath($relative_path);
530 if ($mail_ids === []) {
531 return;
532 }
533
534 $db = $this->helper->getDatabase();
535 $db->manipulateF(
536 'UPDATE mail SET attachments = %s WHERE ' . $db->in('mail_id', $mail_ids, false, ilDBConstants::T_INTEGER),
538 [$rcid->serialize()]
539 );
540 }

References ILIAS\ResourceStorage\Identification\AbstractIdentification\serialize(), ilDBConstants\T_INTEGER, and ilDBConstants\T_TEXT.

Referenced by ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS\migrateSentAttachmentDirectories().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ warning()

ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS::warning ( string  $message,
array  $context = [] 
)
private
Parameters
array<string,mixed>$context

Definition at line 574 of file MigrateMailAttachmentsToIRSS.php.

574 : void
575 {
576 $this->report('WARNING', $message, $context);
577 }

References $message.

Referenced by ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS\migrateSentAttachmentDirectories().

+ Here is the caller graph for this function:

Field Documentation

◆ $helper

ilResourceStorageMigrationHelper ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS::$helper = null
private

Definition at line 47 of file MigrateMailAttachmentsToIRSS.php.

◆ $io

AdminInteraction ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS::$io = null
private

Definition at line 48 of file MigrateMailAttachmentsToIRSS.php.

◆ $statistics

array ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS::$statistics = []
private

Definition at line 52 of file MigrateMailAttachmentsToIRSS.php.

◆ $step_number

int ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS::$step_number = 0
private

Definition at line 49 of file MigrateMailAttachmentsToIRSS.php.

◆ MAILS_PER_STEP

const int ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS::MAILS_PER_STEP = 50
private

Definition at line 44 of file MigrateMailAttachmentsToIRSS.php.

◆ PATHS_PER_STEP

const int ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS::PATHS_PER_STEP = 25
private

Definition at line 43 of file MigrateMailAttachmentsToIRSS.php.

◆ SKIPPED_MARKER

const string ILIAS\Mail\Setup\Migration\MigrateMailAttachmentsToIRSS::SKIPPED_MARKER = '-'
private

Definition at line 45 of file MigrateMailAttachmentsToIRSS.php.


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