Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for migrating from legacy version #979

Merged
merged 6 commits into from
Oct 18, 2020
Merged

Fixes for migrating from legacy version #979

merged 6 commits into from
Oct 18, 2020

Conversation

benbz
Copy link
Contributor

@benbz benbz commented Sep 24, 2020

Tested with a MySQL DB dump & config of a 0.3.5 instance.

I'm able to:

  • Go through the upgrade wizard successfully
  • Toggle between MySQL/sqlite & enter incorrect values on the database settings form, and don't get moved onto until I correct the values
  • Login to the admin UI & interact with dav.php as a normal user after migration, having migrated with a non-standard auth realm

Things still not migrated:

  • BAIKAL_ENCRYPTION_KEY - this doesn't appear to be read anywhere, so I didn't bother fixing the migration for that. If you desire I can update this PR to either migrate it (if there's some use I haven't spotted) or stop storing it altogether.
  • BAIKAL_CARD_BASEURI, BAIKAL_CAL_BASEURI & BAIKAL_DAV_BASEURI - the use of these from card.php, cal.php & dav.php respectively appears to have been removed. In my legacy instance all 3 of these were set to PROJECT_BASEURI. This allowed my nginx config to rewrite any request that wasn't to /admin or /res to /dav.php, so that dav.php didn't show up in the URL. I haven't figured out how to replicate this in 0.7.1 but I feel that is a separate problem to what I'm solve with this PR.

Fixes #942 #946 I think

Previously, any form submission would persist the database settings
giving no chance to validate them or edit them.

Toggling the MySQL enabled checkbox also triggered this as that reloaded
the page.
On the initial load the form morphology hook is called prior to the
morphology being populated with values from the model. Loading from the
YAML won't always work if we're coming from < 0.7.0.

Loading from the model is safe as:
- The model is initially populated with the YAML
- If legacy config is present then the model is updated with that
- If this isn't the initial load we go down the submitted branch instead
$oStandardConfig = new \Baikal\Model\Config\Standard();
$oStandardConfig->set("configured_version", BAIKAL_CONFIGURED_VERSION);
$oStandardConfig->persist();
}

Choose a reason for hiding this comment

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

Was my assumption right that this config init above leads to just parsed/migrated MySQL settings from config.system.php being overwritten by parsing the baikal.yaml which contains empty MySQL settings?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

baikal.yaml with empty Sqlite/MySQL settings is created during the form submission of the previous step at https://github.com/sabre-io/Baikal/blob/master/Core/Frameworks/BaikalAdmin/Controller/Install/Initialize.php#L76 but with a configured_version of 0.7.1 (the default inside the model).

At the next page load https://github.com/sabre-io/Baikal/blob/master/Core/Frameworks/BaikalAdmin/WWWRoot/install/index.php#L84 sees that the yaml is configured with the current Baikal version (0.7.1) but the INSTALL_DISABLE file isn't present yet, so we went up in this file.

The change you've highlighted here keeps configured_version at 0.7.1 in baikal.yaml until we've also written the Sqlite/MySQL settings to baikal.yaml (the additions in this commit are inside a $this->oForm->persisted() branch). configured_version in baikal.yaml is then rolled back to the value in config.system.php so that https://github.com/sabre-io/Baikal/blob/master/Core/Frameworks/BaikalAdmin/WWWRoot/install/index.php#L84 goes forward.

@MichaIng
Copy link

MichaIng commented Sep 26, 2020

The encryption key is freshly created here, so it should be okay to not migrate it:

# Creating system config, and initializing BAIKAL_ENCRYPTION_KEY
$oSystemConfig = new \Baikal\Model\Config\System();
$oSystemConfig->set("encryption_key", md5(microtime() . rand()));

@benbz
Copy link
Contributor Author

benbz commented Sep 26, 2020

The encryption key is freshly created here, so it should be okay to not migrate it:

# Creating system config, and initializing BAIKAL_ENCRYPTION_KEY
$oSystemConfig = new \Baikal\Model\Config\System();
$oSystemConfig->set("encryption_key", md5(microtime() . rand()));

I couldn't see where encryption_key is used. If it isn't used why do we ever even need to store it in baikal.yaml and create it in the code you've linked to. If I've missed where it is used then surely it is problematic if we've changed the encryption_key as part of the migration.

I have a local change to migrate encryption_key if it is needed, which is (on the line you linked to):

-                $oSystemConfig->set("encryption_key", md5(microtime() . rand()));
+                $oSystemConfig->set("encryption_key", defined("BAIKAL_ENCRYPTION_KEY") ? BAIKAL_ENCRYPTION_KEY : md5(microtime() . rand()));

@ByteHamster
Copy link
Member

I couldn't see where encryption_key is used

That's an interesting find. Even when looking at the whole commit history (git log -S BAIKAL_ENCRYPTION_KEY), it looks like that config option was never actually read. It was just written. I wonder why it was introduced in the first place.

@evert do you know why this config option was originally added?

@ByteHamster
Copy link
Member

Sorry for the delay and thanks a lot for working on this. The PR looks good to me. Ready for merging, @benbz?

@benbz
Copy link
Contributor Author

benbz commented Oct 18, 2020

Sorry for the delay and thanks a lot for working on this. The PR looks good to me. Ready for merging, @benbz?

Yup, ready for merging. I've taken a quick look over #938 as I was a little concerned that it could interact, but I think it is fine.

@ByteHamster ByteHamster merged commit ef80df9 into sabre-io:master Oct 18, 2020
@ByteHamster
Copy link
Member

Awesome, thanks!

@benbz benbz deleted the fix-legacy-migration branch October 18, 2020 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error updating from 0.5.0 to 0.7
3 participants