function drush_tripal_bulk_loader_tripal_loader_revert

2.x tripal_bulk_loader.drush.inc drush_tripal_bulk_loader_tripal_loader_revert($nid)
3.x tripal_bulk_loader.drush.inc drush_tripal_bulk_loader_tripal_loader_revert($nid)
1.x tripal_bulk_loader.drush.inc drush_tripal_bulk_loader_tripal_loader_revert($nid)

Revert the records loaded by the last run of the specified loading job. This is only available if the specified loading job is keeping track of inserted IDs.

Parameters

$nid: The Node ID of the bulk Loading Job

Related topics

File

tripal_bulk_loader/tripal_bulk_loader.drush.inc, line 182
Implements drush integration for this module

Code

function drush_tripal_bulk_loader_tripal_loader_revert($nid) {

  // Remove the records from the database that were already inserted
  $resource = db_query('SELECT * FROM {tripal_bulk_loader_inserted} WHERE nid=%d ORDER BY tripal_bulk_loader_inserted_id DESC', $nid);
  while ($r = db_fetch_object($resource)) {
    $ids = preg_split('/,/', $r->ids_inserted);
    db_query('DELETE FROM {%s} WHERE %s IN (%s)', $r->table_inserted_into, $r->table_primary_key, $r->ids_inserted);
    $result = db_fetch_object(db_query('SELECT true as present FROM {%s} WHERE %s IN (%s)', $r->table_inserted_into, $r->table_primary_key, $r->ids_inserted));
    if (!$result->present) {
      drush_print('Successfully Removed data Inserted into the ' . $r->table_inserted_into . ' table.');
      db_query('DELETE FROM {tripal_bulk_loader_inserted} WHERE tripal_bulk_loader_inserted_id=%d', $r->tripal_bulk_loader_inserted_id);
    }
    else {
      drush_print('Unable to remove data Inserted into the ' . $r->table_inserted_into . ' table!');
    }
  }

  // reset status
  db_query("UPDATE {tripal_bulk_loader} SET job_status='%s' WHERE nid=%d", 'Reverted -Data Deleted', $nid);

}