From 983f6090d36524718193d2b9a2bde34f5ed9172b Mon, 17 Oct 2011 16:42:15 +0200
From: Pasqualle <pasqualle@80733.no-reply.drupal.org>
Date: Mon, 17 Oct 2011 16:32:56 +0200
Subject: [PATCH] update_advanced_D7


diff --git a/update_advanced.compare.inc b/update_advanced.compare.inc
deleted file mode 100644
index 5c63f4b..0000000
--- a/update_advanced.compare.inc
+++ /dev/null
@@ -1,79 +0,0 @@
-<?php
-
-/**
- * @file
- * Code required only when comparing available updates to existing data.
- */
-
-// Make sure we always have /modules/update/update.compare.inc loaded.
-module_load_include('inc', 'update', 'update.compare');
-
-/**
- * Populate an array of disabled project data.
- *
- * @see _update_process_info_list()
- */
-function _update_advanced_process_disabled_info_list(&$projects, $list, $project_type) {
-  foreach ($list as $file) {
-    if (!empty($file->status)) {
-      // Skip enabled modules or themes.
-      continue;
-    }
-
-    // Skip if the .info file is broken.
-    if (empty($file->info)) {
-      continue;
-    }
-
-    // Skip if it's a hidden module.
-    if (!empty($file->info['hidden'])) {
-      continue;
-    }
-
-    // If the .info doesn't define the 'project', try to figure it out.
-    if (!isset($file->info['project'])) {
-      $file->info['project'] = update_get_project_name($file);
-    }
-
-    // If we still don't know the 'project', give up.
-    if (empty($file->info['project'])) {
-      continue;
-    }
-
-    // If we don't already know it, grab the change time on the .info file
-    // itself. Note: we need to use the ctime, not the mtime (modification
-    // time) since many (all?) tar implementations will go out of their way to
-    // set the mtime on the files it creates to the timestamps recorded in the
-    // tarball. We want to see the last time the file was changed on disk,
-    // which is left alone by tar and correctly set to the time the .info file
-    // was unpacked.
-    if (!isset($file->info['_info_file_ctime'])) {
-      $info_filename = dirname($file->filename) .'/'. $file->name .'.info';
-      $file->info['_info_file_ctime'] = filectime($info_filename);
-    }
-
-    if (!isset($file->info['datestamp'])) {
-      $file->info['datestamp'] = 0;
-    }
-
-    $project_name = $file->info['project'];
-    if (!isset($projects[$project_name])) {
-      // Only process this if we haven't done this project, since a single
-      // project can have multiple modules or themes.
-      $projects[$project_name] = array(
-        'name' => $project_name,
-        'info' => $file->info,
-        'datestamp' => $file->info['datestamp'],
-        'includes' => array($file->name => $file->info['name']),
-        // Core can't be disabled, there's no reason to special-case it here.
-        'project_type' => $project_type,
-      );
-    }
-    // Only record include data for disabled projects.
-    elseif ($projects[$project_name]['project_type'] == $project_type) {
-      $projects[$project_name]['includes'][$file->name] = $file->info['name'];
-      $projects[$project_name]['info']['_info_file_ctime'] = max($projects[$project_name]['info']['_info_file_ctime'], $file->info['_info_file_ctime']);
-      $projects[$project_name]['datestamp'] = max($projects[$project_name]['datestamp'], $file->info['datestamp']);
-    }
-  }
-}
diff --git a/update_advanced.info b/update_advanced.info
index 52f1934..0a92ad6 100644
--- a/update_advanced.info
+++ b/update_advanced.info
@@ -1,4 +1,4 @@
 name = Update status advanced settings
 description = Adds advanced settings and extra functionality to the Update status module in core.
-core = 6.x
+core = 7.x
 dependencies[] = update
diff --git a/update_advanced.install b/update_advanced.install
index 93c6689..9a1422a 100644
--- a/update_advanced.install
+++ b/update_advanced.install
@@ -6,9 +6,8 @@
  */
 
 /**
- * Implementation of hook_uninstall().
+ * Implements hook_uninstall().
  */
 function update_advanced_uninstall() {
-  variable_del('update_advanced_check_disabled');
   variable_del('update_advanced_project_settings');
 }
