themeRegistration = $themeRegistration; $this->themeCollection = $themeCollection; $this->themeLoader = $themeLoader; $this->logger = $logger; $this->appState = $appState; } /** * Add new theme from filesystem and update existing * * @param AbstractAction $subject * @param RequestInterface $request * * @return void * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function beforeDispatch( AbstractAction $subject, RequestInterface $request ) { try { if ($this->appState->getMode() != AppState::MODE_PRODUCTION) { $this->themeRegistration->register(); $this->updateThemeData(); } } catch (LocalizedException $e) { $this->logger->critical($e); } } /** * Update theme data * * @return void */ protected function updateThemeData() { $themesFromConfig = $this->themeCollection->loadData(); /** @var \Magento\Theme\Model\Theme $themeFromConfig */ foreach ($themesFromConfig as $themeFromConfig) { /** @var \Magento\Theme\Model\Theme $themeFromDb */ $themeFromDb = $this->themeLoader->getThemeByFullPath( $themeFromConfig->getArea() . Theme::THEME_PATH_SEPARATOR . $themeFromConfig->getThemePath() ); if ($themeFromConfig->getParentTheme()) { $parentThemeFromDb = $this->themeLoader->getThemeByFullPath( $themeFromConfig->getParentTheme()->getFullPath() ); $themeFromDb->setParentId($parentThemeFromDb->getId()); } $themeFromDb->setThemeTitle($themeFromConfig->getThemeTitle()); $themeFromDb->save(); } } }