I have created a custom table, and using views I have created a view of the data in thtat table.
Now I need an easy way of removing rows in that table, so I created a trigger that can remove the line, but it don't appear on "Selected operations:"; what else do I need to do?

function cc_projects_action_info() {
  return array(
    'cc_projects_deleteData_action' => array(
      'description' => 'Delete a row',
      'type' => 'cc_projecte_data',
      'configurable' => FALSE,
      'hooks' => array('any' => TRUE),
    ),
  );
}

function cc_projects_deleteData_action(&$object, $context = array()) {
  $nid=db_result(db_query("SELECT p.project_nid FROM {node_cc_projects_data} p WHERE pid = %d", $pid));
  $node=node_load($nid);
  if (node_access('update', $node)) {
    db_query("DELETE FROM {node_cc_projects_data} WHERE pid = %d",$pid);
  }
}

function cc_projects_bulk_operations_views_bulk_operations_object_info() {
  return array(
    'comment' => array(
      'type' => 'cc_project_data',
      'base_table' => 'node_cc_projects_data',
      'load' => '_cc_projects_loadDataLine',
      'title' => 'pid',
    ),
  );
}

function _cc_projects_loadDataLine($pid){
  return db_fetch_object(db_query("SELECT * FROM {node_cc_projects_data} WHERE pid = %d", $pid));
}

Comments

enboig’s picture

Solved at last, I paste the correct code here just if sometime is useful to anybody:



function cc_projects_action_info() {
  return array(
    'cc_projects_deletedata_action' => array(
      'description' => 'Delete one row',
      'type' => 'cc_project_data',
      'configurable' => FALSE,
      'hooks' => array('any' => TRUE),
    ),
  );
}

function cc_projects_deletedata_action(&$object, $context = array()) {
  $node=node_load($object->project_nid);
  if (node_access('update', $node)) {
    db_query("DELETE FROM {node_cc_projects_data} WHERE pid = %d",$object->pid);
  }
}

function cc_projects_views_bulk_operations_object_info() {
  return array(
    'cc_project_data' => array(
      'type' => 'cc_project_data',
      'base_table' => 'node_cc_projects_data',
      'load' => '_cc_projects_loaddataLine',
      'title' => 'project_data_line',
    ),
  );
}

function _cc_projects_loaddataLine($pid){
  return db_fetch_object(db_query("SELECT * FROM {node_cc_projects_data} WHERE pid = %d", $pid));
}
infojunkie’s picture

Status: Active » Fixed

Thanks for documenting your fix. As far as I can tell from diffing between the original and fixed code, you had forgotten to change the key of your views_bulk_operations_object_info() entry from 'comment' to 'cc_project_data'. Is that correct?

enboig’s picture

Yes, that was the problem; the first time I copy&pasted and missed to change it.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.