annotate relation_processor/FeedsRelationProcessor.inc @ 41:5b3cd0b66b30

fix bug with multiple-saved nodes.
author casties
date Wed, 02 Nov 2016 16:56:27 +0100
parents 1c73c660c2f2
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
1 <?php
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
2
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
3 /**
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
4 * @file
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
5 * Class definition of FeedsNodeProcessor.
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
6 */
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
7
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
8 /**
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
9 * Creates nodes from feed items.
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
10 */
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
11 class FeedsRelationProcessor extends FeedsProcessor {
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
12
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
13 /**
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
14 * Define entity type.
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
15 */
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
16 public function entityType() {
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
17 return 'relation';
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
18 }
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
19
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
20 /**
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
21 * Implements parent::entityInfo().
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
22 */
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
23 protected function entityInfo() {
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
24 $info = parent::entityInfo();
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
25 $info['label plural'] = t('Relations');
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
26 return $info;
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
27 }
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
28
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
29 /**
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
30 * Creates a new node in memory and returns it.
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
31 */
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
32 protected function newEntity(FeedsSource $source) {
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
33 /*$node = new stdClass();
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
34 $node->type = $this->bundle();
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
35 $node->changed = REQUEST_TIME;
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
36 $node->created = REQUEST_TIME;
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
37 $node->language = LANGUAGE_NONE;
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
38 $node->is_new = TRUE;
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
39 node_object_prepare($node);
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
40 // Populate properties that are set by node_object_prepare().
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
41 $node->log = 'Created by FeedsNodeProcessor';
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
42 $node->uid = $this->config['author'];
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
43 */
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
44
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
45
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
46 $relation = new stdClass();
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
47 $relation->is_new = TRUE;
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
48
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
49 $relation->relation_type = $this->bundle();
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
50 $relation->uid = $this->config['author'];
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
51 $relation->endpoints[LANGUAGE_NONE] = Null;
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
52
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
53 $relation->changed = REQUEST_TIME;
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
54 $relation->created = REQUEST_TIME;
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
55
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
56 return $relation;
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
57
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
58 }
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
59
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
60 /**
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
61 * Loads an existing node.
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
62 *
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
63 * If the update existing method is not FEEDS_UPDATE_EXISTING, only the node
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
64 * table will be loaded, foregoing the node_load API for better performance.
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
65 *
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
66 * @todo Reevaluate the use of node_object_prepare().
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
67 */
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
68 protected function entityLoad(FeedsSource $source, $nid) {
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
69
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
70 $node = relation_load($nid);
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
71
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
72 if ($this->config['update_existing'] != FEEDS_UPDATE_EXISTING) {
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
73 $node->uid = $this->config['author'];
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
74 }
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
75
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
76 /* node_object_prepare($node);
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
77
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
78 // Workaround for issue #1247506. See #1245094 for backstory.
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
79 if (!empty($node->menu)) {
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
80 // If the node has a menu item(with a valid mlid) it must be flagged
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
81 // 'enabled'.
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
82 $node->menu['enabled'] = (int) (bool) $node->menu['mlid'];
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
83 }
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
84 */
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
85 // Populate properties that are set by node_object_prepare().
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
86 if ($this->config['update_existing'] == FEEDS_UPDATE_EXISTING) {
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
87 $node->log = 'Updated by FeedsNodeProcessor';
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
88 }
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
89 else {
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
90 $node->log = 'Replaced by FeedsNodeProcessor';
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
91 }
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
92 return $node;
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
93 }
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
94
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
95 /**
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
96 * Check that the user has permission to save a node.
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
97 */
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
98 protected function entitySaveAccess($entity) {
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
99
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
100 // The check will be skipped for anonymous nodes.
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
101 if ($this->config['authorize'] && !empty($entity->uid)) {
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
102
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
103 $author = user_load($entity->uid);
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
104
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
105 // If the uid was mapped directly, rather than by email or username, it
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
106 // could be invalid.
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
107 if (!$author) {
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
108 $message = 'User %uid is not a valid user.';
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
109 throw new FeedsAccessException(t($message, array('%uid' => $entity->uid)));
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
110 }
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
111
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
112 if (empty($entity->nid) || !empty($entity->is_new)) {
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
113 $op = 'create';
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
114 $access = node_access($op, $entity->type, $author);
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
115 }
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
116 else {
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
117 $op = 'update';
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
118 $access = node_access($op, $entity, $author);
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
119 }
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
120
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
121 if (!$access) {
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
122 $message = 'User %name is not authorized to %op content type %content_type.';
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
123 throw new FeedsAccessException(t($message, array('%name' => $author->name, '%op' => $op, '%content_type' => $entity->type)));
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
124 }
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
125 }
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
126 }
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
127
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
128 /**
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
129 * Validates a node.
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
130 */
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
131 protected function entityValidate($entity) {
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
132 if (!isset($entity->uid) || !is_numeric($entity->uid)) {
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
133 $entity->uid = $this->config['author'];
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
134 }
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
135 }
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
136 /**
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
137 * Save a node.
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
138 */
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
139 public function entitySave($entity) {
5
1c73c660c2f2 new relation_processor
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
140
0
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
141 relation_save($entity);
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
142 }
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
143
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
144 /**
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
145 * Delete a series of nodes.
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
146 */
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
147 protected function entityDeleteMultiple($nids) {
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
148 relation_delete_multiple($nids);
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
149 }
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
150
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
151 /**
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
152 * Implement expire().
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
153 *
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
154 * @todo: move to processor stage?
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
155 */
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
156 public function expire($time = NULL) {
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
157 if ($time === NULL) {
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
158 $time = $this->expiryTime();
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
159 }
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
160 if ($time == FEEDS_EXPIRE_NEVER) {
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
161 return;
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
162 }
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
163 $count = $this->getLimit();
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
164 $nodes = db_query_range("SELECT n.nid FROM {node} n JOIN {feeds_item} fi ON fi.entity_type = 'node' AND n.nid = fi.entity_id WHERE fi.id = :id AND n.created < :created", 0, $count, array(':id' => $this->id, ':created' => REQUEST_TIME - $time));
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
165 $nids = array();
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
166 foreach ($nodes as $node) {
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
167 $nids[$node->nid] = $node->nid;
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
168 }
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
169 $this->entityDeleteMultiple($nids);
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
170 if (db_query_range("SELECT 1 FROM {node} n JOIN {feeds_item} fi ON fi.entity_type = 'node' AND n.nid = fi.entity_id WHERE fi.id = :id AND n.created < :created", 0, 1, array(':id' => $this->id, ':created' => REQUEST_TIME - $time))->fetchField()) {
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
171 return FEEDS_BATCH_ACTIVE;
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
172 }
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
173 return FEEDS_BATCH_COMPLETE;
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
174 }
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
175
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
176 /**
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
177 * Return expiry time.
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
178 */
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
179 public function expiryTime() {
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
180 return $this->config['expire'];
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
181 }
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
182
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
183 /**
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
184 * Override parent::configDefaults().
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
185 */
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
186 public function configDefaults() {
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
187 return array(
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
188 'expire' => FEEDS_EXPIRE_NEVER,
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
189 'author' => 0,
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
190 'authorize' => TRUE,
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
191 ) + parent::configDefaults();
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
192 }
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
193
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
194 /**
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
195 * Override parent::configForm().
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
196 */
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
197 public function configForm(&$form_state) {
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
198 $form = parent::configForm($form_state);
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
199
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
200 $author = user_load($this->config['author']);
5
1c73c660c2f2 new relation_processor
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
201
1c73c660c2f2 new relation_processor
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
202
1c73c660c2f2 new relation_processor
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
203 $options =$this->bundleOptions();
1c73c660c2f2 new relation_processor
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
204 $form['bundle'] = array(
1c73c660c2f2 new relation_processor
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
205 '#type' => 'select',
1c73c660c2f2 new relation_processor
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
206 '#options' => $options,
1c73c660c2f2 new relation_processor
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
207 '#title' => !empty($info['bundle name']) ? $info['bundle name'] : t('Bundle'),
1c73c660c2f2 new relation_processor
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
208 '#required' => false,
1c73c660c2f2 new relation_processor
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
209 '#description' => t('if set to generic, relation_name has to be one of the mappings'),
1c73c660c2f2 new relation_processor
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
210 '#default_value' => "generic",
1c73c660c2f2 new relation_processor
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
211 );
1c73c660c2f2 new relation_processor
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
212
1c73c660c2f2 new relation_processor
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
213
1c73c660c2f2 new relation_processor
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
214
1c73c660c2f2 new relation_processor
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
215
1c73c660c2f2 new relation_processor
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
216
0
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
217 $form['author'] = array(
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
218 '#type' => 'textfield',
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
219 '#title' => t('Author'),
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
220 '#description' => t('Select the author of the nodes to be created - leave empty to assign "anonymous".'),
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
221 '#autocomplete_path' => 'user/autocomplete',
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
222 '#default_value' => empty($author->name) ? 'anonymous' : check_plain($author->name),
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
223 );
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
224 $form['authorize'] = array(
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
225 '#type' => 'checkbox',
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
226 '#title' => t('Authorize'),
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
227 '#description' => t('Check that the author has permission to create the node.'),
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
228 '#default_value' => $this->config['authorize'],
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
229 );
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
230 $period = drupal_map_assoc(array(FEEDS_EXPIRE_NEVER, 3600, 10800, 21600, 43200, 86400, 259200, 604800, 2592000, 2592000 * 3, 2592000 * 6, 31536000), 'feeds_format_expire');
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
231 $form['expire'] = array(
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
232 '#type' => 'select',
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
233 '#title' => t('Expire nodes'),
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
234 '#options' => $period,
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
235 '#description' => t('Select after how much time nodes should be deleted. The node\'s published date will be used for determining the node\'s age, see Mapping settings.'),
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
236 '#default_value' => $this->config['expire'],
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
237 );
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
238 return $form;
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
239 }
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
240
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
241 /**
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
242 * Override parent::configFormValidate().
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
243 */
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
244 public function configFormValidate(&$values) {
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
245 if ($author = user_load_by_name($values['author'])) {
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
246 $values['author'] = $author->uid;
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
247 }
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
248 else {
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
249 $values['author'] = 0;
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
250 }
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
251 }
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
252
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
253 /**
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
254 * Reschedule if expiry time changes.
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
255 */
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
256 public function configFormSubmit(&$values) {
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
257 if ($this->config['expire'] != $values['expire']) {
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
258 feeds_reschedule($this->id);
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
259 }
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
260 parent::configFormSubmit($values);
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
261 }
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
262
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
263 /**
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
264 * Override setTargetElement to operate on a target item that is a node.
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
265 */
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
266 public function setTargetElement(FeedsSource $source, $target_node, $target_element, $value) {
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
267 switch ($target_element) {
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
268 case 'created':
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
269 $target_node->created = feeds_to_unixtime($value, REQUEST_TIME);
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
270 break;
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
271 case 'feeds_source':
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
272 // Get the class of the feed node importer's fetcher and set the source
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
273 // property. See feeds_node_update() how $node->feeds gets stored.
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
274 if ($id = feeds_get_importer_id($this->bundle())) {
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
275 $class = get_class(feeds_importer($id)->fetcher);
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
276 $target_node->feeds[$class]['source'] = $value;
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
277 // This effectively suppresses 'import on submission' feature.
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
278 // See feeds_node_insert().
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
279 $target_node->feeds['suppress_import'] = TRUE;
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
280 }
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
281 break;
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
282 case 'user_name':
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
283 if ($user = user_load_by_name($value)) {
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
284 $target_node->uid = $user->uid;
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
285 }
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
286 break;
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
287 case 'user_mail':
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
288 if ($user = user_load_by_mail($value)) {
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
289 $target_node->uid = $user->uid;
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
290 }
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
291 break;
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
292 default:
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
293 parent::setTargetElement($source, $target_node, $target_element, $value);
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
294 break;
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
295 }
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
296 }
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
297
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
298 /**
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
299 * Return available mapping targets.
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
300 */
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
301 public function getMappingTargets() {
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
302 $type = relation_type_load($this->bundle());
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
303
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
304 $targets = parent::getMappingTargets();
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
305
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
306 $targets['source_id'] = array(
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
307 'name' => t('Source Field'),
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
308 'description' => t('Source.'),
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
309 'optional_unique' => FALSE,
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
310 );
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
311
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
312 $targets['target_id'] = array(
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
313 'name' => t('Target Field'),
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
314 'description' => t('Target.'),
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
315 'optional_unique' => FALSE,
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
316 );
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
317
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
318
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
319 $targets['relation_name'] = array(
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
320 'name' => t('Relation type'),
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
321 'description' => t('Target.'),
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
322 'optional_unique' => FALSE,
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
323 );
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
324
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
325
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
326 $targets['nid'] = array(
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
327 'name' => t('Node ID'),
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
328 'description' => t('The nid of the node. NOTE: use this feature with care, node ids are usually assigned by Drupal.'),
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
329 'optional_unique' => TRUE,
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
330 );
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
331 $targets['uid'] = array(
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
332 'name' => t('User ID'),
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
333 'description' => t('The Drupal user ID of the node author.'),
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
334 );
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
335 $targets['user_name'] = array(
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
336 'name' => t('Username'),
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
337 'description' => t('The Drupal username of the node author.'),
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
338 );
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
339 $targets['user_mail'] = array(
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
340 'name' => t('User email'),
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
341 'description' => t('The email address of the node author.'),
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
342 );
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
343 $targets['status'] = array(
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
344 'name' => t('Published status'),
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
345 'description' => t('Whether a node is published or not. 1 stands for published, 0 for not published.'),
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
346 );
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
347 $targets['created'] = array(
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
348 'name' => t('Published date'),
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
349 'description' => t('The UNIX time when a node has been published.'),
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
350 );
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
351
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
352 // Include language field if Locale module is enabled.
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
353 if (module_exists('locale')) {
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
354 $targets['language'] = array(
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
355 'name' => t('Language'),
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
356 'description' => t('The two-character language code of the node.'),
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
357 );
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
358 }
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
359
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
360
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
361 // If the target content type is a Feed node, expose its source field.
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
362 if ($id = feeds_get_importer_id($this->bundle())) {
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
363 $name = feeds_importer($id)->config['name'];
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
364 $targets['feeds_source'] = array(
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
365 'name' => t('Feed source'),
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
366 'description' => t('The content type created by this processor is a Feed Node, it represents a source itself. Depending on the fetcher selected on the importer "@importer", this field is expected to be for example a URL or a path to a file.', array('@importer' => $name)),
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
367 'optional_unique' => TRUE,
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
368 );
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
369 }
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
370
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
371 // Let other modules expose mapping targets.
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
372 self::loadMappers();
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
373
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
374 // load nodes mapper
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
375 require_once("nodes.inc");
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
376 //$entity_type = $this->entityType();
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
377 $entity_type = "relation";
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
378 $bundle = $this->bundle();
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
379
5
1c73c660c2f2 new relation_processor
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
380 #drupal_alter('feeds_processor_targets', $targets, $entity_type, $bundle);
1c73c660c2f2 new relation_processor
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents: 0
diff changeset
381 relation_feeds_processor_targets_alter($targets, $entity_type, $bundle);
0
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
382 return $targets;
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
383 }
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
384
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
385 /**
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
386 * Get nid of an existing feed item node if available.
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
387 */
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
388 protected function existingEntityId(FeedsSource $source, FeedsParserResult $result) {
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
389 if ($nid = parent::existingEntityId($source, $result)) {
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
390 return $nid;
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
391 }
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
392
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
393 // Iterate through all unique targets and test whether they do already
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
394 // exist in the database.
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
395 foreach ($this->uniqueTargets($source, $result) as $target => $value) {
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
396 switch ($target) {
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
397 case 'nid':
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
398 $nid = db_query("SELECT rid FROM {relation} WHERE rid = :rid", array(':rid' => $value))->fetchField();
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
399 break;
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
400 case 'title':
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
401 $nid = db_query("SELECT rid FROM {relation} WHERE title = :title AND type = :type", array(':title' => $value, ':type' => $this->bundle()))->fetchField();
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
402 break;
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
403 case 'feeds_source':
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
404 if ($id = feeds_get_importer_id($this->bundle())) {
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
405 $nid = db_query("SELECT fs.feed_nid FROM {relation} n JOIN {feeds_source} fs ON n.rid = fs.feed_nid WHERE fs.id = :id AND fs.source = :source", array(':id' => $id, ':source' => $value))->fetchField();
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
406 }
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
407 break;
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
408 }
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
409 if ($nid) {
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
410 // Return with the first nid found.
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
411 return $nid;
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
412 }
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
413 }
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
414 return 0;
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
415 }
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
416
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
417
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
418 /**
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
419 * Provides a list of bundle options for use in select lists.
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
420 *
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
421 * @return array
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
422 * A keyed array of bundle => label.
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
423 */
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
424 public function bundleOptions() {
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
425 $options = array();
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
426
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
427 $options = relation_get_types_options();
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
428 return $options;
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
429
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
430 }
124ef8f3b22d initial
Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de>
parents:
diff changeset
431 }