PHP8 compatibility fixes (T7241)

This commit is contained in:
Aleksander Machniak 2023-06-16 11:36:22 +02:00
parent 7f764413f6
commit 5fcf64fd9f
4 changed files with 43 additions and 19 deletions

View file

@ -2115,22 +2115,24 @@ $("#rcmfd_new_category").keypress(function(event) {
// check for organizer in attendees list // check for organizer in attendees list
$organizer = null; $organizer = null;
foreach ((array) $event['attendees'] as $i => $attendee) { if (!empty($event['attendees'])) {
if (!empty($attendee['role']) && $attendee['role'] == 'ORGANIZER') { foreach ((array) $event['attendees'] as $i => $attendee) {
$organizer = $attendee; if (!empty($attendee['role']) && $attendee['role'] == 'ORGANIZER') {
} $organizer = $attendee;
if (!empty($attendee['status']) && $attendee['status'] == 'DELEGATED' && empty($attendee['rsvp'])) { }
$event['attendees'][$i]['noreply'] = true; if (!empty($attendee['status']) && $attendee['status'] == 'DELEGATED' && empty($attendee['rsvp'])) {
} $event['attendees'][$i]['noreply'] = true;
else { }
unset($event['attendees'][$i]['noreply']); else {
unset($event['attendees'][$i]['noreply']);
}
} }
} }
if ($organizer === null && !empty($event['organizer'])) { if ($organizer === null && !empty($event['organizer'])) {
$organizer = $event['organizer']; $organizer = $event['organizer'];
$organizer['role'] = 'ORGANIZER'; $organizer['role'] = 'ORGANIZER';
if (!is_array($event['attendees'])) { if (!isset($event['attendees']) || !is_array($event['attendees'])) {
$event['attendees'] = [$organizer]; $event['attendees'] = [$organizer];
} }
} }

View file

@ -507,7 +507,7 @@ abstract class calendar_driver
// add to output if in range // add to output if in range
if (($next_event['start'] <= $end && $next_event['end'] >= $start)) { if (($next_event['start'] <= $end && $next_event['end'] >= $start)) {
$next_event['_instance'] = $next_event['start']->format($recurrence_id_format); $next_event['_instance'] = $next_event['start']->format($recurrence_id_format);
$next_event['id'] = $next_event['uid'] . '-' . $exception['_instance']; $next_event['id'] = $next_event['uid'] . '-' . $next_event['_instance'];
$next_event['recurrence_id'] = $event['uid']; $next_event['recurrence_id'] = $event['uid'];
$events[] = $next_event; $events[] = $next_event;
} }
@ -647,7 +647,7 @@ abstract class calendar_driver
$year2 = $end->format('Y'); $year2 = $end->format('Y');
$events = []; $events = [];
$search = mb_strtolower($search); $search = mb_strtolower((string) $search);
$rcmail = rcmail::get_instance(); $rcmail = rcmail::get_instance();
$cache = $rcmail->get_cache('calendar.birthdays', 'db', 3600); $cache = $rcmail->get_cache('calendar.birthdays', 'db', 3600);
$cache->expunge(); $cache->expunge();
@ -786,18 +786,14 @@ abstract class calendar_driver
} }
try { try {
$bday = $contact['birthday']; $bday = libcalendaring_datetime::createFromAny($contact['birthday'], true);
if (!$bday instanceof DateTimeInterface) {
$bday = new DateTime($bday, new DateTimeZone('UTC'));
}
$bday->_dateonly = true;
} }
catch (Exception $e) { catch (Exception $e) {
rcube::raise_error([ rcube::raise_error([
'code' => 600, 'code' => 600,
'file' => __FILE__, 'file' => __FILE__,
'line' => __LINE__, 'line' => __LINE__,
'message' => 'BIRTHDAY PARSE ERROR: ' . $e->getMessage() 'message' => 'Failed to parse contact birthday: ' . $e->getMessage()
], ],
true, false true, false
); );

View file

@ -26,4 +26,30 @@
class libcalendaring_datetime extends DateTime class libcalendaring_datetime extends DateTime
{ {
public $_dateonly = false; public $_dateonly = false;
/**
* Create an instance from a date string or object
*
* @param DateTimeInterface|string $date Date
* @param bool $dateonly Date only (ignore time)
*/
public static function createFromAny($date, bool $dateonly = false)
{
if (!$date instanceof DateTimeInterface) {
$date = new DateTime($date, new DateTimeZone('UTC'));
}
// Note: On PHP8 we have DateTime::createFromInterface(), but not on PHP7
$result = self::createFromFormat(
'Y-m-d\\TH:i:s',
$date->format('Y-m-d\\TH:i:s'),
// Sabre will loose timezone on all-day events, use the event start's timezone
$date->getTimezone()
);
$result->_dateonly = $dateonly;
return $result;
}
} }

View file

@ -853,7 +853,7 @@ class libcalendaring extends rcube_plugin
return $this->gettext('ondate') . ' ' . join(', ', $rdates) . ($more ? '...' : ''); return $this->gettext('ondate') . ' ' . join(', ', $rdates) . ($more ? '...' : '');
} }
$output = sprintf('%s %d ', $this->gettext('every'), $rrule['INTERVAL'] ?: 1); $output = sprintf('%s %d ', $this->gettext('every'), !empty($rrule['INTERVAL']) ? $rrule['INTERVAL'] : 1);
switch ($rrule['FREQ']) { switch ($rrule['FREQ']) {
case 'DAILY': case 'DAILY':