Forum

Thread tagged as: Runway

Import API & Cronjob

Awesome, with https://perchrunway.com/blog/2017-02-10-importing-content-into-collections it will be a breeze to pull external content into perch.

Not only once, but also on a regular basis. I do this very often in another CMS, pulling in members lists, courses, etc from APIs or as exported CSVs from Dropboxes. All you need is a cronjob and $Importer->empty_collection();, so you can import the whole collection again, say every hour.

What I'm not sure is the duration of the gap between empty_collection() and add_item(). In theory, there will be a moment where the collection will be empty. For a small dataset it probably won't matter.

What do you think about that time/data gap?

PS: Here's a next step for later :-)

$Importer->update_item([
    'match_field' => 'source_id',
    'source_id' => '12345',
    'title'    => 'Breaking news!',
    'body'     => 'Some **exciting news** has _just_ broken...',
    'slug'     => 'breaking-news',
    'date'     => '2012-04-28 12:23:09',
    'category' => ['articles/news', 'articles/flippin-exciting'],
  ]); 

$Importer->delete_orphaned_items([
    'match_field' => 'source_id',
  ]); 
Urs Bräm

Urs Bräm 1 points

  • 4 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

I don't understand your question. What problem are you experiencing?

Hi Drew - not a problem. Just pondering:

  • If the importer would be used not for one time imports but on a regular, scheduled basis in a productive system,
  • in order update records in Perch that are maintained in another tool (e.g. an event planner)
  • One could run $Importer->empty_collection(); frequently and import fresh data easily

I wondered if you find that a good idea or not

Drew McLellan

Drew McLellan 2638 points
Perch Support

That would be fine.

cool !