diff --git a/setup/src/MageOS/Installer/Model/Command/ThemeConfigurer.php b/setup/src/MageOS/Installer/Model/Command/ThemeConfigurer.php index 629350ec7a0..042e68fbb2f 100644 --- a/setup/src/MageOS/Installer/Model/Command/ThemeConfigurer.php +++ b/setup/src/MageOS/Installer/Model/Command/ThemeConfigurer.php @@ -4,6 +4,7 @@ namespace MageOS\Installer\Model\Command; +use MageOS\Installer\Model\VO\DatabaseConfiguration; use MageOS\Installer\Model\VO\ThemeConfiguration; use Symfony\Component\Console\Output\OutputInterface; @@ -24,12 +25,17 @@ public function __construct( * Apply selected theme to default store view * * @param ThemeConfiguration $themeConfig + * @param DatabaseConfiguration $dbConfig * @param string $baseDir * @param OutputInterface $output * @return bool True if successful */ - public function apply(ThemeConfiguration $themeConfig, string $baseDir, OutputInterface $output): bool - { + public function apply( + ThemeConfiguration $themeConfig, + DatabaseConfiguration $dbConfig, + string $baseDir, + OutputInterface $output + ): bool { if (!$themeConfig->install || empty($themeConfig->theme)) { return true; // No theme to apply } @@ -38,7 +44,7 @@ public function apply(ThemeConfiguration $themeConfig, string $baseDir, OutputIn $output->write('🎨 Applying theme...'); // Get theme ID from theme table - $themeId = $this->getThemeId($themeConfig->theme, $baseDir); + $themeId = $this->getThemeId($themeConfig->theme, $dbConfig); if ($themeId === null) { $output->writeln(' ⚠️'); @@ -77,56 +83,31 @@ public function apply(ThemeConfiguration $themeConfig, string $baseDir, OutputIn } /** - * Get theme ID from theme code + * Get theme ID by querying the database directly * - * @param string $themeCode Theme code (e.g., 'hyva-default', 'Hyva/default') - * @param string $baseDir + * @param string $themeCode Theme code (e.g., 'hyva', 'Hyva/default') + * @param DatabaseConfiguration $dbConfig * @return int|null Theme ID or null if not found */ - private function getThemeId(string $themeCode, string $baseDir): ?int + private function getThemeId(string $themeCode, DatabaseConfiguration $dbConfig): ?int { - // Try to find theme using CLI - $result = $this->processRunner->runMagentoCommand( - ['theme:list'], - $baseDir, - timeout: 30 - ); + try { + $pdo = new \PDO( + sprintf('mysql:host=%s;dbname=%s;charset=utf8mb4', $dbConfig->host, $dbConfig->name), + $dbConfig->user, + $dbConfig->password, + [\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION, \PDO::ATTR_TIMEOUT => 5] + ); - if (!$result->isSuccess()) { - return null; - } + $stmt = $pdo->prepare( + "SELECT theme_id FROM theme WHERE area = 'frontend' AND theme_path LIKE :path LIMIT 1" + ); + $stmt->execute([':path' => '%' . $themeCode . '%']); + $id = (int) $stmt->fetchColumn(); - // Parse output to find theme ID - // Format: "| | | | ... |" - $lines = explode("\n", $result->output); - - foreach ($lines as $line) { - // Match lines with theme data (contains pipe separators) - if (!str_contains($line, '|')) { - continue; - } - - // Split by pipe and trim - $parts = array_map('trim', explode('|', $line)); - - if (count($parts) < 4) { - continue; - } - - // Check if this is our theme - // Match on theme code or path (handles 'hyva-default' or 'Hyva/default') - $themePath = $parts[3] ?? ''; - - if (stripos($themePath, $themeCode) !== false || - stripos($themePath, str_replace('-', '/', $themeCode)) !== false - ) { - $themeId = (int) $parts[1]; - if ($themeId > 0) { - return $themeId; - } - } + return $id > 0 ? $id : null; + } catch (\PDOException $e) { + return null; } - - return null; } } diff --git a/setup/src/MageOS/Installer/Model/Stage/PostInstallConfigStage.php b/setup/src/MageOS/Installer/Model/Stage/PostInstallConfigStage.php index d2a1445c11d..d054a8fd4c6 100644 --- a/setup/src/MageOS/Installer/Model/Stage/PostInstallConfigStage.php +++ b/setup/src/MageOS/Installer/Model/Stage/PostInstallConfigStage.php @@ -119,8 +119,9 @@ public function execute(InstallationContext $context, OutputInterface $output): // Apply selected theme to store view $theme = $context->getTheme(); - if ($theme) { - $this->themeConfigurer->apply($theme, BP, $output); + $db = $context->getDatabase(); + if ($theme && $db) { + $this->themeConfigurer->apply($theme, $db, BP, $output); } // Set indexers to schedule mode for better performance diff --git a/setup/src/MageOS/Installer/Model/Stage/ThemeInstallationStage.php b/setup/src/MageOS/Installer/Model/Stage/ThemeInstallationStage.php index 50a15875e03..90970d2c981 100644 --- a/setup/src/MageOS/Installer/Model/Stage/ThemeInstallationStage.php +++ b/setup/src/MageOS/Installer/Model/Stage/ThemeInstallationStage.php @@ -81,8 +81,8 @@ public function execute(InstallationContext $context, OutputInterface $output): $baseDir = BP; - // Install theme - $this->themeInstaller->install($baseDir, $theme->toArray(), $output); + // Install theme (pass sensitive=true so Hyva credentials are included) + $this->themeInstaller->install($baseDir, $theme->toArray(true), $output); return StageResult::continue(); } diff --git a/setup/src/MageOS/Installer/Model/VO/ThemeConfiguration.php b/setup/src/MageOS/Installer/Model/VO/ThemeConfiguration.php index 7a9ebc14b92..8dd613d6b52 100644 --- a/setup/src/MageOS/Installer/Model/VO/ThemeConfiguration.php +++ b/setup/src/MageOS/Installer/Model/VO/ThemeConfiguration.php @@ -14,25 +14,36 @@ class ThemeConfiguration /** * @param bool $install * @param string $theme + * @param string $hyvaProjectKey + * @param string $hyvaApiToken */ public function __construct( public readonly bool $install, - public readonly string $theme = '' + public readonly string $theme = '', + public readonly string $hyvaProjectKey = '', + public readonly string $hyvaApiToken = '' ) { } /** * Convert to array * - * @param bool $includeSensitive Whether to include sensitive fields (none here) + * @param bool $includeSensitive Whether to include sensitive fields like API tokens * @return array */ public function toArray(bool $includeSensitive = false): array { - return [ + $data = [ 'install' => $this->install, - 'theme' => $this->theme + 'theme' => $this->theme, + 'hyva_project_key' => $this->hyvaProjectKey, ]; + + if ($includeSensitive) { + $data['hyva_api_token'] = $this->hyvaApiToken; + } + + return $data; } /** @@ -45,7 +56,9 @@ public static function fromArray(array $data): self { return new self( $data['install'] ?? false, - $data['theme'] ?? '' + $data['theme'] ?? '', + $data['hyva_project_key'] ?? '', + $data['hyva_api_token'] ?? '' ); } }