3131
3232use Doctrine \DBAL \Types \Types ;
3333use OCP \DB \ISchemaWrapper ;
34+ use OCP \IDBConnection ;
3435use OCP \Migration \IOutput ;
3536use OCP \Migration \SimpleMigrationStep ;
3637
3738class Version13000Date20170718121200 extends SimpleMigrationStep {
3839
40+ /** @var IDBConnection */
41+ private $ connection ;
42+
43+ public function __construct (IDBConnection $ connection ) {
44+ $ this ->connection = $ connection ;
45+ }
46+
47+ public function preSchemaChange (IOutput $ output , \Closure $ schemaClosure , array $ options ) {
48+ /** @var ISchemaWrapper $schema */
49+ $ schema = $ schemaClosure ();
50+
51+ if (!$ schema ->hasTable ('properties ' )) {
52+ return ;
53+ }
54+ // in case we have a properties table from oc we drop it since we will only migrate
55+ // the dav_properties values in the postSchemaChange step
56+ $ table = $ schema ->getTable ('properties ' );
57+ if ($ table ->hasColumn ('fileid ' )) {
58+ $ qb = $ this ->connection ->getQueryBuilder ();
59+ $ qb ->delete ('properties ' );
60+ $ qb ->execute ();
61+ }
62+ }
63+
64+
3965 /**
4066 * @param IOutput $output
4167 * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
@@ -122,6 +148,15 @@ public function changeSchema(IOutput $output, \Closure $schemaClosure, array $op
122148 $ table ->addIndex (['root_id ' ], 'mounts_root_index ' );
123149 $ table ->addIndex (['mount_id ' ], 'mounts_mount_id_index ' );
124150 $ table ->addUniqueIndex (['user_id ' , 'root_id ' ], 'mounts_user_root_index ' );
151+ } else {
152+ $ table = $ schema ->getTable ('mounts ' );
153+ $ table ->addColumn ('mount_id ' , Types::BIGINT , [
154+ 'notnull ' => false ,
155+ 'length ' => 20 ,
156+ ]);
157+ if (!$ table ->hasIndex ('mounts_mount_id_index ' )) {
158+ $ table ->addIndex (['mount_id ' ], 'mounts_mount_id_index ' );
159+ }
125160 }
126161
127162 if (!$ schema ->hasTable ('mimetypes ' )) {
@@ -320,6 +355,27 @@ public function changeSchema(IOutput $output, \Closure $schemaClosure, array $op
320355 $ table ->setPrimaryKey (['id ' ]);
321356 $ table ->addIndex (['userid ' ], 'property_index ' );
322357 $ table ->addIndex (['userid ' , 'propertypath ' ], 'properties_path_index ' );
358+ } else {
359+ $ table = $ schema ->getTable ('properties ' );
360+ if ($ table ->hasColumn ('propertytype ' )) {
361+ $ table ->dropColumn ('propertytype ' );
362+ }
363+ if ($ table ->hasColumn ('fileid ' )) {
364+ $ table ->dropColumn ('fileid ' );
365+ }
366+ if (!$ table ->hasColumn ('propertypath ' )) {
367+ $ table ->addColumn ('propertypath ' , 'string ' , [
368+ 'notnull ' => true ,
369+ 'length ' => 255 ,
370+ ]);
371+ }
372+ if (!$ table ->hasColumn ('userid ' )) {
373+ $ table ->addColumn ('userid ' , 'string ' , [
374+ 'notnull ' => false ,
375+ 'length ' => 64 ,
376+ 'default ' => '' ,
377+ ]);
378+ }
323379 }
324380
325381 if (!$ schema ->hasTable ('share ' )) {
@@ -415,6 +471,14 @@ public function changeSchema(IOutput $output, \Closure $schemaClosure, array $op
415471 $ table ->addIndex (['parent ' ], 'parent_index ' );
416472 $ table ->addIndex (['uid_owner ' ], 'owner_index ' );
417473 $ table ->addIndex (['uid_initiator ' ], 'initiator_index ' );
474+ } else {
475+ $ table = $ schema ->getTable ('share ' );
476+ if (!$ table ->hasColumn ('password ' )) {
477+ $ table ->addColumn ('password ' , 'string ' , [
478+ 'notnull ' => false ,
479+ 'length ' => 255 ,
480+ ]);
481+ }
418482 }
419483
420484 if (!$ schema ->hasTable ('jobs ' )) {
@@ -505,25 +569,25 @@ public function changeSchema(IOutput $output, \Closure $schemaClosure, array $op
505569 'default ' => '' ,
506570 ]);
507571 $ table ->addColumn ('type ' , 'smallint ' , [
508- 'notnull ' => true ,
572+ 'notnull ' => false ,
509573 'length ' => 2 ,
510574 'default ' => 0 ,
511575 'unsigned ' => true ,
512576 ]);
513577 $ table ->addColumn ('remember ' , 'smallint ' , [
514- 'notnull ' => true ,
578+ 'notnull ' => false ,
515579 'length ' => 1 ,
516580 'default ' => 0 ,
517581 'unsigned ' => true ,
518582 ]);
519583 $ table ->addColumn ('last_activity ' , 'integer ' , [
520- 'notnull ' => true ,
584+ 'notnull ' => false ,
521585 'length ' => 4 ,
522586 'default ' => 0 ,
523587 'unsigned ' => true ,
524588 ]);
525589 $ table ->addColumn ('last_check ' , 'integer ' , [
526- 'notnull ' => true ,
590+ 'notnull ' => false ,
527591 'length ' => 4 ,
528592 'default ' => 0 ,
529593 'unsigned ' => true ,
@@ -534,6 +598,11 @@ public function changeSchema(IOutput $output, \Closure $schemaClosure, array $op
534598 $ table ->setPrimaryKey (['id ' ]);
535599 $ table ->addUniqueIndex (['token ' ], 'authtoken_token_index ' );
536600 $ table ->addIndex (['last_activity ' ], 'authtoken_last_activity_idx ' );
601+ } else {
602+ $ table = $ schema ->getTable ('authtoken ' );
603+ $ table ->addColumn ('scope ' , 'text ' , [
604+ 'notnull ' => false ,
605+ ]);
537606 }
538607
539608 if (!$ schema ->hasTable ('bruteforce_attempts ' )) {
@@ -936,4 +1005,32 @@ public function changeSchema(IOutput $output, \Closure $schemaClosure, array $op
9361005 }
9371006 return $ schema ;
9381007 }
1008+
1009+ public function postSchemaChange (IOutput $ output , \Closure $ schemaClosure , array $ options ) {
1010+ /** @var ISchemaWrapper $schema */
1011+ $ schema = $ schemaClosure ();
1012+ if (!$ schema ->hasTable ('dav_properties ' )) {
1013+ return ;
1014+ }
1015+ $ query = $ this ->connection ->getQueryBuilder ();
1016+ $ query ->select ('* ' )
1017+ ->from ('dav_properties ' );
1018+
1019+ $ insert = $ this ->connection ->getQueryBuilder ();
1020+ $ insert ->insert ('properties ' )
1021+ ->setValue ('propertypath ' , $ insert ->createParameter ('propertypath ' ))
1022+ ->setValue ('propertyname ' , $ insert ->createParameter ('propertyname ' ))
1023+ ->setValue ('propertyvalue ' , $ insert ->createParameter ('propertyvalue ' ))
1024+ ->setValue ('userid ' , $ insert ->createParameter ('userid ' ));
1025+
1026+ $ result = $ query ->execute ();
1027+ while ($ row = $ result ->fetch ()) {
1028+ preg_match ('/(calendar)\/([A-z0-9-@_]+)\// ' , $ row ['propertypath ' ], $ match );
1029+ $ insert ->setParameter ('propertypath ' , (string ) $ row ['propertypath ' ])
1030+ ->setParameter ('propertyname ' , (string ) $ row ['propertyname ' ])
1031+ ->setParameter ('propertyvalue ' , (string ) $ row ['propertyvalue ' ])
1032+ ->setParameter ('userid ' , (string ) ($ match [2 ] ?? '' ));
1033+ $ insert ->execute ();
1034+ }
1035+ }
9391036}
0 commit comments