Commit 024968ae authored by heddn's avatar heddn Committed by heddn
Browse files

Issue #3092777 by heddn: Fail in place update if modified files hash is not available

parent ffe12a44
......@@ -114,7 +114,15 @@ class InPlaceUpdate {
*/
protected static function checkModifiedFiles($project_name, \ArchiverZip $archive) {
$extensions = self::getInfos();
$files = iterator_to_array(ModifiedFilesService::getModifiedFiles([$extensions[$project_name]]));
try {
$files = iterator_to_array(ModifiedFilesService::getModifiedFiles([$extensions[$project_name]], TRUE));
}
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) {
......
......@@ -10,24 +10,37 @@ use Drupal\Signify\Verifier;
class ModifiedFilesService {
/**
* ModifiedCode constructor.
* Get list of modified files.
*
* @param array $extensions
* The list of extensions, keyed by extension name with values an info
* array.
* @param bool $exception_on_failure
* (optional) Throw exception on HTTP failures, defaults to FALSE.
*
* @return \Iterator
* The modified files.
*/
public function __construct() {
public static function getModifiedFiles(array $extensions = [], $exception_on_failure = FALSE) {
$project_root = drupal_get_path('module', 'automatic_updates');
require_once $project_root . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
}
/**
* {@inheritdoc}
*/
public static function getModifiedFiles(array $extensions = []) {
$modified_files = new \ArrayIterator();
foreach (static::getHashRequests($extensions) as $hash_info) {
$response = drupal_http_request(reset($hash_info));
$url = reset($hash_info);
$response = drupal_http_request($url);
$extension_name = key($hash_info);
if (isset($response->code) && ($response->code === 200)) {
if (isset($response->code) && ($response->code === '200')) {
static::processHashes($response->data, $extensions[$extension_name], $modified_files);
}
else if ($exception_on_failure) {
throw new \RuntimeException(sprintf('Request for %s resulted in %s.', $url, $response->error));
}
else {
watchdog('automatic_updates', 'Request for @url resulted in @error.', [
'@url' => $url,
'@error' => $response->error,
], WATCHDOG_WARNING);
}
}
return $modified_files;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment