commit cbe2196ee2fecf06eac4b2d4a9b77704f7d0121d Author: Erik Stielstra Date: Fri Jan 18 10:46:16 2013 +0100 #15 diff --git a/core/includes/project.inc b/core/includes/project.inc deleted file mode 100644 index a4ed278..0000000 --- a/core/includes/project.inc +++ /dev/null @@ -1,331 +0,0 @@ -get('project_list')) { - $projects = $cached->data; - } - else { - $module_data = system_rebuild_module_data(); - $theme_data = system_rebuild_theme_data(); - project_process_info_list($projects, $module_data, 'module', TRUE); - project_process_info_list($projects, $theme_data, 'theme', TRUE); - project_process_info_list($projects, $module_data, 'module', FALSE); - project_process_info_list($projects, $theme_data, 'theme', FALSE); - // Allow other modules to alter projects before fetching and comparing. - drupal_alter('project_list', $projects); - // Cache the site's project data for at most 1 hour. - cache()->set('project_list', $projects, REQUEST_TIME + 3600); - } - return $projects; -} - -/** - * Populates an array of project data. - * - * This iterates over a list of the installed modules or themes and groups them - * by project and status. A few parts of this function assume that enabled - * modules and themes are always processed first, and if disabled modules or - * themes are being processed (there is a setting to control if disabled code - * should be included or not in the 'Available updates' report), those are only - * processed after $projects has been populated with information about the - * enabled code. Modules and themes set as hidden are always ignored. This - * function also records the latest change time on the .info files for each - * module or theme, which is important data which is used when deciding if the - * cached available update data should be invalidated. - * - * @param $projects - * Reference to the array of project data of what's installed on this site. - * @param $list - * Array of data to process to add the relevant info to the $projects array. - * @param $project_type - * The kind of data in the list. Can be 'module' or 'theme'. - * @param $status - * Boolean that controls what status (enabled or disabled) to process out of - * the $list and add to the $projects array. - * - * @see update_get_projects() - */ -function project_process_info_list(&$projects, $list, $project_type, $status) { - foreach ($list as $file) { - // A disabled base theme of an enabled sub-theme still has all of its code - // run by the sub-theme, so we include it in our "enabled" projects list. - if ($status && !$file->status && !empty($file->sub_themes)) { - foreach ($file->sub_themes as $key => $name) { - // Build a list of enabled sub-themes. - if ($list[$key]->status) { - $file->enabled_sub_themes[$key] = $name; - } - } - // If there are no enabled subthemes, we should ignore this base theme - // for the enabled case. If the site is trying to display disabled - // themes, we'll catch it then. - if (empty($file->enabled_sub_themes)) { - continue; - } - } - // Otherwise, just add projects of the proper status to our list. - elseif ($file->status != $status) { - continue; - } - - - // Skip if the .info file is broken. - if (empty($file->info)) { - continue; - } - - // Skip if it's a hidden module or theme. - if (!empty($file->info['hidden'])) { - continue; - } - - // If the .info doesn't define the 'project', try to figure it out. - if (!isset($file->info['project'])) { - $file->info['project'] = project_file_get_name($file); - } - - // If we still don't know the 'project', give up. - if (empty($file->info['project'])) { - continue; - } - - // If we don't already know it, grab the change time on the .info file - // itself. Note: we need to use the ctime, not the mtime (modification - // time) since many (all?) tar implementations will go out of their way to - // set the mtime on the files it creates to the timestamps recorded in the - // tarball. We want to see the last time the file was changed on disk, - // which is left alone by tar and correctly set to the time the .info file - // was unpacked. - if (!isset($file->info['_info_file_ctime'])) { - $info_filename = dirname($file->uri) . '/' . $file->name . '.info'; - $file->info['_info_file_ctime'] = filectime($info_filename); - } - - if (!isset($file->info['datestamp'])) { - $file->info['datestamp'] = 0; - } - - $project_name = $file->info['project']; - - // Figure out what project type we're going to use to display this module - // or theme. If the project name is 'drupal', we don't want it to show up - // under the usual "Modules" section, we put it at a special "Drupal Core" - // section at the top of the report. - if ($project_name == 'drupal') { - $project_display_type = 'core'; - } - else { - $project_display_type = $project_type; - } - if (empty($status) && empty($file->enabled_sub_themes)) { - // If we're processing disabled modules or themes, append a suffix. - // However, we don't do this to a a base theme with enabled - // subthemes, since we treat that case as if it is enabled. - $project_display_type .= '-disabled'; - } - // Add a list of sub-themes that "depend on" the project and a list of base - // themes that are "required by" the project. - if ($project_name == 'drupal') { - // Drupal core is always required, so this extra info would be noise. - $sub_themes = array(); - $base_themes = array(); - } - else { - // Add list of enabled sub-themes. - $sub_themes = !empty($file->enabled_sub_themes) ? $file->enabled_sub_themes : array(); - // Add list of base themes. - $base_themes = !empty($file->base_themes) ? $file->base_themes : array(); - } - if (!isset($projects[$project_name])) { - // Only process this if we haven't done this project, since a single - // project can have multiple modules or themes. - $projects[$project_name] = array( - 'name' => $project_name, - // Only save attributes from the .info file we care about so we do not - // bloat our RAM usage needlessly. - 'info' => project_filter_info($file->info), - 'datestamp' => $file->info['datestamp'], - 'includes' => array($file->name => $file->info['name']), - 'project_type' => $project_display_type, - 'project_status' => $status, - 'sub_themes' => $sub_themes, - 'base_themes' => $base_themes, - ); - } - elseif ($projects[$project_name]['project_type'] == $project_display_type) { - // Only add the file we're processing to the 'includes' array for this - // project if it is of the same type and status (which is encoded in the - // $project_display_type). This prevents listing all the disabled - // modules included with an enabled project if we happen to be checking - // for disabled modules, too. - $projects[$project_name]['includes'][$file->name] = $file->info['name']; - $projects[$project_name]['info']['_info_file_ctime'] = max($projects[$project_name]['info']['_info_file_ctime'], $file->info['_info_file_ctime']); - $projects[$project_name]['datestamp'] = max($projects[$project_name]['datestamp'], $file->info['datestamp']); - if (!empty($sub_themes)) { - $projects[$project_name]['sub_themes'] += $sub_themes; - } - if (!empty($base_themes)) { - $projects[$project_name]['base_themes'] += $base_themes; - } - } - elseif (empty($status)) { - // If we have a project_name that matches, but the project_display_type - // does not, it means we're processing a disabled module or theme that - // belongs to a project that has some enabled code. In this case, we add - // the disabled thing into a separate array for separate display. - $projects[$project_name]['disabled'][$file->name] = $file->info['name']; - } - } -} - -/** - * Determines version and type information for currently installed projects. - * - * Processes the list of projects on the system to figure out the currently - * installed versions, and other information that is required before we can - * compare against the available releases to produce the status report. - * - * @param $projects - * Array of project information from project_list(). - */ -function project_process_version_info(&$projects) { - foreach ($projects as $key => $project) { - // Assume an official release until we see otherwise. - $install_type = 'official'; - - $info = $project['info']; - - if (isset($info['version'])) { - // Check for development snapshots - if (preg_match('@(dev|HEAD)@', $info['version'])) { - $install_type = 'dev'; - } - - // Figure out what the currently installed major version is. We need - // to handle both contribution (e.g. "5.x-1.3", major = 1) and core - // (e.g. "5.1", major = 5) version strings. - $matches = array(); - if (preg_match('/^(\d+\.x-)?(\d+)\..*$/', $info['version'], $matches)) { - $info['major'] = $matches[2]; - } - elseif (!isset($info['major'])) { - // This would only happen for version strings that don't follow the - // drupal.org convention. We let contribs define "major" in their - // .info in this case, and only if that's missing would we hit this. - $info['major'] = -1; - } - } - else { - // No version info available at all. - $install_type = 'unknown'; - $info['version'] = t('Unknown'); - $info['major'] = -1; - } - - // Finally, save the results we care about into the $projects array. - $projects[$key]['existing_version'] = $info['version']; - $projects[$key]['existing_major'] = $info['major']; - $projects[$key]['install_type'] = $install_type; - } -} - -/** - * Determines what project a given file object belongs to. - * - * @param $file - * A file object as returned by system_get_files_database(). - * - * @return - * The canonical project short name. - * - * @see system_get_files_database() - */ -function project_file_get_name($file) { - $project_name = ''; - if (isset($file->info['project'])) { - $project_name = $file->info['project']; - } - elseif (isset($file->info['package']) && (strpos($file->info['package'], 'Core') === 0)) { - $project_name = 'drupal'; - } - return $project_name; -} - -/** - * Filters the project .info data to only save attributes we need. - * - * The saved attributes will be a predefined list plus all the attributes - * whose name start with 'project'. - * - * @param array $info - * Array of .info file data as returned by drupal_parse_info_file(). - * - * @return - * Array of .info file data we need for the project list. - * - * @see project_process_info_list() - */ -function project_filter_info($info) { - $whitelist = array( - '_info_file_ctime', - 'datestamp', - 'major', - 'name', - 'package', - 'version', - ); - $return = array(); - foreach ($info as $name => $data) { - if (in_array($name, $whitelist) || strpos($name, 'project') === 0) { - $return[$name] = $data; - } - } - return $return; -} diff --git a/core/lib/Drupal/Core/Project/Project.php b/core/lib/Drupal/Core/Project/Project.php new file mode 100644 index 0000000..3267e59 --- /dev/null +++ b/core/lib/Drupal/Core/Project/Project.php @@ -0,0 +1,94 @@ +project_type = $type; + $this->name = $name; + } + + /** + * Gets human readable project name. + * + * @return string + * Human readable project name. Falls back to machine name if not available. + */ + public function getProjectName() { + return isset($this->info['name']) ? $this->project->info['name'] : $this->name; + } +} \ No newline at end of file diff --git a/core/lib/Drupal/Core/Project/ProjectBuilder.php b/core/lib/Drupal/Core/Project/ProjectBuilder.php new file mode 100644 index 0000000..9d22e25 --- /dev/null +++ b/core/lib/Drupal/Core/Project/ProjectBuilder.php @@ -0,0 +1,303 @@ +parse($module_data, 'module', TRUE); + if ($this->include_disabled) { + $this->parse($module_data, 'module', FALSE); + } + } + + /** + * Parses theme .info files data to collect project information. + */ + public function parseThemes() { + $theme_data = system_rebuild_theme_data(); + $this->parse($theme_data, 'theme', TRUE); + if ($this->include_disabled) { + $this->parse($theme_data, 'theme', FALSE); + } + } + + /** + * Returns all build projects. + * + * @return + * Array of projects keyed by project machine name. + */ + public function getAllProjects() { + return $this->projects; + } + + /** + * Returns a single project object. + * + * @return Drupal\Core\Project\Project + * The selected project or NULL if not found. + */ + public function getProject($name) { + if (isset($this->projects[$name])) { + return $this->projects[$name]; + } + } + + /** + * Stores a project in the internal project array. + * + * @param $project + * Project object. + */ + protected function setProject($project) { + $this->projects[$project->name] = $project; + } + + /** + * Sets a flag to include disable modules or themes when parsing. + */ + public function includeDisabled($include_disabled) { + $this->include_disabled = $include_disabled; + } + + /** + * Parse project list and retrieve project data. + * + * This iterates over a list of the installed modules or themes and groups them + * by project and status. A few parts of this function assume that enabled + * modules and themes are always processed first, and if disabled modules or + * themes are being processed (there is a setting to control if disabled code + * should be included or not in the 'Available updates' report), those are only + * processed after $projects has been populated with information about the + * enabled code. Modules and themes set as hidden are always ignored. This + * function also records the latest change time on the .info files for each + * module or theme, which is important data which is used when deciding if the + * cached available update data should be invalidated. + * + * @param $list + * Array of data to process to add the relevant info to the $projects array. + * @param $project_type + * The kind of data in the list. Can be 'module' or 'theme'. + * @param $status + * Boolean that controls what status (enabled or disabled) to process out of + * the $list and add to the $projects array. + */ + public function parse($list, $project_type, $status) { + foreach ($list as $file) { + // A disabled base theme of an enabled sub-theme still has all of its code + // run by the sub-theme, so we include it in our "enabled" projects list. + if ($status && !$file->status && !empty($file->sub_themes)) { + foreach ($file->sub_themes as $key => $name) { + // Build a list of enabled sub-themes. + if ($list[$key]->status) { + $file->enabled_sub_themes[$key] = $name; + } + } + // If there are no enabled subthemes, we should ignore this base theme + // for the enabled case. If the site is trying to display disabled + // themes, we'll catch it then. + if (empty($file->enabled_sub_themes)) { + continue; + } + } + // Otherwise, just add projects of the proper status to our list. + elseif ($file->status != $status) { + continue; + } + + // Skip if the .info file is broken. + if (empty($file->info)) { + continue; + } + + // Skip if it's a hidden module or theme. + if (!empty($file->info['hidden'])) { + continue; + } + + // If the .info doesn't define the 'project', try to figure it out. + if (!isset($file->info['project'])) { + $file->info['project'] = $this->fileGetName($file); + } + + // If we still don't know the 'project', give up. + if (empty($file->info['project'])) { + continue; + } + + // If we don't already know it, grab the change time on the .info file + // itself. Note: we need to use the ctime, not the mtime (modification + // time) since many (all?) tar implementations will go out of their way to + // set the mtime on the files it creates to the timestamps recorded in the + // tarball. We want to see the last time the file was changed on disk, + // which is left alone by tar and correctly set to the time the .info file + // was unpacked. + if (!isset($file->info['_info_file_ctime'])) { + $info_filename = dirname($file->uri) . '/' . $file->name . '.info'; + $file->info['_info_file_ctime'] = filectime($info_filename); + } + + if (!isset($file->info['datestamp'])) { + $file->info['datestamp'] = 0; + } + + $project_name = $file->info['project']; + + // Figure out what project type we're going to use to display this module + // or theme. If the project name is 'drupal', we don't want it to show up + // under the usual "Modules" section, we put it at a special "Drupal Core" + // section at the top of the report. + if ($project_name == 'drupal') { + $project_display_type = 'core'; + } + else { + $project_display_type = $project_type; + } + if (empty($status) && empty($file->enabled_sub_themes)) { + // If we're processing disabled modules or themes, append a suffix. + // However, we don't do this to a a base theme with enabled + // subthemes, since we treat that case as if it is enabled. + $project_display_type .= '-disabled'; + } + // Add a list of sub-themes that "depend on" the project and a list of base + // themes that are "required by" the project. + if ($project_name == 'drupal') { + // Drupal core is always required, so this extra info would be noise. + $sub_themes = array(); + $base_themes = array(); + } + else { + // Add list of enabled sub-themes. + $sub_themes = !empty($file->enabled_sub_themes) ? $file->enabled_sub_themes : array(); + // Add list of base themes. + $base_themes = !empty($file->base_themes) ? $file->base_themes : array(); + } + if (!$project = $this->getProject($project_name)) { + // Only process this if we haven't done this project, since a single + // project can have multiple modules or themes. + // @todo dynamically define a class. + $project = new $this->project_class($project_name, $project_display_type); + // Only save attributes from the .info file we care about so we do not + // bloat our RAM usage needlessly. + $project->info = $this->filterInfo($file->info); + $project->datestamp = $file->info['datestamp']; + $project->includes = array($file->name => $file->info['name']); + $project->project_status = $status; + $project->sub_themes = $sub_themes; + $project->base_themes = $base_themes; + } + elseif ($project->project_type == $project_display_type) { + // Only add the file we're processing to the 'includes' array for this + // project if it is of the same type and status (which is encoded in the + // $project_display_type). This prevents listing all the disabled + // modules included with an enabled project if we happen to be checking + // for disabled modules, too. + $project->includes[$file->name] = $file->info['name']; + $project->info['_info_file_ctime'] = max($this->getProject($project_name)->info['_info_file_ctime'], $file->info['_info_file_ctime']); + $project->datestamp = max($project->datestamp, $file->info['datestamp']); + if (!empty($sub_themes)) { + $project->sub_themes += $sub_themes; + } + if (!empty($base_themes)) { + $project->base_themes += $base_themes; + } + } + elseif (empty($status)) { + // If we have a project_name that matches, but the project_display_type + // does not, it means we're processing a disabled module or theme that + // belongs to a project that has some enabled code. In this case, we add + // the disabled thing into a separate array for separate display. + $project->disabled[$file->name] = $file->info['name']; + } + + // Store the project. + if (!empty($project)) { + $this->setProject($project); + } + } + } + + /** + * Determines what project a given file object belongs to. + * + * @param $file + * A file object as returned by system_get_files_database(). + * + * @return + * The canonical project short name. + */ + protected function fileGetName($file) { + $project_name = ''; + if (isset($file->info['project'])) { + $project_name = $file->info['project']; + } + elseif (isset($file->info['package']) && (strpos($file->info['package'], 'Core') === 0)) { + $project_name = 'drupal'; + } + return $project_name; + } + + /** + * Filters the project .info data to only save attributes we need. + * + * The saved attributes will be a predefined list plus all the attributes + * whose name start with 'project'. + * + * @param array $info + * Array of .info file data as returned by drupal_parse_info_file(). + * + * @return + * Array of .info file data we need for the project list. + */ + // @todo Reduce this to an acceptable minimum. + protected function filterInfo($info) { + $return = array(); + $whitelist = array( + '_info_file_ctime', + 'datestamp', + 'major', + 'name', + 'package', + 'version', + ); + + foreach ($info as $name => $data) { + if (in_array($name, $whitelist) || strpos($name, 'project') === 0) { + $return[$name] = $data; + } + } + return $return; + } +} diff --git a/core/modules/locale/lib/Drupal/locale/Project/LocaleProjectBuilder.php b/core/modules/locale/lib/Drupal/locale/Project/LocaleProjectBuilder.php new file mode 100644 index 0000000..cf9b8dd --- /dev/null +++ b/core/modules/locale/lib/Drupal/locale/Project/LocaleProjectBuilder.php @@ -0,0 +1,36 @@ + $data) { + if (in_array($name, $whitelist)) { + $return[$name] = $data; + } + } + return $return; + } +} diff --git a/core/modules/locale/locale.compare.inc b/core/modules/locale/locale.compare.inc index 4be14d5..feb2a6f 100644 --- a/core/modules/locale/locale.compare.inc +++ b/core/modules/locale/locale.compare.inc @@ -5,10 +5,8 @@ * The API for comparing project translation status with available translation. */ -// Include project API. -require_once DRUPAL_ROOT . '/core/includes/project.inc'; - use Drupal\Core\Cache; +use Drupal\locale\Project\LocaleProjectBuilder; /** * Load the common translation API. @@ -62,10 +60,10 @@ function locale_translation_build_projects() { // If project is a dev release, or core, find the latest available release. $project_updates = module_exists('update') ? update_get_available(TRUE) : array(); - foreach ($projects as $name => $data) { + foreach ($projects as $name => $project) { if (isset($project_updates[$name]['releases']) && $project_updates[$name]['project_status'] != 'not-fetched') { // Find out if a dev version is installed. - if (preg_match("/^[0-9]+\.x-([0-9]+)\..*-dev$/", $data['info']['version'], $matches)) { + if (preg_match("/^[0-9]+\.x-([0-9]+)\..*-dev$/", $project->info['version'], $matches)) { // Find a suitable release to use as alternative translation. foreach ($project_updates[$name]['releases'] as $project_release) { // The first release with the same major release number which is not a @@ -85,22 +83,20 @@ function locale_translation_build_projects() { } if (!empty($release['version'])) { - $data['info']['version'] = $release['version']; + $project->info['version'] = $release['version']; } unset($release); } // For every project store information. - $data += array( - 'version' => isset($data['info']['version']) ? $data['info']['version'] : '', - 'core' => isset($data['info']['core']) ? $data['info']['core'] : DRUPAL_CORE_COMPATIBILITY, + $project->version = isset($project->info['version']) ? $project->info['version'] : ''; + $project->core = isset($project->info['core']) ? $project->info['core'] : DRUPAL_CORE_COMPATIBILITY; // A project can provide the path and filename pattern to download the // gettext file. Use the default if not. - 'server_pattern' => isset($data['info']['project translation server pattern']) && $data['info']['project translation server pattern'] ? $data['info']['project translation server pattern'] : $default_server['pattern'], - 'status' => !empty($data['project_status']) ? 1 : 0, - ); - $project = (object) $data; + $project->server_pattern = isset($project->info['project translation server pattern']) && $project->info['project translation server pattern'] ? $project->info['project translation server pattern'] : $default_server['pattern']; + $project->status = !empty($project->project_status) ? 1 : 0; + $projects[$name] = $project; // Create or update the project record. @@ -135,10 +131,14 @@ function locale_translation_project_list() { $projects = &drupal_static(__FUNCTION__, array()); if (empty($projects)) { $include_disabled = config('locale.settings')->get('translation.check_disabled_modules'); - $projects = array_filter(project_list(), function ($project) use ($include_disabled) { - return ($include_disabled || !empty($project['project_status'])) && - (!isset($project['info']['project translation server pattern']) || $project['info']['project translation server pattern']); - }); + + $builder = new LocaleProjectBuilder(); + $builder->parseModules($include_disabled); + $builder->parseThemes($include_disabled); + $projects = $builder->getAllProjects(); + + // Allow other modules to alter projects before fetching and comparing. + drupal_alter('locale_project_list', $projects); } return $projects; } diff --git a/core/modules/update/lib/Drupal/update/Project/UpdateProject.php b/core/modules/update/lib/Drupal/update/Project/UpdateProject.php new file mode 100644 index 0000000..4302ae4 --- /dev/null +++ b/core/modules/update/lib/Drupal/update/Project/UpdateProject.php @@ -0,0 +1,37 @@ +processVersionInfo(); + } + + /** + * Overrides Drupal\Core\Project\ProjectBuilder::parseThemes(). + */ + public function parseThemes() { + parent::parseThemes(); + $this->processVersionInfo(); + } + + /** + * Returns all build projects as arrays instead of objecs. + * + * @todo Remove this function when Update module is converted to use project + * objects instead of arrays. + * + * @return + * Array of projects keyed by project machine name. + */ + public function getAllProjectsAsArray() { + $result = array(); + foreach ($this->projects as $name => $project) { + $result[$name] = (array) $project; + } + return $result; + } + + /** + * Determines version and type information for currently installed projects. + * + * Processes the list of projects on the system to figure out the currently + * installed versions, and other information that is required before we can + * compare against the available releases to produce the status report. + */ + protected function processVersionInfo() { + foreach ($this->projects as $key => $project) { + // Assume an official release until we see otherwise. + $install_type = 'official'; + + $info = $project->info; + + if (isset($info['version'])) { + // Check for development snapshots + if (preg_match('@(dev|HEAD)@', $info['version'])) { + $install_type = 'dev'; + } + + // Figure out what the currently installed major version is. We need + // to handle both contribution (e.g. "5.x-1.3", major = 1) and core + // (e.g. "5.1", major = 5) version strings. + $matches = array(); + if (preg_match('/^(\d+\.x-)?(\d+)\..*$/', $info['version'], $matches)) { + $info['major'] = $matches[2]; + } + elseif (!isset($info['major'])) { + // This would only happen for version strings that don't follow the + // drupal.org convention. We let contribs define "major" in their + // .info in this case, and only if that's missing would we hit this. + $info['major'] = -1; + } + } + else { + // No version info available at all. + $install_type = 'unknown'; + $info['version'] = t('Unknown'); + $info['major'] = -1; + } + + // Finally, save the results we care about into the projects array. + $this->projects[$key]->existing_version = $info['version']; + $this->projects[$key]->existing_major = $info['major']; + $this->projects[$key]->install_type = $install_type; + } + } + + /** + * Overrides Drupal\Core\Project\ProjectBuilder::filterInfo(). + */ + // @todo Make this more specific for Update module requirements. + protected function filterInfo($info) { + $return = array(); + $whitelist = array( + '_info_file_ctime', + 'datestamp', + 'major', + 'name', + 'package', + 'version', + ); + + foreach ($info as $name => $data) { + if (in_array($name, $whitelist) || strpos($name, 'project') === 0) { + $return[$name] = $data; + } + } + return $return; + } +} diff --git a/core/modules/update/update.compare.inc b/core/modules/update/update.compare.inc index bcfc078..f858b28 100644 --- a/core/modules/update/update.compare.inc +++ b/core/modules/update/update.compare.inc @@ -5,8 +5,7 @@ * Code required only when comparing available updates to existing data. */ -// Include project API. -require_once DRUPAL_ROOT . '/core/includes/project.inc'; +use Drupal\update\Project\UpdateProjectBuilder; /** * Fetches an array of installed and enabled projects. @@ -16,256 +15,30 @@ * * @return * An associative array of currently enabled projects keyed by the - * machine-readable project short name as defined by project_list(). + * machine-readable project name. * - * @see project_process_version_info() * @see update_calculate_project_data() * @see update_project_cache() */ function update_get_projects() { $projects = &drupal_static(__FUNCTION__, array()); if (empty($projects)) { - $include_disabled = config('update.settings')->get('check.disabled_extensions'); - $projects = array_filter(project_list(), function ($project) use ($include_disabled) { - return ($include_disabled || !empty($project['project_status'])) && - (!isset($project['info']['project status url']) || $project['info']['project status url']); - }); - } - return $projects; -} - -/** - * Populates an array of project data. - * - * This iterates over a list of the installed modules or themes and groups them - * by project and status. A few parts of this function assume that enabled - * modules and themes are always processed first, and if disabled modules or - * themes are being processed (there is a setting to control if disabled code - * should be included or not in the 'Available updates' report), those are only - * processed after $projects has been populated with information about the - * enabled code. Modules and themes set as hidden are always ignored. This - * function also records the latest change time on the .info files for each - * module or theme, which is important data which is used when deciding if the - * cached available update data should be invalidated. - * - * @param $projects - * Reference to the array of project data of what's installed on this site. - * @param $list - * Array of data to process to add the relevant info to the $projects array. - * @param $project_type - * The kind of data in the list. Can be 'module' or 'theme'. - * @param $status - * Boolean that controls what status (enabled or disabled) to process out of - * the $list and add to the $projects array. - * @param $additional_whitelist - * (optional) Array of additional elements to be collected from the .info - * file. Defaults to array(). - * - * @see update_get_projects() - */ -function update_process_info_list(&$projects, $list, $project_type, $status, $additional_whitelist = array()) { - foreach ($list as $file) { - // A disabled base theme of an enabled sub-theme still has all of its code - // run by the sub-theme, so we include it in our "enabled" projects list. - if ($status && !$file->status && !empty($file->sub_themes)) { - foreach ($file->sub_themes as $key => $name) { - // Build a list of enabled sub-themes. - if ($list[$key]->status) { - $file->enabled_sub_themes[$key] = $name; - } - } - // If there are no enabled subthemes, we should ignore this base theme - // for the enabled case. If the site is trying to display disabled - // themes, we'll catch it then. - if (empty($file->enabled_sub_themes)) { - continue; - } - } - // Otherwise, just add projects of the proper status to our list. - elseif ($file->status != $status) { - continue; - } - - // Skip if the .info file is broken. - if (empty($file->info)) { - continue; - } - - // Skip if it's a hidden module or theme. - if (!empty($file->info['hidden'])) { - continue; - } - - // If the .info doesn't define the 'project', try to figure it out. - if (!isset($file->info['project'])) { - $file->info['project'] = update_get_project_name($file); - } - - // If we still don't know the 'project', give up. - if (empty($file->info['project'])) { - continue; - } - - // If we don't already know it, grab the change time on the .info file - // itself. Note: we need to use the ctime, not the mtime (modification - // time) since many (all?) tar implementations will go out of their way to - // set the mtime on the files it creates to the timestamps recorded in the - // tarball. We want to see the last time the file was changed on disk, - // which is left alone by tar and correctly set to the time the .info file - // was unpacked. - if (!isset($file->info['_info_file_ctime'])) { - $info_filename = dirname($file->uri) . '/' . $file->name . '.info'; - $file->info['_info_file_ctime'] = filectime($info_filename); - } - - if (!isset($file->info['datestamp'])) { - $file->info['datestamp'] = 0; - } - - $project_name = $file->info['project']; - - // Figure out what project type we're going to use to display this module - // or theme. If the project name is 'drupal', we don't want it to show up - // under the usual "Modules" section, we put it at a special "Drupal Core" - // section at the top of the report. - if ($project_name == 'drupal') { - $project_display_type = 'core'; - } - else { - $project_display_type = $project_type; - } - if (empty($status) && empty($file->enabled_sub_themes)) { - // If we're processing disabled modules or themes, append a suffix. - // However, we don't do this to a a base theme with enabled - // subthemes, since we treat that case as if it is enabled. - $project_display_type .= '-disabled'; + // Retrieve the projects from cache, if present. + $projects = update_project_cache('update_project_projects'); + if (empty($projects)) { + $include_disabled = config('update.settings')->get('check.disabled_extensions'); + $builder = new UpdateProjectBuilder(); + $builder->parseModules($include_disabled); + $builder->parseThemes($include_disabled); + $projects = $builder->getAllProjectsAsArray(); + + // Allow other modules to alter projects before fetching and comparing. + drupal_alter('update_projects', $projects); + // Cache the site's project data for at most 1 hour. + _update_cache_set('update_project_projects', $projects, REQUEST_TIME + 3600); } - // Add a list of sub-themes that "depend on" the project and a list of base - // themes that are "required by" the project. - if ($project_name == 'drupal') { - // Drupal core is always required, so this extra info would be noise. - $sub_themes = array(); - $base_themes = array(); - } - else { - // Add list of enabled sub-themes. - $sub_themes = !empty($file->enabled_sub_themes) ? $file->enabled_sub_themes : array(); - // Add list of base themes. - $base_themes = !empty($file->base_themes) ? $file->base_themes : array(); - } - if (!isset($projects[$project_name])) { - // Only process this if we haven't done this project, since a single - // project can have multiple modules or themes. - $projects[$project_name] = array( - 'name' => $project_name, - // Only save attributes from the .info file we care about so we do not - // bloat our RAM usage needlessly. - 'info' => update_filter_project_info($file->info, $additional_whitelist), - 'datestamp' => $file->info['datestamp'], - 'includes' => array($file->name => $file->info['name']), - 'project_type' => $project_display_type, - 'project_status' => $status, - 'sub_themes' => $sub_themes, - 'base_themes' => $base_themes, - ); - } - elseif ($projects[$project_name]['project_type'] == $project_display_type) { - // Only add the file we're processing to the 'includes' array for this - // project if it is of the same type and status (which is encoded in the - // $project_display_type). This prevents listing all the disabled - // modules included with an enabled project if we happen to be checking - // for disabled modules, too. - $projects[$project_name]['includes'][$file->name] = $file->info['name']; - $projects[$project_name]['info']['_info_file_ctime'] = max($projects[$project_name]['info']['_info_file_ctime'], $file->info['_info_file_ctime']); - $projects[$project_name]['datestamp'] = max($projects[$project_name]['datestamp'], $file->info['datestamp']); - if (!empty($sub_themes)) { - $projects[$project_name]['sub_themes'] += $sub_themes; - } - if (!empty($base_themes)) { - $projects[$project_name]['base_themes'] += $base_themes; - } - } - elseif (empty($status)) { - // If we have a project_name that matches, but the project_display_type - // does not, it means we're processing a disabled module or theme that - // belongs to a project that has some enabled code. In this case, we add - // the disabled thing into a separate array for separate display. - $projects[$project_name]['disabled'][$file->name] = $file->info['name']; - } - } -} - -/** - * Determines what project a given file object belongs to. - * - * @param $file - * A file object as returned by system_get_files_database(). - * - * @return - * The canonical project short name. - * - * @see system_get_files_database() - */ -function update_get_project_name($file) { - $project_name = ''; - if (isset($file->info['project'])) { - $project_name = $file->info['project']; - } - elseif (isset($file->filename) && (strpos($file->filename, 'core/modules') === 0)) { - $project_name = 'drupal'; - } - return $project_name; -} - -/** - * Determines version and type information for currently installed projects. - * - * Processes the list of projects on the system to figure out the currently - * installed versions, and other information that is required before we can - * compare against the available releases to produce the status report. - * - * @param $projects - * Array of project information from update_get_projects(). - */ -function update_process_project_info(&$projects) { - foreach ($projects as $key => $project) { - // Assume an official release until we see otherwise. - $install_type = 'official'; - - $info = $project['info']; - - if (isset($info['version'])) { - // Check for development snapshots - if (preg_match('@(dev|HEAD)@', $info['version'])) { - $install_type = 'dev'; - } - - // Figure out what the currently installed major version is. We need - // to handle both contribution (e.g. "5.x-1.3", major = 1) and core - // (e.g. "5.1", major = 5) version strings. - $matches = array(); - if (preg_match('/^(\d+\.x-)?(\d+)\..*$/', $info['version'], $matches)) { - $info['major'] = $matches[2]; - } - elseif (!isset($info['major'])) { - // This would only happen for version strings that don't follow the - // drupal.org convention. We let contribs define "major" in their - // .info in this case, and only if that's missing would we hit this. - $info['major'] = -1; - } - } - else { - // No version info available at all. - $install_type = 'unknown'; - $info['version'] = t('Unknown'); - $info['major'] = -1; - } - - // Finally, save the results we care about into the $projects array. - $projects[$key]['existing_version'] = $info['version']; - $projects[$key]['existing_major'] = $info['major']; - $projects[$key]['install_type'] = $install_type; } + return $projects; } /** @@ -289,7 +62,6 @@ function update_process_project_info(&$projects) { * * @see update_get_available() * @see update_get_projects() - * @see project_process_version_info() * @see update_project_cache() */ function update_calculate_project_data($available) { @@ -301,7 +73,6 @@ function update_calculate_project_data($available) { return $projects; } $projects = update_get_projects(); - project_process_version_info($projects); foreach ($projects as $project => $project_info) { if (isset($available[$project])) { update_calculate_project_update_status($projects[$project], $available[$project]);