Converting from V1 to V2: Collections

Hello everyone,

I am a new team at a company that uses Cockpit CMS (V1) for our local/internal business application. My long-term project is to upgrade our current Cockpit version (and our custom add-on) to the latest version. I am breaking this project down into two main parts:

  1. Migrating our existing collections to ensure that there is no data loss.
  2. Rebuilding/tweaking our add-on to work with the new interface.
  • Our add-on consists of 10 custom pages that are navigable from the menu bar.

Currently, I am seeking guidance on the first step of migrating our collections. I have attempted to copy all of the collections from the /storage/collections directory to the new V2 installation, but the collections are not appearing. Any advice or guidance would be greatly appreciated. Thank you!

Note: If you have any suggestions/thoughts on how to best migrate an add-on/how to rebuild the custom pages, it Iā€™m all ears!

I attempted to migrate from v1 to v2 a week ago,
and I posted an article about migrating Cockpit v1 to v2.

I hope it helps you.

1 Like

Thanks for sharing the post. Unfortunately, we use MongoDB as our database so it isnā€™t as relevant. Iā€™ve made a little bit of progress myself.

Here are the high level steps I have for migrating your existing MongoDB collections over to a new V2 instance.

  1. Install your desired version (core for me)
  2. Add your existing config.php file to the config folder (this has your mongodb server details)
  3. Navigate to the /install url to ensure all dependencies are installed.
  4. Create a new model, which should match one of your old collections that youā€™re trying to migrate

Note: This is the part that I"m hoping to get a little more clarity onā€¦ when you create a new model and then your first item the new collection is added to your database. For example, if your model is title ā€œCockpitTestā€ your collection will show up as ā€œcontent_collections_CockpitTestā€. In the associated CockPitTest.model.php file, there is no reference to that collection name. In V1 you could add a line like ā€œ_uidā€ => ā€˜CockpitTestā€™ which would correspond to the default collection name of ā€œcollections_CockPitTestā€. If I add the ā€œ_idā€ line with my old collections name it doesnā€™t work.

  1. The workaround, after you create your first item and the associated collection is created in MongoDB. Rename (or delete?) the recently created collection to anything else. Then rename your old collection to match the automatically generated collection name you just changed.

For example, if your old collection is called ā€œcollections_CockpitTestā€ rename it to ā€œcontent_collections_CockpitTestā€ and all of your items will show up in the V2 instance. They will be unpublished to start.

Edit: You donā€™t need to create an item after creating the model, you can then rename your old collection to the new naming convention.

Is there a way to point to the existing collections names or do we have to rename them to the new schema?

1 Like

Its pretty straightforward to rename all the collections. I just wrote a simple python script to rename them. The issue Iā€™m running into now is that previous collection links arenā€™t showing up. For example, if I have a ā€œContent Linkā€ (previously ā€œCollectionLinkā€ in V1) to a specific document in another collection it doesnā€™t show the content. It only shows a button ā€œLink Collection Itemā€ which opens up a dialog to select the specific item, which is obviously not going to work for over tens of thousands of items.

Iā€™ve copied over the same JSON options from V1 to V2, such as:

{
  link: 'Customers',
  display: 'Name',
  multiple: true,
  limit: false,
  filter: null,
}

Iā€™m wondering if the expected MongoDB structure has changed? For example, if I query a specific document in my collection I get:

{
  _id: ObjectId("5db1e5206c11890231685138"),
  Name: 'Part XYZ',
  ShortName: 'XYZ',
  CustomerSpecific: true,
  Customer: [
    {
      _id: '5d262b2ff22765286848c965',
      link: 'Customers',
      display: 'Cockpit CMS'
    }
  ],
  ...
}

When I load this specific document in the V2 Cockpit Admin interface Iā€™m expecting to have a link ready to click saying ā€œCockpit CMSā€ that takes me to the associated document.

Anyone aware of anything that has changed around the expected structure in MongoDB or JSON settings to get this to link correctly?

Showing view in admin interface

Showing settings of specific field item in the model
CleanShot 2023-04-12 at 14.04.07

Edit 1: It looks like if I use the admin interface to make a new connection it updates the mongodb structure to:

Customer: { _model: 'Customers', _id: '5cdb2debf257657a85226862' }

Which means I need to write some scripts that look for all links and change them to _model in my collections. The last thing here I need to figure out is how to display the name of the linked item. In a forum search it looks like using a syntax similar to ${Name} in the Display input will solve the problem, but I still havenā€™t cracked the code.

Edit 2: It was in the documentation (kind of)! For me, Iā€™m trying to show the ā€œNameā€ field so modifying my JSON options to the below works:

{
  link: 'Customers',
  display: '${data.Name}',
  multiple: true,
  limit: false,
  filter: null,
}

Removing the JSON options and only putting ${data.Name} in the Display field didnā€™t work.

1 Like

Hi :wave:

I saw that there is a multiple option set to true. In v2 you donā€™t need that as any field can set to have multiple values.

Just check the checkbox ā€œAllow multiple valuesā€ in the general field settings. That way the display value should work again if you have a list|array of customers.

1 Like