summaryrefslogtreecommitdiffstats
path: root/apps/dav/lib/Migration
diff options
context:
space:
mode:
authorGeorg Ehrke <developer@georgehrke.com>2018-06-28 13:07:33 +0200
committerGeorg Ehrke <developer@georgehrke.com>2018-11-07 13:25:14 +0100
commit30d13bb760b233eb4b55b46066deb4bf05d41ce4 (patch)
tree0d7af03bab6ce7ca549df78eeb2d87163c597320 /apps/dav/lib/Migration
parentb56cb41e2fc5bd8ec4ef4661009b6feb4c75b7dc (diff)
downloadnextcloud-server-30d13bb760b233eb4b55b46066deb4bf05d41ce4.tar.gz
nextcloud-server-30d13bb760b233eb4b55b46066deb4bf05d41ce4.zip
cache webcal calendars on server
Signed-off-by: Georg Ehrke <developer@georgehrke.com>
Diffstat (limited to 'apps/dav/lib/Migration')
-rw-r--r--apps/dav/lib/Migration/RefreshWebcalJobRegistrar.php83
-rw-r--r--apps/dav/lib/Migration/Version1006Date20180628111625.php105
2 files changed, 188 insertions, 0 deletions
diff --git a/apps/dav/lib/Migration/RefreshWebcalJobRegistrar.php b/apps/dav/lib/Migration/RefreshWebcalJobRegistrar.php
new file mode 100644
index 00000000000..912e0aec98e
--- /dev/null
+++ b/apps/dav/lib/Migration/RefreshWebcalJobRegistrar.php
@@ -0,0 +1,83 @@
+<?php
+declare(strict_types=1);
+/**
+ * @copyright 2018 Georg Ehrke <oc.list@georgehrke.com>
+ *
+ * @author Georg Ehrke <oc.list@georgehrke.com>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * 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
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\DAV\Migration;
+
+use OCA\DAV\BackgroundJob\RefreshWebcalJob;
+use OCP\BackgroundJob\IJobList;
+use OCP\IDBConnection;
+use OCP\Migration\IOutput;
+use OCP\Migration\IRepairStep;
+
+class RefreshWebcalJobRegistrar implements IRepairStep {
+
+ /** @var IDBConnection */
+ private $connection;
+
+ /** @var IJobList */
+ private $jobList;
+
+ /**
+ * FixBirthdayCalendarComponent constructor.
+ *
+ * @param IDBConnection $connection
+ * @param IJobList $jobList
+ */
+ public function __construct(IDBConnection $connection, IJobList $jobList) {
+ $this->connection = $connection;
+ $this->jobList = $jobList;
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function getName() {
+ return 'Registering background jobs to update cache for webcal calendars';
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function run(IOutput $output) {
+ $query = $this->connection->getQueryBuilder();
+ $query->select(['principaluri', 'uri'])
+ ->from('calendarsubscriptions');
+ $stmt = $query->execute();
+
+ $count = 0;
+ while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
+ $args = [
+ 'principaluri' => $row['principaluri'],
+ 'uri' => $row['uri'],
+ ];
+
+ if (!$this->jobList->has(RefreshWebcalJob::class, $args)) {
+ $this->jobList->add(RefreshWebcalJob::class, $args);
+ $count++;
+ }
+ }
+
+ $output->info("Added $count background jobs to update webcal calendars");
+ }
+}
diff --git a/apps/dav/lib/Migration/Version1006Date20180628111625.php b/apps/dav/lib/Migration/Version1006Date20180628111625.php
new file mode 100644
index 00000000000..8113b4c69bf
--- /dev/null
+++ b/apps/dav/lib/Migration/Version1006Date20180628111625.php
@@ -0,0 +1,105 @@
+<?php
+declare(strict_types=1);
+/**
+ * @copyright 2018 Georg Ehrke <oc.list@georgehrke.com>
+ *
+ * @author Georg Ehrke <oc.list@georgehrke.com>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * 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
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\DAV\Migration;
+
+use Doctrine\DBAL\Types\Type;
+use OCP\DB\ISchemaWrapper;
+use OCP\Migration\SimpleMigrationStep;
+use OCP\Migration\IOutput;
+
+class Version1006Date20180628111625 extends SimpleMigrationStep {
+
+ /**
+ * @param IOutput $output
+ * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
+ * @param array $options
+ * @return null|ISchemaWrapper
+ */
+ public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) {
+ /** @var ISchemaWrapper $schema */
+ $schema = $schemaClosure();
+
+ if ($schema->hasTable('calendarchanges')) {
+ $calendarChangesTable = $schema->getTable('calendarchanges');
+ $calendarChangesTable->addColumn('calendartype', Type::INTEGER, [
+ 'notnull' => true,
+ 'default' => 0,
+ ]);
+
+ if ($calendarChangesTable->hasIndex('calendarid_synctoken')) {
+ $calendarChangesTable->dropIndex('calendarid_synctoken');
+ }
+ $calendarChangesTable->addIndex(['calendarid', 'calendartype', 'synctoken'], 'calendarid_calendartype_synctoken');
+ }
+
+ if ($schema->hasTable('calendarobjects')) {
+ $calendarObjectsTable = $schema->getTable('calendarobjects');
+ $calendarObjectsTable->addColumn('calendartype', Type::INTEGER, [
+ 'notnull' => true,
+ 'default' => 0,
+ ]);
+
+ if ($calendarObjectsTable->hasIndex('calobjects_index')) {
+ $calendarObjectsTable->dropIndex('calobjects_index');
+ }
+ $calendarObjectsTable->addUniqueIndex(['calendarid', 'calendartype', 'uri'], 'calobjects_index');
+ }
+
+ if ($schema->hasTable('calendarobjects_props')) {
+ $calendarObjectsPropsTable = $schema->getTable('calendarobjects_props');
+ $calendarObjectsPropsTable->addColumn('calendartype', Type::INTEGER, [
+ 'notnull' => true,
+ 'default' => 0,
+ ]);
+
+
+ if ($calendarObjectsPropsTable->hasIndex('calendarobject_index')) {
+ $calendarObjectsPropsTable->dropIndex('calendarobject_index');
+ }
+ if ($calendarObjectsPropsTable->hasIndex('calendarobject_name_index')) {
+ $calendarObjectsPropsTable->dropIndex('calendarobject_name_index');
+ }
+ if ($calendarObjectsPropsTable->hasIndex('calendarobject_value_index')) {
+ $calendarObjectsPropsTable->dropIndex('calendarobject_value_index');
+ }
+
+ $calendarObjectsPropsTable->addIndex(['objectid', 'calendartype'], 'calendarobject_index');
+ $calendarObjectsPropsTable->addIndex(['name', 'calendartype'], 'calendarobject_name_index');
+ $calendarObjectsPropsTable->addIndex(['value', 'calendartype'], 'calendarobject_value_index');
+ }
+
+ if ($schema->hasTable('calendarsubscriptions')) {
+ $calendarSubscriptionsTable = $schema->getTable('calendarsubscriptions');
+ $calendarSubscriptionsTable->addColumn('synctoken', 'integer', [
+ 'notnull' => true,
+ 'default' => 1,
+ 'length' => 10,
+ 'unsigned' => true,
+ ]);
+ }
+
+ return $schema;
+ }
+}