[development] Module updater module

Sammy Spets sammys-drupal at synerger.com
Wed Nov 22 09:55:53 UTC 2006


Nice module Angela!!! :)

I've gone and changed it around a little. Might not be what you want, 
but my itch has been scratched.

It now presents a list of modules that aren't 5.0 compatible yet (marked 
by the lack of a .info file). The modules can be anywhere in:
 /modules
 /sites/all/modules
 /sites/<whatever is being used>/modules

It presents a list of those modules and then reads the code from that
module file. Nothing else has changed. It still displays the code on the
results page and you need to copy it.

I'm thinking of making a downloadable copy of the resulting module file 
as well.

Please find the patch attached.

Cheers,

-- 
Sammy Spets
Synerger Pty Ltd
http://synerger.com

On 22-Nov-06 01:40, Angela Byron wrote:
> I set out to port my 3rd or 4th module to 5.x today, and started  
> doing calculations about time/effort spent per module, and also  
> started musing about the fact that I needed some way to flex my regex  
> muscles, so I came up with this:
> 
> http://cvs.drupal.org/viewcvs/drupal/contributions/sandbox/webchick/ 
> module_updater/
> 
> it's in my sandbox rather than an actual project, because about 10  
> hours into it when I only had a couple functions written, it started  
> to get really daunting and I wasn't sure if I really wanted to  
> continue working on it or not. ;P I'll see again in the morning. ;)
> 
> In the meantime:
> 
> - It generates an .info file and removes the description from  
> hook_help (or hook_help altogether if that's all that was in it)
> - It adds a menu item for any hook_settings() and changes the return  
> $form to return system_settings_form($form)
> - It replaces user_mail with drupal_mail() and generates a unique  
> $mailkey for each instance.
> - It replaces module_exist with module_exists() ;)
> - It replaces user_mail_wrapper with drupal_mail_wrapper. :P
> - It also provides documentation for certain changes so that people  
> can alter the "guess" behaviour that the script has to do (ex:  
> dependencies in .info files)
> - It drupal_set_message()s any changes that it made so that you can  
> go back and correct the work if necessary.
> 
> It is also probably horribly buggy and has a very long way to go  
> before all of the items at http://drupal.org/node/64279 are covered  
> (I've created skeleton functions in the .inc file for all transition  
> issues). The next ones I'll probably focus on are the t() changes,  
> the hook_view changes, and the hook_link changes, as those have all  
> bit me before.
> 
> But anyway, if someone wants to take a look, it's there. Or, if  
> someone wants to work on it with me for some reason, let me know!  
> Thanks to eaton, merlinofchaos, dopry and whoever else was in #drupal  
> at the time who helped me brainstorm about this. :)
> 
> -Angie
> 
-------------- next part --------------
Index: module_updater.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/sandbox/webchick/module_updater/module_updater.module,v
retrieving revision 1.5
diff -u -p -r1.5 module_updater.module
--- module_updater.module	22 Nov 2006 07:19:34 -0000	1.5
+++ module_updater.module	22 Nov 2006 09:50:42 -0000
@@ -34,27 +34,40 @@ function module_updater_perm() {
 }
 
 /**
+ * Returns a list of modules that don't have .info files. The returned
+ * array has module_name => (object) where the object contains name, filename
+ * and basename members.
+ */
+function module_updater_get_module_list() {
+  $files = drupal_system_listing('\.module$', 'modules', 'name', 0);
+
+  foreach ($files as $filename => $file) {
+    $info = _module_parse_info_file(dirname($file->filename) .'/'. $file->name .'.info');
+    if (!empty($info)) {
+      unset($files[$filename]);
+    }
+  }
+
+  return $files;
+}
+
+/**
  * The module updater form.
  */
 function module_updater_form($form_values = NULL) {
   $form['#multistep'] = TRUE;
   $form['#redirect'] = FALSE;
+  
+  $modules = module_updater_get_module_list();
 
   if ($form_values === NULL) {
     // Display the form.
     $form['module_name'] = array(
-      '#type' => 'textfield',
+      '#type' => 'select',
       '#title' => t('Module name'),
-      '#description' => t('Enter the name of the module you wish to convert.'),
-      '#required' => TRUE,
-    );
-    $form['module_code'] = array(
-      '#type' => 'textarea',
-      '#title' => t('Module code'),
-      '#rows' => 10,
-      '#cols' => 20,
-      '#description' => t("Copy and paste the code from the module's .module file here."),
+      '#description' => t('Select the name of the module you wish to convert.'),
       '#required' => TRUE,
+      '#options' => array_merge(array(0 => '--'), drupal_map_assoc(array_keys($modules)))
     );
     $form['version'] = array(
       '#type' => 'select',
@@ -73,7 +86,7 @@ function module_updater_form($form_value
     $form['results'] = array(
       '#type' => 'item',
       '#title' => t('The results'),
-      '#value' => module_updater_results($form_values),
+      '#value' => module_updater_results($form_values, $modules),
     );
   }
 
@@ -83,11 +96,17 @@ function module_updater_form($form_value
 /**
  * Submit handler for module updater form.
  */
-function module_updater_results($form_values) {
+function module_updater_results(&$form_values, &$modules) {
   // Initialize variables.
   $output = '';
   $module_name = drupal_strtolower($form_values['module_name']);
-  $module_code = $form_values['module_code'];
+  $module_filename = $modules[$module_name]->filename;
+  if (($module_code = file_get_contents($module_filename)) === FALSE) {
+    $messages = array(
+      t('Unable to open module file: !filename', array('!filename' => $module_filename))
+    );
+    return theme('module_updater_code', "$module_name.module", $messages, '');
+  }
   $version = $form_values['version'];
 
   // Include the appropriate functions for the selected Drupal version.


More information about the development mailing list