Index: webform.install =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/webform/webform.install,v retrieving revision 1.42 diff -u -r1.42 webform.install --- webform.install 8 Mar 2010 01:04:42 -0000 1.42 +++ webform.install 13 Mar 2010 02:02:58 -0000 @@ -386,260 +386,12 @@ /** * Set the minimum upgrade version. * - * This should allow updates from any 2.x version of Webform (for D5 or D6), - * but prevent updates from any version prior to Webform 1.10. + * Currently you cannot upgrade from 2.x in Drupal 6 to 3.x in Drupal 7. However + * there are no database changes between the 3.x versions, so no update is + * needed at all to move from 3.x in Drupal 6 to Drupal 7. */ function webform_update_last_removed() { - return 6205; -} - -/** - * Add a separate column for confirmation message input format. - */ -function webform_update_6301() { - // Safety check to prevent re-adding existing column. - if (db_column_exists('webform', 'confirmation_format')) { - return; - } - - db_add_field('webform', 'confirmation_format', array('type' => 'int', 'size' => 'tiny', 'not null' => TRUE, 'default' => 0)); - $result = db_query("SELECT n.nid, nr.format FROM {node} n INNER JOIN {node_revisions} nr ON n.vid = nr.vid WHERE n.type = 'webform'"); - while ($node = db_fetch_object($result)) { - db_query('UPDATE {webform} SET confirmation_format = :confirmation_format WHERE nid = :nid', array('confirmation_format' => $node->format, 'nid' => $node->nid)); - } -} - -/** - * Convert node-level e-mail settings to new webform_emails table. - */ -function webform_update_6302() { - // Safety check to prevent recreating the webform_emails table. - if (db_table_exists('webform_emails')) { - return; - } - - $table = array( - 'fields' => array( - 'nid' => array( - 'type' => 'int', - 'unsigned' => TRUE, - 'not null' => TRUE, - 'default' => 0, - ), - 'eid' => array( - 'type' => 'int', - 'unsigned' => TRUE, - 'size' => 'small', - 'not null' => TRUE, - 'default' => 0, - ), - 'email' => array( - 'type' => 'text', - 'not null' => FALSE, - ), - 'subject' => array( - 'type' => 'varchar', - 'length' => '255', - 'not null' => FALSE, - ), - 'from_name' => array( - 'type' => 'varchar', - 'length' => '255', - 'not null' => FALSE, - ), - 'from_address' => array( - 'type' => 'varchar', - 'length' => '255', - 'not null' => FALSE, - ), - 'template' => array( - 'type' => 'text', - 'not null' => FALSE, - ) - ), - 'primary key' => array('nid', 'eid'), - ); - - db_create_table('webform_emails', $table); - - // Move over data from the webform table. - $result = db_query("SELECT w.nid, w.email, w.email_from_name, w.email_from_address, w.email_subject, wc.cid, wc.extra FROM {webform} w LEFT JOIN {webform_component} wc ON w.nid = wc.nid AND type IN ('select', 'hidden', 'email') ORDER BY nid"); - $nid = 0; - foreach ($result->execute() as $row) { - // Insert an e-mail settings row for the default e-mail. - if ($row->nid != $nid) { - $nid = $row->nid; - $eid = 0; - if (!empty($row->email)) { - $eid++; - db_query("INSERT INTO {webform_emails} (nid, eid, email, subject, from_name, from_address, template) VALUES (:nid, :eid, :email, :subject, :from, :address, 'default')", array(':nid' => $nid, ':eid' => $eid, ':email' => $row->email, ':subject' => $row->email_subject, ':from' => $row->email_from_name, ':address' => $row->email_from_address)); - } - } - - // Check for an e-mail based on a component. - if ($row->extra) { - $extra = unserialize($row->extra); - if ($extra['email']) { - $eid++; - unset($extra['email']); - db_query("INSERT INTO {webform_emails} (nid, eid, email, subject, from_name, from_address, template) VALUES (:nid, :eid, :cid, :subject, :from, :address, 'default')", array(':nid' => $nid, ':eid' => $eid, ':cid' => $row->cid, ':subject' => $row->email_subject, ':from' => $row->email_from_name, ':address' => $row->email_from_address)); - db_query("UPDATE {webform_component} SET extra = :extra WHERE nid = :nid AND cid = :cid", array(':extra' => serialize($extra), ':nid' => $row->nid, ':cid' => $row->cid)); - } - } - } - - // Remove columns from webform table. - db_drop_field('webform', 'email'); - db_drop_field('webform', 'email_from_name'); - db_drop_field('webform', 'email_from_address'); - db_drop_field('webform', 'email_subject'); -} - -/** - * Add the submit_notice field and update all existing webforms to the 2.x previous submissions notice default. - */ -function webform_update_6303() { - db_add_field('webform', 'submit_notice', array('type' => 'int', 'size' => 'tiny', 'not null' => TRUE, 'default' => 0)); - db_query("UPDATE {webform} SET submit_notice = 1 WHERE submit_notice = 0"); -} - -/** - * Convert the webform content type to be owned by Node module. - */ -function webform_update_6304() { - db_query("UPDATE {node_type} SET module = 'node', custom = 1, modified = 1, locked = 0 WHERE type = 'webform'"); - if (!db_affected_rows()) { - db_query("INSERT INTO {node_type} (type, name, module, description, help, has_title, title_label, has_body, body_label, min_word_count, custom, modified, locked, orig_type) VALUES ('webform', 'Webform', 'node', 'Create a new form or questionnaire accessible to users. Submission results and statistics are recorded and accessible to privileged users.', '', 1, 'Title', 1, 'Body', 0, 1, 1, 0, 'webform')"); - } -} - -/** - * Migrate the renamed permissions. Add separate permissions for delete. - */ -function webform_update_6305() { - $updated_permissions = array( - 'create webforms' => array('add webform content'), - 'edit own webforms' => array('edit own webform content', 'delete own webform content'), - 'edit webforms' => array('edit any webform content', 'delete any webform content'), - 'access webform results' => array('access all webform results'), - 'edit webform submissions' => array('edit all webform submissions'), - 'edit own webform submissions' => array('edit own webform submissions', 'delete own webform submissions'), - 'clear webform results' => array('delete all webform submissions'), - ); - - foreach ($updated_permissions as $old_perm => $new_perms) { - $result = db_query("SELECT * FROM {user_permission} WHERE permission = :old_perm", array(':old_perm' => $old_perm)); - foreach ($result->execute() as $permission) { - foreach ($new_perms as $new_perm) { - db_query("INSERT INTO {permission} (rid, permission, module) VALUES (:rid, :permission, 'webform')", array(':rid' => $permission->rid, ':permission' => $new_perm)); - } - } - } -} - -/** - * Add the ability to save as draft. - */ -function webform_update_6306() { - if (!db_column_exists('webform', 'allow_draft')) { - db_add_field('webform', 'allow_draft', array('type' => 'int', 'size' => 'tiny', 'not null' => TRUE, 'default' => 0)); - db_add_field('webform_submissions', 'is_draft', array('type' => 'int', 'size' => 'tiny', 'not null' => TRUE, 'default' => 0)); - } -} - -/** - * Convert the file component to use only FIDs instead of serialized arrays. - */ -function webform_update_6307() { - $result = db_query("SELECT d.*, s.uid, s.submitted FROM {webform_submitted_data} d INNER JOIN {webform_component} c ON d.cid = c.cid AND d.nid = c.nid AND c.type = 'file' INNER JOIN {webform_submissions} s ON d.sid = s.sid"); - foreach ($result->execute() as $row) { - $file = @unserialize($row->data); - // File name should always exist, even when upgrading from Drupal 5. - if ($file && isset($file['filename'])) { - // Create an entry in the files table if needed. - if (!isset($file['fid'])) { - $fid = db_query("INSERT INTO {files} (uid, filename, filepath, filemime, filesize, status, timestamp) VALUES (:uid, :filename, :filepath, :filemime, :filesize, 1, :timestamp)", array(':uid' => $row->uid, ':filename' => $file['filename'], ':filepath' => $file['filepath'], ':filemime' => $file['filemime'], ':filesize' => $file['filesize'], ':timestamp' => $row->submitted)); - } - else { - $fid = $file['fid']; - } - // Update the submitted data with the FID. - db_query("UPDATE {webform_submitted_data} SET data = :fid WHERE nid = :nid AND sid = :sid AND cid = :cid", array(':fid' => $fid, ':nid' => $row->nid, ':sid' => $row->sid, ':cid' => $row->cid)); - } - // Insert an empty entry, now just an empty string. - else { - db_query("UPDATE {webform_submitted_data} SET data = '' WHERE nid = :nid AND sid = :sid AND cid = :cid", array(':nid' => $row->nid, ':sid' => $row->sid, ':cid' => $row->cid)); - } - } -} - -/** - * Convert "Include in e-mail" from the component-level to a per e-mail setting. - */ -function webform_update_6308() { - $ret = array(); - - // Add the new column to the e-mail table. - db_add_field($ret, 'webform_emails', 'excluded_components', array('type' => 'text', 'not null' => TRUE, 'default' => '')); - - // Build up our EXCLUSION lists, finding all components not in e-mails. - $result = db_query("SELECT nid, cid FROM {webform_component} WHERE email = 0 ORDER BY nid"); - $nid = 0; - $excluded_components = array(); - foreach ($result->execute() as $row) { - if ($nid != $row->nid) { - if (!empty($excluded_components)) { - db_query("UPDATE {webform_emails} SET excluded_components = :exclude WHERE nid = :nid", array(':exclude' => implode(',', $excluded_components), ':nid' => $nid)); - } - $nid = $row->nid; - $excluded_components = array(); - } - $excluded_components[] = $row->cid; - } - - // One last query for the last form in the list. - if (!empty($excluded_components)) { - db_query("UPDATE {webform_emails} SET excluded_components = :excluded WHERE nid = :nid", array(':exclude' => implode(',', $excluded_components), ':nid' => $nid)); - } - - db_drop_field('webform_component', 'email'); -} - -/** - * Fix permissions for all roles by adding an additional space after comma. - */ -function webform_update_6309() { - // This update is not needed in the D6 -> D7 upgrade. -} - -/** - * Add the redirect_url field and update existing webforms to use it. - */ -function webform_update_6310() { - // Safety check to prevent re-adding existing column. - if (db_column_exists('webform', 'redirect_url')) { - return; - } - - // Add the new redirect_url column. - db_add_field('webform', 'redirect_url', array('type' => 'varchar', 'length' => '255')); - - // If the webform is using the confirmation field as a redirect then move it - // to the new redirect_url field. - $result = db_query("SELECT nid, confirmation FROM {webform}"); - foreach ($result->execute() as $row) { - $confirmation = trim(strip_tags($row->confirmation, '')); - if (valid_url($confirmation, TRUE) || preg_match('/^internal:/', $confirmation)) { - $redirect_url = preg_replace('/^internal:/', '', $confirmation); - db_query("UPDATE {webform} SET redirect_url = :redirect_url WHERE nid = :nid", array(':redirect_url' => $redirect_url, ':nid' => $row->nid)); - db_query("UPDATE {webform} SET confirmation = '' WHERE nid = :nid", array(':nid' => $row->nid)); - } - elseif (preg_match('/^message:/', $confirmation)) { - $message = preg_replace('/^message:/', '', $confirmation); - db_query("UPDATE {webform} SET redirect_url = :redirect_url WHERE nid = :nid", array(':redirect_url' => 'node/' . $row->nid, ':nid' => $row->nid)); - db_query("UPDATE {webform} SET confirmation = :confirmation WHERE nid = :nid", array(':confirmation' => $message, ':nid' => $row->nid)); - } - } + return 6310; } /**