Okay
  Public Ticket #2548150
CSV Cron Job Import / ICS documentation
Open

Comments

  •  2
    Santiago started the conversation

    Hi -- I'm trying to create a job to import events. Two questions

    1) Availability of CSV scheduled jobs

    Ideally it would be on CSV as it's easier for my exporting pipeline, but I don't see the option for scheduling a job to pick up a CSV -- only ICS. Can you please confirm if CSV is not currently supported?

    2) ICS schema

    It does look like scheduling a ICS import job is possible, but I don't see anywhere the documentation for the fields. I exported my current events but noticed that fields like 'Image' are not present, to name one. Where can I learn the full schema?

    Thanks!

  •  876
    Zhivko replied

    1) CSV cron jobs are not supported yet.

    2) ICS contains following data:

    • Event Title
    • Start Date
    • End Date
    • Location
    • Event Description
    • Repeat scheme (RRULE)
    • Visibility (Private/Public)

    Unfortunately the ICS format does not support images.


    Stachethemes Developer

  •  2
    Santiago replied

    Ok bummer. I might need to create a custom script to inject the events and the images on the WP DB then. Are there any articles / answers written on this that you could point me to?

  •  876
    Zhivko replied

    Here's how you can create event via PHP:

    /**
     * For all available methods check get_class_methods($event);
     * or wp-content\plugins\stachethemes_event_calendar\assets\php\o.event.php  */
    $event = new \Stachethemes\Stec\Event_Post(); $event->set_title('Event Title');
    $event->set_start_date('2020-01-31 00:00:00');
    $event->set_end_date_date('2020-01-31 12:00:00'); /**
     *  1,2,3,4 are the images IDS number from your WP Media
     *  You will have to upload the images to your WP Media first
     */
    $event->set_images(array(1, 2, 3, 4)); $event->insert_post();



    Stachethemes Developer

  •  876
    Zhivko replied

    Additionally what you could do is write your own cron and use the calendar csv importer.

    Example:

    add_action('stec_cronjobs_hourly', function() {
        $csv_url  = 'https://link-to-your.csv';
        $importer = new \Stachethemes\Stec\Import();     $importer->set_ignore_expired(false);
        $importer->set_overwrite_events(true);
        $importer->set_delete_removed(false);
        $importer->set_download_images(true);
        $importer->set_create_categories(true);
        $importer->set_create_locations(true);
        $importer->set_calendar_id(2154); // make sure the calendar id exists
        $importer->set_csv_url($csv_url);     $result = $importer->import_csv();
    });


    Stachethemes Developer

  •  2
    Santiago replied

    Ah, that's a good idea. This seems like a snippet of code I should only run once, right? (because it lodges the cron job, somewhere). What's the best practice for executing these? Do I just create a random php page and then visit it with the browser, to trigger the php to run server-side?

  •  876
    Zhivko replied

    Place it in your functions.php file and leave it as is. Do not remove it. 

    Note: this is WP Cron, not real cron job. It should run automatically every hour but if your site is not visited it won't trigger. That's how wp cron works... 

    The good thing is you can replace wp cron with real one.

    Example tutorial here.


    Stachethemes Developer

  •  2
    Santiago replied

    Oh, interesting, I see. Thanks!

  • Michela replied

    Since this code isn't working anymore, do you have a different solution?

    Thanks