浏览代码

Add migration step

tags/v9.1.0RC1
Thomas Müller 8 年前
父节点
当前提交
f013cfc530
没有帐户链接到提交者的电子邮件

+ 1
- 1
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>

+ 1
- 0
apps/dav/appinfo/update.php 查看文件

@@ -24,3 +24,4 @@ use OCA\DAV\AppInfo\Application;

$app = new Application();
$app->generateBirthdays();
$app->migrateClassification();

+ 18
- 0
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);
}
}
}

+ 41
- 0
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'];
}
}

正在加载...
取消
保存