'@name.update.inc', 'header' => 'Update functions for @title module.', 'hooks' => array( 'update_[^(]*', ), ), ); /** * @} End of "defgroup all_modules". */ /* -------------------------------------------------------------------------- */ /** * Script application. */ foreach ($config as $source => $targets) { $files = file_scan_directory('.', $source); foreach ($files as $file) { // @todo Looks like moved actions in test modules are not found. // testActionsCron fails for any reason. 06/06/2009 sun if (strpos($file->filepath, 'test') !== FALSE) { continue; } $module = preg_replace($source, '$1', $file->filename); // Skip error_test.module due to hard-coded line numbers for expected // exceptions. if ($module == 'error_test') { continue; } // Fetch the source file content. $content = file_get_contents($file->filepath); foreach ($targets as $rewrite) { $newfile = (object) array( 'filepath' => dirname($file->filepath) . '/' . strtr($rewrite['target'], array('@name' => $module)), 'filename' => strtr($rewrite['target'], array('@name' => $module)), ); // Retrieve code to move. $remove = array(); if (empty($rewrite['reorder'])) { $rewrite['hooks'] = array(implode('|', $rewrite['hooks'])); } foreach ($rewrite['hooks'] as $hook) { // Dunno why, but this only matches 1 function. Who cares, while() helps. 21/05/2009 sun $s = '@ (?:^/\*\*(?:(?!\*\*).)+?\*/\s+)? # Optional PHPDoc ^function\ ' . $module . '_(?:' . $hook . ')\(.*?\) # Function name + arguments (?:(?!^\}).)+? # Function body ^\} # Closing function body \s+ # White-space to next function @smx'; while (preg_match($s, $content, $matches) && !empty($matches[0])) { $remove[] = $matches[0]; $content = str_replace($matches[0], '', $content); } } // Continue to next rewrite target if there's nothing to rewrite. if (empty($remove)) { continue; } echo "$file->filepath => $newfile->filepath\n"; // Write new target file. $newcontent = ''; if (file_exists($newfile->filepath)) { $flags = FILE_APPEND; } else { $flags = 0; $header = ' ucfirst($module))); $newcontent = strtr($header, array('@summary' => $summary)); } $newcontent .= implode('', $remove); file_put_contents($newfile->filepath, $newcontent, $flags); // Remove code from source file. file_put_contents($file->filepath, $content); // Add target file to .info file. $infofile = dirname($file->filepath) . '/' . $module . '.info'; if (file_exists($infofile)) { $info_content = file_get_contents($infofile); if (strpos($info_content, $newfile->filename) === FALSE) { file_put_contents($infofile, 'files[] = ' . $newfile->filename . "\n", FILE_APPEND); } } // Add target file to CVS. $CVS = dirname($file->filepath) . '/CVS/Entries'; if (file_exists($CVS)) { $CVS_content = file_get_contents($CVS); if (strpos($CVS_content, $newfile->filename) === FALSE) { file_put_contents($CVS, '/' . $newfile->filename . "/0/Initial import.//\n", FILE_APPEND); } } } } }