Skip to content

Conversation

@phisch
Copy link
Contributor

@phisch phisch commented Aug 14, 2017

Description

This is a follow-up to #28655. This migrates storages defined in data/mount.json to the database.

Related Issue

#28655

How Has This Been Tested?

Has been tested manually with the limited storage options i had (local mount).

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New (old?) feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

… external stores, marked files_external to use migrations
@phisch phisch added this to the development milestone Aug 14, 2017
@phisch phisch self-assigned this Aug 14, 2017
Copy link
Contributor

@PVince81 PVince81 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine so far

public function run(IOutput $out) {

/** @var GlobalStoragesService $globalStoragesService */
$globalStoragesService = \OC::$server->query('GlobalStoragesService');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copy-pasted indents failed

* @return array list of mount configs
*/
protected function readLegacyConfig() {
$mountConfig = new \OC_Mount_Config();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use LegacyUtil instead to not re-add a dependency on this horrible class.

Most of the code was moved from OC_Mount_Config to \OC\Files\External\LegacyUtil

$storageOptions['priority'] = $backend->getPriority();
}
$storageConfig->setPriority($storageOptions['priority']);
if ($mountType === \OC_Mount_Config::MOUNT_TYPE_USER) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same for the constants

if (isset($storageOptions['authMechanism']) && $storageOptions['authMechanism'] !== 'builtin::builtin') {
$authMechanism = $this->backendService->getAuthMechanism($storageOptions['authMechanism']);
} else {
$authMechanism = $backend->getLegacyAuthMechanism($storageOptions);
Copy link
Contributor Author

@phisch phisch Aug 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PVince81 the backend doesn't have this method anymore. Why do we set the storage option to null, but throw an exception when there is no legacy auth mechanism? edit: should i un-delete this method, or can we work around this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before we introduced the concept of "one storage can have multiple auth mechanisms", every storage could only have a single one. I think the legacy auth value was there to tell which of the multiple ones the migration should default to if none is specified. (I'm not 100% sure of this though)

If specifying null here is problematic, maybe we need to change the logic to make "null" automatically default to the only auth mechanism supported by the backend, if any.

// but at this point we don't know the max-id, so use
// first group it by config hash
$storageOptions['mountpoint'] = $rootMountPath;
$configId = \OC_Mount_Config::makeConfigHash($storageOptions);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PVince81 makeConfigHash doesn't exist anymore, do you know if it is important that this is actually the hashed config, or does it just has to be unique? Can't we use uniqidfor this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bring it back and put it into LegacyUtil. It must be a hash of all config values because this is used to deduplicate configurations. Storing duplicate configs with slight variations (like "applicable" field) is the way mount.json used to work...

$authMechanism = $this->backendService->getAuthMechanism($storageOptions['authMechanism']);
} else {
$authMechanisms = $this->backendService->getAuthMechanisms();
$authMechanism = $authMechanisms[0];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the first available AuthMechanism should be fine.

Copy link
Contributor

@PVince81 PVince81 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks better. I still have some doubt about your usage of "null" storage, but am also confused about the difference between "$storageOptions" and setAuthMechanism. Did you find out ?

public function run(IOutput $out) {

/** @var GlobalStoragesService $globalStoragesService */
$globalStoragesService = \OC::$server->query('GlobalStoragesService');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess injection in constructor doesn't work in migrations ?

Copy link
Contributor Author

@phisch phisch Aug 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Migration files are required by the MigrationService, so we can't use the DI for them. Making them "container aware" like that should be fine. (even if container aware stinks)


/** @var GlobalStoragesService $globalStoragesService */
$globalStoragesService = \OC::$server->query('GlobalStoragesService');
$legacyStoragesService = new LegacyStoragesService(\OC::$server->getStoragesBackendService());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

above you query by string name and here by direct method, consistency would be nice (injection even better)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not want to add the LegacyStorageService to the DI container, just so others don't get the idea to use it 😛

</types>
<ocsid>166048</ocsid>

<use-migrations>true</use-migrations>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you likely also need to increase the app version to trigger the migrations?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, forgot about that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But for anyone who actually needs this migration, the version would already bump. (oc8 update).

} else {
$authMechanisms = $this->backendService->getAuthMechanisms();
$authMechanism = $authMechanisms[0];
$storageOptions['authMechanism'] = 'null'; // to make error handling easier
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't this make it use the "null" authentication mechanism ?
shouldn't this be replaced to the value of $authMechanism or its alias ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is about what the old code was like, just that it gets another $authMechanism here. I really don't know what the idea behind the old code was.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it works fine then ok

@phisch
Copy link
Contributor Author

phisch commented Aug 14, 2017

No, i did not find out more regarding the $storageOptions and setAuthMechanism. It is complicated to understand what the intention behind that was when the code is not compatible anymore. I think using the first available AuthMechanism should be about the best we can do there.

@PVince81
Copy link
Contributor

Test matrix:

  • Axis 1: mount type
    • system-wide, applicable to all
    • system-wide, applicable to some users and groups
    • personal mount
  • Axis 2: storage type
    • SFTP (has 2 auth mech in OC 10)
    • SMB (has 2 auth mech in OC 10)
    • GDrive (1 auth mech)
  • Axis 3: source version
    • upgrade from 8.2.10
    • upgrade from 9.0.9

Steps:

  1. Check out version from axis 3
  2. Create several external storages based on axis 1 and 2
  3. Upgrade to this PR
  4. Check that storages still work and make sense

@PVince81
Copy link
Contributor

Tested updating from 8.2.11 with GDrive, SFTP, SFTP + RSA key and different "applicable" values to stable10 daily + this PR: the conversion of the configs worked.

Copy link
Contributor

@PVince81 PVince81 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@PVince81 PVince81 merged commit 5e85c80 into master Aug 14, 2017
@PVince81 PVince81 deleted the migrate-mounts branch August 14, 2017 13:23
@felixboehm felixboehm mentioned this pull request Aug 17, 2017
31 tasks
@lock
Copy link

lock bot commented Aug 2, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Aug 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants