4

Is there any best practice how to import info Craft 3 data from external source, or should I backtrack it from the database?

3

I think you have to know what you need and what you want to achieve. You need to decide if you want to add elements or records because there is a huge difference between those two types of objects and how you need to import and implement them

Elements
Pros:

  • it does not take a lot of time to make them manageable for clients
  • they can use all Craft features (relation fields, lists, edit forms....)
  • they are really flexible

Cons:

  • you'll need a little bit of time to dig into the concept if you are totally new to Craft
  • they'll have a record in your elements table so for larger projects you'll have to pay attention at your performance

Records
Pros

  • easy to handle
  • it does not require much time to create/import records since they are standalone and have no requirements
  • Yii's activerecord object is really powerful and intuitive in searching records
  • they don't create a massive overhead in your db

Cons

  • If you are going to make your records editable to users/customers in the cp you'll need to create everything on your own (templates/forms....) because they have no field layout and it's a mess to redefine them as elements to use Craft features... I did it once, it was not funny
  • You are not able to use Craft relations by default and have to create custom relation tables if you are going to do fancy stuff

After you decided what to use, you have to decide how you would like to proceed. You can create a custom element type or use an existing one (entries, categories) and how complex it needs to be. But without more information from your site it's hard to give any further advice.

I suggest everyone to create a custom plugin for imports to handle them. Due to Crafts/Yii2's plugin management and services it's totally trivial to create a data import because everything is really easy to understand and to manage. You can create a custom controller to fetch the data you need, set the values of your elements/records and use their save functions. The rest happens nearly automatically

3
  • Do you know the performance bottleneck for elements? We will use external services for search for example but still we are planing to put over 100k record with 10-20 fields. Guess it will not to slow specially if the search will be external - fron algolia Feb 18 '18 at 3:52
  • 100k should not be that bad. I've never tested the exact number so I can't say for sure. Does your client need to see/manipulate the imported data in the cp? If not records are totally enough Feb 18 '18 at 7:35
  • Manipukation is needed. Need the flexibility of craft for content management. After import they will have a workflow task to make the content sexy before publising. Anyhow we will test it anyway:) but thx for the hints and links! Feb 18 '18 at 19:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.