I'm looking to setup a script to automatically create a monthly report page in drupal from my custom database. I was hoping to use the BlogAPI module to post my data from my application to drupal, but have had little luck in finding a PHP script that can do this for me that still works (most are outdated trying to redeclare XML-RPC functions built-in to php).
Anyone have any experience doing this and could shed some light on the subject? Am I just going to have to write my own XML-RPC calls or is there a pre-built library that can do this via one of the supported APIs (blogger/mt/etc)?
TIA
This isn't very hard at all in Drupal. To start with querying multiple DBs, update your settings.php to look something like this:
$db_url['default'] = the default settings for your drupal db $db_url['mydb'] = connection settings for my db (NOTE: the two databases must be of the same type, i.e. MySQL)
then in a custom module, do something like this:
<?php function mymodule_save_my_data($params) { $default_db = db_set_active('mydb'); $query = 'FETCH MY DATA - A SINGLE RECORD'; $result = db_query($query, $params) db_set_active($default_db); $my_data = db_fetch_object($result);
$node = array();
$node = array(); $node['title'] = $my_data->title; $node['type'] = 'NODE TYPE GOES HERE'; $node['name'] = $my_data->author; $node['status'] = 1; $node['promote'] = 0; $node['sticky'] = 0; $log = 'Imported on: ' . date('g:i:s a'); $node['log'] = $log;
$node['CCK FIELD NAME GOES HERE'] = array( 0 => array( 'FIELD ATTRIBUTE' => $my_data->field_id, 'FIELD ATTRIBUTE' => $my_data->field_value, 'FIELD ATTRIBUTE' => '', ), );
if ($node['title']) { $node = (object)$node; $node = node_submit($node); node_save($node);
$nid = $node->nid;
$message = 'Saved as node id '. l('#'. $nid, 'node/'. $nid); drupal_set_message($message); }
// Optionally return the node here to whatever function called us, so they can act on the node as well return $node; } ?>
And you'll have a new node with the data from your other DB, as you've mapped it in your function.
-Mike
On Aug 14, 2008, at 1:18 PM, Errol Sayre wrote:
I'm looking to setup a script to automatically create a monthly report page in drupal from my custom database. I was hoping to use the BlogAPI module to post my data from my application to drupal, but have had little luck in finding a PHP script that can do this for me that still works (most are outdated trying to redeclare XML-RPC functions built-in to php).
Anyone have any experience doing this and could shed some light on the subject? Am I just going to have to write my own XML-RPC calls or is there a pre-built library that can do this via one of the supported APIs (blogger/mt/etc)?
TIA
[ Drupal support list | http://lists.drupal.org/ ]
__________________ Michael Prasuhn mike@mikeyp.net http://mikeyp.net 503.488.5433 714.356.0168 cell 949.200.7670 fax
On Aug 14, 2008, at 3:36 PM, Michael Prasuhn wrote:
if ($node['title']) { $node = (object)$node; $node = node_submit($node); node_save($node);
$nid = $node->nid;
$message = 'Saved as node id '. l('#'. $nid, 'node/'. $nid); drupal_set_message($message);
Expanding on this idea, is there any formal API for creating a node externally and passing it off to Drupal? How would I access a custom module like this programmatically on the same server? I had assumed I'd have to go through some web frontend on drupal to get access to things in the proper context...
Looking at this page: http://api.drupal.org/api/file/modules/node/node.module/5
I see that node.module is "The core that allows content to be submitted to the site. Modules and scripts may programmatically submit nodes using the usual form API pattern."
However, what's the "usual form API pattern" it's talking about here?
A tutorial on using php and curl to automate creating nodes... this may do what I need.
Apart from the BlogAPI, Drupal supports a feature-rich Services module.
See http://drupal.org/project/services
I have blogged on using the XMLRPC node.load and node.save services: http://awebfactory.com.ar/node/297 (Leveraging XML-RPC services with the Services Module)
Victor Kane http://awebfactory.com.ar
On Thu, Aug 14, 2008 at 5:18 PM, Errol Sayre errol.sayre@gmail.com wrote:
I'm looking to setup a script to automatically create a monthly report page in drupal from my custom database. I was hoping to use the BlogAPI module to post my data from my application to drupal, but have had little luck in finding a PHP script that can do this for me that still works (most are outdated trying to redeclare XML-RPC functions built-in to php).
Anyone have any experience doing this and could shed some light on the subject? Am I just going to have to write my own XML-RPC calls or is there a pre-built library that can do this via one of the supported APIs (blogger/mt/etc)?
TIA
[ Drupal support list | http://lists.drupal.org/ ]