Article via external script Topic is solved

For Joomla! 3.x Coding related discussions, please use: http://groups.google.com/group/joomla-dev-general

Moderator: ooffick

Forum rules
Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.
Post Reply
edboder
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Sat Jan 12, 2019 8:53 pm

Article via external script

Post by edboder » Sat Jan 12, 2019 10:04 pm

Hi there,
I have a question regarding creating new article in Joomla 3.9 ... outside of Joomla. My task is simple - I need to add one new article everyday... The article supposed to contain only link to [youtube] video that was recorded same day via live stream. I wanted to schedule a script via cron to perform this task for me automatically. My php knowledge is rather moderate and I wasn't able to retrieve functions out of Joomla code that add articles and adjust them to fit my needs. I decided to write directly to database.
I was able to add article by following commands but even that article is displayed properly in back-end (and status shows that it's published) it doesn't show on front-end. I don't know why. Right now I'm adding new record only to _content table. Are there any other tables that need be updated? I know about _assets but I'm not getting much further. or maybe there is simpler way to do so? I don't want to mess with db too much. I will appreciate any input and help on this matter. This is what I currently do:
1) change php variables to remove zeros
mode: STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER
to new_mode: STRICT_ALL_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER

2)INSERT INTO `gplef_content` (`id`, `asset_id`, `title`, `alias`, `introtext`, `fulltext`, `state`, `catid`, `created`, `created_by`, `created_by_alias`, `modified`, `modified_by`, `checked_out`, `checked_out_time`, `publish_up`, `publish_down`, `images`, `urls`, `attribs`, `version`, `ordering`, `metakey`, `metadesc`, `access`, `hits`, `metadata`, `featured`, `language`, `xreference`, `note`) VALUES ( NULL, 239, 'Thursday(10-01-2019 17:00)', 'Thursday-10-01-2019-1700', '{[youtube]}abcdefghij{/[youtube]}','', 1, 23, FROM_UNIXTIME(1547157066), 442, '', FROM_UNIXTIME(1547157066), 0, 0, '0000-00-00 00:00:00', FROM_UNIXTIME(1547157066), '0000-00-00 00:00:00', '{\"image_intro\":\"\",\"float_intro\":\"\",\"image_intro_alt\":\"\",\"image_intro_caption\":\"\",\"image_fulltext\":\"\",\"float_fulltext\":\"\",\"image_fulltext_alt\":\"\",\"image_fulltext_caption\":\"\"}', '{\"urla\":false,\"urlatext\":\"\",\"targeta\":\"\",\"urlb\":false,\"urlbtext\":\"\",\"targetb\":\"\",\"urlc\":false,\"urlctext\":\"\",\"targetc\":\"\"}', '{\"article_layout\":\"\",\"show_title\":\"\",\"link_titles\":\"\",\"show_tags\":\"\",\"show_intro\":\"\",\"info_block_position\":\"\",\"info_block_show_title\":\"\",\"show_category\":\"\",\"link_category\":\"\",\"show_parent_category\":\"\",\"link_parent_category\":\"\",\"show_associations\":\"\",\"show_author\":\"\",\"link_author\":\"\",\"show_create_date\":\"\",\"show_modify_date\":\"\",\"show_publish_date\":\"\",\"show_item_navigation\":\"\",\"show_icons\":\"\",\"show_print_icon\":\"\",\"show_email_icon\":\"\",\"show_vote\":\"\",\"show_hits\":\"\",\"show_noauth\":\"\",\"urls_position\":\"\",\"alternative_readmore\":\"\",\"article_page_title\":\"\",\"show_publishing_options\":\"\",\"show_article_options\":\"\",\"show_urls_images_backend\":\"\",\"show_urls_images_frontend\":\"\"}', 1, 0, '', '', 1, 0, '{\"robots\":\"\",\"author\":\"\",\"rights\":\"\",\"xreference\":\"\"}', 0, '*', '', '');

3) reversing variables to original ones:
STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER
Last edited by toivo on Sun Jan 13, 2019 7:55 am, edited 1 time in total.
Reason: mod note: moved to 3.x Coding

User avatar
toivo
Joomla! Master
Joomla! Master
Posts: 10286
Joined: Thu Feb 15, 2007 5:48 am
Location: Oxford, UK
Contact:

Re: Article via external script

Post by toivo » Sun Jan 13, 2019 9:13 am

Does your external script boot the Joomla framework? If it does, you should use the same methods as the com_content component. The following snippets are from a working custom component.

Code: Select all

	$article			= JTable::getInstance('content');
	$article->title     = $title;
	$article->alias		= $alias;
        // etc
	try
	{
		// add to content table
		$ok = $article->store(true);
	}
	catch (RuntimeException $e)
	{
		$msg	= $prefix . ' store() failed page ' . $count . ' title "' . $article->title . '", alias "' . $article->alias . '"';
        // etc
It is also useful to add new menu entries of the new articles to a menu, which does not have to be displayed.
Toivo Talikka, Global Moderator
my first programs were assembled and run in 16KB :)
troubleshooting smtp and other articles https://talikka.com/joomla

edboder
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Sat Jan 12, 2019 8:53 pm

Re: Article via external script

Post by edboder » Sun Jan 13, 2019 12:51 pm

Thanks Toivo for your reply and snippet. It works properly - article is being created. Unfortunately my case is a little bit more complicated. I forgot to mention that. Website is hosted on server that currently doesn't provide cron feature for clients - they have plans to do so mid-year. That was the reason for me to go old-fashioned way with sending sql statements directly to db from server that provides cron. Is there anything I can do to reach Joomla framework directly from other server? I would definitely prefer to use Joomla framework then play with inserts. Any ideas?

User avatar
toivo
Joomla! Master
Joomla! Master
Posts: 10286
Joined: Thu Feb 15, 2007 5:48 am
Location: Oxford, UK
Contact:

Re: Article via external script

Post by toivo » Sun Jan 13, 2019 1:21 pm

If you have Joomla 3.9.1 installed on the other server simply for the purpose of running your PHP script, your script can load the Joomla framework from that site and then access the external database from the main Joomla site using the Joomla classes and methods: https://docs.joomla.org/Connecting_to_a ... l_database
Toivo Talikka, Global Moderator
my first programs were assembled and run in 16KB :)
troubleshooting smtp and other articles https://talikka.com/joomla


Post Reply

Return to “Joomla! 3.x Coding”