W3cubDocs

/Drupal 8

function update_verify_update_archive

update_verify_update_archive($project, $archive_file, $directory)

Implements hook_verify_update_archive().

First, we ensure that the archive isn't a copy of Drupal core, which the update manager does not yet support. See https://www.drupal.org/node/606592.

Then, we make sure that at least one module included in the archive file has an .info.yml file which claims that the code is compatible with the current version of Drupal core.

See also

\Drupal\Core\Extension\ExtensionDiscovery

_system_rebuild_module_data()

File

core/modules/update/update.module, line 585
Handles updates of Drupal core and contributed projects.

Code

function update_verify_update_archive($project, $archive_file, $directory) {
  $errors = array();

  // Make sure this isn't a tarball of Drupal core.
  if (
  file_exists("$directory/$project/index.php")
   && file_exists("$directory/$project/core/install.php")
     && file_exists("$directory/$project/core/includes/bootstrap.inc")
     && file_exists("$directory/$project/core/modules/node/node.module")
     && file_exists("$directory/$project/core/modules/system/system.module")
    ) {
    return array(
      'no-core' => t('Automatic updating of Drupal core is not supported. See the <a href=":upgrade-guide">upgrade guide</a> for information on how to update Drupal core manually.', array(':upgrade-guide' => 'https://www.drupal.org/upgrade')),
    );
  }

  // Parse all the .info.yml files and make sure at least one is compatible with
  // this version of Drupal core. If one is compatible, then the project as a
  // whole is considered compatible (since, for example, the project may ship
  // with some out-of-date modules that are not necessary for its overall
  // functionality).
  $compatible_project = FALSE;
  $incompatible = array();
  $files = file_scan_directory("$directory/$project", '/^' . DRUPAL_PHP_FUNCTION_PATTERN . '\.info.yml$/', array('key' => 'name', 'min_depth' => 0));
  foreach ($files as $file) {
    // Get the .info.yml file for the module or theme this file belongs to.
    $info = \Drupal::service('info_parser')->parse($file->uri);

    // If the module or theme is incompatible with Drupal core, set an error.
    if (empty($info['core']) || $info['core'] != \Drupal::CORE_COMPATIBILITY) {
      $incompatible[] = !empty($info['name']) ? $info['name'] : t('Unknown');
    }
    else {
      $compatible_project = TRUE;
      break;
    }
  }

  if (empty($files)) {
    $errors[] = t('%archive_file does not contain any .info.yml files.', array('%archive_file' => drupal_basename($archive_file)));
  }
  elseif (!$compatible_project) {
    $errors[] = \Drupal::translation()->formatPlural(
    count($incompatible), 
    '%archive_file contains a version of %names that is not compatible with Drupal @version.', 
    '%archive_file contains versions of modules or themes that are not compatible with Drupal @version: %names', 
    array('@version' => \Drupal::CORE_COMPATIBILITY, '%archive_file' => drupal_basename($archive_file), '%names' => implode(', ', $incompatible))
    );
  }

  return $errors;
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!modules!update!update.module/function/update_verify_update_archive/8.1.x