Migrate Data with Database Connection

I need to move over hundreds of items from a current website with a database over to Kirby.

How do I complete this automatically?

Items are within current “category” pages with a structured field.

Current Database Site

New Website with Structured Field




its a bit hard to say without the db table schema. i would do it like this

  • connect to db
  • select all pages from that table
  • loop over rows and create a page with needed content
  • since there are no subpages but a structure do a select on that data, transform the array to match the structure, convert to yaml and update previous created page object

also consider using using the terminal to call the import with a kirby 3.9 cli command to avoid running out of execution time.

Also, if what @bnomei wrote above doesn’t help, please explain in detail the steps that are not clear to you and where you need help.

Now I have the structures showing as Virtual Pages. Is there an easy approach to that?

No matter if you use the structure as virtual pages or not, you still want to store the data from the DB in those structure fields. So no change, unless you want to keep the database.

What if I already created the pages within Kirby?

So the current Database table is called perch3_content_items

The Data is in JSON

Example:

{"_id":"2216","productImage":{"assetID":"8422","title":"13074","_default":"\/masonry\/resources\/13074.jpg","bucket":"default","path":"13074.jpg","size":118494,"w":801,"h":462,"mime":"image\/jpeg","sizes":{"thumb":{"w":"150","h":"86","target_w":150,"target_h":150,"density":2,"path":"13074-thumb@2x.jpg","size":27161,"mime":"image\/jpeg","assetID":"8423"}}},"alt":"13074","itemNumber":"13074","newItem":null,"reducedTo":null,"price":"200","productShortDescription":{"_flang":"html","raw":"<p><strong>CSA 11-KB, 10&cent; deep blue<\/strong> (4 margins) tied <strong>RICHMOND \/ VA<\/strong>. cds on pristine <strong>manuscript semi-official<\/strong> cover with ms &ldquo;<strong>Office of Commissioner of Taxes<\/strong>&rdquo; at top, addressed to C. J. Linton, Esq. Richmond, Va. thus an <strong>OVERPAID DROP<\/strong> cover with docketing up left side &ldquo;December 1864&rdquo;. $200.<\/p>","processed":"<p><strong>CSA 11-KB, 10&cent; deep blue<\/strong> (4 margins) tied <strong>RICHMOND \/ VA<\/strong>. cds on pristine <strong>manuscript semi-official<\/strong> cover with ms &ldquo;<strong>Office of Commissioner of Taxes<\/strong>&rdquo; at top, addressed to C. J. Linton, Esq. Richmond, Va. thus an <strong>OVERPAID DROP<\/strong> cover with docketing up left side &ldquo;December 1864&rdquo;. $200.<\/p>"},"productFullDescription":{"_flang":"html","raw":"<p><strong>CSA 11-KB, 10&cent; deep blue<\/strong> (4 margins) tied <strong>RICHMOND \/ VA<\/strong>. cds on pristine <strong>manuscript semi-official<\/strong> cover with ms &ldquo;<strong>Office of Commissioner of Taxes<\/strong>&rdquo; at top, addressed to C. J. Linton, Esq. Richmond, Va. thus an <strong>OVERPAID DROP<\/strong> cover with docketing up left side &ldquo;December 1864&rdquo;. [VA] $200.<\/p>","processed":"<p><strong>CSA 11-KB, 10&cent; deep blue<\/strong> (4 margins) tied <strong>RICHMOND \/ VA<\/strong>. cds on pristine <strong>manuscript semi-official<\/strong> cover with ms &ldquo;<strong>Office of Commissioner of Taxes<\/strong>&rdquo; at top, addressed to C. J. Linton, Esq. Richmond, Va. thus an <strong>OVERPAID DROP<\/strong> cover with docketing up left side &ldquo;December 1864&rdquo;. [VA] $200.<\/p>"}}

Here is the current database structure. It has all items in one table and then it filters by pageID. All data is in JSON too. I’ve already created all of the pages in Kirby with the structure field for the items.

Is there an easy approach to this?

Database Structure:


That question is a bit general and hard to answer.

What do you already know? Have you been able to connect to your database with Kirby yet? That would be the first thing to do.

Basically, you would now loop through the pages you have already created in Kirby.

For each of these pages, you make a query to the database for the items you want to store in the structure field.

When you get the rows from the database, you create an array item with the fields in your structure field and assign the values from each row and append to the array you want to store.

Then you do a $page->update() with the yaml encoded array.

Connect to database and simple queries: Database | Kirby CMS

I was able to connect to database but keep getting a invalid table error within Kirby debug.

I will definitely need help with how to code this as I am not that advanced or have that experience doing it.

I think you have two options here:

  1. Post a paid job in the jobs’ category to find a developer who can do this for you.
  2. Keep trying it yourself and ask specific questions where you get stuck. Something like

is not really something anyone can help with without knowing what code you tried and what exactly the error is.

Okay thanks.