Calling a Composr API function "in batch mode"
Posted
#9230
(In Topic #3183)

Standard member

I would like to call the add_news function in the news package from a php script launched by a Cron job
Hello all. First off, apologies! I am brand new to Composr. I also have not been able to simply figure out how to search the forum for previously asked topics -- I hope I'm not wasting peoples' time.I have almost completed an ETL implementation that will basically gather a bunch of news articles from various sources (the extract), scrub the article text and meta data into a common format (the transform), and I now would like to add these articles, "unvalidated", via an api call to the add_news function in the news package (the load).
The purpose of the ETL implementation is to run on a scheduled basis (using Cron), with the end result being that our Composr administrator simply needs to check the resultant queue of articles not yet validated. At that point, the administrator will choose to either validate / publish or discard each article in the queue. Hence, this is by design a background process.
I'm looking for any sort of sample that someone has written to do this sort of thing?
Thanks in advance.
Bob
Posted

Site director

See Composr Tutorial: Commandr - Composr .
Essentially, you would create a file (no extension) in your Composr installation under data/modules/admin_commandr (or /bin if using webDAV or Commandr directly to create the file).
Prefix the file contents with a : to enter PHP mode. And you can write in your PHP script as necessary. For example, you'll need to require_code("news2"); to gain access to the add_news function, which you can then call later down in the script.
Once your script is written and saved, you can create a Cron that calls the script via a web request (you cannot use PHP cli because the script requires a POST parameter). Call data/commandr.php and POST command=name_of_script_file.
Last edit: by Patrick Schmalstig
- Need support for version 10? The core development team is no-longer offering it for free (unless it's a critical bug that breaks your entire site or a serious security hole). Please consider hiring me instead if you need v10 support or a non-critical bug fix. Or, ask the community in the forums!
- Do you enjoy Composr? Please consider contributing your talent to the project or recommending Composr to others. Even small contributions make a big impact in the Composr community.
- Do you have feedback for us? You can report bugs, suggest features, or give feedback on the Free support options page.
- Do you need professional service with your Composr website? Please consider contracting me for your needs through my company, PDStig, LLC. Doing so will also help fund Composr development.
- Want to watch live streams of me developing Composr CMS? Please subscribe to me on Twitch to be notified when I stream. Composr development streams are usually spontaneous / not scheduled in advance as work priorities come first.
1 guest and 0 members have just viewed this.