@@ -8,9 +8,9 @@ be installed to allow migration of user data.
88App developers can integrate into User migration and provide ways to export
99and import the app data of a user. Please note that this should not be used
1010as a backup and restore utility, as app developers should avoid deletion of
11- existing user data during migration. For further information, check out
11+ existing user data during migration. For further information, check out
1212`this discussion <https://github.com/nextcloud/user_migration/discussions/1090 >`_
13- as well as
13+ as well as
1414`this issue <https://github.com/nextcloud/user_migration/issues/1096 >`_.
1515
1616Register a migrator
@@ -19,6 +19,11 @@ Register a migrator
1919A migrator is represented by a class implementing the
2020``OCP\\UserMigration\\IMigrator `` interface. This class is instantiated
2121whenever a user export or import begins.
22+ It should also implement ``OCP\UserMigration\ISizeEstimationMigrator `` if possible,
23+ and return a size estimation in method ``getEstimatedExportSize ``.
24+ You can use the trait ``OCP\UserMigration\TMigratorBasicVersionHandling `` for basic version handling,
25+ in this case the version is stored in $this->version (defaults to 1), and importing from a newer version is forbidden.
26+ If you prefer you can implement ``getVersion `` and ``canImport `` instead.
2227
2328.. code-block :: php
2429
@@ -44,20 +49,14 @@ whenever a user export or import begins.
4449 class MyAppMigrator implements IMigrator, ISizeEstimationMigrator {
4550 use TMigratorBasicVersionHandling;
4651
47- private IMyAppManager $myAppManager;
48-
49- private IL10N $l10n;
50-
5152 private const PATH_ROOT = Application::APP_ID . '/';
5253
5354 private const PATH_MYAPP_FILE = MyAppMigrator::PATH_ROOT . 'myapp.json';
5455
5556 public function __construct(
56- IMyAppManager $myAppManager,
57- IL10N $l10n
57+ private IMyAppManager $myAppManager,
58+ private IL10N $l10n,
5859 ) {
59- $this->myAppManager = $myAppManager;
60- $this->l10n = $l10n;
6160 }
6261
6362 /**
@@ -103,9 +102,8 @@ whenever a user export or import begins.
103102
104103 $output->writeln('Importing myapp information from ' . MyAppMigrator::PATH_MYAPP_FILE . '…');
105104
106- $data = json_decode($importSource->getFileContents(MyAppMigrator::PATH_MYAPP_FILE), true, 512, JSON_THROW_ON_ERROR);
107-
108105 try {
106+ $data = json_decode($importSource->getFileContents(MyAppMigrator::PATH_MYAPP_FILE), true, 512, JSON_THROW_ON_ERROR);
109107 $this->myAppManager->setUserData($user, $data);
110108 } catch (Throwable $e) {
111109 throw new UserMigrationException('Could not import myapp information', 0, $e);
0 commit comments