diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2016-04-19 11:47:06 +0200 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2016-06-09 11:09:13 +0200 |
commit | f013cfc5309666729ee657b9084ead9e7f93a772 (patch) | |
tree | c0018377e9c64bda7a901d9a8fd936a54b5de541 /apps | |
parent | fbdec59f22a23a84b36248001bc8680d3746bb7b (diff) | |
download | nextcloud-server-f013cfc5309666729ee657b9084ead9e7f93a772.tar.gz nextcloud-server-f013cfc5309666729ee657b9084ead9e7f93a772.zip |
Add migration step
Diffstat (limited to 'apps')
-rw-r--r-- | apps/dav/appinfo/database.xml | 2 | ||||
-rw-r--r-- | apps/dav/appinfo/update.php | 1 | ||||
-rw-r--r-- | apps/dav/lib/AppInfo/Application.php | 18 | ||||
-rw-r--r-- | apps/dav/lib/migration/classification.php | 41 |
4 files changed, 61 insertions, 1 deletions
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 ( <field> <comments>0 - public, 1 - private, 2 - confidential</comments> <name>classification</name> - <type>int</type> + <type>integer</type> <default>0</default> </field> <index> 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 @@ +<?php + +namespace OCA\DAV\Migration; + +use OCA\DAV\CalDAV\CalDavBackend; +use OCP\IUser; + +class Classification { + + /** + * Classification constructor. + * + * @param CalDavBackend $calDavBackend + */ + public function __construct(CalDavBackend $calDavBackend) { + $this->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']; + } +} |