Upload module variable name has collision possibility: http://drupal.org/node/270302

From: andrew morton <drewish@katherinehouse.com>


---

 modules/system/system.api.php |    8 +++---
 modules/upload/upload.install |   22 +++++++++++++++++
 modules/upload/upload.module  |   11 +++++---
 modules/upload/upload.test    |   54 ++++++++++++++++++++++++++++-------------
 4 files changed, 70 insertions(+), 25 deletions(-)


diff --git modules/system/system.api.php modules/system/system.api.php
index b99d95c..d9e74ad 100644
--- modules/system/system.api.php
+++ modules/system/system.api.php
@@ -288,7 +288,7 @@ function hook_page_alter($page) {
  * One popular use of this hook is to add form elements to the node form. When
  * altering a node form, the node object retrieved at from $form['#node'].
  *
- * Note that you can also use hook_FORM_ID_alter() to alter a specific form,
+ * Note that you can also use hook_form_FORM_ID_alter() to alter a specific form,
  * instead of this hook, which gets called for all forms.
  *
  * @param $form
@@ -302,11 +302,11 @@ function hook_page_alter($page) {
  *   None.
  */
 function hook_form_alter(&$form, $form_state, $form_id) {
-  if (isset($form['type']) && $form['type']['#value'] . '_node_settings' == $form_id) {
-    $form['workflow']['upload_' . $form['type']['#value']] = array(
+  if ($form_id == 'node_type_form' && isset($form['identity']['type'])) {
+    $form['workflow']['upload_node_type'] = array(
       '#type' => 'radios',
       '#title' => t('Attachments'),
-      '#default_value' => variable_get('upload_' . $form['type']['#value'], 1),
+      '#default_value' => variable_get('upload_node_type_' . $form['#node_type']->type, 1),
       '#options' => array(t('Disabled'), t('Enabled')),
     );
   }
diff --git modules/upload/upload.install modules/upload/upload.install
index 5e04267..6312eed 100644
--- modules/upload/upload.install
+++ modules/upload/upload.install
@@ -82,4 +82,26 @@ function upload_schema() {
   return $schema;
 }
 
+/**
+ * Drupal 6.x to 7.x updates
+ */
+
+/**
+ * Rename upload_<node_type> variables to upload_node_type_<node_type>.
+ */
+function upload_update_7000() {
+  $variables = db_query("SELECT * FROM {variable} WHERE name LIKE 'upload_%'")
+    ->fetchAllKeyed();
+  $node_types = db_query("SELECT type FROM {node_type}")
+    ->fetchCol();
+  foreach ($node_types as $node_type) {
+    if (isset($variables['upload_' . $node_type])) {
+      variable_set('upload_node_type_' . $node_type, $variables['upload_' . $node_type]);
+      variable_del('upload_' . $node_type);
+    }
+  }
+}
 
+/**
+ * End of 6.x to 7.x updates
+ */
\ No newline at end of file
diff --git modules/upload/upload.module modules/upload/upload.module
index 6ba2dfb..b4994c8 100644
--- modules/upload/upload.module
+++ modules/upload/upload.module
@@ -211,19 +211,22 @@ function upload_node_form_submit(&$form, &$form_state) {
   }
 }
 
+/*
+ * Implementation of hook_form_alter().
+ */
 function upload_form_alter(&$form, $form_state, $form_id) {
   if ($form_id == 'node_type_form' && isset($form['identity']['type'])) {
-    $form['workflow']['upload'] = array(
+    $form['workflow']['upload_node_type'] = array(
       '#type' => 'radios',
       '#title' => t('Attachments'),
-      '#default_value' => variable_get('upload_' . $form['#node_type']->type, 1),
+      '#default_value' => variable_get('upload_node_type_' . $form['#node_type']->type, 1),
       '#options' => array(t('Disabled'), t('Enabled')),
     );
   }
 
   if (!empty($form['#node_edit_form'])) {
     $node = $form['#node'];
-    if (variable_get("upload_$node->type", TRUE)) {
+    if (variable_get('upload_node_type_' . $node->type, TRUE)) {
       // Attachments fieldset
       $form['attachments'] = array(
         '#type' => 'fieldset',
@@ -306,7 +309,7 @@ function upload_node_load($nodes, $types) {
   // Collect all the revision ids for nodes with upload enabled.
   $node_vids = array();
   foreach ($nodes as $node) {
-    if (variable_get("upload_$node->type", 1) == 1) {
+    if (variable_get('upload_node_type_' . $node->type, 1) == 1) {
       $node_vids[$node->vid] = $node->vid;
       $node->files = array();
     }
diff --git modules/upload/upload.test modules/upload/upload.test
index ac8c2eb..25a7a6b 100644
--- modules/upload/upload.test
+++ modules/upload/upload.test
@@ -2,6 +2,9 @@
 // $Id: upload.test,v 1.14 2009-03-31 01:49:55 webchick Exp $
 
 class UploadTestCase extends DrupalWebTestCase {
+  protected $admin_user;
+  protected $web_user;
+
   public static function getInfo() {
     return array(
       'name' => t('Upload functionality'),
@@ -12,6 +15,8 @@ class UploadTestCase extends DrupalWebTestCase {
 
   function setUp() {
     parent::setUp('upload');
+    $this->admin_user = $this->drupalCreateUser(array('administer site configuration', 'administer content types'));
+    $this->web_user = $this->drupalCreateUser(array('access content', 'edit any page content', 'upload files', 'view uploaded files'));
   }
 
   /**
@@ -19,10 +24,7 @@ class UploadTestCase extends DrupalWebTestCase {
    */
   function testNodeUpload() {
     global $base_url;
-    $admin_user = $this->drupalCreateUser(array('administer site configuration'));
-    $web_user = $this->drupalCreateUser(array('access content', 'edit any page content', 'upload files', 'view uploaded files'));
-
-    $this->drupalLogin($admin_user);
+    $this->drupalLogin($this->admin_user);
 
     // Setup upload settings.
     $edit = array();
@@ -34,7 +36,7 @@ class UploadTestCase extends DrupalWebTestCase {
     $this->assertText('The configuration options have been saved.', 'Upload setting saved.');
 
     $this->drupalLogout();
-    $this->drupalLogin($web_user);
+    $this->drupalLogin($this->web_user);
 
     // Create a node and attempt to attach files.
     $node = $this->drupalCreateNode();
@@ -84,13 +86,34 @@ class UploadTestCase extends DrupalWebTestCase {
   }
 
   /**
+   * Test disabling attachments.
+   */
+  function testContentTypeSettings() {
+    $this->drupalLogin($this->admin_user);
+
+    // Setup upload settings.
+    $edit = array();
+    $edit['upload_node_type'] = '0'; // Disabled.
+    $this->drupalPost('admin/build/node-type/article', $edit, 'Save content type');
+    $this->assertText(t('The content type Article has been updated.'), 'Attachment setting saved.');
+
+    // Add a new article. Because attachments are disabled, we should not see a
+    // 'File Attachments'-fieldset.
+    $this->drupalGet('node/add/article');
+    $this->assertNoText(t('File attachments'), 'Node add page does not contain a File Attachments fieldset.');
+
+    // Enable file attachments again for other tests.
+    $edit = array();
+    $edit['upload_node_type'] = '1'; // Enabled.
+    $this->drupalPost('admin/build/node-type/article', $edit, 'Save content type');
+    $this->assertText(t('The content type Article has been updated.'), 'Attachment setting saved.');
+  }
+
+  /**
    * Ensure the the file filter works correctly by attempting to upload a non-allowed file extension.
    */
   function testFilesFilter() {
-    $admin_user = $this->drupalCreateUser(array('administer site configuration'));
-    $web_user = $this->drupalCreateUser(array('access content', 'edit any page content', 'upload files', 'view uploaded files'));
-
-    $this->drupalLogin($admin_user);
+    $this->drupalLogin($this->admin_user);
 
     // Setup upload settings.
     $settings = array();
@@ -98,9 +121,9 @@ class UploadTestCase extends DrupalWebTestCase {
     $settings['upload_extensions'] = 'html';
     $settings['upload_uploadsize'] = '1';
     $settings['upload_usersize'] = '1';
-    $this->setUploadSettings($settings, $this->getSimpletestRoleId($web_user));
+    $this->setUploadSettings($settings, $this->getSimpletestRoleId($this->web_user));
 
-    $this->drupalLogin($web_user);
+    $this->drupalLogin($this->web_user);
 
     $node = $this->drupalCreateNode();
 
@@ -130,10 +153,7 @@ class UploadTestCase extends DrupalWebTestCase {
     $files = $this->drupalGetTestFiles('text', 1310720); // 1 MB.
     $file = current($files)->filepath;
 
-    $admin_user = $this->drupalCreateUser(array('administer site configuration'));
-    $web_user = $this->drupalCreateUser(array('access content', 'edit any page content', 'upload files', 'view uploaded files'));
-
-    $this->drupalLogin($admin_user);
+    $this->drupalLogin($this->admin_user);
 
     // Setup upload settings.
     $settings = array();
@@ -141,9 +161,9 @@ class UploadTestCase extends DrupalWebTestCase {
     $settings['upload_extensions'] = 'jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp';
     $settings['upload_uploadsize'] = '0.5';
     $settings['upload_usersize'] = '1.5';
-    $this->setUploadSettings($settings, $this->getSimpletestRoleId($web_user));
+    $this->setUploadSettings($settings, $this->getSimpletestRoleId($this->web_user));
 
-    $this->drupalLogin($web_user);
+    $this->drupalLogin($this->web_user);
 
     $node = $this->drupalCreateNode();
 
