function SandboxDatabaseUpdatesValidator::hasStagedUpdates

Same name and namespace in other branches
  1. main core/modules/package_manager/src/Validator/SandboxDatabaseUpdatesValidator.php \Drupal\package_manager\Validator\SandboxDatabaseUpdatesValidator::hasStagedUpdates()

Determines if a staged extension has changed update functions.

@todo In https://drupal.org/i/3253828 use a more sophisticated method to detect changes in the staged extension. Right now, we just compare hashes of the .install and .post_update.php files in both copies of the given extension, but this will cause false positives for changes to comments, whitespace, or runtime code like requirements checks. It would be preferable to use a static analyzer to detect new or changed functions that are actually executed during an update. No matter what, this method must NEVER cause false negatives, since that could result in code which is incompatible with the current database schema being copied to the active directory.

Parameters

string $stage_dir: The path of the stage directory.

\Drupal\Core\Extension\Extension $extension: The extension to check.

Return value

bool TRUE if the staged copy of the extension has changed update functions compared to the active copy, FALSE otherwise.

1 call to SandboxDatabaseUpdatesValidator::hasStagedUpdates()
SandboxDatabaseUpdatesValidator::getExtensionsWithDatabaseUpdates in core/modules/package_manager/src/Validator/SandboxDatabaseUpdatesValidator.php
Gets extensions that have database updates in the stage directory.

File

core/modules/package_manager/src/Validator/SandboxDatabaseUpdatesValidator.php, line 76

Class

SandboxDatabaseUpdatesValidator
Flags a warning if there are database updates in a staged update.

Namespace

Drupal\package_manager\Validator

Code

public function hasStagedUpdates(string $stage_dir, Extension $extension) : bool {
  $active_dir = $this->pathLocator
    ->getProjectRoot();
  $web_root = $this->pathLocator
    ->getWebRoot();
  if ($web_root) {
    $active_dir .= DIRECTORY_SEPARATOR . $web_root;
    $stage_dir .= DIRECTORY_SEPARATOR . $web_root;
  }
  $active_functions = $this->getUpdateFunctions($active_dir, $extension);
  $staged_functions = $this->getUpdateFunctions($stage_dir, $extension);
  return (bool) array_diff($staged_functions, $active_functions);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.