3131
3232namespace OCA \Circles \Service ;
3333
34- use OCA \Circles \Tools \Model \SimpleDataStore ;
35- use OCA \Circles \Tools \Traits \TNCLogger ;
36- use OCA \Circles \Tools \Traits \TStringTools ;
3734use Exception ;
3835use OC ;
3936use OCA \Circles \AppInfo \Application ;
6461use OCA \Circles \Model \Member ;
6562use OCA \Circles \Model \Probes \CircleProbe ;
6663use OCA \Circles \Model \ShareToken ;
64+ use OCA \Circles \Tools \Model \SimpleDataStore ;
65+ use OCA \Circles \Tools \Traits \TNCLogger ;
66+ use OCA \Circles \Tools \Traits \TStringTools ;
6767use OCA \DAV \CardDAV \ContactsManager ;
6868use OCP \Contacts \IManager ;
6969use OCP \IDBConnection ;
@@ -198,8 +198,6 @@ public function migration(bool $force = false): void {
198198 );
199199
200200 $ this ->migrationTo22 ();
201- $ this ->migrationTo22_1 ();
202- // $this->migrationTo23();
203201
204202 $ this ->configService ->setAppValue (ConfigService::MIGRATION_RUN , '0 ' );
205203 }
@@ -213,6 +211,12 @@ private function migrationTo22(): void {
213211 return ;
214212 }
215213
214+ if (!$ this ->migrationTo22Feasibility ()) {
215+ $ this ->configService ->setAppValue (ConfigService::MIGRATION_22 , '1 ' );
216+
217+ return ;
218+ }
219+
216220 $ this ->outputService ->output ('Migrating to 22 ' );
217221
218222 $ this ->migrationTo22_Circles ();
@@ -221,11 +225,43 @@ private function migrationTo22(): void {
221225 $ this ->migrationTo22_Members_Memberships ();
222226
223227 $ this ->migrationTo22_Tokens ();
228+ $ this ->migrationTo22_1_SubShares ();
224229
225230 $ this ->configService ->setAppValue (ConfigService::MIGRATION_22 , '1 ' );
226231 }
227232
228233
234+ /**
235+ * run migration if:
236+ * - old tables exist.
237+ * - new tables are (almost) empty.
238+ *
239+ * @return bool
240+ * @throws \OCP\DB\Exception
241+ */
242+ public function migrationTo22Feasibility (): bool {
243+ $ qb = $ this ->dbConnection ->getQueryBuilder ();
244+ $ qb ->select ('* ' )->from ('circle_circles ' );
245+
246+ try {
247+ $ cursor = $ qb ->executeQuery ();
248+ $ cursor ->closeCursor ();
249+ } catch (\OCP \DB \Exception $ e ) {
250+ return false ;
251+ }
252+
253+ $ qb = $ this ->dbConnection ->getQueryBuilder ();
254+ $ qb ->select ('* ' )->from ('circles_circle ' );
255+
256+ $ cursor = $ qb ->executeQuery ();
257+ if ($ cursor ->rowCount () > 1 ) {
258+ return false ;
259+ }
260+ $ cursor ->closeCursor ();
261+
262+ return true ;
263+ }
264+
229265 /**
230266 * @throws RequestBuilderException
231267 */
@@ -258,20 +294,6 @@ public function migrationTo22_Members_Memberships(): void {
258294 }
259295
260296
261- /**
262- *
263- */
264- private function migrationTo22_1 (): void {
265- if ($ this ->configService ->getAppValueBool (ConfigService::MIGRATION_22_1 )) {
266- return ;
267- }
268-
269- $ this ->outputService ->output ('Migrating to 22.1.x ' );
270- $ this ->migrationTo22_1_SubShares ();
271- $ this ->configService ->setAppValue (ConfigService::MIGRATION_22_1 , '1 ' );
272- }
273-
274-
275297 /**
276298 *
277299 */
0 commit comments