backdrop-contrib / paragraphs

Paragraphs module to control your content flow
https://backdropcms.org/project/paragraphs
GNU General Public License v2.0
5 stars 11 forks source link

Upgrade from Drupal 7 field collection into paragraphs #53

Open jenlampton opened 4 years ago

jenlampton commented 4 years ago

I'm interested in working on an upgrade path from Drupal 7 field collection. Is anyone else working on this, and if so, can we collaborate or would others be willing to help me test?

laryn commented 4 years ago

I haven't heard of anyone working on this, but I'd be happy to do some basic testing. I haven't used Field Collection so would probably only be able to test a basic set up / upgrade.

bobchristenson commented 3 years ago

I've used both of those modules pretty heavily in Drupal 7 and I'm not sure Field Collection and Paragraphs serve the same purpose.

Field collection is more like a field that contains multiple fields. It really only has a single way to display that field in the end. It's sorta like a 'grouping' of fields.

Paragraphs on the other hand, while it's also a 'grouping of fields', is intended to have multiple "types" of field groupings with different fields within each grouping. (wow, thats hard to explain 'out loud'!). Each paragraph type would display differently than the others and contain different subfields.

While both modules are objects that contain multiple sub-fields, I don't see them as interchangeable. I could keep blabbing, but I'll see if anyone else agrees with me first before going further in an explanation. :)

laryn commented 3 years ago

I suppose this (from the FC module page) is what prompted the original idea:

Use Paragraphs and Entity Reference Revisions instead of field collection for Drupal 8 projects.

There exists a FC -> Multifield module already, apparently:

jenlampton commented 3 years ago

Of course, it someone really wanted field_collection for Backdrop, I imagine it could be ported without too much trouble.

bobchristenson commented 2 years ago

For the reocrd, I think I changed my mind. I think Paragraphs may be a replacement for field_collection. I'm working right now to see if I can migrate the data from fc->paragraphs and see if it does everything I need it to!

oadaeh commented 2 years ago

Of course, it someone really wanted field_collection for Backdrop, I imagine it could be ported without too much trouble.

That and the fact that over 22% of D7 sites use Field Collection are the reasons I started it:

It definitely still needs work.

bobchristenson commented 2 years ago

I'm a big fan of field collection...but I'm also a big fan of consolidation. Since paragraphs has been established in Backdrop already and was deemed the way forward in D8...it makes me wonder if focus should be on determining whether Paragraphs can be truly a 100% replacement (or not). If the answer is 'yes', then maybe time is better spent on a process to convert field collections to paragraphs, thereby leaving only one long term module to maintain (paragraphs) rather than 2. Just a thought.

jenlampton commented 2 years ago

I know there's a migration path in D7 for field collection to paragraphs. If your site is already in backdrop, perhaps that can be ported too?

On Wed, Nov 10, 2021, 8:03 AM Bob Christenson @.***> wrote:

I'm a big fan of field collection...but I'm also a big fan of consolidation. Since paragraphs has been established in Backdrop already and was deemed the way forward in D8...it makes me wonder if focus should be on determining whether Paragraphs can be truly a 100% replacement (or not). If the answer is 'yes', then maybe time is better spent on a process to convert field collections to paragraphs, thereby leaving only one long term module to maintain (paragraphs) rather than 2. Just a thought.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/backdrop-contrib/paragraphs/issues/53#issuecomment-965479598, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADBERZXMLXAVTDQB5XMU7TULKJWVANCNFSM4LOX6NFQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

bobchristenson commented 2 years ago

@jenlampton It would be good if you posted any existing migration tools from fc->paragraphs. When I googled I didn't find anything usable for D7.

jenlampton commented 2 years ago

