[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

/modules/update/ -> update.compare.inc (source)

   1  <?php
   2  // $Id: update.compare.inc,v 1.8.2.9 2010/03/05 09:10:49 goba Exp $
   3  
   4  /**
   5   * @file
   6   * Code required only when comparing available updates to existing data.
   7   */
   8  
   9  /**
  10   * Fetch an array of installed and enabled projects.
  11   *
  12   * This is only responsible for generating an array of projects (taking into
  13   * account projects that include more than one module or theme). Other
  14   * information like the specific version and install type (official release,
  15   * dev snapshot, etc) is handled later in update_process_project_info() since
  16   * that logic is only required when preparing the status report, not for
  17   * fetching the available release data.
  18   *
  19   * This array is fairly expensive to construct, since it involves a lot of
  20   * disk I/O, so we cache the results into the {cache_update} table using the
  21   * 'update_project_projects' cache ID. However, since this is not the data
  22   * about available updates fetched from the network, it is ok to invalidate it
  23   * somewhat quickly. If we keep this data for very long, site administrators
  24   * are more likely to see incorrect results if they upgrade to a newer version
  25   * of a module or theme but do not visit certain pages that automatically
  26   * clear this cache.
  27   *
  28   * @see update_process_project_info()
  29   * @see update_calculate_project_data()
  30   * @see update_project_cache()
  31   */
  32  function update_get_projects() {
  33    static $projects = array();
  34    if (empty($projects)) {
  35      // Retrieve the projects from cache, if present.
  36      $projects = update_project_cache('update_project_projects');
  37      if (empty($projects)) {
  38        // Still empty, so we have to rebuild the cache.
  39        _update_process_info_list($projects, module_rebuild_cache(), 'module');
  40        _update_process_info_list($projects, system_theme_data(), 'theme');
  41        // Allow other modules to alter projects before fetching and comparing.
  42        drupal_alter('update_projects', $projects);
  43        // Cache the site's project data for at most 1 hour.
  44        _update_cache_set('update_project_projects', $projects, time() + 3600);
  45      }
  46    }
  47    return $projects;
  48  }
  49  
  50  /**
  51   * Populate an array of project data.
  52   */
  53  function _update_process_info_list(&$projects, $list, $project_type) {
  54    foreach ($list as $file) {
  55      // A disabled base theme of an enabled sub-theme still has all of its code
  56      // run by the sub-theme, so we include it in our "enabled" projects list.
  57      if (!$file->status && !empty($file->sub_themes)) {
  58        foreach ($file->sub_themes as $key => $name) {
  59          // Build a list of enabled sub-themes.
  60          if ($list[$key]->status) {
  61            $file->enabled_sub_themes[$key] = $name;
  62          }
  63        }
  64        // If there are no enabled subthemes, we should ingore this theme and go
  65        // on to the next one.
  66        if (empty($file->enabled_sub_themes)) {
  67          continue;
  68        }
  69      }
  70      elseif (empty($file->status)) {
  71        // Skip disabled modules or themes.
  72        continue;
  73      }
  74  
  75      // Skip if the .info file is broken.
  76      if (empty($file->info)) {
  77        continue;
  78      }
  79  
  80      // If the .info doesn't define the 'project', try to figure it out.
  81      if (!isset($file->info['project'])) {
  82        $file->info['project'] = update_get_project_name($file);
  83      }
  84  
  85      // If we still don't know the 'project', give up.
  86      if (empty($file->info['project'])) {
  87        continue;
  88      }
  89  
  90      // If we don't already know it, grab the change time on the .info file
  91      // itself. Note: we need to use the ctime, not the mtime (modification
  92      // time) since many (all?) tar implementations will go out of their way to
  93      // set the mtime on the files it creates to the timestamps recorded in the
  94      // tarball. We want to see the last time the file was changed on disk,
  95      // which is left alone by tar and correctly set to the time the .info file
  96      // was unpacked.
  97      if (!isset($file->info['_info_file_ctime'])) {
  98        $info_filename = dirname($file->filename) .'/'. $file->name .'.info';
  99        $file->info['_info_file_ctime'] = filectime($info_filename);
 100      }
 101  
 102      if (!isset($file->info['datestamp'])) {
 103        $file->info['datestamp'] = 0;
 104      }
 105  
 106      $project_name = $file->info['project'];
 107  
 108      // Add a list of sub-themes that "depend on" the project and a list of base
 109      // themes that are "required by" the project.
 110      if ($project_name == 'drupal') {
 111        // Drupal core is always required, so this extra info would be noise.
 112        $sub_themes = array();
 113        $base_themes = array();
 114      }
 115      else {
 116        // Add list of enabled sub-themes.
 117        $sub_themes = !empty($file->enabled_sub_themes) ? $file->enabled_sub_themes : array();
 118        // Add list of base themes.
 119        $base_themes = !empty($file->base_themes) ? $file->base_themes : array();
 120      }
 121  
 122      if (!isset($projects[$project_name])) {
 123        // Only process this if we haven't done this project, since a single
 124        // project can have multiple modules or themes.
 125        $projects[$project_name] = array(
 126          'name' => $project_name,
 127          // Only save attributes from the .info file we care about so we do not
 128          // bloat our RAM usage needlessly.
 129          'info' => update_filter_project_info($file->info),
 130          'datestamp' => $file->info['datestamp'],
 131          'includes' => array($file->name => $file->info['name']),
 132          'project_type' => $project_name == 'drupal' ? 'core' : $project_type,
 133          'sub_themes' => $sub_themes,
 134          'base_themes' => $base_themes,
 135        );
 136      }
 137      else {
 138        $projects[$project_name]['includes'][$file->name] = $file->info['name'];
 139        $projects[$project_name]['info']['_info_file_ctime'] = max($projects[$project_name]['info']['_info_file_ctime'], $file->info['_info_file_ctime']);
 140        $projects[$project_name]['datestamp'] = max($projects[$project_name]['datestamp'], $file->info['datestamp']);
 141        $projects[$project_name]['sub_themes'] = array_merge($projects[$project_name]['sub_themes'], $sub_themes);
 142        $projects[$project_name]['base_themes'] = array_merge($projects[$project_name]['base_themes'], $base_themes);
 143      }
 144    }
 145  }
 146  
 147  /**
 148   * Given a $file object (as returned by system_get_files_database()), figure
 149   * out what project it belongs to.
 150   *
 151   * @see system_get_files_database()
 152   */
 153  function update_get_project_name($file) {
 154    $project_name = '';
 155    if (isset($file->info['project'])) {
 156      $project_name = $file->info['project'];
 157    }
 158    elseif (isset($file->info['package']) && (strpos($file->info['package'], 'Core -') !== FALSE)) {
 159      $project_name = 'drupal';
 160    }
 161    elseif (in_array($file->name, array('bluemarine', 'chameleon', 'garland', 'marvin', 'minnelli', 'pushbutton'))) {
 162      // Unfortunately, there's no way to tell if a theme is part of core,
 163      // so we must hard-code a list here.
 164      $project_name = 'drupal';
 165    }
 166    return $project_name;
 167  }
 168  
 169  /**
 170   * Process the list of projects on the system to figure out the currently
 171   * installed versions, and other information that is required before we can
 172   * compare against the available releases to produce the status report.
 173   *
 174   * @param $projects
 175   *   Array of project information from update_get_projects().
 176   */
 177  function update_process_project_info(&$projects) {
 178    foreach ($projects as $key => $project) {
 179      // Assume an official release until we see otherwise.
 180      $install_type = 'official';
 181  
 182      $info = $project['info'];
 183  
 184      if (isset($info['version'])) {
 185        // Check for development snapshots
 186        if (preg_match('@(dev|HEAD)@', $info['version'])) {
 187          $install_type = 'dev';
 188        }
 189  
 190        // Figure out what the currently installed major version is. We need
 191        // to handle both contribution (e.g. "5.x-1.3", major = 1) and core
 192        // (e.g. "5.1", major = 5) version strings.
 193        $matches = array();
 194        if (preg_match('/^(\d+\.x-)?(\d+)\..*$/', $info['version'], $matches)) {
 195          $info['major'] = $matches[2];
 196        }
 197        elseif (!isset($info['major'])) {
 198          // This would only happen for version strings that don't follow the
 199          // drupal.org convention. We let contribs define "major" in their
 200          // .info in this case, and only if that's missing would we hit this.
 201          $info['major'] = -1;
 202        }
 203      }
 204      else {
 205        // No version info available at all.
 206        $install_type = 'unknown';
 207        $info['version'] = t('Unknown');
 208        $info['major'] = -1;
 209      }
 210  
 211      // Finally, save the results we care about into the $projects array.
 212      $projects[$key]['existing_version'] = $info['version'];
 213      $projects[$key]['existing_major'] = $info['major'];
 214      $projects[$key]['install_type'] = $install_type;
 215    }
 216  }
 217  
 218  /**
 219   * Given the installed projects and the available release data retrieved from
 220   * remote servers, calculate the current status.
 221   *
 222   * This function is the heart of the update status feature. It iterates over
 223   * every currently installed project. For each one, it first checks if the
 224   * project has been flagged with a special status like "unsupported" or
 225   * "insecure", or if the project node itself has been unpublished. In any of
 226   * those cases, the project is marked with an error and the next project is
 227   * considered.
 228   *
 229   * If the project itself is valid, the function decides what major release
 230   * series to consider. The project defines what the currently supported major
 231   * versions are for each version of core, so the first step is to make sure
 232   * the current version is still supported. If so, that's the target version.
 233   * If the current version is unsupported, the project maintainer's recommended
 234   * major version is used. There's also a check to make sure that this function
 235   * never recommends an earlier release than the currently installed major
 236   * version.
 237   *
 238   * Given a target major version, it scans the available releases looking for
 239   * the specific release to recommend (avoiding beta releases and development
 240   * snapshots if possible). This is complicated to describe, but an example
 241   * will help clarify. For the target major version, find the highest patch
 242   * level. If there is a release at that patch level with no extra ("beta",
 243   * etc), then we recommend the release at that patch level with the most
 244   * recent release date. If every release at that patch level has extra (only
 245   * betas), then recommend the latest release from the previous patch
 246   * level. For example:
 247   *
 248   * 1.6-bugfix <-- recommended version because 1.6 already exists.
 249   * 1.6
 250   *
 251   * or
 252   *
 253   * 1.6-beta
 254   * 1.5 <-- recommended version because no 1.6 exists.
 255   * 1.4
 256   *
 257   * It also looks for the latest release from the same major version, even a
 258   * beta release, to display to the user as the "Latest version" option.
 259   * Additionally, it finds the latest official release from any higher major
 260   * versions that have been released to provide a set of "Also available"
 261   * options.
 262   *
 263   * Finally, and most importantly, it keeps scanning the release history until
 264   * it gets to the currently installed release, searching for anything marked
 265   * as a security update. If any security updates have been found between the
 266   * recommended release and the installed version, all of the releases that
 267   * included a security fix are recorded so that the site administrator can be
 268   * warned their site is insecure, and links pointing to the release notes for
 269   * each security update can be included (which, in turn, will link to the
 270   * official security announcements for each vulnerability).
 271   *
 272   * This function relies on the fact that the .xml release history data comes
 273   * sorted based on major version and patch level, then finally by release date
 274   * if there are multiple releases such as betas from the same major.patch
 275   * version (e.g. 5.x-1.5-beta1, 5.x-1.5-beta2, and 5.x-1.5). Development
 276   * snapshots for a given major version are always listed last.
 277   *
 278   * The results of this function are expensive to compute, especially on sites
 279   * with lots of modules or themes, since it involves a lot of comparisons and
 280   * other operations. Therefore, we cache the results into the {cache_update}
 281   * table using the 'update_project_data' cache ID. However, since this is not
 282   * the data about available updates fetched from the network, it is ok to
 283   * invalidate it somewhat quickly. If we keep this data for very long, site
 284   * administrators are more likely to see incorrect results if they upgrade to
 285   * a newer version of a module or theme but do not visit certain pages that
 286   * automatically clear this cache.
 287   *
 288   * @param $available
 289   *  Array of data about available project releases.
 290   *
 291   * @see update_get_available()
 292   * @see update_get_projects()
 293   * @see update_process_project_info()
 294   * @see update_project_cache()
 295   */
 296  function update_calculate_project_data($available) {
 297    // Retrieve the projects from cache, if present.
 298    $projects = update_project_cache('update_project_data');
 299    // If $projects is empty, then the cache must be rebuilt.
 300    // Otherwise, return the cached data and skip the rest of the function.
 301    if (!empty($projects)) {
 302      return $projects;
 303    }
 304    $projects = update_get_projects();
 305    update_process_project_info($projects);
 306    foreach ($projects as $project => $project_info) {
 307      if (isset($available[$project])) {
 308  
 309        // If the project status is marked as something bad, there's nothing
 310        // else to consider.
 311        if (isset($available[$project]['project_status'])) {
 312          switch ($available[$project]['project_status']) {
 313            case 'insecure':
 314              $projects[$project]['status'] = UPDATE_NOT_SECURE;
 315              if (empty($projects[$project]['extra'])) {
 316                $projects[$project]['extra'] = array();
 317              }
 318              $projects[$project]['extra'][] = array(
 319                'class' => 'project-not-secure',
 320                'label' => t('Project not secure'),
 321                '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!'),
 322              );
 323              break;
 324            case 'unpublished':
 325            case 'revoked':
 326              $projects[$project]['status'] = UPDATE_REVOKED;
 327              if (empty($projects[$project]['extra'])) {
 328                $projects[$project]['extra'] = array();
 329              }
 330              $projects[$project]['extra'][] = array(
 331                'class' => 'project-revoked',
 332                'label' => t('Project revoked'),
 333                'data' => t('This project has been revoked, and is no longer available for download. Disabling everything included by this project is strongly recommended!'),
 334              );
 335              break;
 336            case 'unsupported':
 337              $projects[$project]['status'] = UPDATE_NOT_SUPPORTED;
 338              if (empty($projects[$project]['extra'])) {
 339                $projects[$project]['extra'] = array();
 340              }
 341              $projects[$project]['extra'][] = array(
 342                'class' => 'project-not-supported',
 343                'label' => t('Project not supported'),
 344                'data' => t('This project is no longer supported, and is no longer available for download. Disabling everything included by this project is strongly recommended!'),
 345              );
 346              break;
 347            case 'not-fetched':
 348              $projects[$project]['status'] = UPDATE_NOT_FETCHED;
 349              $projects[$project]['reason'] = t('Failed to fetch available update data');
 350              break;
 351  
 352            default:
 353              // Assume anything else (e.g. 'published') is valid and we should
 354              // perform the rest of the logic in this function.
 355              break;
 356          }
 357        }
 358  
 359        if (!empty($projects[$project]['status'])) {
 360          // We already know the status for this project, so there's nothing
 361          // else to compute. Just record everything else we fetched from the
 362          // XML file into our projects array and move to the next project.
 363          $projects[$project] += $available[$project];
 364          continue;
 365        }
 366  
 367        // Figure out the target major version.
 368        $existing_major = $project_info['existing_major'];
 369        $supported_majors = array();
 370        if (isset($available[$project]['supported_majors'])) {
 371          $supported_majors = explode(',', $available[$project]['supported_majors']);
 372        }
 373        elseif (isset($available[$project]['default_major'])) {
 374          // Older release history XML file without supported or recommended.
 375          $supported_majors[] = $available[$project]['default_major'];
 376        }
 377  
 378        if (in_array($existing_major, $supported_majors)) {
 379          // Still supported, stay at the current major version.
 380          $target_major = $existing_major;
 381        }
 382        elseif (isset($available[$project]['recommended_major'])) {
 383          // Since 'recommended_major' is defined, we know this is the new XML
 384          // format. Therefore, we know the current release is unsupported since
 385          // its major version was not in the 'supported_majors' list. We should
 386          // find the best release from the recommended major version.
 387          $target_major = $available[$project]['recommended_major'];
 388          $projects[$project]['status'] = UPDATE_NOT_SUPPORTED;
 389        }
 390        elseif (isset($available[$project]['default_major'])) {
 391          // Older release history XML file without recommended, so recommend
 392          // the currently defined "default_major" version.
 393          $target_major = $available[$project]['default_major'];
 394        }
 395        else {
 396          // Malformed XML file? Stick with the current version.
 397          $target_major = $existing_major;
 398        }
 399  
 400        // Make sure we never tell the admin to downgrade. If we recommended an
 401        // earlier version than the one they're running, they'd face an
 402        // impossible data migration problem, since Drupal never supports a DB
 403        // downgrade path. In the unfortunate case that what they're running is
 404        // unsupported, and there's nothing newer for them to upgrade to, we
 405        // can't print out a "Recommended version", but just have to tell them
 406        // what they have is unsupported and let them figure it out.
 407        $target_major = max($existing_major, $target_major);
 408  
 409        $version_patch_changed = '';
 410        $patch = '';
 411  
 412        // Defend ourselves from XML history files that contain no releases.
 413        if (empty($available[$project]['releases'])) {
 414          $projects[$project]['status'] = UPDATE_UNKNOWN;
 415          $projects[$project]['reason'] = t('No available releases found');
 416          continue;
 417        }
 418        foreach ($available[$project]['releases'] as $version => $release) {
 419          // First, if this is the existing release, check a few conditions.
 420          if ($projects[$project]['existing_version'] === $version) {
 421            if (isset($release['terms']['Release type']) &&
 422                in_array('Insecure', $release['terms']['Release type'])) {
 423              $projects[$project]['status'] = UPDATE_NOT_SECURE;
 424            }
 425            elseif ($release['status'] == 'unpublished') {
 426              $projects[$project]['status'] = UPDATE_REVOKED;
 427              if (empty($projects[$project]['extra'])) {
 428                $projects[$project]['extra'] = array();
 429              }
 430              $projects[$project]['extra'][] = array(
 431                'class' => 'release-revoked',
 432                'label' => t('Release revoked'),
 433                '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!'),
 434              );
 435            }
 436            elseif (isset($release['terms']['Release type']) &&
 437                    in_array('Unsupported', $release['terms']['Release type'])) {
 438              $projects[$project]['status'] = UPDATE_NOT_SUPPORTED;
 439              if (empty($projects[$project]['extra'])) {
 440                $projects[$project]['extra'] = array();
 441              }
 442              $projects[$project]['extra'][] = array(
 443                'class' => 'release-not-supported',
 444                'label' => t('Release not supported'),
 445                '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!'),
 446              );
 447            }
 448          }
 449  
 450          // Otherwise, ignore unpublished, insecure, or unsupported releases.
 451          if ($release['status'] == 'unpublished' ||
 452              (isset($release['terms']['Release type']) &&
 453               (in_array('Insecure', $release['terms']['Release type']) ||
 454                in_array('Unsupported', $release['terms']['Release type'])))) {
 455            continue;
 456          }
 457  
 458          // See if this is a higher major version than our target and yet still
 459          // supported. If so, record it as an "Also available" release.
 460          if ($release['version_major'] > $target_major) {
 461            if (in_array($release['version_major'], $supported_majors)) {
 462              if (!isset($available[$project]['also'])) {
 463                $available[$project]['also'] = array();
 464              }
 465              if (!isset($available[$project]['also'][$release['version_major']])) {
 466                $available[$project]['also'][$release['version_major']] = $version;
 467              }
 468            }
 469            // Otherwise, this release can't matter to us, since it's neither
 470            // from the release series we're currently using nor the recommended
 471            // release. We don't even care about security updates for this
 472            // branch, since if a project maintainer puts out a security release
 473            // at a higher major version and not at the lower major version,
 474            // they must remove the lower version from the supported major
 475            // versions at the same time, in which case we won't hit this code.
 476            continue;
 477          }
 478  
 479          // Look for the 'latest version' if we haven't found it yet. Latest is
 480          // defined as the most recent version for the target major version.
 481          if (!isset($available[$project]['latest_version'])
 482              && $release['version_major'] == $target_major) {
 483            $available[$project]['latest_version'] = $version;
 484          }
 485  
 486          // Look for the development snapshot release for this branch.
 487          if (!isset($available[$project]['dev_version'])
 488              && $release['version_major'] == $target_major
 489              && isset($release['version_extra'])
 490              && $release['version_extra'] == 'dev') {
 491            $available[$project]['dev_version'] = $version;
 492          }
 493  
 494          // Look for the 'recommended' version if we haven't found it yet (see
 495          // phpdoc at the top of this function for the definition).
 496          if (!isset($available[$project]['recommended'])
 497              && $release['version_major'] == $target_major
 498              && isset($release['version_patch'])) {
 499            if ($patch != $release['version_patch']) {
 500              $patch = $release['version_patch'];
 501              $version_patch_changed = $release['version'];
 502            }
 503            if (empty($release['version_extra']) && $patch == $release['version_patch']) {
 504              $available[$project]['recommended'] = $version_patch_changed;
 505            }
 506          }
 507  
 508          // Stop searching once we hit the currently installed version.
 509          if ($projects[$project]['existing_version'] === $version) {
 510            break;
 511          }
 512  
 513          // If we're running a dev snapshot and have a timestamp, stop
 514          // searching for security updates once we hit an official release
 515          // older than what we've got. Allow 100 seconds of leeway to handle
 516          // differences between the datestamp in the .info file and the
 517          // timestamp of the tarball itself (which are usually off by 1 or 2
 518          // seconds) so that we don't flag that as a new release.
 519          if ($projects[$project]['install_type'] == 'dev') {
 520            if (empty($projects[$project]['datestamp'])) {
 521              // We don't have current timestamp info, so we can't know.
 522              continue;
 523            }
 524            elseif (isset($release['date']) && ($projects[$project]['datestamp'] + 100 > $release['date'])) {
 525              // We're newer than this, so we can skip it.
 526              continue;
 527            }
 528          }
 529  
 530          // See if this release is a security update.
 531          if (isset($release['terms']['Release type'])
 532              && in_array('Security update', $release['terms']['Release type'])) {
 533            $projects[$project]['security updates'][] = $release;
 534          }
 535        }
 536  
 537        // If we were unable to find a recommended version, then make the latest
 538        // version the recommended version if possible.
 539        if (!isset($available[$project]['recommended']) && isset($available[$project]['latest_version'])) {
 540          $available[$project]['recommended'] = $available[$project]['latest_version'];
 541        }
 542  
 543        // Stash the info about available releases into our $projects array.
 544        $projects[$project] += $available[$project];
 545  
 546        //
 547        // Check to see if we need an update or not.
 548        //
 549  
 550        if (!empty($projects[$project]['security updates'])) {
 551          // If we found security updates, that always trumps any other status.
 552          $projects[$project]['status'] = UPDATE_NOT_SECURE;
 553        }
 554  
 555        if (isset($projects[$project]['status'])) {
 556          // If we already know the status, we're done.
 557          continue;
 558        }
 559  
 560        // If we don't know what to recommend, there's nothing we can report.
 561        // Bail out early.
 562        if (!isset($projects[$project]['recommended'])) {
 563          $projects[$project]['status'] = UPDATE_UNKNOWN;
 564          $projects[$project]['reason'] = t('No available releases found');
 565          continue;
 566        }
 567  
 568        // If we're running a dev snapshot, compare the date of the dev snapshot
 569        // with the latest official version, and record the absolute latest in
 570        // 'latest_dev' so we can correctly decide if there's a newer release
 571        // than our current snapshot.
 572        if ($projects[$project]['install_type'] == 'dev') {
 573          if (isset($available[$project]['dev_version']) && $available[$project]['releases'][$available[$project]['dev_version']]['date'] > $available[$project]['releases'][$available[$project]['latest_version']]['date']) {
 574            $projects[$project]['latest_dev'] = $available[$project]['dev_version'];
 575          }
 576          else {
 577            $projects[$project]['latest_dev'] = $available[$project]['latest_version'];
 578          }
 579        }
 580  
 581        // Figure out the status, based on what we've seen and the install type.
 582        switch ($projects[$project]['install_type']) {
 583          case 'official':
 584            if ($projects[$project]['existing_version'] === $projects[$project]['recommended'] || $projects[$project]['existing_version'] === $projects[$project]['latest_version']) {
 585              $projects[$project]['status'] = UPDATE_CURRENT;
 586            }
 587            else {
 588              $projects[$project]['status'] = UPDATE_NOT_CURRENT;
 589            }
 590            break;
 591  
 592          case 'dev':
 593            $latest = $available[$project]['releases'][$projects[$project]['latest_dev']];
 594            if (empty($projects[$project]['datestamp'])) {
 595              $projects[$project]['status'] = UPDATE_NOT_CHECKED;
 596              $projects[$project]['reason'] = t('Unknown release date');
 597            }
 598            elseif (($projects[$project]['datestamp'] + 100 > $latest['date'])) {
 599              $projects[$project]['status'] = UPDATE_CURRENT;
 600            }
 601            else {
 602              $projects[$project]['status'] = UPDATE_NOT_CURRENT;
 603            }
 604            break;
 605  
 606          default:
 607            $projects[$project]['status'] = UPDATE_UNKNOWN;
 608            $projects[$project]['reason'] = t('Invalid info');
 609        }
 610      }
 611      else {
 612        $projects[$project]['status'] = UPDATE_UNKNOWN;
 613        $projects[$project]['reason'] = t('No available releases found');
 614      }
 615    }
 616    // Give other modules a chance to alter the status (for example, to allow a
 617    // contrib module to provide fine-grained settings to ignore specific
 618    // projects or releases).
 619    drupal_alter('update_status', $projects);
 620  
 621    // Cache the site's update status for at most 1 hour.
 622    _update_cache_set('update_project_data', $projects, time() + 3600);
 623    return $projects;
 624  }
 625  
 626  /**
 627   * Retrieve data from {cache_update} or empty the cache when necessary.
 628   *
 629   * Two very expensive arrays computed by this module are the list of all
 630   * installed modules and themes (and .info data, project associations, etc),
 631   * and the current status of the site relative to the currently available
 632   * releases. These two arrays are cached in the {cache_update} table and used
 633   * whenever possible. The cache is cleared whenever the administrator visits
 634   * the status report, available updates report, or the module or theme
 635   * administration pages, since we should always recompute the most current
 636   * values on any of those pages.
 637   *
 638   * Note: while both of these arrays are expensive to compute (in terms of disk
 639   * I/O and some fairly heavy CPU processing), neither of these is the actual
 640   * data about available updates that we have to fetch over the network from
 641   * updates.drupal.org. That information is stored with the
 642   * 'update_available_releases' cache ID -- it needs to persist longer than 1
 643   * hour and never get invalidated just by visiting a page on the site.
 644   *
 645   * @param $cid
 646   *   The cache id of data to return from the cache. Valid options are
 647   *   'update_project_data' and 'update_project_projects'.
 648   *
 649   * @return
 650   *   The cached value of the $projects array generated by
 651   *   update_calculate_project_data() or update_get_projects(), or an empty
 652   *   array when the cache is cleared.
 653   */
 654  function update_project_cache($cid) {
 655    $projects = array();
 656  
 657    // On certain paths, we should clear the cache and recompute the projects or
 658    // update status of the site to avoid presenting stale information.
 659    $q = $_GET['q'];
 660    $paths = array('admin/build/modules', 'admin/build/themes', 'admin/reports', 'admin/reports/updates', 'admin/reports/status', 'admin/reports/updates/check');
 661    if (in_array($q, $paths)) {
 662      _update_cache_clear($cid);
 663    }
 664    else {
 665      $cache = _update_cache_get($cid);
 666      if (!empty($cache->data) && $cache->expire > time()) {
 667        $projects = $cache->data;
 668      }
 669    }
 670    return $projects;
 671  }
 672  
 673  /**
 674   * Filter the project .info data to only save attributes we need.
 675   *
 676   * @param array $info
 677   *   Array of .info file data as returned by drupal_parse_info_file().
 678   *
 679   * @return
 680   *   Array of .info file data we need for the Update manager.
 681   *
 682   * @see _update_process_info_list()
 683   */
 684  function update_filter_project_info($info) {
 685    $whitelist = array(
 686      '_info_file_ctime',
 687      'datestamp',
 688      'major',
 689      'name',
 690      'package',
 691      'project',
 692      'project status url',
 693      'version',
 694    );
 695    $whitelist = array_flip($whitelist);
 696    foreach ($info as $key => $value) {
 697      if (!isset($whitelist[$key])) {
 698        unset($info[$key]);
 699      }
 700    }
 701    return $info;
 702  }


Generated: Thu Mar 24 11:18:33 2011 Cross-referenced by PHPXref 0.7