|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @author Thomas Müller <[email protected]> |
|
4
|
|
|
* |
|
5
|
|
|
* @copyright Copyright (c) 2016, ownCloud GmbH. |
|
6
|
|
|
* @license AGPL-3.0 |
|
7
|
|
|
* |
|
8
|
|
|
* This code is free software: you can redistribute it and/or modify |
|
9
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
|
10
|
|
|
* as published by the Free Software Foundation. |
|
11
|
|
|
* |
|
12
|
|
|
* This program is distributed in the hope that it will be useful, |
|
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15
|
|
|
* GNU Affero General Public License for more details. |
|
16
|
|
|
* |
|
17
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
|
18
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
|
19
|
|
|
* |
|
20
|
|
|
*/ |
|
21
|
|
|
|
|
22
|
|
|
namespace OCA\DAV\Migration; |
|
23
|
|
|
|
|
24
|
|
|
use OCA\DAV\CalDAV\BirthdayService; |
|
25
|
|
|
use OCP\IDBConnection; |
|
26
|
|
|
use OCP\Migration\IOutput; |
|
27
|
|
|
use OCP\Migration\IRepairStep; |
|
28
|
|
|
|
|
29
|
|
|
class FixBirthdayCalendarComponent implements IRepairStep { |
|
30
|
|
|
|
|
31
|
|
|
/** @var IDBConnection */ |
|
32
|
|
|
private $connection; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* FixBirthdayCalendarComponent constructor. |
|
36
|
|
|
* |
|
37
|
|
|
* @param IDBConnection $connection |
|
38
|
|
|
*/ |
|
39
|
|
|
public function __construct(IDBConnection $connection) { |
|
40
|
|
|
$this->connection = $connection; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @inheritdoc |
|
45
|
|
|
*/ |
|
46
|
|
|
public function getName() { |
|
47
|
|
|
return 'Fix component of birthday calendars'; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @inheritdoc |
|
52
|
|
|
*/ |
|
53
|
|
View Code Duplication |
public function run(IOutput $output) { |
|
|
|
|
|
|
54
|
|
|
$query = $this->connection->getQueryBuilder(); |
|
55
|
|
|
$updated = $query->update('calendars') |
|
56
|
|
|
->set('components', $query->createNamedParameter('VEVENT')) |
|
57
|
|
|
->where($query->expr()->eq('uri', $query->createNamedParameter(BirthdayService::BIRTHDAY_CALENDAR_URI))) |
|
58
|
|
|
->execute(); |
|
59
|
|
|
|
|
60
|
|
|
$output->info("$updated birthday calendars updated."); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.