From 438de9af80aff09f22bef6917bcd433ef3cba862 Mon Sep 17 00:00:00 2001 From: rajeshreeputra Date: Thu, 9 Jan 2025 12:00:33 +0530 Subject: [PATCH 1/3] ACMS-4234: Add config action to import core site studio packages. --- .../Plugin/ConfigAction/BasePackageImport.php | 144 ++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 modules/acquia_cms_site_studio/src/Plugin/ConfigAction/BasePackageImport.php diff --git a/modules/acquia_cms_site_studio/src/Plugin/ConfigAction/BasePackageImport.php b/modules/acquia_cms_site_studio/src/Plugin/ConfigAction/BasePackageImport.php new file mode 100644 index 000000000..1cf6525f1 --- /dev/null +++ b/modules/acquia_cms_site_studio/src/Plugin/ConfigAction/BasePackageImport.php @@ -0,0 +1,144 @@ +get('config.factory'), + $container->get('settings'), + $container->get('cohesion_sync.package_import_handler'), + $container->get('module_handler'), + ); + } + + /** + * {@inheritdoc} + */ + public function apply(string $configName, mixed $value): void { + if ($configName === 'cohesion.settings' && $value) { + // Update the configuration with the API and organization keys. + $this->updateConfig($configName); + } + } + + /** + * Updates the configuration with API and organization keys. + * + * @param string $configName + * The name of the configuration. + */ + private function updateConfig(string $configName): void { + $config = $this->configFactory->get($configName); + $apiKey = $config->get('api_key'); + $orgKey = $config->get('organization_key'); + + if (!($apiKey && $orgKey)) { + $apiKey = getenv('SITESTUDIO_API_KEY') ?? $this->settings->get('cohesion.settings')->get('api_key'); + $orgKey = getenv('SITESTUDIO_ORG_KEY') ?? $this->settings->get('cohesion.settings')->get('organization_key'); + if (!($apiKey && $orgKey)) { + return; + } + } + + $this->configFactory->getEditable($configName) + ->set('api_key', $apiKey) + ->set('organization_key', $orgKey) + ->save(TRUE); + + // Import the base packages. + $this->importBasePackages(); + } + + /** + * Imports the base Site Studio packages. + */ + private function importBasePackages(): void { + $this->initializeBatch(); + $package_list_path = $this->getPackageListPath(); + $this->importPackages($package_list_path); + $this->processBatchIfCli(); + } + + /** + * Initializes the batch process for importing packages. + */ + private function initializeBatch(): void { + batch_set(AdministrationController::batchAction(TRUE)); + } + + /** + * Gets the path to the package list file. + * + * @return string + * The path to the package list file. + */ + private function getPackageListPath(): string { + $module_path = $this->moduleHandler->getModule('acquia_cms_site_studio')->getPath(); + return $module_path . '/config/site_studio/site_studio.packages.yml'; + } + + /** + * Imports packages from the specified path. + * + * @param string $package_list_path + * The path to the package list file. + */ + private function importPackages(string $package_list_path): void { + $this->packageImportHandler->importPackagesFromPath($package_list_path); + } + + /** + * Processes the batch if running in CLI mode. + */ + private function processBatchIfCli(): void { + if (PHP_SAPI === 'cli') { + drush_backend_batch_process(); + } + } + +} From 5971c004b99f17313da7179a390ba44aaf570c97 Mon Sep 17 00:00:00 2001 From: rajeshreeputra Date: Thu, 9 Jan 2025 10:49:36 +0530 Subject: [PATCH 2/3] ACMS-4237: Add patch for site studio drupal 11.1 compatibility. --- composer.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.lock b/composer.lock index da7b39f56..ff0ceff1d 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "f7f9e623cf8da30e566ee0d0052fb980", + "content-hash": "a285aa0789cbf1a0b52f8b799237b02c", "packages": [ { "name": "acquia/acquia-cms-starterkit", From 61ae5e00525ee491d47d3afe1405b6c80fbcd09e Mon Sep 17 00:00:00 2001 From: rajeshreeputra Date: Wed, 12 Feb 2025 16:13:45 +0530 Subject: [PATCH 3/3] ACMS-4234: Rebased with latest changes. --- composer.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.lock b/composer.lock index ff0ceff1d..da7b39f56 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "a285aa0789cbf1a0b52f8b799237b02c", + "content-hash": "f7f9e623cf8da30e566ee0d0052fb980", "packages": [ { "name": "acquia/acquia-cms-starterkit",