Monday, July 14, 2008

Document Sharing Conundrum

I have this nifty idea (or so I think)-- combine Drupal and PLR. I have most of two modules written: a "PLR Hub"-- a central point where lists of modules are stored (like a search engine for content); and a "PLR Exchange"-- something you keep on your site to declare where/how you share your data with other sites. When in swing, you will be able to write content, post it to your site and make it available for others via the PLR Exchange. Then the PLR Hub will spider your site and get a list of available PLR Exchange articles. On the Hub, you will be able to search based on keywords, categories and other criteria. Then, you can choose an article, "pay for it" (variable payment terms are available-- pay $0.00 to $1.00 per piece), and it gets downloaded and added to your site automatically (if you also have PLR Exchange in place).
The problem: I am having a mental block with Services (see below). Does anyone feel like helping? If so: please contact me.
I've been trying to build two modules that will talk to each when installed on separate sites. The functions appear to work in unit testing, but they do not talk to each other. I am not sure what I'm doing wrong. I made up a hook_xmlrpc and a hook_service function to see if that was the difference, but no luck there.

Function on calling site and the function that "should" be calling the remote site:

// basically the cron job-- the tool that updates the links and spiders for new entries
function plrhub_update_index($site_id = -1) {
if ($site_id == -1) {
$result = db_query_range('SELECT site, site_id, api_key, last_index FROM {plrhub_site} WHERE status = 1 AND UNIX_TIMESTAMP() < (last_index + frequency + site_id)', 0, 10); } else { $result = db_query_range('SELECT site, site_id, api_key, last_index FROM {plrhub_site} WHERE status = 1 AND site_id = '.intval($site_id), 0, 10); } while ($site = db_fetch_object($result)) { $node_list = xmlrpc($site->site.'/xmlrpc.php', 'plrex.getNodeList', -1, array(), array(), -1, -1, -1, $site->last_index, $site->api_key);

watchdog('plrhub',' going to '.$site->site.'/xmlrpc.php for
'.print_r($node_list, TRUE).'
');

db_query('UPDATE plrhub_site SET last_index = %d WHERE site_id = %d', time(), $site->site_id);
$plrhub_list = plrhub_update_list($node_list, $site->site_id);
plrhub_update_search($plrhub_list);
}
}


Function on remote site that would have to be called:

function plrex_xmlrpc() {
return array(
array(
'plrex.getNodeList',
'plrex_service_node_list',
array('int', 'array', 'array', 'int', 'int', 'int', 'int', 'string'),
t('Returns a list of nodes that match your criteria.'))
);
}

function plrex_service() {
return array(
// plrex.getNodeList
array(
'#method' => 'plrex.getNodeList',
'#callback' => 'plrex_service_node_list',
'#args' => array(
array(
'#name' => 'nid',
'#type' => 'int',
'#description' => t('A node id.')),
array(
'#name' => 'fields',
'#type' => 'array',
'#optional' => TRUE,
'#description' => t('A list of fields to return.')),
array(
'#name' => 'tids',
'#type' => 'array',
'#optional' => TRUE,
'#description' => t('The terms that match the taxonomy of a list')),
array(
'#name' => 'plrx.ratings',
'#type' => 'int',
'#optional' => TRUE,
'#description' => t('Minimum ratings')),
array(
'#name' => 'plrx.downloads',
'#type' => 'int',
'#optional' => TRUE,
'#description' => t('The maximum number of downloads')),
array(
'#name' => 'plrx.cost',
'#type' => 'int',
'#optional' => TRUE,
'#description' => t('Maximum cost')),
array(
'#name' => 'changed',
'#type' => 'int',
'#optional' => TRUE,
'#description' => t('Changed date')),
array(
'#name' => 'api_key',
'#type' => 'string',
'#description' => t('The API Key'))),
'#return' => 'struct',
'#help' => t('Returns a list of nodes that match your criteria.')),
);
}

I have a watchdog log on the remote site and there is no sign of the local site calling the remote site. When I called the "plrex_service_node_list" function in a test on the remote site (from a test page calling the function), that function worked fine in isolation. I am not getting back any errors of any sort-- just the absence of output from the remote site and it looks like it's not called in the first place.

Any ideas? Any pointers? Any where I can dig for more info on what I'm missing?

No comments: