/[drupal]/contributions/modules/awesome_install/awesome_install.module
ViewVC logotype

Diff of /contributions/modules/awesome_install/awesome_install.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.2, Wed Mar 5 22:11:55 2008 UTC revision 1.3, Thu Mar 6 05:05:56 2008 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: awesome_install.module,v 1.1 2008/03/05 21:15:51 cwgordon7 Exp $  // $Id: awesome_install.module,v 1.2 2008/03/05 22:11:55 cwgordon7 Exp $
3    
4  define('AWESOME_INSTALL_SETTINGS', 0);  // Ugliness!
5  define('AWESOME_INSTALL_BLOCKS', 1);  if (isset($_SESSION['awesome install'])) {
6  define('AWESOME_INSTALL_PERMS', 2);    if ($_SESSION['awesome install']) {
7  define('AWESOME_INSTALL_FINAL', 3);      if ($_GET['q'] != $_SESSION['awesome install']['path']) {
8          drupal_goto($_SESSION['awesome install']['path']);
9        }
10      }
11    }
12    
13  /**  /**
14   * Implementation of hook_form_alter().   * Implementation of hook_form_alter().
15   */   */
16  function awesome_install_form_alter(&$form, $form_state, $form_id) {  function awesome_install_form_alter(&$form, $form_state, $form_id) {
17    //drupal_set_message(print_r($form_state, TRUE));    if (arg(2) == 'search') {
18    if ($form_id == 'system_modules') {      drupal_set_message(print_r($_SESSION, TRUE));
19      if (isset($form_state['storage']['form'])) {    }
20        $form = $form_state['storage']['form'];    if ($form_id == 'system_modules' || isset($_SESSION['awesome install'])) {
21      }      if ($form_id == 'system_modules') {
     else {  
22        $form['old_modules'] = array('#type' => 'value', '#value' => module_list());        $form['old_modules'] = array('#type' => 'value', '#value' => module_list());
23      }      }
     if (isset($form_state['storage']['title'])) {  
       drupal_set_title($form_state['storage']['title']);  
     }  
24      $form['#submit'][] = 'awesome_install_submit';      $form['#submit'][] = 'awesome_install_submit';
25    }    }
26  }  }
27    
28    /**
29     * Submit callback, for like, all forms in existence.
30     * (Yes, it's awesome).
31     */
32  function awesome_install_submit($form, &$form_state) {  function awesome_install_submit($form, &$form_state) {
33    if (!isset($form_state['storage']['modsleft'])) {    $data = $_SESSION['awesome install'];
34      if (!isset($data['modsleft'])) {
35        if (!empty($form_state['storage'])) {
36          // It's an alien! Abort!
37          return;
38        }
39      $status = $form_state['values']['status'];      $status = $form_state['values']['status'];
40      $old = $form_state['values']['old_modules'];      $old = $form_state['values']['old_modules'];
41      foreach ($status as $module => $enabled) {      foreach ($status as $module => $enabled) {
# Line 37  function awesome_install_submit($form, & Line 46  function awesome_install_submit($form, &
46          unset($status[$module]);          unset($status[$module]);
47        }        }
48      }      }
49      $form_state['storage']['modsleft'] = $status;      $data['modsleft'] = $status;
50      }
51      if (!isset($data['steps'])) {
52        $data['steps'] = module_invoke_all('configuration_steps');
53    }    }
54    $form_state['redirect'] = FALSE;    // Continue through the modules while $continue.
55    $continue = TRUE;    $continue = TRUE;
56    while ($continue) {    while ($continue) {
57      $continue = FALSE;      $continue = FALSE;
58      $module = reset($form_state['storage']['modsleft']);      if (!isset($data['module'])) {
59          $module = reset($data['modsleft']);
60        }
61        else {
62          $module = $data['module'];
63        }
64      if (!$module) {      if (!$module) {
65        unset($form_state['storage']['form']);        // We're as done as we're going to be, I guess.
66          unset($_SESSION['awesome install']);
67        return;        return;
68      }      }
69      if (empty($form_state['storage']['install_step'])) {      $steps = $data['steps'];
70        $form_state['storage']['install_step'] = AWESOME_INSTALL_SETTINGS;      if (!isset($data['step'])) {
71      }        $data['step'] = reset($steps);
72      $modulepath = db_result(db_query("SELECT filename FROM {system} WHERE name = '%s' AND type = 'module'", $module));      }
73      // This is basically the next step. We prepare for it, or we skip it.      $continue2 = TRUE;
74      switch ($form_state['storage']['install_step']) {      while ($continue2) {
75        case AWESOME_INSTALL_SETTINGS:        foreach ($steps as $step) {
76          $form_state['storage']['install_step']++;          if ($data['step'] == $step) {
77          $form = awesome_install_find_settings_form($module);            $path = $step($module);
78          if (!empty($form)) {            if (!empty($path)) {
79            $null = array('storage' => NULL, 'submitted' => FALSE, 'post' => array());              $data['path'] = $path;
80            $form_state['storage']['form'] = drupal_retrieve_form($form, $null);              $continue2 = FALSE;
81            $form_state['storage']['title'] = t('Configure @module', array('@module' => $module));              break;
82            break;            }
83          }            else {
84                $data['step'] = next($steps);
       case AWESOME_INSTALL_BLOCKS:  
         $form_state['storage']['install_step']++;  
         if (module_hook($module, 'block')) {  
           // @TODO: Do stuff here.  
           break;  
         }  
   
       case AWESOME_INSTALL_PERMS:  
         $form_state['storage']['install_step']++;  
         if (module_hook($module, 'perm')) {  
           // @TODO: Do stuff here.  
           break;  
         }  
   
       case AWESOME_INSTALL_FINAL:  
         drupal_set_message(t('Install process for @module completed successfully.', array('@module' => $module)));  
         foreach ($form_state['storage']['modsleft'] as $key => $mod) {  
           if ($mod == $module) {  
             unset($form_state['storage']['modsleft'][$key]);  
85            }            }
86          }          }
87          unset($form_state['storage']['install_step']);        }
88          $continue = TRUE;        if ($continue2) {
89          break;          $data['module'] = next($data['modsleft']);
90            $module = $data['module'];
91            if (!$module) {
92              unset($_SESSION['awesome install']);
93              return;
94            }
95            $data['step'] = reset($steps);
96          }
97      }      }
98    }    }
99      $_SESSION['awesome install'] = $data;
100  }  }
101    
102  function awesome_install_find_settings_form($module) {  function awesome_install_find_settings_form($module) {

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

  ViewVC Help
Powered by ViewVC 1.1.2