Re: Insert articles to Joomla programmatically

616 views
Skip to first unread message

MBaas

unread,
Jun 11, 2013, 5:26:09 AM6/11/13
to joomla-de...@googlegroups.com
It seems you have the Plugin TorTags installed which probably needs some extra info. Perhaps the best thing is to first disable TorTags and make sure your plugin works as expected in a "clean" environment and then to "increase difficulty" by enablng TorTags and debug further...

Cheers

Michael 

Am Dienstag, 11. Juni 2013 04:25:30 UTC+2 schrieb Jindan Zhou:
I have this code from http://forum.joomla.org/viewtopic.php?f=615&t=727313 to insert my scraped data from a crawl bot written in python:


<?php
define( '_JEXEC', 1 );
define('JPATH_BASE', dirname(dirname(__FILE__)));
define( 'DS', DIRECTORY_SEPARATOR );

require_once (JPATH_BASE . DS . 'includes' . DS . 'defines.php');
require_once (JPATH_BASE . DS . 'includes' . DS . 'framework.php');
require_once (JPATH_BASE . DS . 'libraries' . DS . 'joomla' . DS . 'factory.php' );
define('JPATH_COMPONENT_ADMINISTRATOR', JPATH_BASE . DS . 'administrator' . DS . 'components' . DS . 'com_content');
$mainframe = JFactory::getApplication('site');

require_once (JPATH_ADMINISTRATOR.'/components/com_content/models/article.php');

$new_article = new ContentModelArticle();

$data = array(
    'catid' => 8,
    'title' => 'SOME TITLE',
    'introtext' => 'SOME TEXT',
    'fulltext' => 'SOME TEXT',
    'state' => 1,
    'metadata' => '{"robots":"","author":"","rights":"","xreference":"","tags":null}',
);
$new_article->save($data);

It works well except I am getting plugin (specifically tortags, but could be other, too) error like this:

PHP Warning:  Parameter 2 to plgContentTorTags::onContentAfterSave() expected to be a reference, value given in /var/www/www.example.com/htdocs/libraries/joomla/event/event.php on line 71
PHP Stack trace:
PHP   1. {main}() /var/www/www.example.com/htdocs/administrator/a_instance.php:0
PHP   2. ContentModelArticle->save() /var/www/www.example.com/htdocs/administrator/a_instance.php:27
PHP   3. JModelAdmin->save() /var/www/www.example.com/htdocs/administrator/components/com_content/models/article.php:456
PHP   4. JEventDispatcher->trigger() /var/www/www.example.com/htdocs/libraries/legacy/model/admin.php:1081
PHP   5. JEvent->update() /var/www/www.example.com/htdocs/libraries/joomla/event/dispatcher.php:161
PHP   6. call_user_func_array() /var/www/www.example.com/htdocs/libraries/joomla/event/event.php:71

I am new to Joomla development, what I am suspecting is that my $data that is to feed to $new_article is not well formed, I have no knowledge to check as what could or should I include in $data array and in what form? Can someone educate me on that?

Thanks,

Jindan Zhou

unread,
Jun 11, 2013, 2:01:02 PM6/11/13
to joomla-de...@googlegroups.com
Thanks, I now use a different code which seems to clear the PHP warning. The tortags plugin works fine if article was save via the back end, it just raises warning if the article was inserted via php cli.

Effectively the plugin adds field in the editor form which allows you to put some tags and save them into a different table (#_tortags), I am now wondering how do I simulate such data and have code process them as if the article was saved via editor?

Mark Dexter

unread,
Jun 11, 2013, 2:15:44 PM6/11/13
to joomla-de...@googlegroups.com
Perhaps you should ask the developers of the tortags plugin? Mark
> --
> You received this message because you are subscribed to the Google Groups
> "Joomla! General Development" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to joomla-dev-gene...@googlegroups.com.
> To post to this group, send an email to joomla-de...@googlegroups.com.
> Visit this group at
> http://groups.google.com/group/joomla-dev-general?hl=en-GB.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Jindan Zhou

unread,
Jun 11, 2013, 3:38:30 PM6/11/13
to joomla-de...@googlegroups.com
Yeah, I am going to shot the problem with multiple approaches, or I could just switch to com_tags that was shipped with Joomla 3.1.1.

By the way, I have a copy of  your book and it has been a *great* resource for me for the past days;-) Kudos to you!
> email to joomla-dev-general+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages