'@name.build.inc', 'header' => 'Registry-type hooks for @title module.', 'hooks' => array( 'flush_caches', 'system_info_alter', 'menu', 'menu_alter', 'menu_link_alter', 'theme', 'theme_registry_alter', 'element_info', 'node_info', 'entity_info', 'field_build_modes', 'field_info', 'field_info_alter', 'field_widget_info', 'field_widget_info_alter', 'field_formatter_info', 'field_formatter_info_alter', 'action_info', 'action_info_alter', 'trigger_info', 'trigger_info_alter', // All hook_modules_* hooks are invoked in info rebuild scenarios only. 'modules_[^(]*', ), 'reorder' => TRUE, ), array( 'target' => '@name.block.inc', 'header' => 'Block hooks for @title module.', 'hooks' => array( 'block_info', 'block_info_alter', 'block_configure', 'block_save', 'block_view', 'block_view_alter', 'block_view_[^(]*_alter', ), 'reorder' => TRUE, ), array( 'target' => '@name.comment.inc', 'header' => 'Comment hooks for @title module.', 'hooks' => array( 'comment_presave', 'comment_insert', 'comment_load', 'comment_update', 'comment_delete', 'comment_view', 'comment_build_alter', 'comment_publish', 'comment_unpublish', 'comment_validate', // still existent? 12/11/2009 sun ), 'reorder' => TRUE, ), array( 'target' => '@name.taxonomy.inc', 'header' => 'Taxonomy hooks for @title module.', 'hooks' => array( 'taxonomy_vocabulary_insert', 'taxonomy_vocabulary_load', 'taxonomy_vocabulary_update', 'taxonomy_vocabulary_delete', 'taxonomy_term_insert', 'taxonomy_term_load', 'taxonomy_term_update', 'taxonomy_term_delete', ), 'reorder' => TRUE, ), array( 'target' => '@name.search.inc', 'header' => 'Search hooks for @title module.', 'hooks' => array( 'search_info', 'search_page', 'search_access', 'search_execute', 'search_admin', 'search_status', 'search_reset', 'update_index', // @todo Breaks SearchAdvancedSearchForm test. 05/06/2009 sun 'node_update_index', 'search_preprocess', 'ranking', ), 'reorder' => TRUE, ), array( 'target' => '@name.aggregator.inc', 'header' => 'Aggregator hooks for @title module.', 'hooks' => array( 'aggregator_fetch_info', 'aggregator_fetch', 'aggregator_parse_info', 'aggregator_parse', 'aggregator_process_info', 'aggregator_process', 'aggregator_remove', ), 'reorder' => TRUE, ), ); /** * @} 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->uri, '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->uri); foreach ($targets as $rewrite) { $newfile = (object) array( 'uri' => dirname($file->uri) . '/' . 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->uri => $newfile->uri\n"; // Write new target file. $newcontent = ''; if (file_exists($newfile->uri)) { $flags = FILE_APPEND; } else { $flags = 0; $header = ' ucfirst($module))); $newcontent = strtr($header, array('@summary' => $summary)); } $newcontent .= implode('', $remove); file_put_contents($newfile->uri, $newcontent, $flags); // Remove code from source file. file_put_contents($file->uri, $content); // Add target file to .info file. $infofile = dirname($file->uri) . '/' . $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->uri) . '/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); } } } } }