5 * Drush commands for FeedAPI.
9 * Implementation of hook_drush_help().
11 function feedapi_drush_help($section) {
13 case
'drush:feedapi create':
14 return dt('Creates a feed.');
15 case
'drush:feedapi refresh':
16 return dt('Refreshes a feed.');
17 case
'drush:feedapi delete':
18 return dt('Deletes a feed.');
19 case
'drush:feedapi parse':
20 return dt('Parses a feed and shows you the output.');
21 case
'drush:feedapi config':
22 return dt('Shows the config of a parser of a processor.');
28 * Implementation of hook_drush_command().
30 function feedapi_drush_command() {
31 $options['--type'] = 'The node type of the feed. Default value: feed, the built-in content-type of FeedAPI.';
32 $items['feedapi create'] = array(
33 'callback' => 'feedapi_drush_create',
34 'description' => dt('Creates a feed'),
35 'options' => $options,
37 'url' => 'A feed URL. Mandatory.',
40 $items['feedapi refresh'] = array(
41 'callback' => 'feedapi_drush_refresh',
42 'description' => dt('Refreshes a feed'),
44 'feed' => 'A feed URL or node nid. Mandatory.',
47 $items['feedapi parse'] = array(
48 'callback' => 'feedapi_drush_parse',
49 'description' => dt('Parses a feed and outputs the result to the stdout'),
50 'options' => $options,
52 'url' => 'A feed URL. Mandatory.',
53 'parser' => 'The name of the parser. Mandatory.',
56 $items['feedapi config'] = array(
57 'callback' => 'feedapi_drush_config',
58 'description' => dt('Shows the config of a given parser or processor'),
59 'options' => $options,
61 'name' => 'The name of the parser or the processor. Mandatory.',
72 function feedapi_drush_create($url) {
73 $node_template = new
stdClass();
74 $node_template->type
= drush_get_option('type') ?
drush_get_option('type') : 'feed';
75 feedapi_create_node($node_template, $url);
80 * When the feed URL is not enough to exactly define a feed, use the nid
85 function feedapi_drush_refresh($feed) {
86 $nid = _feedapi_drush_get_nid($feed);
87 if (is_numeric($nid)) {
88 $node = node_load(array('nid' => $nid));
89 feedapi_invoke('refresh', $node->feed
, FALSE
);
94 * Invokes the parser and displays the output
96 function feedapi_drush_parse($url, $parser) {
97 $type = drush_get_option('type') ?
drush_get_option('type') : 'feed';
98 $settings = feedapi_get_settings($type);
99 $feed = new
stdClass();
101 drush_print_r(_feedapi_call_parsers($feed, array($parser), $settings));
104 function feedapi_drush_config($name) {
105 $type = drush_get_option('type') ?
drush_get_option('type') : 'feed';
106 $settings = variable_get('feedapi_settings_'.
$type, array());
107 if (isset($settings['parsers'][$name])) {
108 drush_print_r($settings['parsers'][$name]);
110 elseif (isset($settings['processors'][$name])) {
111 drush_print_r($settings['processors'][$name]);
115 function _feedapi_drush_get_nid($feed) {
116 if (valid_url($feed, TRUE
) || strpos($feed, '://')) {
117 return db_result(db_query("SELECT nid FROM {feedapi} WHERE url = '%s'", $feed));