You are here

protected static function InPlaceUpdate::checkModifiedFiles in Automatic Updates 7

Check if files are modified before applying updates.

Parameters

string $project_name: The project name.

\ArchiverZip $archive: The archive.

Return value

bool Return TRUE if modified files exist, FALSE otherwise.

1 call to InPlaceUpdate::checkModifiedFiles()
InPlaceUpdate::update in ./InPlaceUpdate.php

File

./InPlaceUpdate.php, line 141

Class

InPlaceUpdate
Class to apply in-place updates.

Code

protected static function checkModifiedFiles($project_name, \ArchiverZip $archive) {
  $extensions = self::getInfos();
  try {
    $files = iterator_to_array(ModifiedFilesService::getModifiedFiles([
      $extensions[$project_name],
    ]));
  } catch (\RuntimeException $exception) {
    watchdog_exception('automatic_updates', $exception);

    // While not strictly true there are modified files, we can't be sure
    // there aren't any. So assume the worst.
    return TRUE;
  }
  $files = array_unique($files);
  $archive_files = $archive
    ->listContents();
  foreach ($archive_files as $index => &$archive_file) {
    $skipped_files = [
      self::DELETION_MANIFEST,
    ];

    // Skip certain files and all directories.
    if (in_array($archive_file, $skipped_files, TRUE) || substr($archive_file, -1) === '/') {
      unset($archive_files[$index]);
      continue;
    }
    self::stripFileDirectoryPath($archive_file);
  }
  unset($archive_file);
  if ($intersection = array_intersect($files, $archive_files)) {
    watchdog('automatic_updates', 'Can not update because %count files are modified: %paths', [
      '%count' => count($intersection),
      '%paths' => implode(', ', $intersection),
    ], WATCHDOG_ERROR);
    return TRUE;
  }
  return FALSE;
}