data); } } $project_name = !empty($project['project']) ? $project['project'] : cvs_deploy_get_project_name($project); if (isset($available[$project_name]['releases'])) { foreach ($available[$project_name]['releases'] as $release) { if (isset($release['tag']) && $release['tag'] == 'HEAD') { $version = $release['version']; break; } } } } } /** * Private helper to alter the 'project' of a module based on what directory * in the CVS repository the module has been checked out from. */ function cvs_deploy_get_project_name($project) { static $projects = array(); $module_name = $project['name']; if (empty($projects[$module_name])) { // TODO: cache this in {cache}, too? $cvs_dir = dirname($project['filename']) .'/CVS'; if (is_dir($cvs_dir)) { $repository = ''; if (file_exists($cvs_dir .'/Repository')) { $repo_file = trim(file_get_contents($cvs_dir .'/Repository')); if ($repo_file) { $parts = explode('/', $repo_file); if ($parts[0] == 'drupal') { $projects[$module_name] = $parts[0]; } else { $projects[$module_name] = $parts[2]; } } } } } return $projects[$module_name]; } /** * Recursive helper function to find the latest modification time on every * CVS/Entires file in the current directory tree. * * @param $dir * The directory to search. * @param $timestamp * The current latest modification timestamp on any CVS/Entries file. * @return * The latest mtime based on what we learned in the current directory. */ function _cvs_deploy_find_latest_update($dir, $timestamp) { if (is_dir($dir)) { $fp = opendir($dir); while (FALSE !== ($file = readdir($fp))) { if ($file == '.' || $file == '..') { continue; } if ($file == 'CVS' && is_dir("$dir/CVS")) { $entries_file = $dir .'/CVS/Entries'; if (file_exists($entries_file)) { $mtime = filemtime($entries_file); $timestamp = ($mtime > $timestamp) ? $mtime : $timestamp; } } elseif (is_dir("$dir/$file")) { $timestamp = _cvs_deploy_find_latest_update("$dir/$file", $timestamp); } } closedir($fp); } return $timestamp; } /** * Implementation of hook_form_alter(). * * Modifies the system modules page (admin/build/modules) to add * human-readable version strings for modules deployed via CVS. */ function cvs_deploy_form_alter($form_id, &$form) { if ($form_id == 'system_modules') { if (isset($form['confirm'])) { return; } $files = $form['validation_modules']['#value']; foreach ($files as $modulename => $file) { $project = array(); $project['filename'] = $file->filename; $project['name'] = $file->name; if (empty($project['project'])) { $project['project'] = cvs_deploy_get_project_name($project); } _cvs_deploy_version_alter($file->info['version'], $project); $form['version'][$modulename]['#value'] = $file->info['version']; } } }