Projet

Général

Profil

Révision 41cc1b08

Ajouté par Assos Assos il y a presque 9 ans

Update feeds 7.x-2.0-alpha9 -> 7.x-2.0-beta1

Install lib simplepie 1.3.1

Voir les différences:

drupal7/sites/all/modules/feeds/plugins/FeedsNodeProcessor.inc
5 5
 * Class definition of FeedsNodeProcessor.
6 6
 */
7 7

  
8
/**
9
 * Option for handling content in Drupal but not in source data (unpublish
10
 * instead of skip/delete).
11
 */
12
define('FEEDS_UNPUBLISH_NON_EXISTENT', 'unpublish');
13

  
8 14
/**
9 15
 * Creates nodes from feed items.
10 16
 */
......
104 110
      }
105 111

  
106 112
      if (!$access) {
107
        $message = 'User %name is not authorized to %op content type %content_type.';
108
        throw new FeedsAccessException(t($message, array('%name' => $author->name, '%op' => $op, '%content_type' => $entity->type)));
113
        $message = t('The user %name is not authorized to %op content of type %content_type. To import this item, either the user "@name" (author of the item) must be given the permission to @op content of type @content_type, or the option "Authorize" on the Node processor settings must be turned off.', array(
114
          '%name' => $author->name,
115
          '%op' => $op,
116
          '%content_type' => $entity->type,
117
          '@name' => $author->name,
118
          '@op' => $op,
119
          '@content_type' => $entity->type,
120
        ));
121
        throw new FeedsAccessException($message);
109 122
      }
110 123
    }
111 124
  }
......
134 147
  }
135 148

  
136 149
  /**
137
   * Implement expire().
138
   *
139
   * @todo: move to processor stage?
150
   * Overrides parent::expiryQuery().
140 151
   */
141
  public function expire($time = NULL) {
142
    if ($time === NULL) {
143
      $time = $this->expiryTime();
144
    }
145
    if ($time == FEEDS_EXPIRE_NEVER) {
146
      return;
147
    }
148
    $count = $this->getLimit();
149
    $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));
150
    $nids = array();
151
    foreach ($nodes as $node) {
152
      $nids[$node->nid] = $node->nid;
153
    }
154
    $this->entityDeleteMultiple($nids);
155
    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()) {
156
      return FEEDS_BATCH_ACTIVE;
157
    }
158
    return FEEDS_BATCH_COMPLETE;
152
  protected function expiryQuery(FeedsSource $source, $time) {
153
    $select = parent::expiryQuery($source, $time);
154
    $select->condition('e.created', REQUEST_TIME - $time, '<');
155
    return $select;
159 156
  }
160 157

  
161 158
  /**
......
201 198
      '#type' => 'select',
202 199
      '#title' => t('Expire nodes'),
203 200
      '#options' => $period,
204
      '#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.'),
201
      '#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."),
205 202
      '#default_value' => $this->config['expire'],
206 203
    );
204
    // Add on the "Unpublish" option for nodes, update wording.
205
    if (isset($form['update_non_existent'])) {
206
      $form['update_non_existent']['#options'][FEEDS_UNPUBLISH_NON_EXISTENT] = t('Unpublish non-existent nodes');
207
    }
207 208
    return $form;
208 209
  }
209 210

  
......
338 339
      );
339 340
    }
340 341

  
341
    // Let other modules expose mapping targets.
342
    self::loadMappers();
343
    $entity_type = $this->entityType();
344
    $bundle = $this->bundle();
345
    drupal_alter('feeds_processor_targets', $targets, $entity_type, $bundle);
342
    $this->getHookTargets($targets);
346 343

  
347 344
    return $targets;
348 345
  }
......
378 375
    }
379 376
    return 0;
380 377
  }
378

  
379
  /**
380
   * Overrides FeedsProcessor::clean().
381
   *
382
   * Allow unpublish instead of delete.
383
   *
384
   * @param FeedsState $state
385
   *   The FeedsState object for the given stage.
386
   */
387
  protected function clean(FeedsState $state) {
388
    // Delegate to parent if not unpublishing or option not set.
389
    if (!isset($this->config['update_non_existent']) || $this->config['update_non_existent'] != FEEDS_UNPUBLISH_NON_EXISTENT) {
390
      return parent::clean($state);
391
    }
392

  
393
    $total = count($state->removeList);
394
    if ($total) {
395
      $nodes = node_load_multiple($state->removeList);
396
      foreach ($nodes as &$node) {
397
        $this->loadItemInfo($node);
398
        // Update the hash value of the feed item to ensure that the item gets
399
        // updated in case it reappears in the feed.
400
        $node->feeds_item->hash = $this->config['update_non_existent'];
401
        node_unpublish_action($node);
402
        node_save($node);
403
        $state->unpublished++;
404
      }
405
    }
406
  }
407

  
381 408
}

Formats disponibles : Unified diff