Skip to content

Commit f93d1fe

Browse files
ACMS-4234: Update config action to work with drupal core php script command.
1 parent e6f9bc0 commit f93d1fe

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

modules/acquia_cms_site_studio/src/Plugin/ConfigAction/BasePackageImport.php

+33-3
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,17 @@
66

77
use Drupal\cohesion\Controller\AdministrationController;
88
use Drupal\cohesion_sync\Services\PackageImportHandler;
9+
use Drupal\Component\Render\PlainTextOutput;
910
use Drupal\Core\Config\Action\Attribute\ConfigAction;
1011
use Drupal\Core\Config\Action\ConfigActionPluginInterface;
1112
use Drupal\Core\Config\ConfigFactoryInterface;
1213
use Drupal\Core\Extension\ModuleHandler;
1314
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
1415
use Drupal\Core\Site\Settings;
1516
use Drupal\Core\StringTranslation\TranslatableMarkup;
17+
use Symfony\Component\Console\Input\ArgvInput;
18+
use Symfony\Component\Console\Output\ConsoleOutput;
19+
use Symfony\Component\Console\Style\SymfonyStyle;
1620
use Symfony\Component\DependencyInjection\ContainerInterface;
1721

1822
/**
@@ -61,7 +65,6 @@ public static function create(ContainerInterface $container, array $configuratio
6165
*/
6266
public function apply(string $configName, mixed $value): void {
6367
if ($configName === 'cohesion.settings' && $value) {
64-
// Update the configuration with the API and organization keys.
6568
$this->updateConfig($configName);
6669
}
6770
}
@@ -90,8 +93,35 @@ private function updateConfig(string $configName): void {
9093
->set('organization_key', $orgKey)
9194
->save(TRUE);
9295

93-
// Import the base packages.
94-
$this->importBasePackages();
96+
if (PHP_SAPI === 'cli' && !function_exists('drush_backend_batch_process')) {
97+
$this->notifyManualImport();
98+
} else {
99+
$this->importBasePackages();
100+
}
101+
}
102+
103+
/**
104+
* Notifies the user to import packages manually from the UI.
105+
*/
106+
private function notifyManualImport(): void {
107+
$output = new SymfonyStyle(new ArgvInput(), new ConsoleOutput());
108+
$output->warning($this->toPlainString(
109+
t('Please import site studio packages from UI: @uri.', [
110+
'@uri' => '/admin/cohesion/configuration/account-settings'
111+
])));
112+
}
113+
114+
/**
115+
* Converts a stringable like TranslatableMarkup to a plain text string.
116+
*
117+
* @param \Stringable|string $text
118+
* The string to convert.
119+
*
120+
* @return string
121+
* The plain text string.
122+
*/
123+
private function toPlainString(\Stringable|string $text): string {
124+
return PlainTextOutput::renderFromHtml((string) $text);
95125
}
96126

97127
/**

0 commit comments

Comments
 (0)