[development] Evil hack: admin/modules without memory restrictions

Allie Micka allie at pajunas.com
Sat Jan 21 15:13:47 UTC 2006


On Jan 20, 2006, at 11:26 PM, Gerhard Killesreiter wrote:

> 1) read the module files
> 2) looking for help, init, exit hooks
> 3) write these hooks to a file
> 4) include that file
> 5) delete the file

This would actually do well in core if you could get rid of the  
intermediate file-writing step.  Why not just evaluate the $output  
after you've found the help/etc function?



> Index: modules/system.module
> ===================================================================
> RCS file: /cvs/drupal/drupal/modules/system.module,v
> retrieving revision 1.279
> diff -u -p -r1.279 system.module
> --- modules/system.module	17 Jan 2006 17:35:47 -0000	1.279
> +++ modules/system.module	21 Jan 2006 04:31:23 -0000
> @@ -898,9 +898,37 @@ function system_modules() {
>
>    ksort($files);
>
> +  $tmpdir = file_directory_temp();
> +
>    foreach ($files as $filename => $file) {
>      drupal_get_filename('module', $file->name, $file->filename);
> -    drupal_load('module', $file->name);
> +    // drupal_load('module', $file->name);
> +    if (!function_exists($file->name .'_help')) {
> +      $fp = fopen($file->filename, 'r');
> +      $help_found = FALSE;
> +      $output = "<?php\n";
> +      while (!feof($fp)) {
> +        $line = fgets($fp, 2048);
> +        if (preg_match('/^function '. $file->name .'_(help|init| 
> exit)[ (]/', $line)) {
> +          $help_found = TRUE;
> +        }
> +        if ($help_found && preg_match("/^}/", $line)) {
> +          $output .= $line;
> +          $help_found = FALSE;
> +        }
> +        if ($help_found) {
> +          $output .= $line;
> +        }
> +      }
> +      $output .= "\n";
> +      fclose($fp);
> +      $tmpfile = tempnam($tmpdir, $file->name .'.module.');
> +      $fp = fopen($tmpfile, 'w');
> +      fwrite($fp, $output);
> +      fclose($fp);
> +      include_once $tmpfile;
> +      unlink($tmpfile);
> +    }
>
>      $file->description = module_invoke($file->name, 'help', 'admin/ 
> modules#description');
>

Allie Micka
pajunas interactive, inc.
http://www.pajunas.com

scalable web hosting and open source strategies



More information about the development mailing list