You are here

public function FeedsDataHandler::delete in Feeds 6

Delete records from this handler's base table and all joined tables.

@todo Push this functionality into DataHandler.

Parameters

$clause: Array that is a WHERE clause for the delete statement. The keys of the array are the field of the WHERE clause. If the value for a key is a simple type, then key = value is assumed. If the value is an array, then the first value of that array is the operation, the second value is the value to compare against.

Example:

This where clause would delete all records WHERE feed_nid = 10 AND timestamp < 1255623780

array( 'feed_nid' => 10, 'timestamp' => array( '<', 1255623780, ), );

Overrides DataHandler::delete

File

includes/FeedsDataHandler.inc, line 177
Data handler used in FeedsDataProcessor.

Class

FeedsDataHandler
Simple multidimensional data handler. Treats tables that join to this handler's table through FeedsDatahandler::key as a cluster. Records in this cluster are regarded as belonging to one multidimensional data set joined by FeedsDatahandler::key.

Code

public function delete($clause) {
  $query = new DataQuery($this->table);
  $schema = drupal_get_schema($this->table);
  $fields = $schema['fields'];
  $this_table = db_escape_table($this->table);
  foreach ($clause as $key => $value) {
    $operator = '=';
    if (is_array($value)) {
      $operator = array_shift($value);
      $value = array_shift($value);
    }
    $query
      ->addWhere($this_table . '.' . db_escape_string($key) . " " . $operator . " " . db_type_placeholder($fields[$key]['type']), $value);
  }
  foreach ($this->joined_tables as $table) {
    $table = db_escape_table($table);
    $query
      ->addSubject($table);
    $query
      ->addJoin($table, "{$table}.{$this->key} = {$this_table}.{$this->key}", 'LEFT JOIN');
  }
  drupal_alter('data_delete_query', $query, $this->table);
  if (!empty($query->where)) {
    $query
      ->execute();
  }
  return db_affected_rows();
}