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

Import QTS slugs options and meta data into QTX #1171

Merged
merged 32 commits into from
May 29, 2022
Merged

Import QTS slugs options and meta data into QTX #1171

merged 32 commits into from
May 29, 2022

Conversation

herrvigg
Copy link
Collaborator

@herrvigg herrvigg commented May 22, 2022

When slugs is uninstalled all QTS data are erased and will be lost for QTX. The options and meta data from the legacy plugin should be properly imported in QTX to separate entries.

Add new features in the import settings to migrated QTS data:

  • QTS postmeta / termmeta slugs are migrated renaming _qts_slug_ prefix to qtranslate_slug_ prefix.
  • QTS qts_options slugs are migrated to qtranslate_module_slugs options, after removing the _qts_ prefix for each type entry.

ATTENTION: existing slugs options and meta before migration are erased! A confirmation is required. Without this, a dry-run mode allows to see the effects before change.

Update prefix constants accordingly for QTX:

  • rename QTS_META_PREFIX to QTX_SLUGS_META_PREFIX
  • delete QTS_PREFIX made obsolete.

Add a new admin notice to suggest import when old QTS options and meta are found. The import can be done manually by the admin at any time.
Remove most of the HTML id attributes from the Slugs settings form, not needed (name attributes matter).

@herrvigg
Copy link
Collaborator Author

@spleen1981 please check this carefully on your side and let me know how it goes before merging it.

Attention: the current options that may have been changed during the last commits in master (stored in qtranslate_module_slugs) will be erased during import. The legacy QTS options are unchanged in any case.

This solves several issues of migration on activation which are hard to maintain and may create problems in the future. The main idea here is that manual import from QTS is required before being able to use slugs in QTX.

Copy link
Collaborator Author

@herrvigg herrvigg left a comment

Choose a reason for hiding this comment

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

Good remarks

modules/slugs/includes/qtranslate-slug-import.php Outdated Show resolved Hide resolved
modules/slugs/includes/qtranslate-slug-import.php Outdated Show resolved Hide resolved
modules/slugs/includes/qtranslate-slug-import.php Outdated Show resolved Hide resolved
modules/slugs/includes/qtranslate-slug-import.php Outdated Show resolved Hide resolved
@herrvigg
Copy link
Collaborator Author

herrvigg commented May 28, 2022

@spleen1981 I'm starting to think this is getting too complicated for what we need... and the problem of QTS cleanup is not solved yet. What about doing a import-migration instead?

  1. delete all existing QTX config about slugs
  2. import options and meta from QTS by renaming the keys.

No selective import, it's all or nothing. It looks like my first solution but the QTS legacy is not kept anymore, it's a full transfer.

Pros:

  • simpler: less code, clearer consequence of the action
  • solves the problem of QTS cleanup at the same time as all is moved. No leftovers in QTS.

Cons:

  • the migration is irreversible from the admin panel. If old keys wanted to be restored it's possible but it has to be done by hand in SQL. But normally there's literally no reason to continue using QTS after import. The labels will made clearer. Admin should still do a DB backup before.
  • current changes done in options (not meta) on master branch would be lost, but that affects very few people (developers like you who are testing slugs). Imo not worth handling this in the regular source base. The changes should be limited as the QTS values still exist at this point.

@spleen1981
Copy link
Contributor

@herrvigg this solution is much better IMO, cons are not an issue as the legacy plugin is dead and is an external module anyways. I liked this approach more from the beginning, the simpler the better.

@herrvigg
Copy link
Collaborator Author

herrvigg commented May 28, 2022

OK - finally! The new version is much simpler, it becomes a migration as described above:

  1. delete all existing QTX config about slugs
  2. import options and meta from QTS by renaming the keys.

There's a step 0, I added a temporary hack to preserve the options for master dev (solving cons point 2)! There was a nasty side effect of saving new options with new keys leading to empty slugs. The hack restores the previous QTS options as before so the migration falls back to the general case again (I didn't think about meta data at that time). It's really ugly but this will go away before release. Normal QTS users don't need this.

The patch should be ready for review. For security, save the content of option_name = qtranslate_module_slugs before confirming migration. The meta data are easy to recover if you want to repeat the migration In that case just rename the meta keys the other way around:

UPDATE wp_postmeta
SET meta_key = REPLACE(meta_key, 'qtranslate_', '_qts_') 
WHERE meta_key like 'qtranslate_%';

UPDATE wp_termmeta
SET meta_key = REPLACE(meta_key, 'qtranslate_', '_qts_') 
WHERE meta_key like 'qtranslate_%';

Attention: all data are lost if done twice in a row without restoring QTS data!

Let me know how it goes.

herrvigg added 2 commits May 29, 2022 12:16
* Remove internal QTS filter hooks

The QTS filters come from the legacy plugin. There's no clear
justification to use those in QTX.

For easier maintenance remove those filters and replace them
with direct calls instead.

Rename validate term/post slugs as sanitize.
Fix phpdoc.

* Revert checks on empty slug strings
@herrvigg herrvigg marked this pull request as draft May 29, 2022 10:44
@herrvigg
Copy link
Collaborator Author

@spleen1981 let me know how the new version looks and I can merge it with an updated commit message.
After that I think we are finally ready for release 3.12.0.

Copy link
Contributor

@spleen1981 spleen1981 left a comment

Choose a reason for hiding this comment

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

Looks good!

@herrvigg herrvigg marked this pull request as ready for review May 29, 2022 13:34
@herrvigg herrvigg merged commit 346d2ee into master May 29, 2022
@herrvigg herrvigg deleted the slugs-import branch May 29, 2022 13:34
herrvigg added a commit that referenced this pull request May 29, 2022
- the checks on migrated items is made obsolete by new migration
- the quick check is incompatible with renamed `qts_options`.
  Disable it temporarily, to be restored before new release.
herrvigg added a commit that referenced this pull request May 29, 2022
- the checks on migrated items is made obsolete by new migration
- the quick check is incompatible with renamed `qts_options`.
  Disable it temporarily, to be restored before new release.
herrvigg added a commit that referenced this pull request Jun 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants