Вопрос
I'm trying to delete from the dr_cache_form table,in D7, but somehow the record does not get deleted
function mymodule_multistep_form_submit($form, &$form_state) {
//.....
$form_id = array();
$form_id[0]='form_' . $form_state['values']['form_build_id'];
$form_id[1]='form_state_' . $form_state['values']['form_build_id'];
dd($form_id,'$form_id=');
$query = db_select('cache_form', 'cf');
$query->fields('cf',array('cid'))
->condition('cid', $form_id[0], '=');
$result = $query->execute()->fetchAll();
dd($result,'$result=');
$deleted=db_delete('cache_form')
//->condition('cid', $form_id, 'IN')
->condition('cid', $form_id[0], '=')
->execute();
//dpq($deleted);
// dd($deleted);
}
So in my drupal_debug.log file I find the entries corresponding to the above lines, but when I go to the database in mysql and select * from dr_cache_form where cid='the form id that was printed in the drupal_deug"; then the row is there, it isn't actually deleted.
Do I need to flush somehow the db_delete... all other database operations are working fine, insert, update, select... just this delete does not want to actual delete the row in the db.
the $delete variable is set to 1 after db_delete
I'm calling it from an multistep form in the last step of the form, thus the cid exists in the dr_cache_form table before db_delete is called, as I can see it via phpmyadmin, and also it gets printed in the drupal_debug whit the $result variable
Решение
db_delete works fine, but the problem is that I was trying to delete the cache of the current form from within the code of that form e.g. submit form. Logically this is ok for me because I was trying to delete the cache at the end of my multistep form where the user cannot do anything else but navigate away.
There must be a check somewhere either in db_delete not to allow to delete the cache of the current form. I tried and I managed to delete from cache_form other entries from the exact same place in the code, just not targeting the current_form cache.
I was aware that I'm deleting the cache of the current form, but I just wanted to test that the db_delete works, and then move on with a more complicated logic where I would not delete the current cache but the previous form from the cache.