Topic-icon Autopost Not Working With Computer Generated Stories

Active Subscriptions:

None
I've developed a PHP program which auto-generates Joomla articles once a day using function $new_article = new ContentModelArticle();

Autopost to my Facebook channel does not happen when these articles are generated.

However if I unpublish and republish from the backend autopost works.

Is there some trigger which needs to be executed when I save my auto-generated article? Or maybe the JFBC plugin is in the wrong order?

Any help appreciated.
The topic has been locked.
Support Specialist
We use the Joomla plugin system to trigger the autoposts. Specifically, both onContentAfterSave and onContentChangeState are used. In both cases, an attempt to auto-post is made if the article is published, not 'special' and has never been published before (based on the article ID).

The 'context' parameter of those calls must be set to 'com_content.article' or 'com_content.form' so our plugin knows that it's a Joomla article being saved/state changed.

Generally, Joomla manages this automatically but I'm not sure if the ContentModelArticle makes those calls or it's something higher up in the chain (like the controller) when an article is edited and saved.

I hope that gives you a starting point.

Thanks,
Alex
The topic has been locked.
Active Subscriptions:

None
Alex, its given me a starting point but I'm now totally confused.

I'm using the save($data) function as in require_once (JPATH_ADMINISTRATOR.'/components/com_content/models/article.php');

In article.php onContentAfterSave is triggered after batch moves and copies but not after an article save. Obviously it is triggered if I save an article in the backend because JFCB autoposts OK. So now the mystery is where does that happen?

I can't find it in any of the controllers or the helpers or views.

Any ideas?
The topic has been locked.
Active Subscriptions:

None
I can't find where the save function does onContentAfterSave.

This is my code. It saves the article but doesn't trigger onContentAfterSave, or at least if it does JBFC doesn't post to FB.

function PublishArticle ($title,$introtext,$today)
{
JPluginHelper::importPlugin('content');
$dispatcher = JEventDispatcher::getInstance();
$new_article = new ContentModelArticle();
$data = array(
'title' => $title,
'introtext' => $introtext,
'state' => 1,
'catid' => 20,
'created' => $today,
'created_by' => 68,
'language' => "en-GB",
'publish_up' => $today,
'access' => 1,
'featured' => 0,
'metadata' => array(
'robots' => "",
'author' => "",
),
);
if ($result = $new_article->save($data))
{
$dispatcher->trigger('onContentAfterSave', array('com_content.article', $result, true));
}
}
The topic has been locked.
Support Specialist
5 years 3 months ago #64888 by mel
Thought I'd jump into this one to help out :) If you've already resolved the issue, please ignore.

Let's look at the call you have to trigger the onContentAfterSave
$dispatcher->trigger('onContentAfterSave', array('com_content.article', $result, true));

OnContentAfterSave is expecting an article object. However, you're passing in $result which is the return from the save method.
$result = $new_article->save($data)

If you delve into the save method, there's a true/false success being returned, not the article. I think you should just be able to pass in new_article instead.

-Melissa
The topic has been locked.