Add migration step
This commit is contained in:
parent
fbdec59f22
commit
f013cfc530
|
@ -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>
|
||||
|
|
|
@ -24,3 +24,4 @@ use OCA\DAV\AppInfo\Application;
|
|||
|
||||
$app = new Application();
|
||||
$app->generateBirthdays();
|
||||
$app->migrateClassification();
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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'];
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue