summaryrefslogtreecommitdiffstats
path: root/apps/dav/lib/CalDAV/CalDavBackend.php
diff options
context:
space:
mode:
authorThomas Citharel <tcit@tcit.fr>2017-07-26 12:33:32 +0200
committerThomas Citharel <tcit@tcit.fr>2019-01-16 13:58:33 +0100
commit943d48cb3e9ab2b97ad6a72c953df59318c2f17e (patch)
treefbbfc913f75f5206d216009cf47108388d6340fc /apps/dav/lib/CalDAV/CalDavBackend.php
parentcff89c2a44336424121de72640334d3c00878523 (diff)
downloadnextcloud-server-943d48cb3e9ab2b97ad6a72c953df59318c2f17e.tar.gz
nextcloud-server-943d48cb3e9ab2b97ad6a72c953df59318c2f17e.zip
Add command to move a calendar from an user to another
Signed-off-by: Thomas Citharel <tcit@tcit.fr> Add a basic check for displaynames in case we fail to get calendar from uri and put some sf console styles & refactor a bit Signed-off-by: Thomas Citharel <tcit@tcit.fr> basic Tests Signed-off-by: Thomas Citharel <tcit@tcit.fr> add forgotten createNamedParameter() Signed-off-by: Thomas Citharel <tcit@tcit.fr>
Diffstat (limited to 'apps/dav/lib/CalDAV/CalDavBackend.php')
-rw-r--r--apps/dav/lib/CalDAV/CalDavBackend.php43
1 files changed, 43 insertions, 0 deletions
diff --git a/apps/dav/lib/CalDAV/CalDavBackend.php b/apps/dav/lib/CalDAV/CalDavBackend.php
index 187ba4ecdcf..1214d11f360 100644
--- a/apps/dav/lib/CalDAV/CalDavBackend.php
+++ b/apps/dav/lib/CalDAV/CalDavBackend.php
@@ -2522,6 +2522,49 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
}
/**
+ * Move a calendar from one user to another
+ *
+ * @param string $uriName
+ * @param string $uriOrigin
+ * @param string $uriDestination
+ */
+ public function moveCalendar($uriName, $uriOrigin, $uriDestination)
+ {
+ $query = $this->db->getQueryBuilder();
+ $query->update('calendars')
+ ->set('principaluri', $query->createNamedParameter($uriDestination))
+ ->where($query->expr()->eq('principaluri', $query->createNamedParameter($uriOrigin)))
+ ->andWhere($query->expr()->eq('uri', $query->createNamedParameter($uriName)))
+ ->execute();
+ }
+
+ /**
+ * @param string $displayName
+ * @param string|null $principalUri
+ * @return array
+ */
+ public function findCalendarsUrisByDisplayName($displayName, $principalUri = null)
+ {
+ // Ideally $displayName would be sanitized the same way as stringUtility.js does in calendar
+
+ $query = $this->db->getQueryBuilder();
+ $query->select('uri')
+ ->from('calendars')
+ ->where($query->expr()->iLike('displayname',
+ $query->createNamedParameter('%'.$this->db->escapeLikeParameter($displayName).'%')));
+ if ($principalUri) {
+ $query->andWhere($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri)));
+ }
+ $result = $query->execute();
+
+ $calendarUris = [];
+ while($row = $result->fetch()) {
+ $calendarUris[] = $row['uri'];
+ }
+ return $calendarUris;
+ }
+
+ /**
* read VCalendar data into a VCalendar object
*
* @param string $objectData