From f013cfc5309666729ee657b9084ead9e7f93a772 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Thomas=20M=C3=BCller?= Date: Tue, 19 Apr 2016 11:47:06 +0200 Subject: [PATCH] Add migration step --- apps/dav/appinfo/database.xml | 2 +- apps/dav/appinfo/update.php | 1 + apps/dav/lib/AppInfo/Application.php | 18 ++++++++++ apps/dav/lib/migration/classification.php | 41 +++++++++++++++++++++++ 4 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 apps/dav/lib/migration/classification.php diff --git a/apps/dav/appinfo/database.xml b/apps/dav/appinfo/database.xml index 5687158b090..9578526a705 100644 --- a/apps/dav/appinfo/database.xml +++ b/apps/dav/appinfo/database.xml @@ -275,7 +275,7 @@ CREATE TABLE calendarobjects ( 0 - public, 1 - private, 2 - confidential classification - int + integer 0 diff --git a/apps/dav/appinfo/update.php b/apps/dav/appinfo/update.php index d2ee06cc9fe..2941725086f 100644 --- a/apps/dav/appinfo/update.php +++ b/apps/dav/appinfo/update.php @@ -24,3 +24,4 @@ use OCA\DAV\AppInfo\Application; $app = new Application(); $app->generateBirthdays(); +$app->migrateClassification(); diff --git a/apps/dav/lib/AppInfo/Application.php b/apps/dav/lib/AppInfo/Application.php index ba0ef421f97..0de61b12e26 100644 --- a/apps/dav/lib/AppInfo/Application.php +++ b/apps/dav/lib/AppInfo/Application.php @@ -31,10 +31,12 @@ use OCA\DAV\CardDAV\SyncService; use OCA\DAV\Connector\Sabre\Principal; use OCA\DAV\DAV\GroupPrincipalBackend; use OCA\DAV\HookManager; +use OCA\DAV\Migration\Classification; use \OCP\AppFramework\App; use OCP\AppFramework\IAppContainer; use OCP\Contacts\IManager; use OCP\IUser; +use Sabre\VObject\Reader; use Symfony\Component\EventDispatcher\GenericEvent; class Application extends App { @@ -168,4 +170,20 @@ class Application extends App { $this->getContainer()->getServer()->getLogger()->logException($ex); } } + + public function migrateClassification() { + try { + /** @var CalDavBackend $calDavBackend */ + $calDavBackend = $this->getContainer()->query('CalDavBackend'); + $migration = new Classification($calDavBackend); + $userManager = $this->getContainer()->getServer()->getUserManager(); + + $userManager->callForAllUsers(function($user) use($migration) { + /** @var IUser $user */ + $migration->runForUser($user); + }); + } catch (\Exception $ex) { + $this->getContainer()->getServer()->getLogger()->logException($ex); + } + } } diff --git a/apps/dav/lib/migration/classification.php b/apps/dav/lib/migration/classification.php new file mode 100644 index 00000000000..48e62e6158b --- /dev/null +++ b/apps/dav/lib/migration/classification.php @@ -0,0 +1,41 @@ +calDavBackend = $calDavBackend; + } + + /** + * @param IUser $user + */ + public function runForUser($user) { + $principal = 'principals/users/' . $user->getUID(); + $calendars = $this->calDavBackend->getCalendarsForUser($principal); + foreach ($calendars as $calendar) { + $objects = $this->calDavBackend->getCalendarObjects($calendar['id']); + foreach ($objects as $object) { + $calObject = $this->calDavBackend->getCalendarObject($calendar['id'], $object['id']); + $classification = $this->extractClassification($calObject['calendardata']); + $this->calDavBackend->setClassification($object['id'], $classification); + } + } + } + + /** + * @param $calObject + */ + protected function extractClassification($calendarData) { + return $this->calDavBackend->getDenormalizedData($calendarData)['classification']; + } +} -- 2.39.5