webmaster@1: status)) { webmaster@1: // Skip disabled modules or themes. webmaster@1: continue; webmaster@1: } webmaster@1: webmaster@1: // Skip if the .info file is broken. webmaster@1: if (empty($file->info)) { webmaster@1: continue; webmaster@1: } webmaster@1: webmaster@1: // If the .info doesn't define the 'project', try to figure it out. webmaster@1: if (!isset($file->info['project'])) { webmaster@1: $file->info['project'] = update_get_project_name($file); webmaster@1: } webmaster@1: webmaster@1: // If we still don't know the 'project', give up. webmaster@1: if (empty($file->info['project'])) { webmaster@1: continue; webmaster@1: } webmaster@1: webmaster@1: // If we don't already know it, grab the change time on the .info file webmaster@1: // itself. Note: we need to use the ctime, not the mtime (modification webmaster@1: // time) since many (all?) tar implementations will go out of their way to webmaster@1: // set the mtime on the files it creates to the timestamps recorded in the webmaster@1: // tarball. We want to see the last time the file was changed on disk, webmaster@1: // which is left alone by tar and correctly set to the time the .info file webmaster@1: // was unpacked. webmaster@1: if (!isset($file->info['_info_file_ctime'])) { webmaster@1: $info_filename = dirname($file->filename) .'/'. $file->name .'.info'; webmaster@1: $file->info['_info_file_ctime'] = filectime($info_filename); webmaster@1: } webmaster@1: webmaster@1: $project_name = $file->info['project']; webmaster@1: if (!isset($projects[$project_name])) { webmaster@1: // Only process this if we haven't done this project, since a single webmaster@1: // project can have multiple modules or themes. webmaster@1: $projects[$project_name] = array( webmaster@1: 'name' => $project_name, webmaster@1: 'info' => $file->info, webmaster@1: 'datestamp' => isset($file->info['datestamp']) ? $file->info['datestamp'] : 0, webmaster@1: 'includes' => array($file->name => $file->info['name']), webmaster@1: 'project_type' => $project_name == 'drupal' ? 'core' : $project_type, webmaster@1: ); webmaster@1: } webmaster@1: else { webmaster@1: $projects[$project_name]['includes'][$file->name] = $file->info['name']; webmaster@1: $projects[$project_name]['info']['_info_file_ctime'] = max($projects[$project_name]['info']['_info_file_ctime'], $file->info['_info_file_ctime']); webmaster@1: } webmaster@1: } webmaster@1: } webmaster@1: webmaster@1: /** webmaster@1: * Given a $file object (as returned by system_get_files_database()), figure webmaster@1: * out what project it belongs to. webmaster@1: * webmaster@1: * @see system_get_files_database() webmaster@1: */ webmaster@1: function update_get_project_name($file) { webmaster@1: $project_name = ''; webmaster@1: if (isset($file->info['project'])) { webmaster@1: $project_name = $file->info['project']; webmaster@1: } webmaster@1: elseif (isset($file->info['package']) && (strpos($file->info['package'], 'Core -') !== FALSE)) { webmaster@1: $project_name = 'drupal'; webmaster@1: } webmaster@1: elseif (in_array($file->name, array('bluemarine', 'chameleon', 'garland', 'marvin', 'minnelli', 'pushbutton'))) { webmaster@1: // Unfortunately, there's no way to tell if a theme is part of core, webmaster@1: // so we must hard-code a list here. webmaster@1: $project_name = 'drupal'; webmaster@1: } webmaster@1: return $project_name; webmaster@1: } webmaster@1: webmaster@1: /** webmaster@1: * Process the list of projects on the system to figure out the currently webmaster@1: * installed versions, and other information that is required before we can webmaster@1: * compare against the available releases to produce the status report. webmaster@1: * webmaster@1: * @param $projects webmaster@1: * Array of project information from update_get_projects(). webmaster@1: */ webmaster@1: function update_process_project_info(&$projects) { webmaster@1: foreach ($projects as $key => $project) { webmaster@1: // Assume an official release until we see otherwise. webmaster@1: $install_type = 'official'; webmaster@1: webmaster@1: $info = $project['info']; webmaster@1: webmaster@1: if (isset($info['version'])) { webmaster@1: // Check for development snapshots webmaster@1: if (preg_match('@(dev|HEAD)@', $info['version'])) { webmaster@1: $install_type = 'dev'; webmaster@1: } webmaster@1: webmaster@1: // Figure out what the currently installed major version is. We need webmaster@1: // to handle both contribution (e.g. "5.x-1.3", major = 1) and core webmaster@1: // (e.g. "5.1", major = 5) version strings. webmaster@1: $matches = array(); webmaster@1: if (preg_match('/^(\d+\.x-)?(\d+)\..*$/', $info['version'], $matches)) { webmaster@1: $info['major'] = $matches[2]; webmaster@1: } webmaster@1: elseif (!isset($info['major'])) { webmaster@1: // This would only happen for version strings that don't follow the webmaster@1: // drupal.org convention. We let contribs define "major" in their webmaster@1: // .info in this case, and only if that's missing would we hit this. webmaster@1: $info['major'] = -1; webmaster@1: } webmaster@1: } webmaster@1: else { webmaster@1: // No version info available at all. webmaster@1: $install_type = 'unknown'; webmaster@1: $info['version'] = t('Unknown'); webmaster@1: $info['major'] = -1; webmaster@1: } webmaster@1: webmaster@1: // Finally, save the results we care about into the $projects array. webmaster@1: $projects[$key]['existing_version'] = $info['version']; webmaster@1: $projects[$key]['existing_major'] = $info['major']; webmaster@1: $projects[$key]['install_type'] = $install_type; webmaster@1: unset($projects[$key]['info']); webmaster@1: } webmaster@1: } webmaster@1: webmaster@1: /** webmaster@1: * Given the installed projects and the available release data retrieved from webmaster@1: * remote servers, calculate the current status. webmaster@1: * webmaster@1: * This function is the heart of the update status feature. It iterates over webmaster@1: * every currently installed project. For each one, it first checks if the webmaster@1: * project has been flagged with a special status like "unsupported" or webmaster@1: * "insecure", or if the project node itself has been unpublished. In any of webmaster@1: * those cases, the project is marked with an error and the next project is webmaster@1: * considered. webmaster@1: * webmaster@1: * If the project itself is valid, the function decides what major release webmaster@1: * series to consider. The project defines what the currently supported major webmaster@1: * versions are for each version of core, so the first step is to make sure webmaster@1: * the current version is still supported. If so, that's the target version. webmaster@1: * If the current version is unsupported, the project maintainer's recommended webmaster@1: * major version is used. There's also a check to make sure that this function webmaster@1: * never recommends an earlier release than the currently installed major webmaster@1: * version. webmaster@1: * webmaster@1: * Given a target major version, it scans the available releases looking for webmaster@1: * the specific release to recommend (avoiding beta releases and development webmaster@1: * snapshots if possible). This is complicated to describe, but an example webmaster@1: * will help clarify. For the target major version, find the highest patch webmaster@1: * level. If there is a release at that patch level with no extra ("beta", webmaster@1: * etc), then we recommend the release at that patch level with the most webmaster@1: * recent release date. If every release at that patch level has extra (only webmaster@1: * betas), then recommend the latest release from the previous patch webmaster@1: * level. For example: webmaster@1: * webmaster@1: * 1.6-bugfix <-- recommended version because 1.6 already exists. webmaster@1: * 1.6 webmaster@1: * webmaster@1: * or webmaster@1: * webmaster@1: * 1.6-beta webmaster@1: * 1.5 <-- recommended version because no 1.6 exists. webmaster@1: * 1.4 webmaster@1: * webmaster@1: * It also looks for the latest release from the same major version, even a webmaster@1: * beta release, to display to the user as the "Latest version" option. webmaster@1: * Additionally, it finds the latest official release from any higher major webmaster@1: * versions that have been released to provide a set of "Also available" webmaster@1: * options. webmaster@1: * webmaster@1: * Finally, and most importantly, it keeps scanning the release history until webmaster@1: * it gets to the currently installed release, searching for anything marked webmaster@1: * as a security update. If any security updates have been found between the webmaster@1: * recommended release and the installed version, all of the releases that webmaster@1: * included a security fix are recorded so that the site administrator can be webmaster@1: * warned their site is insecure, and links pointing to the release notes for webmaster@1: * each security update can be included (which, in turn, will link to the webmaster@1: * official security announcements for each vulnerability). webmaster@1: * webmaster@1: * This function relies on the fact that the .xml release history data comes webmaster@1: * sorted based on major version and patch level, then finally by release date webmaster@1: * if there are multiple releases such as betas from the same major.patch webmaster@1: * version (e.g. 5.x-1.5-beta1, 5.x-1.5-beta2, and 5.x-1.5). Development webmaster@1: * snapshots for a given major version are always listed last. webmaster@1: * webmaster@1: * @param $available webmaster@1: * Array of data about available project releases. webmaster@1: * webmaster@1: * @see update_get_available() webmaster@1: * @see update_get_projects() webmaster@1: * @see update_process_project_info() webmaster@1: */ webmaster@1: function update_calculate_project_data($available) { webmaster@1: // Retrieve the projects from cache, if present. webmaster@1: $projects = update_project_cache('update_project_data'); webmaster@1: // If $projects is empty, then the cache must be rebuilt. webmaster@1: // Otherwise, return the cached data and skip the rest of the function. webmaster@1: if (!empty($projects)) { webmaster@1: return $projects; webmaster@1: } webmaster@1: $projects = update_get_projects(); webmaster@1: update_process_project_info($projects); webmaster@1: foreach ($projects as $project => $project_info) { webmaster@1: if (isset($available[$project])) { webmaster@1: webmaster@1: // If the project status is marked as something bad, there's nothing webmaster@1: // else to consider. webmaster@1: if (isset($available[$project]['project_status'])) { webmaster@1: switch ($available[$project]['project_status']) { webmaster@1: case 'insecure': webmaster@1: $projects[$project]['status'] = UPDATE_NOT_SECURE; webmaster@1: if (empty($projects[$project]['extra'])) { webmaster@1: $projects[$project]['extra'] = array(); webmaster@1: } webmaster@1: $projects[$project]['extra'][] = array( webmaster@1: 'class' => 'project-not-secure', webmaster@1: 'label' => t('Project not secure'), webmaster@1: 'data' => t('This project has been labeled insecure by the Drupal security team, and is no longer available for download. Immediately disabling everything included by this project is strongly recommended!'), webmaster@1: ); webmaster@1: break; webmaster@1: case 'unpublished': webmaster@1: case 'revoked': webmaster@1: $projects[$project]['status'] = UPDATE_REVOKED; webmaster@1: if (empty($projects[$project]['extra'])) { webmaster@1: $projects[$project]['extra'] = array(); webmaster@1: } webmaster@1: $projects[$project]['extra'][] = array( webmaster@1: 'class' => 'project-revoked', webmaster@1: 'label' => t('Project revoked'), webmaster@1: 'data' => t('This project has been revoked, and is no longer available for download. Disabling everything included by this project is strongly recommended!'), webmaster@1: ); webmaster@1: break; webmaster@1: case 'unsupported': webmaster@1: $projects[$project]['status'] = UPDATE_NOT_SUPPORTED; webmaster@1: if (empty($projects[$project]['extra'])) { webmaster@1: $projects[$project]['extra'] = array(); webmaster@1: } webmaster@1: $projects[$project]['extra'][] = array( webmaster@1: 'class' => 'project-not-supported', webmaster@1: 'label' => t('Project not supported'), webmaster@1: 'data' => t('This project is no longer supported, and is no longer available for download. Disabling everything included by this project is strongly recommended!'), webmaster@1: ); webmaster@1: break; webmaster@1: default: webmaster@1: // Assume anything else (e.g. 'published') is valid and we should webmaster@1: // perform the rest of the logic in this function. webmaster@1: break; webmaster@1: } webmaster@1: } webmaster@1: webmaster@1: if (!empty($projects[$project]['status'])) { webmaster@1: // We already know the status for this project, so there's nothing webmaster@1: // else to compute. Just record everything else we fetched from the webmaster@1: // XML file into our projects array and move to the next project. webmaster@1: $projects[$project] += $available[$project]; webmaster@1: continue; webmaster@1: } webmaster@1: webmaster@1: // Figure out the target major version. webmaster@1: $existing_major = $project_info['existing_major']; webmaster@1: $supported_majors = array(); webmaster@1: if (isset($available[$project]['supported_majors'])) { webmaster@1: $supported_majors = explode(',', $available[$project]['supported_majors']); webmaster@1: } webmaster@1: elseif (isset($available[$project]['default_major'])) { webmaster@1: // Older release history XML file without supported or recommended. webmaster@1: $supported_majors[] = $available[$project]['default_major']; webmaster@1: } webmaster@1: webmaster@1: if (in_array($existing_major, $supported_majors)) { webmaster@1: // Still supported, stay at the current major version. webmaster@1: $target_major = $existing_major; webmaster@1: } webmaster@1: elseif (isset($available[$project]['recommended_major'])) { webmaster@1: // Since 'recommended_major' is defined, we know this is the new XML webmaster@1: // format. Therefore, we know the current release is unsupported since webmaster@1: // its major version was not in the 'supported_majors' list. We should webmaster@1: // find the best release from the recommended major version. webmaster@1: $target_major = $available[$project]['recommended_major']; webmaster@1: $projects[$project]['status'] = UPDATE_NOT_SUPPORTED; webmaster@1: } webmaster@1: elseif (isset($available[$project]['default_major'])) { webmaster@1: // Older release history XML file without recommended, so recommend webmaster@1: // the currently defined "default_major" version. webmaster@1: $target_major = $available[$project]['default_major']; webmaster@1: } webmaster@1: else { webmaster@1: // Malformed XML file? Stick with the current version. webmaster@1: $target_major = $existing_major; webmaster@1: } webmaster@1: webmaster@1: // Make sure we never tell the admin to downgrade. If we recommended an webmaster@1: // earlier version than the one they're running, they'd face an webmaster@1: // impossible data migration problem, since Drupal never supports a DB webmaster@1: // downgrade path. In the unfortunate case that what they're running is webmaster@1: // unsupported, and there's nothing newer for them to upgrade to, we webmaster@1: // can't print out a "Recommended version", but just have to tell them webmaster@1: // what they have is unsupported and let them figure it out. webmaster@1: $target_major = max($existing_major, $target_major); webmaster@1: webmaster@1: $version_patch_changed = ''; webmaster@1: $patch = ''; webmaster@1: webmaster@1: // Defend ourselves from XML history files that contain no releases. webmaster@1: if (empty($available[$project]['releases'])) { webmaster@1: $projects[$project]['status'] = UPDATE_UNKNOWN; webmaster@1: $projects[$project]['reason'] = t('No available releases found'); webmaster@1: continue; webmaster@1: } webmaster@1: foreach ($available[$project]['releases'] as $version => $release) { webmaster@1: // First, if this is the existing release, check a few conditions. webmaster@1: if ($projects[$project]['existing_version'] == $version) { webmaster@1: if (isset($release['terms']['Release type']) && webmaster@1: in_array('Insecure', $release['terms']['Release type'])) { webmaster@1: $projects[$project]['status'] = UPDATE_NOT_SECURE; webmaster@1: } webmaster@1: elseif ($release['status'] == 'unpublished') { webmaster@1: $projects[$project]['status'] = UPDATE_REVOKED; webmaster@1: if (empty($projects[$project]['extra'])) { webmaster@1: $projects[$project]['extra'] = array(); webmaster@1: } webmaster@1: $projects[$project]['extra'][] = array( webmaster@1: 'class' => 'release-revoked', webmaster@1: 'label' => t('Release revoked'), webmaster@1: 'data' => t('Your currently installed release has been revoked, and is no longer available for download. Disabling everything included in this release or upgrading is strongly recommended!'), webmaster@1: ); webmaster@1: } webmaster@1: elseif (isset($release['terms']['Release type']) && webmaster@1: in_array('Unsupported', $release['terms']['Release type'])) { webmaster@1: $projects[$project]['status'] = UPDATE_NOT_SUPPORTED; webmaster@1: if (empty($projects[$project]['extra'])) { webmaster@1: $projects[$project]['extra'] = array(); webmaster@1: } webmaster@1: $projects[$project]['extra'][] = array( webmaster@1: 'class' => 'release-not-supported', webmaster@1: 'label' => t('Release not supported'), webmaster@1: 'data' => t('Your currently installed release is now unsupported, and is no longer available for download. Disabling everything included in this release or upgrading is strongly recommended!'), webmaster@1: ); webmaster@1: } webmaster@1: } webmaster@1: webmaster@1: // Otherwise, ignore unpublished, insecure, or unsupported releases. webmaster@1: if ($release['status'] == 'unpublished' || webmaster@1: (isset($release['terms']['Release type']) && webmaster@1: (in_array('Insecure', $release['terms']['Release type']) || webmaster@1: in_array('Unsupported', $release['terms']['Release type'])))) { webmaster@1: continue; webmaster@1: } webmaster@1: webmaster@1: // See if this is a higher major version than our target and yet still webmaster@1: // supported. If so, record it as an "Also available" release. webmaster@1: if ($release['version_major'] > $target_major) { webmaster@1: if (in_array($release['version_major'], $supported_majors)) { webmaster@1: if (!isset($available[$project]['also'])) { webmaster@1: $available[$project]['also'] = array(); webmaster@1: } webmaster@1: if (!isset($available[$project]['also'][$release['version_major']])) { webmaster@1: $available[$project]['also'][$release['version_major']] = $version; webmaster@1: } webmaster@1: } webmaster@1: // Otherwise, this release can't matter to us, since it's neither webmaster@1: // from the release series we're currently using nor the recommended webmaster@1: // release. We don't even care about security updates for this webmaster@1: // branch, since if a project maintainer puts out a security release webmaster@1: // at a higher major version and not at the lower major version, webmaster@1: // they must remove the lower version from the supported major webmaster@1: // versions at the same time, in which case we won't hit this code. webmaster@1: continue; webmaster@1: } webmaster@1: webmaster@1: // Look for the 'latest version' if we haven't found it yet. Latest is webmaster@1: // defined as the most recent version for the target major version. webmaster@1: if (!isset($available[$project]['latest_version']) webmaster@1: && $release['version_major'] == $target_major) { webmaster@1: $available[$project]['latest_version'] = $version; webmaster@1: } webmaster@1: webmaster@1: // Look for the development snapshot release for this branch. webmaster@1: if (!isset($available[$project]['dev_version']) webmaster@1: && $release['version_major'] == $target_major webmaster@1: && isset($release['version_extra']) webmaster@1: && $release['version_extra'] == 'dev') { webmaster@1: $available[$project]['dev_version'] = $version; webmaster@1: } webmaster@1: webmaster@1: // Look for the 'recommended' version if we haven't found it yet (see webmaster@1: // phpdoc at the top of this function for the definition). webmaster@1: if (!isset($available[$project]['recommended']) webmaster@1: && $release['version_major'] == $target_major webmaster@1: && isset($release['version_patch'])) { webmaster@1: if ($patch != $release['version_patch']) { webmaster@1: $patch = $release['version_patch']; webmaster@1: $version_patch_changed = $release['version']; webmaster@1: } webmaster@1: if (empty($release['version_extra']) && $patch == $release['version_patch']) { webmaster@1: $available[$project]['recommended'] = $version_patch_changed; webmaster@1: } webmaster@1: } webmaster@1: webmaster@1: // Stop searching once we hit the currently installed version. webmaster@1: if ($projects[$project]['existing_version'] == $version) { webmaster@1: break; webmaster@1: } webmaster@1: webmaster@1: // If we're running a dev snapshot and have a timestamp, stop webmaster@1: // searching for security updates once we hit an official release webmaster@1: // older than what we've got. Allow 100 seconds of leeway to handle webmaster@1: // differences between the datestamp in the .info file and the webmaster@1: // timestamp of the tarball itself (which are usually off by 1 or 2 webmaster@1: // seconds) so that we don't flag that as a new release. webmaster@1: if ($projects[$project]['install_type'] == 'dev') { webmaster@1: if (empty($projects[$project]['datestamp'])) { webmaster@1: // We don't have current timestamp info, so we can't know. webmaster@1: continue; webmaster@1: } webmaster@1: elseif (isset($release['date']) && ($projects[$project]['datestamp'] + 100 > $release['date'])) { webmaster@1: // We're newer than this, so we can skip it. webmaster@1: continue; webmaster@1: } webmaster@1: } webmaster@1: webmaster@1: // See if this release is a security update. webmaster@1: if (isset($release['terms']['Release type']) webmaster@1: && in_array('Security update', $release['terms']['Release type'])) { webmaster@1: $projects[$project]['security updates'][] = $release; webmaster@1: } webmaster@1: } webmaster@1: webmaster@1: // If we were unable to find a recommended version, then make the latest webmaster@1: // version the recommended version if possible. webmaster@1: if (!isset($available[$project]['recommended']) && isset($available[$project]['latest_version'])) { webmaster@1: $available[$project]['recommended'] = $available[$project]['latest_version']; webmaster@1: } webmaster@1: webmaster@1: // Stash the info about available releases into our $projects array. webmaster@1: $projects[$project] += $available[$project]; webmaster@1: webmaster@1: // webmaster@1: // Check to see if we need an update or not. webmaster@1: // webmaster@1: webmaster@1: if (!empty($projects[$project]['security updates'])) { webmaster@1: // If we found security updates, that always trumps any other status. webmaster@1: $projects[$project]['status'] = UPDATE_NOT_SECURE; webmaster@1: } webmaster@1: webmaster@1: if (isset($projects[$project]['status'])) { webmaster@1: // If we already know the status, we're done. webmaster@1: continue; webmaster@1: } webmaster@1: webmaster@1: // If we don't know what to recommend, there's nothing we can report. webmaster@1: // Bail out early. webmaster@1: if (!isset($projects[$project]['recommended'])) { webmaster@1: $projects[$project]['status'] = UPDATE_UNKNOWN; webmaster@1: $projects[$project]['reason'] = t('No available releases found'); webmaster@1: continue; webmaster@1: } webmaster@1: webmaster@1: // If we're running a dev snapshot, compare the date of the dev snapshot webmaster@1: // with the latest official version, and record the absolute latest in webmaster@1: // 'latest_dev' so we can correctly decide if there's a newer release webmaster@1: // than our current snapshot. webmaster@1: if ($projects[$project]['install_type'] == 'dev') { webmaster@1: if (isset($available[$project]['dev_version']) && $available[$project]['releases'][$available[$project]['dev_version']]['date'] > $available[$project]['releases'][$available[$project]['latest_version']]['date']) { webmaster@1: $projects[$project]['latest_dev'] = $available[$project]['dev_version']; webmaster@1: } webmaster@1: else { webmaster@1: $projects[$project]['latest_dev'] = $available[$project]['latest_version']; webmaster@1: } webmaster@1: } webmaster@1: webmaster@1: // Figure out the status, based on what we've seen and the install type. webmaster@1: switch ($projects[$project]['install_type']) { webmaster@1: case 'official': webmaster@1: if ($projects[$project]['existing_version'] == $projects[$project]['recommended'] || $projects[$project]['existing_version'] == $projects[$project]['latest_version']) { webmaster@1: $projects[$project]['status'] = UPDATE_CURRENT; webmaster@1: } webmaster@1: else { webmaster@1: $projects[$project]['status'] = UPDATE_NOT_CURRENT; webmaster@1: } webmaster@1: break; webmaster@1: webmaster@1: case 'dev': webmaster@1: $latest = $available[$project]['releases'][$projects[$project]['latest_dev']]; webmaster@1: if (empty($projects[$project]['datestamp'])) { webmaster@1: $projects[$project]['status'] = UPDATE_NOT_CHECKED; webmaster@1: $projects[$project]['reason'] = t('Unknown release date'); webmaster@1: } webmaster@1: elseif (($projects[$project]['datestamp'] + 100 > $latest['date'])) { webmaster@1: $projects[$project]['status'] = UPDATE_CURRENT; webmaster@1: } webmaster@1: else { webmaster@1: $projects[$project]['status'] = UPDATE_NOT_CURRENT; webmaster@1: } webmaster@1: break; webmaster@1: webmaster@1: default: webmaster@1: $projects[$project]['status'] = UPDATE_UNKNOWN; webmaster@1: $projects[$project]['reason'] = t('Invalid info'); webmaster@1: } webmaster@1: } webmaster@1: else { webmaster@1: $projects[$project]['status'] = UPDATE_UNKNOWN; webmaster@1: $projects[$project]['reason'] = t('No available releases found'); webmaster@1: } webmaster@1: } webmaster@1: // Give other modules a chance to alter the status (for example, to allow a webmaster@1: // contrib module to provide fine-grained settings to ignore specific webmaster@1: // projects or releases). webmaster@1: drupal_alter('update_status', $projects); webmaster@1: webmaster@1: // Set the projects array into the cache table. webmaster@1: cache_set('update_project_data', $projects, 'cache_update', time() + 3600); webmaster@1: return $projects; webmaster@1: } webmaster@1: webmaster@1: /** webmaster@1: * Retrieve data from {cache_update} or empty the cache when necessary. webmaster@1: * webmaster@1: * Two very expensive arrays computed by this module are the list of all webmaster@1: * installed modules and themes (and .info data, project associations, etc), webmaster@1: * and the current status of the site relative to the currently available webmaster@1: * releases. These two arrays are cached in the {cache_update} table and used webmaster@1: * whenever possible. The cache is cleared whenever the administrator visits webmaster@1: * the status report, available updates report, or the module or theme webmaster@1: * administration pages, since we should always recompute the most current webmaster@1: * values on any of those pages. webmaster@1: * webmaster@1: * @param $cid webmaster@1: * The cache id of data to return from the cache. Valid options are webmaster@1: * 'update_project_data' and 'update_project_projects'. webmaster@1: * webmaster@1: * @return webmaster@1: * The cached value of the $projects array generated by webmaster@1: * update_calculate_project_data() or update_get_projects(), or an empty webmaster@1: * array when the cache is cleared. webmaster@1: */ webmaster@1: function update_project_cache($cid) { webmaster@1: $projects = array(); webmaster@1: webmaster@1: // In some cases, we must clear the cache. Rather than do so on a time webmaster@1: // basis, we check for specific paths. webmaster@1: $q = $_GET['q']; webmaster@1: $paths = array('admin/build/modules', 'admin/build/themes', 'admin/reports', 'admin/reports/updates', 'admin/reports/status', 'admin/reports/updates/check'); webmaster@1: if (in_array($q, $paths)) { webmaster@1: cache_clear_all($cid, 'cache_update'); webmaster@1: } webmaster@1: else { webmaster@1: $cache = cache_get($cid, 'cache_update'); webmaster@1: if (!empty($cache->data) && $cache->expire > time()) { webmaster@1: $projects = $cache->data; webmaster@1: } webmaster@1: } webmaster@1: return $projects; webmaster@1: }