Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Tips please for exporting a blog article table and importing into SS SQL


Go to End


9 Posts   1556 Views

Avatar
Turismo

Community Member, 28 Posts

19 May 2016 at 9:00am

My client has a large volume of blog articles on their existing website, each of which have associated tags, categories and authors. I've installed the SS blog add-on for the new site I'm building for them. As a means of migration, I was thinking about restructuring the tables to match the columns of SS in a test environment, restructuring the columns and naming conventions to match those of SS, and then importing the SQL dump into my SS site.

Does this sound like the recommended approach? Or is there a more effective approach I should be taking?

Avatar
Vlad Belfort

Community Member, 55 Posts

19 May 2016 at 10:00pm

Not an expert but from my experience I'd recommend recreating that as a page type or dataobject (whichever suits your needs best) rather than directly changing the database.

Use SilverStripes ORM to create the fields for you then put the data in. My thoughts are that it'll give you what you need in terms of the table and columns plus this way you'd already have something ready to use in terms of creating new blog articles and retrieving all of them in your template.

I've sub'd to this topic because I'm looking to do some data migration soon so would be interested in hearing about others opinions and also how it goes for you :)

Avatar
Turismo

Community Member, 28 Posts

20 May 2016 at 2:31am

Hi Vlad,

Thanks for the response. Aligning the page type fields to that of the MySQL sounds good, though I'd prefer to prioritise any SS naming conventions for columns over whatever is existing into the import.

My main query however is more towards the import itself. There are hundreds of articles, so I'm trying to establish whether I do an import directly via the phpMyAdmin, or whether there is something within the SS Admin itself I should be using for such an import.

Avatar
Vlad Belfort

Community Member, 55 Posts

20 May 2016 at 3:31am

My main query however is more towards the import itself. There are hundreds of articles, so I'm trying to establish whether I do an import directly via the phpMyAdmin, or whether there is something within the SS Admin itself I should be using for such an import.

Ah okay. I haven't seen anything that comes out-the-box in the admin section that will do that import for you so could be worth doing it via phpMyAdmin.

I recently done something somewhat similar although I decided to add all the data programmatically using the SilverStripe framework wherever possible instead of putting it straight into the database just in case the CMS has it's own way of storing/handling the data.

These links could help you out if you choose to go that route:
https://www.silverstripe.org/community/forums/general-questions/show/18017
http://stackoverflow.com/questions/21780380/how-do-i-programatically-add-a-new-page-to-silverstripe

Avatar
Turismo

Community Member, 28 Posts

21 May 2016 at 12:28am

Hi Vlad,

Gave it a go this morning prepping the SQL exports as .CSV and importing directly via phpMyAdmin. Took quite a bit of data mining, and a good few hours, but successfully managed to import across 300+ articles, complete with tags, publish dates and other values intact.

Thanks again for your tips and advice on this matter.

Avatar
Vlad Belfort

Community Member, 55 Posts

21 May 2016 at 12:43am

I'm glad to hear it worked out well!

Did you do anything in SilverStripe prior to importing or was it all done in the CSV data when you imported?

I've got something similar coming up but with ~40,000 entries to go in separate tables and don't know the best way to go about putting all that in so would love to hear an overview of your story if you don't mind sharing

Avatar
Turismo

Community Member, 28 Posts

21 May 2016 at 1:19am

Hi Vlad,

Gosh that's a lot of records!

Here a brief walkthrough of what I did:

  • Exported the relevant tables from my clients' existing phpMyAdmin as .csv (tick 'Put columns names in the first row' - useful as a reference)
  • Structure the columns in each .csv to be identical to the equivalent table in my SS database (even if some columns have no data)
  • Save each .csv with a filename that matches the relevant table in my SS database (so I know which tables I'm importing into)
  • Create backup of both the .csv files prior to mining, as well as the SS tables that will be imported into (just in case anything goes wrong!)
  • Once completely happy with the columns in each .csv, I removed the column names (first row), as these were just for reference
  • Before importing, make sure ID for each record in each .csv is unique, and that they are NOT already used by an existing record within the tables they'll be imported into (if starting a new project, it's probably best to do this before you start creating any other pages)

I structured the .csv files based on tables required for the blog add-on http://addons.silverstripe.org/add-ons/silverstripe/blog`, so the SS tables I needed a .csv for were (in this order):

  • BlogPost_Tags.csv (prepped, imported and tested this first to familiarise myself with the process, and to check my approach worked!)
  • SiteTree.csv
  • SiteTree_live.csv (identical .csv to SiteTree)
  • SiteTree_versions.csv
  • BlogPost.csv
  • BlogPost_live.csv (identical .csv to BlogPost)
  • BlogPost_versions.csv
  • (I didn't do BlogCategory as the existing articles only had tags, not categories associated with them)

A few additional notes to add:

  • Excel kept mucking around with the date formatting for my `Created` and `LasteEdited` - I stopped it doing this by adding a space before the date in the .csv (once imported, phpMyAdmin ignores the space, and the date formats accordingly)
  • Double check the date formats in your .csv before importing to ensure they match the format in the database
  • I threw some of the date formats and other columns into Sublime Text to make batch formating changes more effectively, and then copied back into Excel
  • Again, make sure you're not trying to import any pages/records which have an ID already used in the relevant SS table
  • For BlogPost.csv, I had to set the `FeaturedImageID` for each record to 0, because in the database it's a required INT, so it couldn't be left empty

I hope the above helps! Obviously feel free to let me know you get on once you reach this point in your project, and happy to assist further. This is my very first SS project, so there might be a better way to the above, but this is just how I went about it; it wasn't much fun by any means, and took a good chunk of the morning up, but was far far better than having to manually re-create 280+ articles via the CMS itself.

Avatar
Vlad Belfort

Community Member, 55 Posts

21 May 2016 at 3:28am

Wow! Thanks for that, I was expecting a few paragraphs but this I'm definitely bookmarking

This is also my first time working with SilverStripe and the community seems very small so any information that gets something working is great to have :)
It's good to know that this approach worked out well for you, I was planning to write a script to get the data in but if I could get away with using something like Excel and phpMyAdmin I can imagine it'd save a lot of time!

Funny you mentioned uploading manually, for fun I suggested we hire someone to do that on the content we have to import (needless to say that isn't going to happen aha)

Go to Top