diff --git a/update_advanced.module b/update_advanced.module
index e1b0fe6..88a1257 100644
--- a/update_advanced.module
+++ b/update_advanced.module
@@ -14,37 +14,27 @@
  */
 
 /**
- * Implementation of hook_theme().
+ * Implements hook_theme().
  */
 function update_advanced_theme() {
   return array(
     'update_advanced_settings' => array(
-      'arguments' => array('form' => NULL),
+      'render element' => 'form',
+      'file' => 'update_advanced.settings.inc',
     ),
   );
 }
 
 /**
- * Implementation of hook_form_FORM_ID_alter().
+ * Implements hook_form_FORM_ID_alter().
  */
-function update_advanced_form_update_settings_alter(&$form, $form_state) {
-  module_load_include('inc', 'update_advanced', 'update_advanced.settings');
+function update_advanced_form_update_settings_alter(&$form, &$form_state, $form_id) {
+  module_load_include('inc', 'update_advanced', 'update_advanced.settings');
   _update_advanced_alter_settings($form, $form_state);
 }
 
 /**
- * Implementation of hook_update_projects_alter().
- */
-function update_advanced_update_projects_alter(&$projects) {
-  if (variable_get('update_advanced_check_disabled', FALSE)) {
-    module_load_include('inc', 'update_advanced', 'update_advanced.compare');
-    _update_advanced_process_disabled_info_list($projects, module_rebuild_cache(), 'disabled-module');
-    _update_advanced_process_disabled_info_list($projects, system_theme_data(), 'disabled-theme');
-  }
-}
-
-/**
- * Implementation of hook_update_status_alter().
+ * Implements hook_update_status_alter().
  *
  * This compares the array of computed information about projects that are
  * missing available updates with the saved settings. If the settings specify
@@ -65,7 +55,7 @@
       $projects[$project]['reason'] = t('Ignored from settings');
       if ($ignored !== TRUE) {
         $projects[$project]['extra'][] = array(
-          'class' => 'admin-note',
+          'class' => array('admin-note'),
           'label' => t('Administrator note'),
           'data' => $ignored,
         );
@@ -86,7 +76,7 @@
  *   ignored in update results, or FALSE otherwise.
  */
 function update_advanced_is_project_ignored($project, $update_info) {
-  static $settings;
+  $settings = &drupal_static(__FUNCTION__);
 
   if (!isset($settings)) {
     $settings = variable_get('update_advanced_project_settings', array());
@@ -108,7 +98,6 @@
     // Return the ignore note if available.
     return $settings[$project]['notes'];
   }
-  else {
-    return $ignored;
-  }
+
+  return $ignored;
 }
diff --git a/update_advanced.settings.inc b/update_advanced.settings.inc
index 2c550b2..b41ccbc 100644
--- a/update_advanced.settings.inc
+++ b/update_advanced.settings.inc
@@ -6,64 +6,59 @@
  */
 
 /**
- * Alters the update_settings form to add advanced, per-project settings.
+ * Alters the update_settings form to add per-project settings.
  */
 function _update_advanced_alter_settings(&$form, $form_state) {
-  $form['update_advanced_check_disabled'] = array(
-    '#type' => 'checkbox',
-    '#title' => t('Check for updates of disabled modules and themes'),
-    '#default_value' => variable_get('update_advanced_check_disabled', FALSE),
+  $available = update_get_available(TRUE);
+  if (!$available) {
+    return;
+  }
+
+  $form['#theme'] = 'update_advanced_settings';
+  $form['#attached']['css'][] = drupal_get_path('module', 'update_advanced') . '/update_advanced.css';
+
+  $values = variable_get('update_advanced_project_settings', array());
+  $form['update_advanced_project_settings'] = array('#tree' => TRUE);
+
+  module_load_include('inc', 'update', 'update.compare');
+  $data = update_calculate_project_data($available);
+  $form['data'] = array('#type' => 'value', '#value' => $data);
+  $form['available'] = array('#type' => 'value', '#value' => $available);
+  // We need to call our own submit callback first, not the one from
+  // update_settings_form, so that we can unset 'data' and 'available'
+  // before they are saved into the {variables} table.
+  array_unshift($form['#submit'], 'update_advanced_settings_submit');
+
+  $form['update_advanced_project_settings_help'] = array(
+    '#markup' => t('These settings allow you to control if a certain project, or even a specific release of that project, should be ignored by the available updates report.  For each project, you can select if it should always warn you about a newer release, never warn you (ignore the project completely), or ignore a specific available release you do not want to upgrade to. You can also specify a note explaining why you are ignoring a specific project or version, and that will be displayed on the available updates report.'),
   );
 
-  if ($available = update_get_available(TRUE)) {
-    drupal_add_css(drupal_get_path('module', 'update_advanced') . '/update_advanced.css');
-
-    $form['#theme'] = 'update_advanced_settings';
-
-    $values = variable_get('update_advanced_project_settings', array());
-    $form['update_advanced_project_settings'] = array('#tree' => TRUE);
-
-    module_load_include('inc', 'update', 'update.compare');
-    $data = update_calculate_project_data($available);
-    $form['data'] = array('#type' => 'value', '#value' => $data);
-    $form['available'] = array('#type' => 'value', '#value' => $available);
-
-    // We need to call our own submit callback first, not the one from
-    // update_settings_form, so that we can unset 'data' and 'available'
-    // before they are saved into the {variables} table.
-    array_unshift($form['#submit'], 'update_advanced_settings_submit');
-
-    $form['update_advanced_project_settings_help'] = array(
-      '#value' => t('These settings allow you to control if a certain project, or even a specific release of that project, should be ignored by the available updates report.  For each project, you can select if it should always warn you about a newer release, never warn you (ignore the project completely), or ignore a specific available release you do not want to upgrade to. You can also specify a note explaining why you are ignoring a specific project or version, and that will be displayed on the available updates report.'),
-    );
-
-    foreach ($data as $key => $project) {
-      if (isset($available[$key])) {
-        if (!isset($values[$key])) {
-          $values[$key] = array(
-            'check' => 'always',
-            'notes' => '',
-          );
-        }
-
-        $options = array();
-        $options['always'] = t('Always');
-        if (isset($project['recommended'])) {
-          $options[$project['recommended']] = t('Ignore @version', array('@version' => $project['recommended']));
-        }
-        $options['never'] = t('Never');
-
-        $form['update_advanced_project_settings'][$key]['check'] = array(
-          '#type' => 'select',
-          '#options' => $options,
-          '#default_value' => $values[$key]['check'],
-        );
-        $form['update_advanced_project_settings'][$key]['notes'] = array(
-          '#type' => 'textfield',
-          '#size' => 50,
-          '#default_value' => $values[$key]['notes'],
+  foreach ($data as $key => $project) {
+    if (isset($available[$key])) {
+      if (!isset($values[$key])) {
+        $values[$key] = array(
+          'check' => 'always',
+          'notes' => '',
         );
       }
+
+      $options = array();
+      $options['always'] = t('Always');
+      if (isset($project['recommended'])) {
+        $options[$project['recommended']] = t('Ignore @version', array('@version' => $project['recommended']));
+      }
+      $options['never'] = t('Never');
+
+      $form['update_advanced_project_settings'][$key]['check'] = array(
+        '#type' => 'select',
+        '#options' => $options,
+        '#default_value' => $values[$key]['check'],
+      );
+      $form['update_advanced_project_settings'][$key]['notes'] = array(
+        '#type' => 'textfield',
+        '#size' => 50,
+        '#default_value' => $values[$key]['notes'],
+      );
     }
   }
 }
@@ -74,20 +69,29 @@
  * Formats the table of per-project settings, and renders the rest of the
  * form elements into their proper places for maximum clarity.
  */
-function theme_update_advanced_settings($form) {
+function theme_update_advanced_settings($variables) {
+  $form = $variables['form'];
+
   $output = '';
-  $output .= drupal_render($form['update_notify_emails']);
+  // Render the core update settings form.
   $output .= drupal_render($form['update_check_frequency']);
+  $output .= drupal_render($form['update_check_disabled']);
+  $output .= drupal_render($form['update_notify_emails']);
   $output .= drupal_render($form['update_notification_threshold']);
-  $output .= drupal_render($form['update_advanced_check_disabled']);
 
   $header = array(
-    array('data' => t('Project'), 'class' => 'update-advanced-project'),
+    array(
+      'data' => t('Project'),
+      'class' => array('update-advanced-project'),
+    ),
     array(
       'data' => t('Warn if out of date'),
       'class' => 'update-advanced-status',
     ),
-    array('data' => t('Notes'), 'class' => 'update-advanced-notes'),
+    array(
+      'data' => t('Notes'),
+      'class' => array('update-advanced-notes'),
+    ),
   );
 
   $data = $form['data']['#value'];
@@ -98,15 +102,15 @@
     if (isset($available[$key])) {
       $row = array();
       $row[] = array(
-        'class' => 'update-project',
+        'class' => array('update-project'),
         'data' => check_plain($available[$key]['title']),
       );
       $row[] = array(
-        'class' => 'update-status',
+        'class' => array('update-status'),
         'data' => drupal_render($form['update_advanced_project_settings'][$key]['check']),
       );
       $row[] = array(
-        'class' => 'update-notes',
+        'class' => array('update-notes'),
         'data' => drupal_render($form['update_advanced_project_settings'][$key]['notes']),
       );
       if (!isset($rows[$project['project_type']])) {
@@ -116,21 +120,22 @@
       $rows[$project['project_type']][$row_key] = $row;
     }
   }
+
   $split_rows = array();
   $project_types = array(
     'core' => t('Drupal core'),
     'module' => t('Modules'),
     'theme' => t('Themes'),
-    'disabled-module' => t('Disabled modules'),
-    'disabled-theme' => t('Disabled themes'),
+    'module-disabled' => t('Disabled modules'),
+    'theme-disabled' => t('Disabled themes'),
   );
   foreach ($project_types as $type_name => $type_label) {
     if (!empty($rows[$type_name])) {
       $split_rows[] = array(
-        'class' => 'update-advanced-settings-label',
+        'class' => array('update-advanced-settings-label'),
         'data' => array(
           array(
-            'class' => 'update-advanced-settings-label',
+            'class' => array('update-advanced-settings-label'),
             'data' => $type_label,
             'colspan' => 3,
           ),
@@ -140,12 +145,13 @@
       $split_rows = array_merge($split_rows, $rows[$type_name]);
     }
   }
-  $output .= theme('table', $header, $split_rows, array('class' => 'update-advanced-settings'));
-  $output .= '<div class="form-item"><div class="description">' ."\n";
+
+  $output .= theme('table', array('header' => $header, 'rows' => $split_rows, 'attributes' => array('class' => array('update-advanced-settings'))));
+  $output .= '<div class="description">' ."\n";
   $output .= drupal_render($form['update_advanced_project_settings_help']);
-  $output .= "</div></div>\n";
-  $output .= drupal_render($form['buttons']);
-  $output .= drupal_render($form);
+  $output .= "</div>\n";
+  $output .= drupal_render($form['actions']);
+  $output .= drupal_render_children($form);
   return $output;
 }
 
@@ -155,22 +161,8 @@
  * Ensures that the temporary form data required for the theme function is not
  * actually saved into the {variables} table, then invokes the true submit
  * handler for the settings form to save or reset all the values.
- *
- * Also invalidates the cache of available updates if the "Check for updates
- * of disabled modules and themes" setting is being changed. Both the advanced
- * settings table and the available updates report need to refetch available
- * update data after this setting changes or they're going to show misleading
- * things (for example, listing all of the disabled projects on the site with
- * the "No available releases found" warning).
  */
 function update_advanced_settings_submit($form, &$form_state) {
   unset($form_state['values']['data']);
   unset($form_state['values']['available']);
-
-  // See if the update_advanced_check_disabled setting is being changed, and
-  // if so, invalidate all cached update status data.
-  $check_disabled = variable_get('update_advanced_check_disabled', FALSE);
-  if ($form_state['values']['update_advanced_check_disabled'] != $check_disabled) {
-    update_invalidate_cache();
-  }
 }
