]> source.dussan.org Git - nextcloud-server.git/commitdiff
Handle oc_dav_properties migration
authorJulius Härtl <jus@bitgrid.net>
Mon, 7 Dec 2020 12:51:17 +0000 (13:51 +0100)
committerJulius Härtl <jus@bitgrid.net>
Mon, 14 Dec 2020 10:12:51 +0000 (11:12 +0100)
Signed-off-by: Julius Härtl <jus@bitgrid.net>
core/Migrations/Version13000Date20170718121200.php

index dc59d43e81b93d7c8c816c6e076382a740192a4a..09fec43b69a1ccde7b3fdd08492b2a0cfc6a24c7 100644 (file)
@@ -31,11 +31,37 @@ namespace OC\Core\Migrations;
 
 use Doctrine\DBAL\Types\Types;
 use OCP\DB\ISchemaWrapper;
+use OCP\IDBConnection;
 use OCP\Migration\IOutput;
 use OCP\Migration\SimpleMigrationStep;
 
 class Version13000Date20170718121200 extends SimpleMigrationStep {
 
+       /** @var IDBConnection */
+       private $connection;
+
+       public function __construct(IDBConnection $connection) {
+               $this->connection = $connection;
+       }
+
+       public function preSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) {
+               /** @var ISchemaWrapper $schema */
+               $schema = $schemaClosure();
+
+               if (!$schema->hasTable('properties')) {
+                       return;
+               }
+               // in case we have a properties table from oc we drop it since we will only migrate
+               // the dav_properties values in the postSchemaChange step
+               $table = $schema->getTable('properties');
+               if ($table->hasColumn('fileid')) {
+                       $qb = $this->connection->getQueryBuilder();
+                       $qb->delete('properties');
+                       $qb->execute();
+               }
+       }
+
+
        /**
         * @param IOutput $output
         * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
@@ -329,6 +355,27 @@ class Version13000Date20170718121200 extends SimpleMigrationStep {
                        $table->setPrimaryKey(['id']);
                        $table->addIndex(['userid'], 'property_index');
                        $table->addIndex(['userid', 'propertypath'], 'properties_path_index');
+               } else {
+                       $table = $schema->getTable('properties');
+                       if ($table->hasColumn('propertytype')) {
+                               $table->dropColumn('propertytype');
+                       }
+                       if ($table->hasColumn('fileid')) {
+                               $table->dropColumn('fileid');
+                       }
+                       if (!$table->hasColumn('propertypath')) {
+                               $table->addColumn('propertypath', 'string', [
+                                       'notnull' => true,
+                                       'length' => 255,
+                               ]);
+                       }
+                       if (!$table->hasColumn('userid')) {
+                               $table->addColumn('userid', 'string', [
+                                       'notnull' => false,
+                                       'length' => 64,
+                                       'default' => '',
+                               ]);
+                       }
                }
 
                if (!$schema->hasTable('share')) {
@@ -956,4 +1003,32 @@ class Version13000Date20170718121200 extends SimpleMigrationStep {
                }
                return $schema;
        }
+
+       public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) {
+               /** @var ISchemaWrapper $schema */
+               $schema = $schemaClosure();
+               if (!$schema->hasTable('dav_properties')) {
+                       return;
+               }
+               $query = $this->connection->getQueryBuilder();
+               $query->select('*')
+                       ->from('dav_properties');
+
+               $insert = $this->connection->getQueryBuilder();
+               $insert->insert('properties')
+                       ->setValue('propertypath', $insert->createParameter('propertypath'))
+                       ->setValue('propertyname', $insert->createParameter('propertyname'))
+                       ->setValue('propertyvalue', $insert->createParameter('propertyvalue'))
+                       ->setValue('userid', $insert->createParameter('userid'));
+
+               $result = $query->execute();
+               while ($row = $result->fetch()) {
+                       preg_match('/(calendar)\/([A-z0-9-@_]+)\//', $row['propertypath'], $match);
+                       $insert->setParameter('propertypath', (string) $row['propertypath'])
+                               ->setParameter('propertyname', (string) $row['propertyname'])
+                               ->setParameter('propertyvalue', (string) $row['propertyvalue'])
+                               ->setParameter('userid', (string) ($match[2] ?? ''));
+                       $insert->execute();
+               }
+       }
 }