Skip to content

Category/tag/global set entrification#12689

Merged
brandonkelly merged 6 commits into
4.4from
feature/dev-1012-categorytagglobal-set--entry-conversion
Feb 17, 2023
Merged

Category/tag/global set entrification#12689
brandonkelly merged 6 commits into
4.4from
feature/dev-1012-categorytagglobal-set--entry-conversion

Conversation

@brandonkelly

@brandonkelly brandonkelly commented Feb 17, 2023

Copy link
Copy Markdown
Member

Description

Adds new entrification commands:

  • entrify/categories
  • entrify/tags
  • entrify/global-set

Plus some supplemental section maangement commands:

  • sections/create
  • sections/delete

Here’s what the workflow for converting categories/tags/global sets to sections and entries will look like:

  1. Run the entrify/* command(s) locally.

    php craft entrify/categories myCategoryGroupHandle

    The command will walk you through creating a new section based on the category/tag group or global set, convert the elements to entries in that section, and optionally also delete the old category/tag group or global set, and convert Categories/Tags fields over to Entries fields.

  2. Update your templates, custom plugin/module code, and GraphQL queries accordingly.

  3. Deploy the changes to another environment.

  4. Run the same command immediately after deployment (after applying project config changes). This time, the new sections will already be in place, and the category/tag groups and global sets will be soft-deleted. So the command will only need to convert the actual category/tag/global set elements to entries.

Warning
Do not hard-delete your old category/tag groups or global sets via garbage collection before step 4. Doing so would also remove the category/tag/global set elements, at which point the content would be lost forever.

An example run through the `entrify/tags` command, for a tag group called “Food”

Related issues

@brandonkelly
brandonkelly requested a review from a team as a code owner February 17, 2023 05:05
@linear

linear Bot commented Feb 17, 2023

Copy link
Copy Markdown
DEV-1012 Category/tag/global set → entry conversion tool

There needs to be some way of converting existing category groups, tag groups, and global sets to sections.

Conversion will need to be split into three steps:

  1. New section creation, based on existing category groups, tag groups, and singles (performed on dev)
  2. Category/tag/global set element → category migration (performed on production after the initial deploy)
  3. Category group/tag group/global set deletion (performed on dev, after everything has been migrated on production)

@brandonkelly
brandonkelly merged commit cdb893b into 4.4 Feb 17, 2023
@brandonkelly
brandonkelly deleted the feature/dev-1012-categorytagglobal-set--entry-conversion branch February 17, 2023 13:06
@vnali

vnali commented Mar 3, 2023

Copy link
Copy Markdown
Contributor

@brandonkelly this is great!
I tried to test it but I received this error after choosing 'yes' on the 'Delete the “xyz” category group?' step on the local environment.

Exception 'yii\base\Exception' with message 'Unable to write new project config files'
in /var/www/html/craft4live/vendor/craftcms/cms/src/services/ProjectConfig.php:1608
Caused by: PHP Warning 'yii\base\ErrorException' with message 'rmdir(/var/www/html/craft4live/config/project/categoryGroups): Directory not empty'

i double-checked permission on the config/project folder and it is writable.
And just for clarification, before deleting category group step, I can see the categoryGroups folder, and after choosing yes and this error, the categoryGroups folder is not in the project folder. although I can see a hidden folder like ..xyz containing category group .yaml file

@brandonkelly

Copy link
Copy Markdown
Member Author

@vnali Weird… it’s gotta be some sort of permission thing. PHP is probably being executed as a different user for CLI requests than it is for web requests. Can you try switching to whatever user account web requests are running as first, via

sudo su - username

@vnali

vnali commented Mar 3, 2023

Copy link
Copy Markdown
Contributor

@brandonkelly thanks! I wasn't sure how to switch to another user on my environment but changing permission on the config folder to 777 worked, so definitely it was a permission issue.

@FrDH

FrDH commented Apr 19, 2023

Copy link
Copy Markdown
Contributor

I had some issues with converting a global set, all went well local, but after pushing to staging I ran the command and got this error:

[me]$ php craft entrify/global-set meldingen --section=instellingen
 → Converting “Meldingen” … ✕
   Error: Changes to the project config are not possible while in read-only mode.

On staging:

  • the single was created, but remained empty
  • the global set was not removed, but emptied

FYI I converted the categories first and that worked as intended 👍

@brandonkelly

Copy link
Copy Markdown
Member Author

@FrDH Did you run craft project-config/apply first? If the new section has already been created via that command (or craft up), then it should work as intended.

@jevans1808

Copy link
Copy Markdown

I just want some clarification on this entrification process. I've run the commands locally, and taken a record of the commands to be run on the server. I've committed my changes to my repo. Once I have deployed, do I run the commands immediately, or do I apply yaml changes, and then run the commands? If I've deleted the categories groups locally, whilst following the prompts thrown by entrification (e.g. "Delete the 'Blog' category group? Yes") and committed these changes to the yaml file, will this cause any issues or conflicts? Or would the categories themselves still exist to be converted to entries, despite the deletion of the group?

Thanks

@brandonkelly

Copy link
Copy Markdown
Member Author

@jevans1808 You’ll run craft up like you normally would first, which will apply the project config changes (including deleting the category group), and then run the entrify command. Even though the category group was deleted, your categories will still exist in the database (soft-deleted), so the command is still able to convert them to entries.

@jevans1808

Copy link
Copy Markdown

@jevans1808 You’ll run craft up like you normally would first, which will apply the project config changes (including deleting the category group), and then run the entrify command. Even though the category group was deleted, your categories will still exist in the database (soft-deleted), so the command is still able to convert them to entries.

Awesome, thank you for the clarification!

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.

4 participants