From ffed431244e7d3e500eb2b19b6952a5ff4df42f3 Mon Sep 17 00:00:00 2001 From: mjansen Date: Thu, 19 Sep 2024 10:16:12 +0200 Subject: [PATCH] Mail: Code cleanup (unused "ns" imports, code style) --- .../Mail/classes/Folder/MailFilterUI.php | 12 +- .../Mail/classes/Folder/MailFolderData.php | 1 + .../Mail/classes/Folder/MailFolderSearch.php | 12 +- .../Mail/classes/Folder/MailFolderTableUI.php | 54 ++-- .../Mail/classes/Message/MailBoxQuery.php | 24 +- .../MailSignatureUserFullnamePlaceholder.php | 1 - .../Mail/classes/class.ilMailFolderGUI.php | 306 +++++++++++------- .../classes/class.ilMailLuceneQueryParser.php | 7 +- .../ILIAS/Mail/classes/class.ilMailbox.php | 25 +- components/ILIAS/Mail/tests/ilMailTest.php | 1 - 10 files changed, 256 insertions(+), 187 deletions(-) diff --git a/components/ILIAS/Mail/classes/Folder/MailFilterUI.php b/components/ILIAS/Mail/classes/Folder/MailFilterUI.php index d019b61274ce..ddc3e82811dd 100644 --- a/components/ILIAS/Mail/classes/Folder/MailFilterUI.php +++ b/components/ILIAS/Mail/classes/Folder/MailFilterUI.php @@ -33,7 +33,6 @@ class MailFilterUI { private FilterComponent $filter; - private ?string $sender; public function __construct( private readonly string $target_url, @@ -48,7 +47,9 @@ public function __construct( if ($this->folder->hasIncomingMails()) { $inputs['sender'] = $this->ui_factory->input()->field()->text($this->lng->txt('mail_filter_sender')); } else { - $inputs['recipients'] = $this->ui_factory->input()->field()->text($this->lng->txt('mail_filter_recipients')); + $inputs['recipients'] = $this->ui_factory->input()->field()->text( + $this->lng->txt('mail_filter_recipients') + ); } $inputs['subject'] = $this->ui_factory->input()->field()->text($this->lng->txt('mail_filter_subject')); @@ -66,8 +67,9 @@ public function __construct( 'with_attachment' => $this->lng->txt('mail_filter_show_with_attachments'), 'without_attachment' => $this->lng->txt('mail_filter_show_without_attachment') ]); - $inputs['period'] = $this->ui_factory->input()->field()->duration($this->lng->txt('mail_filter_period')) - ->withTimezone($this->user_time_zone->getName()); + $inputs['period'] = $this->ui_factory + ->input()->field()->duration($this->lng->txt('mail_filter_period')) + ->withTimezone($this->user_time_zone->getName()); $this->filter = $this->filter_service->standard( self::class, @@ -75,7 +77,7 @@ public function __construct( //elements $inputs, // initially rendered - array_map(fn($value) => true, $inputs), + array_map(fn($value): bool => true, $inputs), false, false ); diff --git a/components/ILIAS/Mail/classes/Folder/MailFolderData.php b/components/ILIAS/Mail/classes/Folder/MailFolderData.php index 4aa9dc4247c0..5d6526f04ea5 100644 --- a/components/ILIAS/Mail/classes/Folder/MailFolderData.php +++ b/components/ILIAS/Mail/classes/Folder/MailFolderData.php @@ -64,6 +64,7 @@ public function isSent(): bool { return $this->type === MailFolderType::SENT; } + public function isTrash(): bool { return $this->type === MailFolderType::TRASH; diff --git a/components/ILIAS/Mail/classes/Folder/MailFolderSearch.php b/components/ILIAS/Mail/classes/Folder/MailFolderSearch.php index a6ff2ab3bd71..e813586a2d29 100644 --- a/components/ILIAS/Mail/classes/Folder/MailFolderSearch.php +++ b/components/ILIAS/Mail/classes/Folder/MailFolderSearch.php @@ -20,8 +20,6 @@ namespace ILIAS\Mail\Folder; -use Exception; -use ilSearchSettings; use ilMailSearchResult; use ilMailLuceneSearcher; use ilMailLuceneQueryParser; @@ -65,10 +63,10 @@ public function __construct( if ($this->lucene_enabled && ( ($this->filter->getSender() ?? '') !== '' || - ($this->filter->getRecipients() ?? '') !== '' || - ($this->filter->getSubject() ?? '') !== '' || - ($this->filter->getBody() ?? '') !== '' || - ($this->filter->getAttachment() ?? '') !== '' + ($this->filter->getRecipients() ?? '') !== '' || + ($this->filter->getSubject() ?? '') !== '' || + ($this->filter->getBody() ?? '') !== '' || + ($this->filter->getAttachment() ?? '') !== '' )) { $query_parser = new ilMailLuceneQueryParser(''); $query_parser->setFields([ @@ -141,7 +139,6 @@ public function getPagedRecords( ?MailBoxOrderColumn $order_column, ?string $order_direction ): array { - return $this->mailbox_query ->withFilteredIds($this->getFilteredIds()) ->withLimit($limit) @@ -154,6 +151,7 @@ public function getPagedRecords( /** * Get the cached mail ids from a lucene search for selected filter criteria * These will be used as additional filter for the mailbox query + * @return null|list */ private function getFilteredIds(): ?array { diff --git a/components/ILIAS/Mail/classes/Folder/MailFolderTableUI.php b/components/ILIAS/Mail/classes/Folder/MailFolderTableUI.php index 0e21f58d41a2..389b49d19f33 100644 --- a/components/ILIAS/Mail/classes/Folder/MailFolderTableUI.php +++ b/components/ILIAS/Mail/classes/Folder/MailFolderTableUI.php @@ -43,7 +43,6 @@ use Psr\Http\Message\ServerRequestInterface; use DateTimeImmutable; use DateTimeZone; -use ILIAS\UI\Component\Symbol\Symbol; class MailFolderTableUI implements \ILIAS\UI\Component\Table\DataRetrieval { @@ -64,7 +63,7 @@ class MailFolderTableUI implements \ILIAS\UI\Component\Table\DataRetrieval private array $avatars = []; /** - * @param MailFolderData[] $user_folders + * @param MailFolderData[] $user_folders */ public function __construct( private readonly URLBuilder $url_builder, @@ -216,13 +215,21 @@ private function getActions(): array foreach ($this->user_folders as $target_folder) { if ($target_folder->getFolderId() !== $this->current_folder->getFolderId()) { - $actions[self::ACTION_MOVE_TO . (string) $target_folder->getFolderId()] = $this->ui_factory->table()->action()->multi( - $this->lng->txt('mail_move_to') . ' ' . $target_folder->getTitle() - . ($target_folder->isTrash() ? ' (' . $this->lng->txt('delete') . ')' : ''), - $this->url_builder->withParameter($this->action_token, self::ACTION_MOVE_TO) - ->withParameter($this->folder_token, (string) $target_folder->getFolderId()), - $this->row_id_token - ); + $action_title = $this->lng->txt('mail_move_to') . ' ' . $target_folder->getTitle(); + if ($target_folder->isTrash()) { + $action_title .= ' (' . $this->lng->txt('delete') . ')'; + } + + $actions[self::ACTION_MOVE_TO . $target_folder->getFolderId()] = $this->ui_factory + ->table() + ->action() + ->multi( + $action_title, + $this->url_builder + ->withParameter($this->action_token, self::ACTION_MOVE_TO) + ->withParameter($this->folder_token, (string) $target_folder->getFolderId()), + $this->row_id_token + ); } } @@ -251,7 +258,6 @@ public function getRows( ?array $filter_data, // not used, because data is filtered by MailDataSearch ?array $additional_parameters // not used ): \Generator { - // mapping of table columns to allowed order columns of the mailbox query $order_columns = [ 'status' => MailBoxOrderColumn::STATUS, @@ -304,9 +310,10 @@ public function getRows( yield $row_builder->buildDataRow( (string) $record->getMailId(), $data - ) - ->withDisabledAction(self::ACTION_REPLY, !$record->hasPersonalSender()) - ->withDisabledAction(self::ACTION_DOWNLOAD_ATTACHMENT, !$record->hasAttachments()); + )->withDisabledAction(self::ACTION_REPLY, !$record->hasPersonalSender())->withDisabledAction( + self::ACTION_DOWNLOAD_ATTACHMENT, + !$record->hasAttachments() + ); } } @@ -365,13 +372,15 @@ private function getSender(MailRecordData $record): string if (!empty($user = ilMailUserCache::getUserObjectById($record->getSenderId()))) { if ($user->hasPublicProfile()) { - return $this->ui_renderer->render($this->ui_factory->link()->standard( - $user->getPublicName(), - (string) $this->url_builder - ->withParameter($this->action_token, self::ACTION_PROFILE) - ->withParameter($this->row_id_token, (string) $record->getMailId()) - ->buildURI() - )); + return $this->ui_renderer->render( + $this->ui_factory->link()->standard( + $user->getPublicName(), + (string) $this->url_builder + ->withParameter($this->action_token, self::ACTION_PROFILE) + ->withParameter($this->row_id_token, (string) $record->getMailId()) + ->buildURI() + ) + ); } return $user->getPublicName(); @@ -392,7 +401,10 @@ private function getSubject(MailRecordData $record): Link return $this->ui_factory->link()->standard( $this->refinery->encode()->htmlSpecialCharsAsEntities()->transform($record->getSubject()), (string) $this->url_builder - ->withParameter($this->action_token, $this->current_folder->isDrafts() ? self::ACTION_EDIT : self::ACTION_SHOW) + ->withParameter( + $this->action_token, + $this->current_folder->isDrafts() ? self::ACTION_EDIT : self::ACTION_SHOW + ) ->withParameter($this->row_id_token, (string) $record->getMailId()) ->buildURI() ); diff --git a/components/ILIAS/Mail/classes/Message/MailBoxQuery.php b/components/ILIAS/Mail/classes/Message/MailBoxQuery.php index 90ec7d8bf983..c26b9c583ff2 100755 --- a/components/ILIAS/Mail/classes/Message/MailBoxQuery.php +++ b/components/ILIAS/Mail/classes/Message/MailBoxQuery.php @@ -21,11 +21,9 @@ namespace ILIAS\Mail\Message; use ilDBInterface; -use ilMail; use ilDBConstants; use DateTimeImmutable; use DateTimeZone; -use ilTimeZone; use ILIAS\Data\Order; use ilUserSearchOptions; @@ -269,10 +267,10 @@ public function query($short): array if ($this->order_column === MailBoxOrderColumn::FROM) { $query .= ' ORDER BY ' - . ' u.firstname ' . $this->order_direction . ', ' - . ' u.lastname ' . $this->order_direction . ', ' - . ' u.login ' . $this->order_direction . ', ' - . ' m.import_name ' . $this->order_direction; + . ' u.firstname ' . $this->order_direction . ', ' + . ' u.lastname ' . $this->order_direction . ', ' + . ' u.login ' . $this->order_direction . ', ' + . ' m.import_name ' . $this->order_direction; } else { $query .= ' ORDER BY ' . $this->order_column->value . ' ' . $this->order_direction; } @@ -379,17 +377,18 @@ private function getWhere(): string if ($this->has_attachment === true) { $parts[] = '(m.attachments != ' . $this->db->quote(serialize(null), ilDBConstants::T_TEXT) - . ' AND m.attachments != ' . $this->db->quote(serialize([]), ilDBConstants::T_TEXT) . ')'; + . ' AND m.attachments != ' . $this->db->quote(serialize([]), ilDBConstants::T_TEXT) . ')'; } elseif ($this->has_attachment === false) { $parts[] = '(m.attachments = ' . $this->db->quote(serialize(null), ilDBConstants::T_TEXT) - . ' OR m.attachments = ' . $this->db->quote(serialize([]), ilDBConstants::T_TEXT) . ')'; + . ' OR m.attachments = ' . $this->db->quote(serialize([]), ilDBConstants::T_TEXT) . ')'; } if ($this->period_start !== null) { $parts[] = 'm.send_time >= ' . $this->db->quote( // convert to server time zone (set by ilias initialisation) - $this->period_start->setTimezone(new DateTimeZone(date_default_timezone_get())) - ->format('Y-m-d H:i:s'), + $this->period_start + ->setTimezone(new DateTimeZone(date_default_timezone_get())) + ->format('Y-m-d H:i:s'), ilDBConstants::T_TIMESTAMP ); } @@ -397,8 +396,9 @@ private function getWhere(): string if ($this->period_end !== null) { $parts[] = 'm.send_time <= ' . $this->db->quote( // convert to server time zone (set by ilias initialisation) - $this->period_end->setTimezone(new DateTimeZone(date_default_timezone_get())) - ->format('Y-m-d H:i:s'), + $this->period_end + ->setTimezone(new DateTimeZone(date_default_timezone_get())) + ->format('Y-m-d H:i:s'), ilDBConstants::T_TIMESTAMP ); } diff --git a/components/ILIAS/Mail/classes/Placeholder/MailSignatureUserFullnamePlaceholder.php b/components/ILIAS/Mail/classes/Placeholder/MailSignatureUserFullnamePlaceholder.php index dbb27e28683d..7d3063f36a5b 100644 --- a/components/ILIAS/Mail/classes/Placeholder/MailSignatureUserFullnamePlaceholder.php +++ b/components/ILIAS/Mail/classes/Placeholder/MailSignatureUserFullnamePlaceholder.php @@ -20,7 +20,6 @@ namespace ILIAS\Mail\Placeholder; -use ilObjUser; use ilLanguage; use ilUserUtil; diff --git a/components/ILIAS/Mail/classes/class.ilMailFolderGUI.php b/components/ILIAS/Mail/classes/class.ilMailFolderGUI.php index 0a8ca4a18d6e..d2c0303f70c7 100755 --- a/components/ILIAS/Mail/classes/class.ilMailFolderGUI.php +++ b/components/ILIAS/Mail/classes/class.ilMailFolderGUI.php @@ -27,7 +27,6 @@ use ILIAS\Mail\Folder\MailFilterUI; use ILIAS\Mail\Folder\MailFolderSearch; use ILIAS\Mail\Folder\MailFolderTableUI; -use ILIAS\Mail\Message\MailBoxQuery; use ILIAS\Mail\Folder\MailFolderData; use ILIAS\Filesystem\Stream\Streams; @@ -107,9 +106,15 @@ protected function initRequest(): void $this->mbox = new ilMailbox($this->user->getId()); if ($this->http->wrapper()->post()->has(self::PARAM_FOLDER_ID)) { - $folder_id = $this->http->wrapper()->post()->retrieve(self::PARAM_FOLDER_ID, $this->refinery->kindlyTo()->int()); + $folder_id = $this->http->wrapper()->post()->retrieve( + self::PARAM_FOLDER_ID, + $this->refinery->kindlyTo()->int() + ); } elseif ($this->http->wrapper()->query()->has(self::PARAM_FOLDER_ID)) { - $folder_id = $this->http->wrapper()->query()->retrieve(self::PARAM_FOLDER_ID, $this->refinery->kindlyTo()->int()); + $folder_id = $this->http->wrapper()->query()->retrieve( + self::PARAM_FOLDER_ID, + $this->refinery->kindlyTo()->int() + ); } else { $folder_id = $this->refinery->byTrying([ $this->refinery->kindlyTo()->int(), @@ -182,9 +187,9 @@ protected function executeTableAction(): void $this->http->wrapper()->query()->retrieve( self::URL_BUILDER_PREFIX . URLBuilder::SEPARATOR . self::PARAM_MAIL_ID, $this->refinery->byTrying([ - $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->string()), - $this->refinery->always([]) - ]) + $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->string()), + $this->refinery->always([]) + ]) ) ); @@ -200,13 +205,17 @@ protected function executeTableAction(): void if ($action === MailFolderTableUI::ACTION_DELETE) { $modal = $this->ui_factory->modal()->lightbox( $this->ui_factory->modal()->lightboxTextPage( - $this->ui_renderer->render($this->ui_factory->messageBox()->failure($this->lng->txt('mail_select_one'))), + $this->ui_renderer->render( + $this->ui_factory->messageBox()->failure($this->lng->txt('mail_select_one')) + ), $this->lng->txt('delete'), ) ); - $this->http->saveResponse($this->http->response()->withBody( - Streams::ofString($this->ui_renderer->renderAsync($modal)) - )); + $this->http->saveResponse( + $this->http->response()->withBody( + Streams::ofString($this->ui_renderer->renderAsync($modal)) + ) + ); $this->http->sendResponse(); $this->http->close(); } else { @@ -225,26 +234,38 @@ protected function executeTableAction(): void return; case MailFolderTableUI::ACTION_EDIT: - $this->ctrl->setParameterByClass(ilMailFormGUI::class, self::PARAM_FOLDER_ID, (string) $this->folder->getFolderId()); + $this->ctrl->setParameterByClass( + ilMailFormGUI::class, + self::PARAM_FOLDER_ID, + (string) $this->folder->getFolderId() + ); $this->ctrl->setParameterByClass(ilMailFormGUI::class, self::PARAM_MAIL_ID, (string) $mail_ids[0]); $this->ctrl->setParameterByClass(ilMailFormGUI::class, 'type', ilMailFormGUI::MAIL_FORM_TYPE_DRAFT); $this->ctrl->redirectByClass(ilMailFormGUI::class); - break; + // no break case MailFolderTableUI::ACTION_REPLY: - $this->ctrl->setParameterByClass(ilMailFormGUI::class, self::PARAM_FOLDER_ID, (string) $this->folder->getFolderId()); + $this->ctrl->setParameterByClass( + ilMailFormGUI::class, + self::PARAM_FOLDER_ID, + (string) $this->folder->getFolderId() + ); $this->ctrl->setParameterByClass(ilMailFormGUI::class, self::PARAM_MAIL_ID, (string) $mail_ids[0]); $this->ctrl->setParameterByClass(ilMailFormGUI::class, 'type', ilMailFormGUI::MAIL_FORM_TYPE_REPLY); $this->ctrl->redirectByClass(ilMailFormGUI::class); - break; + // no break case MailFolderTableUI::ACTION_FORWARD: - $this->ctrl->setParameterByClass(ilMailFormGUI::class, self::PARAM_FOLDER_ID, (string) $this->folder->getFolderId()); + $this->ctrl->setParameterByClass( + ilMailFormGUI::class, + self::PARAM_FOLDER_ID, + (string) $this->folder->getFolderId() + ); $this->ctrl->setParameterByClass(ilMailFormGUI::class, self::PARAM_MAIL_ID, (string) $mail_ids[0]); $this->ctrl->setParameterByClass(ilMailFormGUI::class, 'type', ilMailFormGUI::MAIL_FORM_TYPE_FORWARD); $this->ctrl->redirectByClass(ilMailFormGUI::class); - break; + // no break case MailFolderTableUI::ACTION_DOWNLOAD_ATTACHMENT: $this->deliverAttachments(); return; @@ -311,7 +332,7 @@ protected function executeTableAction(): void } break; - case MailFolderTableUI::ACTION_DELETE: // async call + case MailFolderTableUI::ACTION_DELETE: // async call $this->confirmDeleteMails($mail_ids); break; @@ -342,10 +363,11 @@ protected function emptyTrash(): void */ protected function showUser(): void { - $userId = 0; - if ($this->http->wrapper()->query()->has(self::PARAM_USER_ID)) { - $userId = $this->http->wrapper()->query()->retrieve(self::PARAM_USER_ID, $this->refinery->kindlyTo()->int()); - } + $userId = $this->http->wrapper()->query()->retrieve( + self::PARAM_USER_ID, + $this->refinery->byTrying([$this->refinery->kindlyTo()->int(), $this->refinery->always(0)]) + ); + $this->tpl->setVariable('TBL_TITLE', implode(' ', [ $this->lng->txt('profile_of'), ilObjUser::_lookupLogin($userId), @@ -355,18 +377,21 @@ protected function showUser(): void $profile_gui = new ilPublicUserProfileGUI($userId); - $mailId = 0; - if ($this->http->wrapper()->query()->has(self::PARAM_MAIL_ID)) { - $mailId = $this->http->wrapper()->query()->retrieve(self::PARAM_MAIL_ID, $this->refinery->kindlyTo()->int()); - } + $mailId = $this->http->wrapper()->query()->retrieve( + self::PARAM_MAIL_ID, + $this->refinery->byTrying([$this->refinery->kindlyTo()->int(), $this->refinery->always(0)]) + ); - if (!empty($mailId)) { + if ($mailId > 0) { $this->ctrl->setParameter($this, self::PARAM_MAIL_ID, $mailId); $this->tabs->clearTargets(); $this->tabs->setBackTarget($this->lng->txt('back'), $this->ctrl->getLinkTarget($this, self::CMD_SHOW_MAIL)); } else { $this->tabs->clearTargets(); - $this->tabs->setBackTarget($this->lng->txt('back_to_folder'), $this->ctrl->getLinkTarget($this, self::CMD_SHOW_FOLDER)); + $this->tabs->setBackTarget( + $this->lng->txt('back_to_folder'), + $this->ctrl->getLinkTarget($this, self::CMD_SHOW_FOLDER) + ); } $this->ctrl->clearParameters($this); @@ -382,28 +407,34 @@ protected function showFolder(): void $this->ctrl->setParameter($this, self::PARAM_FOLDER_ID, $this->folder->getFolderId()); if ($this->folder->isUserLocalFolder()) { - $this->toolbar->addComponent($this->ui_factory->button()->standard( - $this->lng->txt('mail_add_subfolder'), - $this->ctrl->getLinkTarget($this, self::CMD_ADD_SUB_FOLDER) - )); + $this->toolbar->addComponent( + $this->ui_factory->button()->standard( + $this->lng->txt('mail_add_subfolder'), + $this->ctrl->getLinkTarget($this, self::CMD_ADD_SUB_FOLDER) + ) + ); } if ($this->folder->isUserFolder()) { - $this->toolbar->addComponent($this->ui_factory->button()->standard( - $this->lng->txt('rename'), - $this->ctrl->getLinkTarget($this, self::CMD_RENAME_SUB_FOLDER) - )); + $this->toolbar->addComponent( + $this->ui_factory->button()->standard( + $this->lng->txt('rename'), + $this->ctrl->getLinkTarget($this, self::CMD_RENAME_SUB_FOLDER) + ) + ); $components[] = $modal = $this->ui_factory->modal()->interruptive( $this->lng->txt('delete'), $this->lng->txt('mail_sure_delete_folder'), $this->ctrl->getLinkTarget($this, self::CMD_DELETE_SUB_FOLDER) ); - $this->toolbar->addComponent($this->ui_factory->button()->standard( - $this->lng->txt('delete'), - '#' - ) - ->withOnClick($modal->getShowSignal())); + $this->toolbar->addComponent( + $this->ui_factory->button()->standard( + $this->lng->txt('delete'), + '#' + ) + ->withOnClick($modal->getShowSignal()) + ); } if ($this->folder->isTrash()) { @@ -412,11 +443,12 @@ protected function showFolder(): void $this->lng->txt('mail_empty_trash_confirmation'), $this->ctrl->getLinkTarget($this, self::CMD_EMPTY_TRASH) ); - $this->toolbar->addComponent($this->ui_factory->button()->standard( - $this->lng->txt('mail_empty_trash'), - '#' - ) - ->withOnClick($modal->getShowSignal())); + $this->toolbar->addComponent( + $this->ui_factory->button()->standard( + $this->lng->txt('mail_empty_trash'), + '#' + )->withOnClick($modal->getShowSignal()) + ); } [ @@ -424,16 +456,18 @@ protected function showFolder(): void $action_token, $row_id_token, $target_token, - ] = (new URLBuilder($this->data_factory->uri( - ilUtil::_getHttpPath() . '/' . - $this->ctrl->getLinkTarget($this, self::CMD_TABLE_ACTION) - )) - )->acquireParameters( - [self::URL_BUILDER_PREFIX], - self::PARAM_ACTION, - self::PARAM_MAIL_ID, - self::PARAM_TARGET_FOLDER - ); + ] = (new URLBuilder( + $this->data_factory->uri( + ilUtil::_getHttpPath() . '/' . + $this->ctrl->getLinkTarget($this, self::CMD_TABLE_ACTION) + ) + ) + )->acquireParameters( + [self::URL_BUILDER_PREFIX], + self::PARAM_ACTION, + self::PARAM_MAIL_ID, + self::PARAM_TARGET_FOLDER + ); $table = new MailFolderTableUI( $url_builder, @@ -462,7 +496,7 @@ protected function showFolder(): void $this->tpl->printToStdout(); } - protected function redirectToFolder() + protected function redirectToFolder(): never { $this->ctrl->clearParameters($this); $this->ctrl->setParameter($this, self::PARAM_FOLDER_ID, $this->folder->getFolderId()); @@ -490,7 +524,7 @@ protected function deleteSubFolder(): void } } - protected function addSubFolder(ilPropertyFormGUI $form = null): void + protected function addSubFolder(): void { $form = $this->ui_factory->input()->container()->form()->standard( $this->ctrl->getFormAction($this, self::CMD_ADD_SUB_FOLDER), @@ -502,17 +536,27 @@ protected function addSubFolder(ilPropertyFormGUI $form = null): void ); $request = $this->http->request(); - if ($request->getMethod() === "POST") { + if ($request->getMethod() === 'POST') { $form = $form->withRequest($request); $data = $form->getData(); if (!empty($data['folder']['title'])) { - $new_folder_id = $this->mbox->addFolder($this->folder->getFolderId(), (string) $data['folder']['title']); + $new_folder_id = $this->mbox->addFolder( + $this->folder->getFolderId(), + (string) $data['folder']['title'] + ); if ($new_folder_id > 0) { - $this->tpl->setOnScreenMessage(ilGlobalTemplateInterface::MESSAGE_TYPE_SUCCESS, $this->lng->txt('mail_folder_created'), true); + $this->tpl->setOnScreenMessage( + ilGlobalTemplateInterface::MESSAGE_TYPE_SUCCESS, + $this->lng->txt('mail_folder_created'), + true + ); $this->ctrl->setParameter($this, self::PARAM_FOLDER_ID, $new_folder_id); $this->ctrl->redirect($this, self::CMD_SHOW_FOLDER); } else { - $this->tpl->setOnScreenMessage(ilGlobalTemplateInterface::MESSAGE_TYPE_FAILURE, $this->lng->txt('mail_folder_exists')); + $this->tpl->setOnScreenMessage( + ilGlobalTemplateInterface::MESSAGE_TYPE_FAILURE, + $this->lng->txt('mail_folder_exists') + ); } } } @@ -520,7 +564,7 @@ protected function addSubFolder(ilPropertyFormGUI $form = null): void $this->tpl->printToStdout(); } - protected function renameSubFolder(ilPropertyFormGUI $form = null): void + protected function renameSubFolder(): void { $form = $this->ui_factory->input()->container()->form()->standard( $this->ctrl->getFormAction($this, self::CMD_RENAME_SUB_FOLDER), @@ -532,15 +576,22 @@ protected function renameSubFolder(ilPropertyFormGUI $form = null): void ); $request = $this->http->request(); - if ($request->getMethod() === "POST") { + if ($request->getMethod() === 'POST') { $form = $form->withRequest($request); $data = $form->getData(); if (!empty($data['folder']['title'])) { if ($this->mbox->renameFolder($this->folder->getFolderId(), (string) $data['folder']['title'])) { - $this->tpl->setOnScreenMessage(ilGlobalTemplateInterface::MESSAGE_TYPE_SUCCESS, $this->lng->txt('mail_folder_name_changed'), true); + $this->tpl->setOnScreenMessage( + ilGlobalTemplateInterface::MESSAGE_TYPE_SUCCESS, + $this->lng->txt('mail_folder_name_changed'), + true + ); $this->redirectToFolder(); } else { - $this->tpl->setOnScreenMessage(ilGlobalTemplateInterface::MESSAGE_TYPE_FAILURE, $this->lng->txt('mail_folder_exists')); + $this->tpl->setOnScreenMessage( + ilGlobalTemplateInterface::MESSAGE_TYPE_FAILURE, + $this->lng->txt('mail_folder_exists') + ); } } } @@ -579,15 +630,19 @@ protected function getFilteredSearch(): MailFolderSearch */ protected function getMailIdsFromRequest(): array { - $mailIds = []; // table actions have a prefix, controller commands and modal items have none - foreach ([self::URL_BUILDER_PREFIX . URLBuilder::SEPARATOR . self::PARAM_MAIL_ID, - self::PARAM_MAIL_ID, - self::PARAM_INTERRUPTIVE_ITEMS - ] as $param + foreach ( + [ + self::URL_BUILDER_PREFIX . URLBuilder::SEPARATOR . self::PARAM_MAIL_ID, + self::PARAM_MAIL_ID, + self::PARAM_INTERRUPTIVE_ITEMS + ] as $param ) { - foreach ([$this->http->wrapper()->post(), - $this->http->wrapper()->query()] as $wrapper + foreach ( + [ + $this->http->wrapper()->post(), + $this->http->wrapper()->query() + ] as $wrapper ) { if ($wrapper->has($param)) { return $wrapper->retrieve( @@ -611,27 +666,23 @@ protected function getMailIdsFromRequest(): array protected function moveSingleMail(): void { $mailIds = $this->getMailIdsFromRequest(); - if (1 !== count($mailIds)) { + if (count($mailIds) !== 1) { $this->showMail(); $this->tpl->setOnScreenMessage('info', $this->lng->txt('mail_select_one')); return; } - $newFolderId = 0; - if ($this->http->wrapper()->query()->has('folder_id')) { - $newFolderId = $this->http->wrapper()->query()->retrieve( - 'folder_id', - $this->refinery->kindlyTo()->int() - ); - } + $newFolderId = $this->http->wrapper()->query()->retrieve( + 'folder_id', + $this->refinery->byTrying([$this->refinery->kindlyTo()->int(), $this->refinery->always(0)]) + ); $redirectFolderId = $newFolderId; foreach ($mailIds as $mailId) { $mailData = $this->umail->getMail($mailId); if (isset($mailData['folder_id']) && is_numeric($mailData['folder_id']) && - (int) $mailData['folder_id'] > 0 - ) { + (int) $mailData['folder_id'] > 0) { $redirectFolderId = (int) $mailData['folder_id']; break; } @@ -647,7 +698,7 @@ protected function moveSingleMail(): void } } - protected function deleteMails(?array $mail_ids = null): void + protected function deleteMails(): void { if (!$this->folder->isTrash()) { $this->tpl->setOnScreenMessage( @@ -659,7 +710,11 @@ protected function deleteMails(?array $mail_ids = null): void } $this->umail->deleteMails($this->getMailIdsFromRequest()); - $this->tpl->setOnScreenMessage(ilGlobalTemplateInterface::MESSAGE_TYPE_INFO, $this->lng->txt('mail_deleted'), true); + $this->tpl->setOnScreenMessage( + ilGlobalTemplateInterface::MESSAGE_TYPE_INFO, + $this->lng->txt('mail_deleted'), + true + ); $this->redirectToFolder(); } @@ -672,7 +727,7 @@ protected function confirmDeleteMails(array $mail_ids): void $user_timezone = new DateTimeZone($this->user->getTimeZone()); $records = $this->getFilteredSearch()->forMailIds($mail_ids)->getPagedRecords(10, 0, null, null); $items = []; - foreach($records as $record) { + foreach ($records as $record) { $prefix = ''; if (!empty($record->getSendTime())) { $time = $record->getSendTime()->setTimezone($user_timezone); @@ -690,9 +745,11 @@ protected function confirmDeleteMails(array $mail_ids): void $this->ctrl->getFormAction($this, self::CMD_DELETE_MAILS) )->withAffectedItems($items); - $this->http->saveResponse($this->http->response()->withBody( - Streams::ofString($this->ui_renderer->renderAsync($modal)) - )); + $this->http->saveResponse( + $this->http->response()->withBody( + Streams::ofString($this->ui_renderer->renderAsync($modal)) + ) + ); $this->http->sendResponse(); $this->http->close(); } @@ -700,7 +757,6 @@ protected function confirmDeleteMails(array $mail_ids): void protected function showMail(): void { $mailId = $this->getMailIdsFromRequest()[0] ?? 0; - if ($mailId <= 0) { $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE); } @@ -820,27 +876,33 @@ protected function showMail(): void $form->addItem($from); $to = new ilCustomInputGUI($this->lng->txt('mail_to') . ':'); - $to->setHtml(ilUtil::htmlencodePlainString( - $this->umail->formatNamesForOutput($mailData['rcp_to'] ?? ''), - false - )); + $to->setHtml( + ilUtil::htmlencodePlainString( + $this->umail->formatNamesForOutput($mailData['rcp_to'] ?? ''), + false + ) + ); $form->addItem($to); if ($mailData['rcp_cc']) { $cc = new ilCustomInputGUI($this->lng->txt('mail_cc') . ':'); - $cc->setHtml(ilUtil::htmlencodePlainString( - $this->umail->formatNamesForOutput($mailData['rcp_cc'] ?? ''), - false - )); + $cc->setHtml( + ilUtil::htmlencodePlainString( + $this->umail->formatNamesForOutput($mailData['rcp_cc']), + false + ) + ); $form->addItem($cc); } if ($mailData['rcp_bcc']) { $bcc = new ilCustomInputGUI($this->lng->txt('mail_bcc') . ':'); - $bcc->setHtml(ilUtil::htmlencodePlainString( - $this->umail->formatNamesForOutput($mailData['rcp_bcc'] ?? ''), - false - )); + $bcc->setHtml( + ilUtil::htmlencodePlainString( + $this->umail->formatNamesForOutput($mailData['rcp_bcc']), + false + ) + ); $form->addItem($bcc); } @@ -849,9 +911,11 @@ protected function showMail(): void $form->addItem($subject); $date = new ilCustomInputGUI($this->lng->txt('mail_sent_datetime') . ':'); - $date->setHtml(ilDatePresentation::formatDate( - new ilDateTime($mailData['send_time'], IL_CAL_DATETIME) - )); + $date->setHtml( + ilDatePresentation::formatDate( + new ilDateTime($mailData['send_time'], IL_CAL_DATETIME) + ) + ); $form->addItem($date); $message = new ilCustomInputGUI($this->lng->txt('message') . ':'); @@ -892,7 +956,6 @@ protected function showMail(): void foreach ($folders as $folder) { if ((!$folder->isTrash() || !$current_folder->isTrash()) && $folder->getFolderId() !== $mailData['folder_id']) { - $move_links[] = $this->ui_factory->button()->shy( sprintf( $this->lng->txt('mail_move_to_folder_x'), @@ -948,7 +1011,7 @@ protected function showMail(): void if ($move_links !== []) { $this->toolbar->addComponent( $this->ui_factory->dropdown()->standard($move_links) - ->withLabel($this->lng->txt('mail_move_to_folder_btn_label')) + ->withLabel($this->lng->txt('mail_move_to_folder_btn_label')) ); } @@ -1066,19 +1129,18 @@ protected function printMail(): void protected function deliverFile(): void { - $mailId = 0; - if ($this->http->wrapper()->query()->has(self::PARAM_MAIL_ID)) { - $mailId = $this->http->wrapper()->query()->retrieve(self::PARAM_MAIL_ID, $this->refinery->kindlyTo()->int()); - } - + $mailId = $this->http->wrapper()->query()->retrieve( + self::PARAM_MAIL_ID, + $this->refinery->byTrying([$this->refinery->kindlyTo()->int(), $this->refinery->always(0)]) + ); if ($mailId <= 0) { $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE); } - $filename = ''; - if ($this->http->wrapper()->post()->has('filename')) { - $filename = $this->http->wrapper()->post()->retrieve('filename', $this->refinery->kindlyTo()->string()); - } + $filename = $this->http->wrapper()->post()->retrieve( + 'filename', + $this->refinery->byTrying([$this->refinery->kindlyTo()->string(), $this->refinery->always('')]) + ); if (is_string(ilSession::get('filename')) && ilSession::get('filename') !== '') { $filename = ilSession::get('filename'); @@ -1112,15 +1174,15 @@ protected function deliverAttachments(): void { try { $mailId = $this->getMailIdsFromRequest()[0] ?? 0; - $mailData = $this->umail->getMail((int) $mailId); + $mailData = $this->umail->getMail($mailId); if (null === $mailData || [] === (array) $mailData['attachments']) { throw new ilMailException('mail_error_reading_attachment'); } - $type = ''; - if ($this->http->wrapper()->query()->has('type')) { - $type = $this->http->wrapper()->query()->retrieve('type', $this->refinery->kindlyTo()->string()); - } + $type = $this->http->wrapper()->query()->retrieve( + 'type', + $this->refinery->byTrying([$this->refinery->kindlyTo()->string(), $this->refinery->always('')]) + ); $mailFileData = new ilFileDataMail($this->user->getId()); if (count($mailData['attachments']) === 1) { @@ -1136,7 +1198,7 @@ protected function deliverAttachments(): void } else { $file = $mailFileData->getAttachmentPathAndFilenameByMd5Hash( md5($attachment), - (int) $mailId + $mailId ); $pathToFile = $file['path']; $fileName = $file['filename']; @@ -1148,7 +1210,7 @@ protected function deliverAttachments(): void } else { $mailFileData->deliverAttachmentsAsZip( $mailData['m_subject'], - (int) $mailId, + $mailId, $mailData['attachments'], 'draft' === $type ); diff --git a/components/ILIAS/Mail/classes/class.ilMailLuceneQueryParser.php b/components/ILIAS/Mail/classes/class.ilMailLuceneQueryParser.php index 973f750cb84d..af56fabcbf21 100755 --- a/components/ILIAS/Mail/classes/class.ilMailLuceneQueryParser.php +++ b/components/ILIAS/Mail/classes/class.ilMailLuceneQueryParser.php @@ -20,7 +20,8 @@ class ilMailLuceneQueryParser extends ilLuceneQueryParser { - protected array $fields = []; + /** @var array{'title': ?string, 'content': ?string, 'mattachment': ?string, 'msender': ?string}|array{} */ + private array $fields = []; public function parse(): void { @@ -62,7 +63,7 @@ public function parse(): void * Set the fields to query for * ILIAS 10: the values are not boolean, but different query strings for the fields * - * @param array{'title': ?string, 'content': ?string, 'mattachment': ?string, 'msender': ?string} $fields + * @param array{'title': ?string, 'content': ?string, 'mattachment': ?string, 'msender': ?string}|array{} $fields */ public function setFields(array $fields): void { @@ -72,7 +73,7 @@ public function setFields(array $fields): void /** * Get the fields to query for * ILIAS 10 the values are not boolean, but different query strings for the fields - * @return array{'title': ?string, 'content': ?string, 'mattachment': ?string, 'msender': ?string} + * @return array{'title': ?string, 'content': ?string, 'mattachment': ?string, 'msender': ?string}|array{} */ public function getFields(): array { diff --git a/components/ILIAS/Mail/classes/class.ilMailbox.php b/components/ILIAS/Mail/classes/class.ilMailbox.php index 5a8a883d75a5..8aa8951e86ee 100755 --- a/components/ILIAS/Mail/classes/class.ilMailbox.php +++ b/components/ILIAS/Mail/classes/class.ilMailbox.php @@ -25,33 +25,33 @@ * Mail Box class * Base class for creating and handling mail boxes * - * @author Stefan Meyer + * @author Stefan Meyer * @version $Id$ * */ class ilMailbox { - protected ilLanguage $lng; - protected ilDBInterface $db; - protected ilTree $mtree; + private ilLanguage $lng; + private ilDBInterface $db; + private ilTree $mtree; /** @var array{b_inbox: string, c_trash: string, d_drafts: string, e_sent: string, z_local : string} */ - protected array $defaultFolders = [ + private array $defaultFolders = [ 'b_inbox' => 'inbox', 'c_trash' => 'trash', 'd_drafts' => 'drafts', 'e_sent' => 'sent', 'z_local' => 'local', ]; - protected string $table_mail_obj_data; - protected string $table_tree; + private string $table_mail_obj_data; + private string $table_tree; public function __construct(protected int $usrId) { global $DIC; if ($usrId < 1) { - throw new InvalidArgumentException("Cannot create mailbox without user id"); + throw new InvalidArgumentException('Cannot create mailbox without user id'); } $this->lng = $DIC->language(); @@ -62,12 +62,7 @@ public function __construct(protected int $usrId) $this->mtree = new ilTree($this->usrId); $this->mtree->setTableNames($this->table_tree, $this->table_mail_obj_data); - // i added this, becaus if i create a new user automatically during - // CAS authentication, we have no $lng variable (alex, 16.6.2006) - // (alternative: make createDefaultFolder call static in ilObjUser->saveAsNew()) - if (is_object($this->lng)) { - $this->lng->loadLanguageModule("mail"); - } + $this->lng->loadLanguageModule('mail'); } public function getRooFolder(): int @@ -303,7 +298,7 @@ public function getSubFolders(): array [$this->usrId, $key] ); $row = $this->db->fetchAssoc($res); - if(is_array($row)) { + if (is_array($row)) { $userFolders[] = $this->getFolderDataFromRow($row); } } diff --git a/components/ILIAS/Mail/tests/ilMailTest.php b/components/ILIAS/Mail/tests/ilMailTest.php index d28db3f1b48f..c96096262c83 100755 --- a/components/ILIAS/Mail/tests/ilMailTest.php +++ b/components/ILIAS/Mail/tests/ilMailTest.php @@ -20,7 +20,6 @@ use ILIAS\Refinery\Factory; use PHPUnit\Framework\MockObject\MockObject; -use ILIAS\Mail\Autoresponder\AutoresponderServiceImpl; use ILIAS\Mail\Autoresponder\AutoresponderService; use ILIAS\LegalDocuments\Conductor; use ILIAS\Refinery\Transformation;