Fix public calendars as they are stored with null on oracle

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2020-11-09 10:40:55 +01:00
parent 8ff0523c3d
commit b6ce689e25
No known key found for this signature in database
GPG Key ID: 7076EA9751AACDDA
1 changed files with 34 additions and 12 deletions

View File

@ -241,8 +241,13 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
$principalUri = $this->convertPrincipal($principalUri, true); $principalUri = $this->convertPrincipal($principalUri, true);
$query = $this->db->getQueryBuilder(); $query = $this->db->getQueryBuilder();
$query->select($query->func()->count('*')) $query->select($query->func()->count('*'))
->from('calendars') ->from('calendars');
->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri)));
if ($principalUri === '') {
$query->where($query->expr()->emptyString('principaluri'));
} else {
$query->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri)));
}
if ($excludeBirthday) { if ($excludeBirthday) {
$query->andWhere($query->expr()->neq('uri', $query->createNamedParameter(BirthdayService::BIRTHDAY_CALENDAR_URI))); $query->andWhere($query->expr()->neq('uri', $query->createNamedParameter(BirthdayService::BIRTHDAY_CALENDAR_URI)));
@ -292,13 +297,21 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
// Making fields a comma-delimited list // Making fields a comma-delimited list
$query = $this->db->getQueryBuilder(); $query = $this->db->getQueryBuilder();
$query->select($fields)->from('calendars') $query->select($fields)
->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))) ->from('calendars')
->orderBy('calendarorder', 'ASC'); ->orderBy('calendarorder', 'ASC');
$stmt = $query->execute();
if ($principalUri === '') {
$query->where($query->expr()->emptyString('principaluri'));
} else {
$query->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri)));
}
$result = $query->execute();
$calendars = []; $calendars = [];
while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { while ($row = $result->fetch()) {
$row['principaluri'] = (string) $row['principaluri'];
$components = []; $components = [];
if ($row['components']) { if ($row['components']) {
$components = explode(',',$row['components']); $components = explode(',',$row['components']);
@ -325,8 +338,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
$calendars[$calendar['id']] = $calendar; $calendars[$calendar['id']] = $calendar;
} }
} }
$result->closeCursor();
$stmt->closeCursor();
// query for shared calendars // query for shared calendars
$principals = $this->principalBackend->getGroupMembership($principalUriOriginal, true); $principals = $this->principalBackend->getGroupMembership($principalUriOriginal, true);
@ -346,17 +358,19 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
$fields[] = 'a.transparent'; $fields[] = 'a.transparent';
$fields[] = 's.access'; $fields[] = 's.access';
$query = $this->db->getQueryBuilder(); $query = $this->db->getQueryBuilder();
$result = $query->select($fields) $query->select($fields)
->from('dav_shares', 's') ->from('dav_shares', 's')
->join('s', 'calendars', 'a', $query->expr()->eq('s.resourceid', 'a.id')) ->join('s', 'calendars', 'a', $query->expr()->eq('s.resourceid', 'a.id'))
->where($query->expr()->in('s.principaluri', $query->createParameter('principaluri'))) ->where($query->expr()->in('s.principaluri', $query->createParameter('principaluri')))
->andWhere($query->expr()->eq('s.type', $query->createParameter('type'))) ->andWhere($query->expr()->eq('s.type', $query->createParameter('type')))
->setParameter('type', 'calendar') ->setParameter('type', 'calendar')
->setParameter('principaluri', $principals, \Doctrine\DBAL\Connection::PARAM_STR_ARRAY) ->setParameter('principaluri', $principals, \Doctrine\DBAL\Connection::PARAM_STR_ARRAY);
->execute();
$result = $query->execute();
$readOnlyPropertyName = '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only'; $readOnlyPropertyName = '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only';
while ($row = $result->fetch()) { while ($row = $result->fetch()) {
$row['principaluri'] = (string) $row['principaluri'];
if ($row['principaluri'] === $principalUri) { if ($row['principaluri'] === $principalUri) {
continue; continue;
} }
@ -427,6 +441,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
$stmt = $query->execute(); $stmt = $query->execute();
$calendars = []; $calendars = [];
while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
$row['principaluri'] = (string) $row['principaluri'];
$components = []; $components = [];
if ($row['components']) { if ($row['components']) {
$components = explode(',',$row['components']); $components = explode(',',$row['components']);
@ -496,6 +511,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
->execute(); ->execute();
while ($row = $result->fetch()) { while ($row = $result->fetch()) {
$row['principaluri'] = (string) $row['principaluri'];
list(, $name) = Uri\split($row['principaluri']); list(, $name) = Uri\split($row['principaluri']);
$row['displayname'] = $row['displayname'] . "($name)"; $row['displayname'] = $row['displayname'] . "($name)";
$components = []; $components = [];
@ -562,6 +578,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
throw new NotFound('Node with name \'' . $uri . '\' could not be found'); throw new NotFound('Node with name \'' . $uri . '\' could not be found');
} }
$row['principaluri'] = (string) $row['principaluri'];
list(, $name) = Uri\split($row['principaluri']); list(, $name) = Uri\split($row['principaluri']);
$row['displayname'] = $row['displayname'] . ' ' . "($name)"; $row['displayname'] = $row['displayname'] . ' ' . "($name)";
$components = []; $components = [];
@ -618,6 +635,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
return null; return null;
} }
$row['principaluri'] = (string) $row['principaluri'];
$components = []; $components = [];
if ($row['components']) { if ($row['components']) {
$components = explode(',',$row['components']); $components = explode(',',$row['components']);
@ -668,6 +686,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
return null; return null;
} }
$row['principaluri'] = (string) $row['principaluri'];
$components = []; $components = [];
if ($row['components']) { if ($row['components']) {
$components = explode(',',$row['components']); $components = explode(',',$row['components']);
@ -717,6 +736,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
return null; return null;
} }
$row['principaluri'] = (string) $row['principaluri'];
$subscription = [ $subscription = [
'id' => $row['id'], 'id' => $row['id'],
'uri' => $row['uri'], 'uri' => $row['uri'],
@ -964,6 +984,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
'classification'=> (int)$row['classification'] 'classification'=> (int)$row['classification']
]; ];
} }
$stmt->closeCursor();
return $result; return $result;
} }
@ -994,6 +1015,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
->andWhere($query->expr()->eq('calendartype', $query->createNamedParameter($calendarType))); ->andWhere($query->expr()->eq('calendartype', $query->createNamedParameter($calendarType)));
$stmt = $query->execute(); $stmt = $query->execute();
$row = $stmt->fetch(\PDO::FETCH_ASSOC); $row = $stmt->fetch(\PDO::FETCH_ASSOC);
$stmt->closeCursor();
if (!$row) { if (!$row) {
return null; return null;