Projet

Général

Profil

Révision ed9a13f1

Ajouté par Assos Assos il y a presque 4 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/feeds/plugins/FeedsNodeProcessor.inc
38 38
  public function languageOptions() {
39 39
    // Content types can have "extended" language enabled, allowing all
40 40
    // available languages, not just enabled. Account for this here.
41
    if (module_exists('i18n_node')) {
41
    if (module_exists('i18n_node') && $this->bundle()) {
42 42
      $node = new stdClass();
43 43
      $node->type = $this->bundle();
44 44
      $node->is_new = TRUE;
......
114 114
      // If the uid was mapped directly, rather than by email or username, it
115 115
      // could be invalid.
116 116
      if (!$author) {
117
        $message = 'User %uid is not a valid user.';
118
        throw new FeedsAccessException(t($message, array('%uid' => $entity->uid)));
117
        throw new FeedsAccessException(t('User %uid is not a valid user.', array(
118
          '%uid' => $entity->uid,
119
        )));
119 120
      }
120 121

  
121 122
      if (empty($entity->nid) || !empty($entity->is_new)) {
......
144 145
  /**
145 146
   * Validates a node.
146 147
   */
147
  protected function entityValidate($entity) {
148
    parent::entityValidate($entity);
149

  
148
  protected function entityValidate($entity, FeedsSource $source = NULL) {
150 149
    // Set or correct user ID.
151 150
    if (!isset($entity->uid) || !is_numeric($entity->uid)) {
152
       $entity->uid = $this->config['author'];
151
      $entity->uid = $this->config['author'];
153 152
    }
154 153
    elseif (!is_int($entity->uid)) {
155 154
      // Cast user ID to an integer to prevent array_flip() notices in
......
157 156
      // not an integer nor a string.
158 157
      $entity->uid = (int) $entity->uid;
159 158
    }
159

  
160
    // When the import should be authorized, make an extra account switch.
161
    if ($source && $this->config['authorize'] && !empty($entity->uid)) {
162
      $author = user_load($entity->uid);
163
      $switcher = $source->accountSwitcher->switchTo($author);
164
    }
165

  
166
    try {
167
      parent::entityValidate($entity, $source);
168
    }
169
    catch (Exception $e) {
170
      // Catch any exceptions, throw these at the end.
171
    }
172

  
173
    // When an user switch happened because of an authorized import, be sure to
174
    // switch back to the previous logged in account.
175
    if (!empty($switcher)) {
176
      $switcher->switchBack();
177
    }
178
    if (!empty($e)) {
179
      throw $e;
180
    }
160 181
  }
161 182

  
162 183
  /**
......
212 233
      '#title' => t('Author'),
213 234
      '#description' => t('Select the author of the nodes to be created - leave empty to assign "anonymous".'),
214 235
      '#autocomplete_path' => 'user/autocomplete',
215
      '#default_value' => empty($author->name) ?  'anonymous' : check_plain($author->name),
236
      '#default_value' => empty($author->name) ? 'anonymous' : check_plain($author->name),
216 237
    );
217 238
    $form['authorize'] = array(
218 239
      '#type' => 'checkbox',
......
220 241
      '#description' => t('Check that the author has permission to create the node.'),
221 242
      '#default_value' => $this->config['authorize'],
222 243
    );
223
    $period = drupal_map_assoc(array(FEEDS_EXPIRE_NEVER, 3600, 10800, 21600, 43200, 86400, 259200, 604800, 2592000, 2592000 * 3, 2592000 * 6, 31536000), 'feeds_format_expire');
244
    $period = drupal_map_assoc(array(
245
      FEEDS_EXPIRE_NEVER,
246
      3600,
247
      10800,
248
      21600,
249
      43200,
250
      86400,
251
      259200,
252
      604800,
253
      2592000,
254
      2592000 * 3,
255
      2592000 * 6,
256
      31536000,
257
    ), 'feeds_format_expire');
224 258
    $form['expire'] = array(
225 259
      '#type' => 'select',
226 260
      '#title' => t('Expire nodes'),
......
265 299
      case 'created':
266 300
        $target_node->created = feeds_to_unixtime($value, REQUEST_TIME);
267 301
        break;
302

  
268 303
      case 'changed':
269 304
        // The 'changed' value will be set on the node in feeds_node_presave().
270 305
        // This is because node_save() always overwrites this value (though
271 306
        // before invoking hook_node_presave()).
272 307
        $target_node->feeds_item->node_changed = feeds_to_unixtime($value, REQUEST_TIME);
273 308
        break;
309

  
274 310
      case 'feeds_source':
275 311
        // Get the class of the feed node importer's fetcher and set the source
276 312
        // property. See feeds_node_update() how $node->feeds gets stored.
......
282 318
          $target_node->feeds['suppress_import'] = TRUE;
283 319
        }
284 320
        break;
321

  
285 322
      case 'user_name':
286 323
        if ($user = user_load_by_name($value)) {
287 324
          $target_node->uid = $user->uid;
288 325
        }
289 326
        break;
327

  
290 328
      case 'user_mail':
291 329
        if ($user = user_load_by_mail($value)) {
292 330
          $target_node->uid = $user->uid;
293 331
        }
294 332
        break;
333

  
295 334
      default:
296 335
        parent::setTargetElement($source, $target_node, $target_element, $value);
297 336
        break;
......
394 433
    foreach ($this->uniqueTargets($source, $result) as $target => $value) {
395 434
      switch ($target) {
396 435
        case 'nid':
397
          $nid = db_query("SELECT nid FROM {node} WHERE nid = :nid", array(':nid' => $value))->fetchField();
436
          $nid = db_query("SELECT nid FROM {node} WHERE nid = :nid", array(
437
            ':nid' => $value,
438
          ))->fetchField();
398 439
          break;
440

  
399 441
        case 'title':
400
          $nid = db_query("SELECT nid FROM {node} WHERE title = :title AND type = :type", array(':title' => $value, ':type' => $this->bundle()))->fetchField();
442
          $nid = db_query("SELECT nid FROM {node} WHERE title = :title AND type = :type", array(
443
            ':title' => $value,
444
            ':type' => $this->bundle(),
445
          ))->fetchField();
401 446
          break;
447

  
402 448
        case 'feeds_source':
403 449
          if ($id = feeds_get_importer_id($this->bundle())) {
404
            $nid = db_query("SELECT fs.feed_nid FROM {node} n JOIN {feeds_source} fs ON n.nid = fs.feed_nid WHERE fs.id = :id AND fs.source = :source", array(':id' => $id, ':source' => $value))->fetchField();
450
            $nid = db_query("SELECT fs.feed_nid FROM {node} n JOIN {feeds_source} fs ON n.nid = fs.feed_nid WHERE fs.id = :id AND fs.source = :source", array(
451
              ':id' => $id,
452
              ':source' => $value,
453
            ))->fetchField();
405 454
          }
406 455
          break;
407 456
      }
457

  
408 458
      if ($nid) {
409 459
        // Return with the first nid found.
410 460
        return $nid;

Formats disponibles : Unified diff