0

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

1
  • log the results of a select after the delete. I'd bet it gets deleted. When you look in the database there can be two reasons you still see it: a) you are looking too soon and the transaction this runs inside somehow is not committed yet b) you are looking at it too late after it got set again... Commented Feb 6, 2021 at 7:34

1 Answer 1

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.