Merge pull request #2263 from nextcloud/remove91_migration
Remove migration steps in app dav
This commit is contained in:
commit
f692ea34f1
|
@ -22,12 +22,8 @@
|
|||
</background-jobs>
|
||||
<repair-steps>
|
||||
<post-migration>
|
||||
<step>OCA\DAV\Migration\Classification</step>
|
||||
<step>OCA\DAV\Migration\FixBirthdayCalendarComponent</step>
|
||||
</post-migration>
|
||||
<live-migration>
|
||||
<step>OCA\DAV\Migration\GenerateBirthdays</step>
|
||||
</live-migration>
|
||||
</repair-steps>
|
||||
<commands>
|
||||
<command>OCA\DAV\Command\CreateAddressBook</command>
|
||||
|
|
|
@ -1,94 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
||||
*
|
||||
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
||||
*
|
||||
* @license AGPL-3.0
|
||||
*
|
||||
* This code is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License, version 3,
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
namespace OCA\DAV\Migration;
|
||||
|
||||
use OCA\DAV\CalDAV\CalDavBackend;
|
||||
use OCP\IUser;
|
||||
use OCP\IUserManager;
|
||||
use OCP\Migration\IOutput;
|
||||
use OCP\Migration\IRepairStep;
|
||||
|
||||
class Classification implements IRepairStep {
|
||||
|
||||
/** @var CalDavBackend */
|
||||
private $calDavBackend;
|
||||
|
||||
/** @var IUserManager */
|
||||
private $userManager;
|
||||
|
||||
/**
|
||||
* Classification constructor.
|
||||
*
|
||||
* @param CalDavBackend $calDavBackend
|
||||
*/
|
||||
public function __construct(CalDavBackend $calDavBackend, IUserManager $userManager) {
|
||||
$this->calDavBackend = $calDavBackend;
|
||||
$this->userManager = $userManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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['uri']);
|
||||
$classification = $this->extractClassification($calObject['calendardata']);
|
||||
$this->calDavBackend->setClassification($object['id'], $classification);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $calendarData
|
||||
* @return integer
|
||||
* @throws \Sabre\DAV\Exception\BadRequest
|
||||
*/
|
||||
protected function extractClassification($calendarData) {
|
||||
return $this->calDavBackend->getDenormalizedData($calendarData)['classification'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getName() {
|
||||
return 'Fix classification for calendar objects';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function run(IOutput $output) {
|
||||
$output->startProgress();
|
||||
$this->userManager->callForAllUsers(function($user) use ($output) {
|
||||
/** @var IUser $user */
|
||||
$output->advance(1, $user->getDisplayName());
|
||||
$this->runForUser($user);
|
||||
});
|
||||
$output->finishProgress();
|
||||
}
|
||||
}
|
|
@ -1,71 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
||||
*
|
||||
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
||||
*
|
||||
* @license AGPL-3.0
|
||||
*
|
||||
* This code is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License, version 3,
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
namespace OCA\DAV\Migration;
|
||||
|
||||
use OCA\DAV\CalDAV\BirthdayService;
|
||||
use OCP\IUser;
|
||||
use OCP\IUserManager;
|
||||
use OCP\Migration\IOutput;
|
||||
use OCP\Migration\IRepairStep;
|
||||
|
||||
class GenerateBirthdays implements IRepairStep {
|
||||
|
||||
/** @var BirthdayService */
|
||||
private $birthdayService;
|
||||
|
||||
/** @var IUserManager */
|
||||
private $userManager;
|
||||
|
||||
/**
|
||||
* GenerateBirthdays constructor.
|
||||
*
|
||||
* @param BirthdayService $birthdayService
|
||||
* @param IUserManager $userManager
|
||||
*/
|
||||
public function __construct(BirthdayService $birthdayService, IUserManager $userManager) {
|
||||
$this->birthdayService = $birthdayService;
|
||||
$this->userManager = $userManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getName() {
|
||||
return 'Regenerate birthday calendar for all users';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function run(IOutput $output) {
|
||||
|
||||
$output->startProgress();
|
||||
$this->userManager->callForAllUsers(function($user) use ($output) {
|
||||
/** @var IUser $user */
|
||||
$output->advance(1, $user->getDisplayName());
|
||||
$this->birthdayService->syncUser($user->getUID());
|
||||
});
|
||||
$output->finishProgress();
|
||||
}
|
||||
}
|
|
@ -1,65 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
||||
*
|
||||
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
||||
*
|
||||
* @license AGPL-3.0
|
||||
*
|
||||
* This code is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License, version 3,
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\DAV\Tests\unit\DAV\Migration;
|
||||
|
||||
use OCA\DAV\CalDAV\CalDavBackend;
|
||||
use OCA\DAV\Migration\Classification;
|
||||
use OCA\DAV\Tests\unit\CalDAV\AbstractCalDavBackendTest;
|
||||
use OCP\IUser;
|
||||
|
||||
/**
|
||||
* Class ClassificationTest
|
||||
*
|
||||
* @group DB
|
||||
*
|
||||
* @package OCA\DAV\Tests\unit\DAV
|
||||
*/
|
||||
class ClassificationTest extends AbstractCalDavBackendTest {
|
||||
public function test() {
|
||||
// setup data
|
||||
$calendarId = $this->createTestCalendar();
|
||||
$eventUri = $this->createEvent($calendarId, '20130912T130000Z', '20130912T140000Z');
|
||||
$object = $this->backend->getCalendarObject($calendarId, $eventUri);
|
||||
|
||||
// assert proper classification
|
||||
$this->assertEquals(CalDavBackend::CLASSIFICATION_PUBLIC, $object['classification']);
|
||||
$this->backend->setClassification($object['id'], CalDavBackend::CLASSIFICATION_CONFIDENTIAL);
|
||||
$object = $this->backend->getCalendarObject($calendarId, $eventUri);
|
||||
$this->assertEquals(CalDavBackend::CLASSIFICATION_CONFIDENTIAL, $object['classification']);
|
||||
|
||||
// run migration
|
||||
$c = new Classification($this->backend, $this->userManager);
|
||||
|
||||
/** @var IUser | \PHPUnit_Framework_MockObject_MockObject $user */
|
||||
$user = $this->getMockBuilder('OCP\IUser')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$user->expects($this->once())->method('getUID')->willReturn('caldav-unit-test');
|
||||
|
||||
$c->runForUser($user);
|
||||
|
||||
// assert classification after migration
|
||||
$object = $this->backend->getCalendarObject($calendarId, $eventUri);
|
||||
$this->assertEquals(CalDavBackend::CLASSIFICATION_PUBLIC, $object['classification']);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue