public function testPublish() { $this->appState->expects($this->once())->method('getMode')->will($this->returnValue(\Magento\Framework\App\State::MODE_PRODUCTION)); $this->staticDirRead->expects($this->once())->method('isExist')->with('some/file.ext')->will($this->returnValue(false)); $this->rootDirWrite->expects($this->once())->method('getRelativePath')->with('/root/some/file.ext')->will($this->returnValue('some/file.ext')); $this->rootDirWrite->expects($this->once())->method('copyFile')->with('some/file.ext', 'some/file.ext', $this->staticDirWrite)->will($this->returnValue(true)); $this->assertTrue($this->object->publish($this->getAsset())); }
/** * @inheritdoc */ protected function generateRelatedFile($relatedFileId, LocalInterface $asset) { $relatedAsset = parent::generateRelatedFile($relatedFileId, $asset); if ($this->hasRelatedPublishing || WorkflowType::CLIENT_SIDE_COMPILATION === $this->scopeConfig->getValue(WorkflowType::CONFIG_NAME_PATH)) { $this->assetPublisher->publish($relatedAsset); } return $relatedAsset; }
public function testPublish() { $this->staticDirRead->expects($this->once())->method('isExist')->with('some/file.ext')->will($this->returnValue(false)); $materializationStrategy = $this->getMock('Magento\\Framework\\App\\View\\Asset\\MaterializationStrategy\\StrategyInterface', [], [], '', false); $this->materializationStrategyFactory->expects($this->once())->method('create')->with($this->getAsset())->will($this->returnValue($materializationStrategy)); $materializationStrategy->expects($this->once())->method('publishFile')->with($this->sourceDirWrite, $this->staticDirWrite, 'file.ext', 'some/file.ext')->will($this->returnValue(true)); $this->assertTrue($this->object->publish($this->getAsset())); }
/** * Deploy a static view file * * @param string $filePath * @param string $area * @param string $themePath * @param string $locale * @param string $module * @return void */ private function deployFile($filePath, $area, $themePath, $locale, $module) { $requestedPath = $filePath; if (substr($filePath, -5) == '.less') { $requestedPath = preg_replace('/.less$/', '.css', $filePath); } $logMessage = "Processing file '{$filePath}' for area '{$area}', theme '{$themePath}', locale '{$locale}'"; if ($module) { $logMessage .= ", module '{$module}'"; } $this->logger->logDebug($logMessage); try { $asset = $this->assetRepo->createAsset($requestedPath, ['area' => $area, 'theme' => $themePath, 'locale' => $locale, 'module' => $module]); $asset = $this->minifyService->getAssets([$asset], true)[0]; $this->logger->logDebug("\tDeploying the file to '{$asset->getPath()}'", '.'); if ($this->isDryRun) { $asset->getContent(); } else { $this->assetPublisher->publish($asset); $this->bundleManager->addAsset($asset); } $this->count++; } catch (\Magento\Framework\View\Asset\File\NotFoundException $e) { // File was not found by Fallback (possibly because it's wrong context for it) - there is nothing to publish $this->logger->logDebug("\tNotice: Could not find file '{$filePath}'. This file may not be relevant for the theme or area."); } catch (\Less_Exception_Compiler $e) { $this->logger->logDebug("\tNotice: Could not parse LESS file '{$filePath}'. " . "This may indicate that the file is incomplete, but this is acceptable. " . "The file '{$filePath}' will be combined with another LESS file."); } catch (\Exception $e) { $this->logger->logError($e->getMessage() . " ({$logMessage})"); $this->logger->logDebug((string) $e); $this->errorCount++; } }
/** * {@inheritdoc} * @throws \InvalidArgumentException */ protected function execute(InputInterface $input, OutputInterface $output) { $area = $input->getOption(self::AREA_OPTION); $locale = $input->getOption(self::LOCALE_OPTION); $theme = $input->getOption(self::THEME_OPTION); $type = $input->getOption(self::TYPE_ARGUMENT); $files = $input->getArgument(self::FILE_ARGUMENT); if (!$this->validator->isValid($locale)) { throw new \InvalidArgumentException($locale . ' argument has invalid value, please run info:language:list for list of available locales'); } if (!preg_match('#^[\\w\\-]+\\/[\\w\\-]+$#', $theme)) { throw new \InvalidArgumentException('Value "' . $theme . '" of the option "' . self::THEME_OPTION . '" has invalid format. The format should be "Vendor/theme".'); } $message = sprintf('<info>Processed Area: %s, Locale: %s, Theme: %s, File type: %s.</info>', $area, $locale, $theme, $type); $output->writeln($message); foreach ($files as $file) { $fileInfo = pathinfo($file); $asset = $this->assetRepository->createAsset($fileInfo['dirname'] . DIRECTORY_SEPARATOR . $fileInfo['basename'] . '.' . $type, ['area' => $area, 'theme' => $theme, 'locale' => $locale]); try { $this->assetPublisher->publish($asset); } catch (\Magento\Framework\View\Asset\File\NotFoundException $e) { throw new \InvalidArgumentException('Verify entered values of the argument and options. ' . $e->getMessage()); } $output->writeln('<comment>-> ' . $asset->getFilePath() . '</comment>'); } $output->writeln('<info>Successfully processed.</info>'); }
/** * Finds requested resource and provides it to the client * * @return \Magento\Framework\App\ResponseInterface * @throws \Exception */ public function launch() { $appMode = $this->state->getMode(); if ($appMode == \Magento\Framework\App\State::MODE_PRODUCTION) { $this->response->setHttpResponseCode(404); } else { try { $path = $this->request->get('resource'); $params = $this->parsePath($path); $this->state->setAreaCode($params['area']); $this->objectManager->configure($this->configLoader->load($params['area'])); $file = $params['file']; unset($params['file']); $asset = $this->assetRepo->createAsset($file, $params); $this->response->setFilePath($asset->getSourceFile()); $this->publisher->publish($asset); } catch (\Exception $e) { if ($appMode == \Magento\Framework\App\State::MODE_DEVELOPER) { throw $e; } $this->response->setHttpResponseCode(404); } } return $this->response; }
/** * Finds requested resource and provides it to the client * * @return \Magento\Framework\App\ResponseInterface * @throws \Exception */ public function launch() { // disabling profiling when retrieving static resource \Magento\Framework\Profiler::reset(); $appMode = $this->state->getMode(); if ($appMode == \Magento\Framework\App\State::MODE_PRODUCTION) { $this->response->setHttpResponseCode(404); } else { $path = $this->request->get('resource'); $params = $this->parsePath($path); $this->state->setAreaCode($params['area']); $this->objectManager->configure($this->configLoader->load($params['area'])); $file = $params['file']; unset($params['file']); $asset = $this->assetRepo->createAsset($file, $params); $this->response->setFilePath($asset->getSourceFile()); $this->publisher->publish($asset); } return $this->response; }
/** * Deploy a static view file * * @param string $filePath * @param string $area * @param string $themePath * @param string $locale * @param string $module * @return void * @SuppressWarnings(PHPMD.NPathComplexity) */ private function deployFile($filePath, $area, $themePath, $locale, $module) { $requestedPath = $filePath; if (substr($filePath, -5) == '.less') { $requestedPath = preg_replace('/.less$/', '.css', $filePath); } $logMessage = "Processing file '$filePath' for area '$area', theme '$themePath', locale '$locale'"; if ($module) { $logMessage .= ", module '$module'"; } if ($this->output->isVeryVerbose()) { $this->output->writeln($logMessage); } try { $asset = $this->assetRepo->createAsset( $requestedPath, ['area' => $area, 'theme' => $themePath, 'locale' => $locale, 'module' => $module] ); $asset = $this->minifyService->getAssets([$asset], true)[0]; if ($this->output->isVeryVerbose()) { $this->output->writeln("\tDeploying the file to '{$asset->getPath()}'"); } else { $this->output->write('.'); } if ($this->isDryRun) { $asset->getContent(); } else { $this->assetPublisher->publish($asset); $this->bundleManager->addAsset($asset); } $this->count++; } catch (\Less_Exception_Compiler $e) { $this->verboseLog( "\tNotice: Could not parse LESS file '$filePath'. " . "This may indicate that the file is incomplete, but this is acceptable. " . "The file '$filePath' will be combined with another LESS file." ); $this->verboseLog("\tCompiler error: " . $e->getMessage()); } catch (\Exception $e) { $this->output->writeln($e->getMessage() . " ($logMessage)"); $this->verboseLog($e->getTraceAsString()); $this->errorCount++; } }
/** * Deploy a static view file * * @param string $filePath * @param string $area * @param string $themePath * @param string $locale * @param string $module * @param string|null $fullPath * @return string * @throws \InvalidArgumentException * @throws LocalizedException * * @SuppressWarnings(PHPMD.NPathComplexity) * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ private function deployFile($filePath, $area, $themePath, $locale, $module, $fullPath = null) { $compiledFile = ''; $extension = pathinfo($filePath, PATHINFO_EXTENSION); foreach ($this->alternativeSources as $name => $alternative) { if (in_array($extension, $alternative->getAlternativesExtensionsNames(), true) && strpos(basename($filePath), '_') !== 0) { $compiledFile = substr($filePath, 0, strlen($filePath) - strlen($extension) - 1); $compiledFile = $compiledFile . '.' . $name; } } if ($this->output->isVeryVerbose()) { $logMessage = "Processing file '{$filePath}' for area '{$area}', theme '{$themePath}', locale '{$locale}'"; if ($module) { $logMessage .= ", module '{$module}'"; } $this->output->writeln($logMessage); } try { $asset = $this->assetRepo->createAsset($filePath, ['area' => $area, 'theme' => $themePath, 'locale' => $locale, 'module' => $module]); if ($this->output->isVeryVerbose()) { $this->output->writeln("\tDeploying the file to '{$asset->getPath()}'"); } else { $this->output->write('.'); } if ($this->getOption(Options::DRY_RUN)) { $asset->getContent(); } else { $this->assetPublisher->publish($asset); $this->bundleManager->addAsset($asset); } $this->count++; } catch (ContentProcessorException $exception) { $pathInfo = $fullPath ?: $filePath; $errorMessage = __('Compilation from source: ') . $pathInfo . PHP_EOL . $exception->getMessage(); $this->errorCount++; $this->output->write(PHP_EOL . PHP_EOL . $errorMessage . PHP_EOL, true); $this->getLogger()->critical($errorMessage); } catch (\Exception $exception) { $this->output->write('.'); $this->verboseLog($exception->getTraceAsString()); $this->errorCount++; } return $compiledFile; }
/** * @inheritdoc * @throws \InvalidArgumentException */ protected function execute(InputInterface $input, OutputInterface $output) { $area = $input->getOption(self::AREA_OPTION); $locale = $input->getOption(self::LOCALE_OPTION); $theme = $input->getOption(self::THEME_OPTION); $type = $input->getOption(self::TYPE_ARGUMENT); $files = $input->getArgument(self::FILE_ARGUMENT); if (!$this->validator->isValid($locale)) { throw new \InvalidArgumentException($locale . ' argument has invalid value, please run info:language:list for list of available locales'); } $message = sprintf('<info>Processed Area: %s, Locale: %s, Theme: %s, File type: %s.</info>', $area, $locale, $theme, $type); $output->writeln($message); foreach ($files as $file) { $fileInfo = pathinfo($file); $asset = $this->assetRepository->createAsset($fileInfo['dirname'] . DIRECTORY_SEPARATOR . $fileInfo['basename'] . '.' . $type, ['area' => $area, 'theme' => $theme, 'locale' => $locale]); $this->assetPublisher->publish($asset); $output->writeln('<comment>-> ' . $asset->getFilePath() . '</comment>'); } $output->writeln('<info>Successfully processed.</info>'); }
/** * Deploy a static view file * * @param string $filePath * @param string $area * @param string $themePath * @param string $locale * @param string $module * @return void */ private function deployFile($filePath, $area, $themePath, $locale, $module) { $requestedPath = $filePath; if (substr($filePath, -5) == '.less') { $requestedPath = preg_replace('/.less$/', '.css', $filePath); } $logModule = $module ? "<{$module}>" : (null === $module ? '<lib>' : '<theme>'); try { $asset = $this->assetRepo->createAsset($requestedPath, ['area' => $area, 'theme' => $themePath, 'locale' => $locale, 'module' => $module]); $this->logger->logDebug("{$logModule} {$filePath} -> {$asset->getPath()}"); if ($this->isDryRun) { $asset->getContent(); } else { $this->assetPublisher->publish($asset); } $this->count++; } catch (\Exception $e) { $this->logger->logError("{$logModule} {$filePath}"); $this->logger->logDebug((string) $e); $this->errorCount++; } }
/** * {inheritdoc} */ protected function generateRelatedFile($relatedFileId, LocalInterface $asset) { $relatedAsset = parent::generateRelatedFile($relatedFileId, $asset); $this->publisher->publish($relatedAsset); return $relatedAsset; }