1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Rules integration.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
|
|
* Implements hook_rules_event_info().
|
10 |
|
|
*/
|
11 |
|
|
function feeds_rules_event_info() {
|
12 |
|
|
// General events definitions.
|
13 |
|
|
$info = array(
|
14 |
|
|
'feeds_before_import' => array(
|
15 |
|
|
'label' => t('Before importing feed'),
|
16 |
|
|
'group' => t('Feeds'),
|
17 |
|
|
'variables' => array('source' => array('type' => 'feeds_source', 'label' => 'Feeds source')),
|
18 |
|
|
),
|
19 |
|
|
'feeds_after_import' => array(
|
20 |
|
|
'label' => t('After importing feed'),
|
21 |
|
|
'group' => t('Feeds'),
|
22 |
|
|
'variables' => array('source' => array('type' => 'feeds_source', 'label' => 'Feeds source')),
|
23 |
|
|
),
|
24 |
|
|
);
|
25 |
|
|
// Per importer events definitions.
|
26 |
|
|
$entity_info = entity_get_info();
|
27 |
|
|
foreach (feeds_importer_load_all() as $importer) {
|
28 |
|
|
$config = $importer->getConfig();
|
29 |
|
|
$processor = feeds_plugin($config['processor']['plugin_key'], $importer->id);
|
30 |
|
|
|
31 |
|
|
// It's possible to get FeedsMissingPlugin here which will break things
|
32 |
|
|
// since it doesn't implement FeedsProcessor::entityType().
|
33 |
|
|
if (!$processor instanceof FeedsProcessor) {
|
34 |
|
|
continue;
|
35 |
|
|
}
|
36 |
|
|
|
37 |
|
|
$entity_type = $processor->entityType();
|
38 |
|
|
$label = isset($entity_info[$entity_type]['label']) ? $entity_info[$entity_type]['label'] : $entity_type;
|
39 |
|
|
|
40 |
|
|
$info['feeds_import_'. $importer->id] = array(
|
41 |
|
|
'label' => t('Before saving an item imported via @name.', array('@name' => $importer->config['name'])),
|
42 |
|
|
'group' => t('Feeds'),
|
43 |
|
|
'variables' => array(
|
44 |
|
|
$entity_type => array(
|
45 |
|
|
'label' => t('Imported @label', array('@label' => $label)),
|
46 |
|
|
'type' => $entity_type,
|
47 |
7295e063
|
Assos Assos
|
'bundle' => $processor->bundle(),
|
48 |
85ad3d82
|
Assos Assos
|
// Saving is handled by feeds anyway (unless the skip action is used).
|
49 |
|
|
'skip save' => TRUE,
|
50 |
|
|
),
|
51 |
|
|
),
|
52 |
|
|
'access callback' => 'feeds_rules_access_callback',
|
53 |
|
|
);
|
54 |
|
|
}
|
55 |
|
|
return $info;
|
56 |
|
|
}
|
57 |
|
|
|
58 |
|
|
/**
|
59 |
|
|
* Implements of hook_rules_action_info().
|
60 |
|
|
*/
|
61 |
|
|
function feeds_rules_action_info() {
|
62 |
|
|
return array(
|
63 |
|
|
'feeds_skip_item' => array(
|
64 |
|
|
'base' => 'feeds_action_skip_item',
|
65 |
|
|
'label' => t('Skip import of feeds item'),
|
66 |
|
|
'group' => t('Feeds'),
|
67 |
|
|
'parameter' => array(
|
68 |
|
|
'entity' => array('type' => 'entity', 'label' => t('The feeds import item to be marked as skipped')),
|
69 |
|
|
),
|
70 |
|
|
'access callback' => 'feeds_rules_access_callback',
|
71 |
|
|
),
|
72 |
|
|
);
|
73 |
|
|
}
|
74 |
|
|
|
75 |
|
|
/**
|
76 |
|
|
* Implements hook_rules_data_info().
|
77 |
|
|
*/
|
78 |
|
|
function feeds_rules_data_info() {
|
79 |
|
|
return array(
|
80 |
|
|
'feeds_source' => array(
|
81 |
|
|
'label' => t('Feeds source'),
|
82 |
|
|
'group' => t('Feeds'),
|
83 |
|
|
'wrap' => TRUE,
|
84 |
|
|
'property info' => array(
|
85 |
|
|
'id' => array(
|
86 |
|
|
'label' => t('ID'),
|
87 |
|
|
'type' => 'text',
|
88 |
|
|
'description' => t("The machine readable name of the source importer."),
|
89 |
|
|
),
|
90 |
|
|
'imported' => array(
|
91 |
|
|
'label' => t('Date imported'),
|
92 |
|
|
'type' => 'date',
|
93 |
|
|
'description' => t("The date the source was last imported."),
|
94 |
|
|
),
|
95 |
|
|
// @TODO: fetcher, parser, state ...
|
96 |
|
|
),
|
97 |
|
|
),
|
98 |
|
|
);
|
99 |
|
|
}
|
100 |
|
|
|
101 |
|
|
/**
|
102 |
|
|
* Mark feeds import item as skipped.
|
103 |
|
|
*/
|
104 |
|
|
function feeds_action_skip_item($entity_wrapper) {
|
105 |
|
|
$entity = $entity_wrapper->value();
|
106 |
|
|
if (isset($entity->feeds_item)) {
|
107 |
|
|
$entity->feeds_item->skip = TRUE;
|
108 |
|
|
}
|
109 |
|
|
}
|
110 |
|
|
|
111 |
|
|
/**
|
112 |
|
|
* Help callback for the skip action.
|
113 |
|
|
*/
|
114 |
|
|
function feeds_action_skip_item_help() {
|
115 |
|
|
return t("This action allows skipping certain feed items during feeds processing, i.e. before an imported item is saved. Once this action is used on a item, the changes to the entity of the feed item are not saved.");
|
116 |
|
|
}
|
117 |
|
|
|
118 |
|
|
/**
|
119 |
|
|
* Access callback for the feeds rules integration.
|
120 |
|
|
*/
|
121 |
|
|
function feeds_rules_access_callback() {
|
122 |
|
|
return user_access('administer feeds');
|
123 |
|
|
} |