Plugin version: 3.2.6
GLPI version: 11.x
Priority: High
Files: src/NotificationMail.php, src/NotificationTargetHoliday.php, vendor/phpmailer/
Summary
The plugin maintains a custom NotificationMail class that extends a bundled PHPMailer instance. GLPI 11 provides a complete, transport-agnostic notification system. Using it eliminates the bundled dependency, reduces plugin size by ~500KB, and ensures notifications behave consistently with the rest of GLPI (queue, templates, admin configuration, etc.).
The infrastructure is already partially in place — src/NotificationTargetHoliday.php exists. The goal is to complete it and remove the custom mail layer.
Step 1 — Complete NotificationTargetHoliday
// src/NotificationTargetHoliday.php
namespace GlpiPlugin\Activity;
use NotificationTarget;
use Session;
use User;
class NotificationTargetHoliday extends NotificationTarget
{
/**
* Declare the events this target handles.
*/
public function getEvents(): array
{
return [
'newvalidation' => __('New holiday validation request', 'activity'),
'answervalidation' => __('Holiday validation answer', 'activity'),
];
}
/**
* Define who receives notifications for each event.
*/
public function addAdditionalTargets(string $event = ''): void
{
switch ($event) {
case 'newvalidation':
// Notify validators
$this->addTarget(
Notification::USER,
__('Validator', 'activity')
);
break;
case 'answervalidation':
// Notify the applicant
$this->addTarget(
Notification::ITEM_TECH_IN_CHARGE,
__('Applicant', 'activity')
);
break;
}
}
/**
* Populate template variables for the notification.
*/
public function addDataForTemplate(string $event, array $options = []): void
{
/** @var Holiday $holiday */
$holiday = $this->obj;
$this->data['##activity.url##'] = $this->formatURL(
$options['additionalTargets'] ?? '',
Holiday::getFormURLWithID($holiday->getID())
);
$this->data['##holiday.status##'] = Holiday::getStatusName($holiday->fields['status']);
$this->data['##holiday.applicant.name##'] = getUserName($holiday->fields['users_id']);
$this->data['##holiday.name##'] = $holiday->fields['name'];
$this->data['##holiday.begin.date##'] = Html::convDate($holiday->fields['begin']);
$this->data['##holiday.end.date##'] = Html::convDate($holiday->fields['end']);
$this->data['##holiday.nbdays##'] = $holiday->fields['actiontime'];
$this->data['##holiday.date.submission##'] = Html::convDateTime($holiday->fields['date']);
$this->data['##holiday.holidaytype##'] = Dropdown::getDropdownName(
'glpi_plugin_activity_holidaytypes',
$holiday->fields['plugin_activity_holidaytypes_id']
);
}
public function getTags(): void
{
$tags = [
'activity.url' => __('URL', 'activity'),
'holiday.status' => __('Status', 'activity'),
'holiday.applicant.name' => __('Applicant', 'activity'),
'holiday.name' => __('Name'),
'holiday.begin.date' => __('Begin date', 'activity'),
'holiday.end.date' => __('End date', 'activity'),
'holiday.nbdays' => __('Number of days', 'activity'),
'holiday.date.submission' => __('Submission date', 'activity'),
'holiday.holidaytype' => __('Holiday type', 'activity'),
];
foreach ($tags as $tag => $label) {
$this->addTagToList(['tag' => $tag, 'label' => $label, 'value' => true]);
}
}
}
Step 2 — Raise events from Holiday and HolidayValidation
// src/Holiday.php — after add()
public function post_addItem(): void
{
NotificationEvent::raiseEvent('newvalidation', $this);
}
// src/HolidayValidation.php — after status change
public function post_updateItem(array $history = []): void
{
$holiday = new Holiday();
$holiday->getFromDB($this->fields['plugin_activity_holidays_id']);
NotificationEvent::raiseEvent('answervalidation', $holiday);
}
Step 3 — Update composer.json
{
"require": {
"fpdf/fpdf": "^1.86"
}
}
Then run:
Step 4 — Delete custom mail files
src/NotificationMail.php ← delete
vendor/phpmailer/ ← deleted by composer update
Benefits
| Before |
After |
| Custom SMTP config in plugin |
Uses GLPI's configured mail transport |
| Notifications bypass GLPI queue |
Queued, logged, and retried by GLPI |
| No admin visibility |
Visible in GLPI notification log |
| Bundled PHPMailer 6.12.0 |
GLPI's PHPMailer (always up to date) |
| ~500KB vendor overhead |
0KB added |
Plugin version: 3.2.6
GLPI version: 11.x
Priority: High
Files:
src/NotificationMail.php,src/NotificationTargetHoliday.php,vendor/phpmailer/Summary
The plugin maintains a custom
NotificationMailclass that extends a bundled PHPMailer instance. GLPI 11 provides a complete, transport-agnostic notification system. Using it eliminates the bundled dependency, reduces plugin size by ~500KB, and ensures notifications behave consistently with the rest of GLPI (queue, templates, admin configuration, etc.).The infrastructure is already partially in place —
src/NotificationTargetHoliday.phpexists. The goal is to complete it and remove the custom mail layer.Step 1 — Complete
NotificationTargetHolidayStep 2 — Raise events from
HolidayandHolidayValidationStep 3 — Update
composer.jsonThen run:
Step 4 — Delete custom mail files
Benefits