Skip to content
Snippets Groups Projects
Verified Commit 04e1bb20 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3442002 by alexpott, larowlan: @larowlan review on #3439923

(cherry picked from commit 0f5f94f92a3a93e9f38edec75e848365c0483968)
parent 28cf67bd
No related branches found
No related tags found
1 merge request!7908Recipes API on 10.3.x
......@@ -31,10 +31,10 @@
* \Drupal\Core\Config\Action\ConfigActionPluginInterface, in namespace
* Plugin\ConfigAction under your module namespace. For more information about
* creating plugins, see the @link plugin_api Plugin API topic. @endlink
* - Config action plugins use the annotations defined by
* \Drupal\Core\Config\Action\Annotation\ConfigAction. See the
* @link annotation Annotations topic @endlink for more information about
* annotations.
* - Config action plugins use the attributes defined by
* \Drupal\Core\Config\Action\Attribute\ConfigAction. See the
* @link attribute Attributes topic @endlink for more information about
* attributes.
*
* Further information and examples:
* - \Drupal\Core\Config\Action\Plugin\ConfigAction\EntityMethod derives
......@@ -97,7 +97,10 @@ public function __construct(
* action plugin ID or a shorthand action ID that is available for the
* entity type of the provided configuration name.
* @param string $configName
* The configuration name.
* The configuration name. This may be the full name of a config object, or
* it may contain wildcards (to target all config entities of a specific
* type, or a subset thereof). See
* ConfigActionManager::getConfigNamesMatchingExpression() for more detail.
* @param mixed $data
* The data for the action.
*
......@@ -105,6 +108,8 @@ public function __construct(
* Thrown when the config action cannot be found.
* @throws \Drupal\Core\Config\Action\ConfigActionException
* Thrown when the config action fails to apply.
*
* @see \Drupal\Core\Config\Action\ConfigActionManager::getConfigNamesMatchingExpression()
*/
public function applyAction(string $action_id, string $configName, mixed $data): void {
if (!$this->hasDefinition($action_id)) {
......
......@@ -252,39 +252,38 @@ public function getCollectionName() {
public function checkpoint(string|\Stringable $label): Checkpoint {
// Generate a new ID based on the state of the current active checkpoint.
$active_checkpoint = $this->checkpoints->getActiveCheckpoint();
if ($active_checkpoint instanceof Checkpoint) {
$collections = $this->getAllCollectionNames();
$collections[] = StorageInterface::DEFAULT_COLLECTION;
foreach ($collections as $collection) {
$current_checkpoint_data[$collection] = $this->getKeyValue($active_checkpoint->id, $collection)->getAll();
// Remove the collections key because it is irrelevant.
unset($current_checkpoint_data[$collection][static::CONFIG_COLLECTION_KEY]);
// If there is no data in the collection then there is no need to hash
// the empty array.
if (empty($current_checkpoint_data[$collection])) {
unset($current_checkpoint_data[$collection]);
}
}
if (!empty($current_checkpoint_data)) {
// Use json_encode() here because it is both quicker and results in
// smaller output than serialize().
$id = hash('sha1', ($active_checkpoint->parent ?? '') . json_encode($current_checkpoint_data));
$active_checkpoint = $this->checkpoints->add($id, $label);
}
else {
$this->logger?->notice('A backup checkpoint was not created because nothing has changed since the "{active}" checkpoint was created.', [
'active' => $active_checkpoint->label,
]);
}
}
else {
if (!$active_checkpoint instanceof Checkpoint) {
// @todo https://www.drupal.org/i/3408525 Consider options for generating
// a real fingerprint.
$id = hash('sha1', random_bytes(32));
$active_checkpoint = $this->checkpoints->add($id, $label);
return $this->checkpoints->add($id, $label);
}
// Determine if we need to create a new checkpoint by checking if
// configuration has changed since the last checkpoint.
$collections = $this->getAllCollectionNames();
$collections[] = StorageInterface::DEFAULT_COLLECTION;
foreach ($collections as $collection) {
$current_checkpoint_data[$collection] = $this->getKeyValue($active_checkpoint->id, $collection)->getAll();
// Remove the collections key because it is irrelevant.
unset($current_checkpoint_data[$collection][static::CONFIG_COLLECTION_KEY]);
// If there is no data in the collection then there is no need to hash
// the empty array.
if (empty($current_checkpoint_data[$collection])) {
unset($current_checkpoint_data[$collection]);
}
}
if (!empty($current_checkpoint_data)) {
// Use json_encode() here because it is both quicker and results in
// smaller output than serialize().
$id = hash('sha1', ($active_checkpoint->parent ?? '') . json_encode($current_checkpoint_data));
return $this->checkpoints->add($id, $label);
}
$this->logger?->notice('A backup checkpoint was not created because nothing has changed since the "{active}" checkpoint was created.', [
'active' => $active_checkpoint->label,
]);
return $active_checkpoint;
}
......
......@@ -143,8 +143,10 @@ private static function parse(string $file): array {
'install' => new Optional([
new All([
new Type('string'),
new NotBlank(),
new Callback(self::validateExtensionIsAvailable(...)),
new Sequentially([
new NotBlank(),
new Callback(self::validateExtensionIsAvailable(...)),
]),
]),
]),
'config' => new Optional([
......@@ -211,10 +213,6 @@ private static function parse(string $file): array {
* @see \Drupal\Core\Extension\ExtensionList::getAllAvailableInfo()
*/
private static function validateExtensionIsAvailable(string $value, ExecutionContextInterface $context): void {
if (empty($value)) {
return;
}
$name = Dependency::createFromString($value)->getName();
$all_available = \Drupal::service(ModuleExtensionList::class)->getAllAvailableInfo() + \Drupal::service(ThemeExtensionList::class)->getAllAvailableInfo();
if (!array_key_exists($name, $all_available)) {
......
......@@ -58,11 +58,6 @@ protected function configure(): void {
protected function execute(InputInterface $input, OutputInterface $output): int {
$io = new SymfonyStyle($input, $output);
if (PHP_VERSION_ID < 80100) {
$io->error('Recipes require PHP 8.1');
return 1;
}
$recipe_path = $input->getArgument('path');
if (!is_string($recipe_path) || !is_dir($recipe_path)) {
$io->error(sprintf('The supplied path %s is not a directory', $recipe_path));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment