Skip to content

Commit d40b3c5

Browse files
committed
feat: improve theme selection handling in CopyFromVendorCommand
1 parent d84ec1e commit d40b3c5

2 files changed

Lines changed: 32 additions & 14 deletions

File tree

src/Console/Command/Theme/CopyFromVendorCommand.php

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,16 +141,29 @@ private function getThemeCode(InputInterface $input): string
141141
throw new \RuntimeException('No themes found to copy to.');
142142
}
143143

144+
if (!$input->isInteractive()) {
145+
$themeList = implode(', ', array_keys($options));
146+
throw new \RuntimeException(
147+
"Theme argument is missing. Available themes: $themeList"
148+
);
149+
}
150+
144151
$this->fixPromptEnvironment();
145152

146-
return (string) search(
147-
label: 'Select target theme',
148-
options: fn (string $value) => array_filter(
149-
$options,
150-
fn ($option) => str_contains(strtolower($option), strtolower($value))
151-
),
152-
placeholder: 'Search for a theme...'
153-
);
153+
try {
154+
$result = search(
155+
label: 'Select target theme',
156+
options: fn (string $value) => array_filter(
157+
$options,
158+
fn ($option) => str_contains(strtolower($option), strtolower($value))
159+
),
160+
placeholder: 'Search for a theme...'
161+
);
162+
\Laravel\Prompts\Prompt::terminal()->restoreTty();
163+
return (string) $result;
164+
} finally {
165+
$this->resetPromptEnvironment();
166+
}
154167
}
155168

156169
/**

src/Service/VendorFileMapper.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -211,29 +211,32 @@ private function isAreaCompatible(string $sourceArea, string $targetArea): bool
211211
*
212212
* @param string $compatModuleName
213213
* @return string|null
214+
* @phpcs:disable Magento2.PHP.LiteralNamespaces.LiteralClassUsage
214215
*/
215216
private function getOriginalModuleFromCompatRegistry(string $compatModuleName): ?string
216217
{
218+
$registryClass = 'Hyva\CompatModuleFallback\Model\CompatModuleRegistry';
219+
//phpcs:enable
220+
217221
// 1. Try Registry (via Emulated Area)
218-
if (!class_exists(\Hyva\CompatModuleFallback\Model\CompatModuleRegistry::class)) {
222+
if (!class_exists($registryClass)) {
219223
return $this->parseCompatModuleXml($compatModuleName);
220224
}
221225

222226
try {
223227
// Emulate frontend area to load proper DI configuration for CompatModuleRegistry
224228
// as CLI commands run in global scope where frontend/di.xml is ignored.
225-
/** @var \Hyva\CompatModuleFallback\Model\CompatModuleRegistry|null $registry */
229+
/** @var mixed|\Hyva\CompatModuleFallback\Model\CompatModuleRegistry|null $registry */
226230
$registry = $this->appState->emulateAreaCode(
227231
Area::AREA_FRONTEND,
228-
function () {
232+
function () use ($registryClass) {
229233
// Use create() to ensure we get a fresh instance with the emulated configuration.
230234
// get() might return a cached instance from global scope (empty).
231-
return $this->objectManager->create(\Hyva\CompatModuleFallback\Model\CompatModuleRegistry::class);
235+
return $this->objectManager->create($registryClass);
232236
}
233237
);
234238

235239
if ($registry) {
236-
/** @var \Hyva\CompatModuleFallback\Model\CompatModuleRegistry $registry */
237240
return $this->findOriginalModuleInRegistry($registry, $compatModuleName);
238241
}
239242
} catch (\Throwable $e) {
@@ -248,7 +251,7 @@ function () {
248251
/**
249252
* Find original module in registry
250253
*
251-
* @param \Hyva\CompatModuleFallback\Model\CompatModuleRegistry $registry
254+
* @param mixed $registry Hyva\CompatModuleFallback\Model\CompatModuleRegistry
252255
* @param string $compatModuleName
253256
* @return string|null
254257
*/
@@ -366,6 +369,8 @@ private function parseDiFileForCompatModule(string $diPath, string $moduleName):
366369
}
367370

368371
/**
372+
* Find original module in XML items
373+
*
369374
* @param \DOMNodeList<\DOMNode> $items
370375
* @param \DOMXPath $xpath
371376
* @param string $moduleName

0 commit comments

Comments
 (0)