Things can always go wrong. Always make a backup of your content folder/Kirby installation before starting out on this journey.
Kirby 2 only had a single upload section for files in the sidebar and it wasn’t possible to assign different types of metadata fields to different types of files. Kirby 3 changes this completely by replacing this fixed single upload section with files sections. Each page blueprint can define as many files sections as the data structure requires. And each of these sections can use different file blueprints that define the Panel setup for files and the fields available for these files.
This new way of dealing with files gives you much more flexibility but it also means that you have to adapt some things when migrating a Kirby 2 site, because you can no longer define the meta data fields in the page blueprint.
This recipe assumes that your content folder has already been updated with the new folder numbers as explained in the main migration guide.
These are the basic steps to migrate your metadata fields to Kirby 3:
- Remove the old file settings from your page blueprints.
- Create new file blueprints for each set of files that shares the same fields and other setup options (accepted mime types, dimensions etc.)
- Fetch/filter the files you want to assign each template to (you might want to filter files according to file type or other criteria).
- Loop through the files and assign the new template
It’s probably best to go through an example.
Let’s assume that in your Kirby 2 project, the children of the projects page use the
project.yml blueprint. In that file, you have the following file settings:
In your new
/site/blueprints/project.yml blueprint, remove these lines.
We now recreate the blueprint with a files section for our files and assign a file template:
Now whenever we upload a new file to this new files section, if will be created with the
But stop. We haven't created a
blueprints/files/project.yml blueprint yet. Let's do this now.
We copy our fields from the old blueprint into the new files blueprint. And since we only want user to upload images to this files section, we add an
With these blueprints in place, all new files will pick up the file blueprint and show up in the files section. But our old images won't just yet, because their blueprint files are missing the template information. Let's change that.
Create a new
update-metadata.php file in your site root.
Then run this script with http://yourdomain.com/update-metadata.php. Delete the script when done.
You can adapt this script to your needs or use it multiple times for different sets of files with different templates.