diff -u b/webform_nosave.install b/webform_nosave.install --- b/webform_nosave.install +++ b/webform_nosave.install @@ -19,7 +19,12 @@ /** - * Add attachment field to Webform NoSave + * Add attachment field to Webform NoSave. */ -function webform_nosave_update_7101() { - $specs = array('description' => t('Delete attachments'), 'type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE); - db_add_field('webform_nosave', 'attachments', $specs); +function webform_nosave_update_7001() { + $table = 'webform_nosave'; + $field = 'attachments'; + $schema = drupal_get_schema_unprocessed($table, $table); + $spec = $schema['fields']['attachments']; + if (!db_field_exists($table, $field)) { + db_add_field($table, $field , $spec); + } } diff -u b/webform_nosave.module b/webform_nosave.module --- b/webform_nosave.module +++ b/webform_nosave.module @@ -15,6 +15,22 @@ } /** + * Implements hook_module_implements_alter(). + */ +function webform_nosave_module_implements_alter(&$implementations, $hook) { + if ($hook == 'rdf_mapping') { + // Move webform_nosave_form_alter() to the end of the list. + // module_implements() iterates through $implementations with a foreach loop + // which PHP iterates in the order that the items were added, so to move an + // item to the end of the array, we remove it and then add it. + $module = 'webform_nosave'; + $group = $implementations[$module]; + unset($implementations[$module]); + $implementations[$module] = $group; + } +} + +/** * Implements hook_node_delete(). */ function webform_nosave_node_delete($node) { @@ -36,28 +52,25 @@ '#default_value' => isset($nosave->nid) ? 1 : 0, ); - if (module_exists('mimemail')) { - $form['advanced']['nosave_attachments'] = array( - '#type' => 'checkbox', - '#title' => t('Also delete submitted files from disk'), - '#description' => t('Check here, if you do not want to store uploaded files on disk. Make sure to add the files to one or more e-mails as attachment and select the "Custom URL" or "No redirect" option and a "Confirmation message". The confirmation page will be replaced with the "No redirect" option via code and the default webform message will be shown.'), - '#default_value' => isset($nosave->attachments) ? 1 : 0, - '#access' => webform_email_html_capable(), - '#states' => array( - 'visible' => array( - ':input[name="nosave"]' => array('checked' => TRUE), - ), + $form['advanced']['nosave_attachments'] = array( + '#type' => 'checkbox', + '#title' => t('Also delete submitted files from disk'), + '#description' => t('Check here, if you do not want to store uploaded files on disk. If adding file(s) to one or more e-mails as attachment(s), select the "Custom URL" or "No redirect" option and a "Confirmation message". The confirmation page will be replaced with the "No redirect" option via code and the default webform message will be shown.'), + '#default_value' => isset($nosave->attachments) ? 1 : 0, + '#states' => array( + 'visible' => array( + ':input[name="nosave"]' => array('checked' => TRUE), ), - ); - } + ), + ); break; case strstr($form_id, 'webform_client_form'): $nosave = webform_nosave_load($form['#node']->nid); $form['#submit'][] = 'webform_nosave_delete_result'; - // If the attachments will be deleted the webform base redirect - // will not work and redirect guests to 403-Forbidden, prevent this + // If the attachments will be deleted, the webform base redirect + // will not work and redirects to 403-Forbidden. Prevent this. if (isset($nosave->attachments)) { $form['#node']->webform['redirect_url'] = ''; @@ -97,18 +110,13 @@ $nosave = webform_nosave_load($nid); if ($sid && $new && $nosave->nid) { - if ($nosave->attachments) { + // Mimemail module installed and setting active -> perform webform delete. + // Events needs to be run AFTER the mimemail has been sent. + if ($node = node_load($nid)) { module_load_include('inc', 'webform', 'includes/webform.submissions'); - - // Mimemail module installed and setting active -> perform webform delete - // Events needs to be run AFTER the mimemail has been sent - $node = node_load($nid); - $submission = webform_get_submission($nid, $sid); - webform_submission_delete($node, $submission); - } else { - // Just delete db entries - db_delete('webform_submissions')->condition('sid', $sid)->execute(); - db_delete('webform_submitted_data')->condition('sid', $sid)->execute(); + if ($submission = webform_get_submission($nid, $sid)) { + webform_submission_delete($node, $submission); + } } } }