I did a quick google and also came up empty. :( I'm (almost) certain I found something before. My recollection is that it was a module named fc2p (or something not entirely obvious) but I could be getting confused with something else... I'll give it a more thorough look when I have some more time.

oadaeh commented 2 years ago

The only one I saw when I was poking around in the last week or two was one for D8 FC->P or D7 FC->D8 P. I did not see one for D7 FC->P, but I think @klonos saw something in some issue comment somewhere.

herbdool commented 1 year ago

I've come up with nothing as well. But I peeked at the data structure of the two to see the difficulty of creating a script.

field_collection_item

Each field that's part of the field collection has entity_type of field_collection_item and a bundle that is the field instance bundle such as field_mycollection. The configuration for the field collection is specific to/part of a field on a "host entity".

paragraphs_item

Each field that's part of the paragraphs has entity_type of paragraphs_item and a bundle that is the paragraphs type (and same as the bundle as appears in paragraphs_item). The paragraph type is it's own configuration and the field instances reference that paragraph type.

A manual process could be something like this (I haven't tried this yet):

  1. Upgrade from d7 to Backdrop.
  2. Leave the field collection tables in the db.
  3. Install paragraphs.
  4. Create a paragraph type for each unique field collection on the old site. Keep a mapping handy of this.
  5. Add a paragraph field on each content type which had the field collection field in D7. If wanting to keep the same file name then may need to manually remove the field_collection fields config files first (make a backup). If field collection is disabled there might not be any errors.
  6. Add the field instances of the fields which were on the field collection to the relevant paragraph type.
  7. Insert all records from field_collection_item, field_collection_revision. Set status = 1. Set the bundle to the paragraph type mapped to the relevant field collection field and the field_name to that of the paragraph field. (For field collection the field name is the same concept as "bundle".)
  8. Update the records in the appropriate fields (field_data_field_NAME, field_revision_field_NAME) so entity_type is paragraphs_item instead of field_collection_item and bundle is the new paragraph type (from your mapping).
INSERT INTO `paragraphs_item_revision`
(`revision_id`, `item_id`)
SELECT `revision_id`, `item_id`
FROM `field_collection_item_revision`;

INSERT INTO `paragraphs_item`
(`item_id`, `revision_id`, `bundle`, `field_name`, `archived`, `status`)
SELECT
  `item_id`
  , `revision_id`
  , CASE
      WHEN `field_name` = "field_apples" THEN "apples"
      WHEN `field_name` = "field_oranges" THEN "oranges"
      ELSE
    END
  , `field_name`
  , `archived`
  , 1
FROM `field_collection_item`;

Updating the field data:

UPDATE `field_data_field_colour`
SET `entity_type` = "paragraphs_item", `bundle` = "apple"
WHERE `bundle` = "field_apples";

UPDATE `field_revision_field_colour`
SET `entity_type` = "paragraphs_item", `bundle` = "apple"
WHERE `bundle` = "field_apples";

UPDATE `field_data_field_sweetness`
SET `entity_type` = "paragraphs_item", `bundle` = "apple"
WHERE `bundle` = "field_apples";

UPDATE `field_revision_field_sweetness`
SET `entity_type` = "paragraphs_item", `bundle` = "apple"
WHERE `bundle` = "field_apples";

The above query assumes the paragraph field names are the same as the field collection ones.

Last step: Clean up: delete field_collection_item* tables no longer needed.

Hmm... this could use some work. I'll be looking into this more in the next coming months so I'll update any progress on a script. I think part of this will always be manual compared to using the D7 to D9 Migrate which can convert the configuration.

UPDATE: I've edited the list.

herbdool commented 1 year ago

I've got a bee script here for converting field collection to paragraphs: https://gist.github.com/herbdool/556b5246544868f66debcaaa0c2ed5b3. It updates the config and updates tables. It automatically creates paragraph types based on the field collection field name. A unique paragraph type per field collection field. It doesn't touch Views though doing a search and replace of field_collection to paragraphs probably goes a long ways. And you'll need to check all the paragraph settings to ensure they're set up correctly.

irinaz commented 6 months ago

I am evaluating a project that might need such conversion and would be interested in making this standard upgrade option.

herbdool commented 6 months ago

I don't I'll be able to spend more time on the script, but it should work fairly well as it is as a bee script.