mirror of
https://github.com/nextcloud/server.git
synced 2026-04-21 22:27:31 -04:00
Improve behavior with dates on 32bits and fix tests or skip them
We do not support events after 2038 on 32bits but still behave better when date range start/end is after 2038. Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
This commit is contained in:
parent
110fc79918
commit
d315bce300
3 changed files with 34 additions and 20 deletions
|
|
@ -72,7 +72,6 @@ use OCP\EventDispatcher\IEventDispatcher;
|
|||
use OCP\IConfig;
|
||||
use OCP\IDBConnection;
|
||||
use OCP\IGroupManager;
|
||||
use OCP\IUser;
|
||||
use OCP\IUserManager;
|
||||
use OCP\Security\ISecureRandom;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
|
@ -120,7 +119,6 @@ use function time;
|
|||
* @package OCA\DAV\CalDAV
|
||||
*/
|
||||
class CalDavBackend extends AbstractBackend implements SyncSupport, SubscriptionSupport, SchedulingSupport {
|
||||
|
||||
use TTransactional;
|
||||
|
||||
public const CALENDAR_TYPE_CALENDAR = 0;
|
||||
|
|
@ -346,7 +344,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
|
|||
$row['principaluri'] = (string) $row['principaluri'];
|
||||
$components = [];
|
||||
if ($row['components']) {
|
||||
$components = explode(',',$row['components']);
|
||||
$components = explode(',', $row['components']);
|
||||
}
|
||||
|
||||
$calendar = [
|
||||
|
|
@ -420,7 +418,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
|
|||
$row['displayname'] = $row['displayname'] . ' (' . ($this->userManager->getDisplayName($name) ?? ($name ?? '')) . ')';
|
||||
$components = [];
|
||||
if ($row['components']) {
|
||||
$components = explode(',',$row['components']);
|
||||
$components = explode(',', $row['components']);
|
||||
}
|
||||
$calendar = [
|
||||
'id' => $row['id'],
|
||||
|
|
@ -469,7 +467,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
|
|||
$row['principaluri'] = (string) $row['principaluri'];
|
||||
$components = [];
|
||||
if ($row['components']) {
|
||||
$components = explode(',',$row['components']);
|
||||
$components = explode(',', $row['components']);
|
||||
}
|
||||
$calendar = [
|
||||
'id' => $row['id'],
|
||||
|
|
@ -521,7 +519,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
|
|||
$row['displayname'] = $row['displayname'] . "($name)";
|
||||
$components = [];
|
||||
if ($row['components']) {
|
||||
$components = explode(',',$row['components']);
|
||||
$components = explode(',', $row['components']);
|
||||
}
|
||||
$calendar = [
|
||||
'id' => $row['id'],
|
||||
|
|
@ -586,7 +584,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
|
|||
$row['displayname'] = $row['displayname'] . ' ' . "($name)";
|
||||
$components = [];
|
||||
if ($row['components']) {
|
||||
$components = explode(',',$row['components']);
|
||||
$components = explode(',', $row['components']);
|
||||
}
|
||||
$calendar = [
|
||||
'id' => $row['id'],
|
||||
|
|
@ -639,7 +637,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
|
|||
$row['principaluri'] = (string) $row['principaluri'];
|
||||
$components = [];
|
||||
if ($row['components']) {
|
||||
$components = explode(',',$row['components']);
|
||||
$components = explode(',', $row['components']);
|
||||
}
|
||||
|
||||
$calendar = [
|
||||
|
|
@ -687,7 +685,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
|
|||
$row['principaluri'] = (string) $row['principaluri'];
|
||||
$components = [];
|
||||
if ($row['components']) {
|
||||
$components = explode(',',$row['components']);
|
||||
$components = explode(',', $row['components']);
|
||||
}
|
||||
|
||||
$calendar = [
|
||||
|
|
@ -779,7 +777,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
|
|||
if (!($properties[$sccs] instanceof SupportedCalendarComponentSet)) {
|
||||
throw new DAV\Exception('The ' . $sccs . ' property must be of type: \Sabre\CalDAV\Property\SupportedCalendarComponentSet');
|
||||
}
|
||||
$values['components'] = implode(',',$properties[$sccs]->getValue());
|
||||
$values['components'] = implode(',', $properties[$sccs]->getValue());
|
||||
} elseif (isset($properties['components'])) {
|
||||
// Allow to provide components internally without having
|
||||
// to create a SupportedCalendarComponentSet object
|
||||
|
|
@ -797,7 +795,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
|
|||
}
|
||||
}
|
||||
|
||||
[$calendarId, $calendarData] = $this->atomic(function() use ($values) {
|
||||
[$calendarId, $calendarData] = $this->atomic(function () use ($values) {
|
||||
$query = $this->db->getQueryBuilder();
|
||||
$query->insert('calendars');
|
||||
foreach ($values as $column => $value) {
|
||||
|
|
@ -1635,10 +1633,19 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
|
|||
}
|
||||
|
||||
if ($timeRange && $timeRange['start']) {
|
||||
$query->andWhere($query->expr()->gt('lastoccurence', $query->createNamedParameter($timeRange['start']->getTimeStamp())));
|
||||
try {
|
||||
$query->andWhere($query->expr()->gt('lastoccurence', $query->createNamedParameter($timeRange['start']->getTimeStamp())));
|
||||
} catch (\ValueError) {
|
||||
/* Will happen for dates too far in the future on 32bit, return no results */
|
||||
return [];
|
||||
}
|
||||
}
|
||||
if ($timeRange && $timeRange['end']) {
|
||||
$query->andWhere($query->expr()->lt('firstoccurence', $query->createNamedParameter($timeRange['end']->getTimeStamp())));
|
||||
try {
|
||||
$query->andWhere($query->expr()->lt('firstoccurence', $query->createNamedParameter($timeRange['end']->getTimeStamp())));
|
||||
} catch (\ValueError) {
|
||||
/* Will happen for dates too far in the future on 32bit, ignore the limit in this case */
|
||||
}
|
||||
}
|
||||
|
||||
$stmt = $query->executeQuery();
|
||||
|
|
@ -1712,7 +1719,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
|
|||
$query->expr()->eq('c.calendarid',
|
||||
$query->createNamedParameter($id)),
|
||||
$query->expr()->eq('c.calendartype',
|
||||
$query->createNamedParameter(self::CALENDAR_TYPE_CALENDAR)));
|
||||
$query->createNamedParameter(self::CALENDAR_TYPE_CALENDAR)));
|
||||
}
|
||||
foreach ($sharedCalendars as $id) {
|
||||
$calendarExpressions[] = $query->expr()->andX(
|
||||
|
|
@ -1860,7 +1867,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
|
|||
}
|
||||
}
|
||||
|
||||
if(isset($options['uid'])) {
|
||||
if (isset($options['uid'])) {
|
||||
$outerQuery->andWhere($outerQuery->expr()->eq('uid', $outerQuery->createNamedParameter($options['uid'])));
|
||||
}
|
||||
|
||||
|
|
@ -2435,7 +2442,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
|
|||
}
|
||||
}
|
||||
|
||||
[$subscriptionId, $subscriptionRow] = $this->atomic(function() use ($values) {
|
||||
[$subscriptionId, $subscriptionRow] = $this->atomic(function () use ($values) {
|
||||
$valuesToInsert = [];
|
||||
$query = $this->db->getQueryBuilder();
|
||||
foreach (array_keys($values) as $name) {
|
||||
|
|
|
|||
|
|
@ -125,7 +125,6 @@ class CalDavBackendTest extends AbstractCalDavBackend {
|
|||
* @dataProvider providesSharingData
|
||||
*/
|
||||
public function testCalendarSharing($userCanRead, $userCanWrite, $groupCanRead, $groupCanWrite, $add): void {
|
||||
|
||||
/** @var IL10N|\PHPUnit\Framework\MockObject\MockObject $l10n */
|
||||
$l10n = $this->createMock(IL10N::class);
|
||||
$l10n
|
||||
|
|
@ -423,7 +422,12 @@ EOD;
|
|||
$events[0] = $this->createEvent($calendarId, '20130912T130000Z', '20130912T140000Z');
|
||||
$events[1] = $this->createEvent($calendarId, '20130912T150000Z', '20130912T170000Z');
|
||||
$events[2] = $this->createEvent($calendarId, '20130912T173000Z', '20130912T220000Z');
|
||||
$events[3] = $this->createEvent($calendarId, '21130912T130000Z', '22130912T130000Z');
|
||||
if (PHP_INT_SIZE > 8) {
|
||||
$events[3] = $this->createEvent($calendarId, '21130912T130000Z', '22130912T130000Z');
|
||||
} else {
|
||||
/* On 32bit we do not support events after 2038 */
|
||||
$events[3] = $this->createEvent($calendarId, '20370912T130000Z', '20370912T130000Z');
|
||||
}
|
||||
|
||||
$result = $this->backend->calendarQuery($calendarId, [
|
||||
'name' => '',
|
||||
|
|
@ -471,7 +475,7 @@ EOD;
|
|||
'only-events' => [[0, 1, 2, 3], [], [['name' => 'VEVENT', 'is-not-defined' => false, 'comp-filters' => [], 'time-range' => ['start' => null, 'end' => null], 'prop-filters' => []]],],
|
||||
'start' => [[1, 2, 3], [], [['name' => 'VEVENT', 'is-not-defined' => false, 'comp-filters' => [], 'time-range' => ['start' => new DateTime('2013-09-12 14:00:00', new DateTimeZone('UTC')), 'end' => null], 'prop-filters' => []]],],
|
||||
'end' => [[0], [], [['name' => 'VEVENT', 'is-not-defined' => false, 'comp-filters' => [], 'time-range' => ['start' => null, 'end' => new DateTime('2013-09-12 14:00:00', new DateTimeZone('UTC'))], 'prop-filters' => []]],],
|
||||
'future' => [[3], [], [['name' => 'VEVENT', 'is-not-defined' => false, 'comp-filters' => [], 'time-range' => ['start' => new DateTime('2099-09-12 14:00:00', new DateTimeZone('UTC')), 'end' => null], 'prop-filters' => []]],],
|
||||
'future' => [[3], [], [['name' => 'VEVENT', 'is-not-defined' => false, 'comp-filters' => [], 'time-range' => ['start' => new DateTime('2036-09-12 14:00:00', new DateTimeZone('UTC')), 'end' => null], 'prop-filters' => []]],],
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -93,7 +93,10 @@ class HelperTest extends \Test\TestCase {
|
|||
/**
|
||||
* @dataProvider sortDataProvider
|
||||
*/
|
||||
public function testSortByName($sort, $sortDescending, $expectedOrder) {
|
||||
public function testSortByName(string $sort, bool $sortDescending, array $expectedOrder) {
|
||||
if (($sort === 'mtime') && (PHP_INT_SIZE < 8)) {
|
||||
$this->skip('Skip mtime sorting on 32bit');
|
||||
}
|
||||
$files = self::getTestFileList();
|
||||
$files = \OCA\Files\Helper::sortFiles($files, $sort, $sortDescending);
|
||||
$fileNames = [];
|
||||
|
|
|
|||
Loading…
Reference in a new issue