Skip to content

Commit b6c6329

Browse files
confirm migration feasibility
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
1 parent 2669deb commit b6c6329

File tree

1 file changed

+41
-19
lines changed

1 file changed

+41
-19
lines changed

lib/Service/MigrationService.php

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@
3131

3232
namespace 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;
3734
use Exception;
3835
use OC;
3936
use OCA\Circles\AppInfo\Application;
@@ -64,6 +61,9 @@
6461
use OCA\Circles\Model\Member;
6562
use OCA\Circles\Model\Probes\CircleProbe;
6663
use 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;
6767
use OCA\DAV\CardDAV\ContactsManager;
6868
use OCP\Contacts\IManager;
6969
use 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

Comments
 (0)