Example #1
0
 /**
  * Clean var/generation, var/di and var/cache
  *
  * @return void
  */
 public function cleanGeneratedFiles()
 {
     if ($this->write->isExist(self::REGENERATE_FLAG)) {
         $enabledCacheTypes = [];
         //TODO: to be removed in scope of MAGETWO-53476
         $deploymentConfig = $this->directoryList->getPath(DirectoryList::CONFIG);
         $configPool = new ConfigFilePool();
         $envPath = $deploymentConfig . '/' . $configPool->getPath(ConfigFilePool::APP_ENV);
         if ($this->write->isExist($this->write->getRelativePath($envPath))) {
             $enabledCacheTypes = $this->getEnabledCacheTypes();
             $this->disableAllCacheTypes();
         }
         //TODO: Till here
         $cachePath = $this->write->getRelativePath($this->directoryList->getPath(DirectoryList::CACHE));
         $generationPath = $this->write->getRelativePath($this->directoryList->getPath(DirectoryList::GENERATION));
         $diPath = $this->write->getRelativePath($this->directoryList->getPath(DirectoryList::DI));
         // Clean var/generation dir
         if ($this->write->isDirectory($generationPath)) {
             $this->write->delete($generationPath);
         }
         // Clean var/di
         if ($this->write->isDirectory($diPath)) {
             $this->write->delete($diPath);
         }
         // Clean var/cache
         if ($this->write->isDirectory($cachePath)) {
             $this->write->delete($cachePath);
         }
         $this->write->delete(self::REGENERATE_FLAG);
         $this->enableCacheTypes($enabledCacheTypes);
     }
 }
Example #2
0
 /**
  * Write down contents to a temporary file and return its absolute path
  *
  * @param string $relativePath
  * @param string $contents
  * @return string
  */
 public function createFile($relativePath, $contents)
 {
     $filePath = $this->config->getLessMaterializationRelativePath() . '/' . $relativePath;
     if (!$this->tmpDirectory->isExist($filePath)) {
         $this->tmpDirectory->writeFile($filePath, $contents);
     }
     return $this->tmpDirectory->getAbsolutePath($filePath);
 }
Example #3
0
 /**
  * Minify template file
  *
  * @param string $file
  * @return void
  */
 public function minify($file)
 {
     $file = $this->rootDirectory->getRelativePath($file);
     $content = preg_replace('#(?<!]]>)\\s+</#', '</', preg_replace('#((?:<\\?php\\s+(?!echo|print|if|elseif|else)[^\\?]*)\\?>)\\s+#', '$1 ', preg_replace('#(?<!' . implode('|', $this->inlineHtmlTags) . ')\\> \\<#', '><', preg_replace('#(?ix)(?>[^\\S ]\\s*|\\s{2,})(?=(?:(?:[^<]++|<(?!/?(?:textarea|pre|script)\\b))*+)' . '(?:<(?>textarea|pre|script)\\b|\\z))#', ' ', preg_replace('#(?<!:|\\\\|\'|")//(?!\\s*\\<\\!\\[)(?!\\s*]]\\>)[^\\n\\r]*#', '', preg_replace('#(?<!:)//[^\\n\\r]*(\\s\\?\\>)#', '$1', preg_replace('#//[^\\n\\r]*(\\<\\?php)[^\\n\\r]*(\\s\\?\\>)[^\\n\\r]*#', '', $this->rootDirectory->readFile($file))))))));
     if (!$this->htmlDirectory->isExist()) {
         $this->htmlDirectory->create();
     }
     $this->htmlDirectory->writeFile($file, rtrim($content));
 }
Example #4
0
 /**
  * {@inheritDoc}
  */
 protected function tearDown()
 {
     /** @var \Magento\TestFramework\App\State $appState */
     $appState = $this->objectManager->get(\Magento\TestFramework\App\State::class);
     $appState->setMode($this->origMode);
     if ($this->staticDir->isExist('frontend/FrameworkViewMinifier')) {
         $this->staticDir->delete('frontend/FrameworkViewMinifier');
     }
     parent::tearDown();
 }
 /**
  * Check whether generation process has already locked
  *
  * @return bool
  * @throws FileSystemException
  */
 private function isProcessLocked()
 {
     if ($this->tmpDirectory->isExist($this->lockFilePath)) {
         $lockTime = (int) $this->tmpDirectory->readFile($this->lockFilePath);
         if (time() - $lockTime >= self::MAX_LOCK_TIME) {
             $this->tmpDirectory->delete($this->lockFilePath);
             return false;
         }
         return true;
     }
     return false;
 }
Example #6
0
 /**
  * Get path to PayPal certificate file, if file does not exist try to create it
  *
  * @return string
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function getCertPath()
 {
     if (!$this->getContent()) {
         throw new \Magento\Framework\Exception\LocalizedException(__('The PayPal certificate does not exist.'));
     }
     $certFileName = sprintf('cert_%s_%s.pem', $this->getWebsiteId(), strtotime($this->getUpdatedAt()));
     $certFile = self::BASEPATH_PAYPAL_CERT . $certFileName;
     if (!$this->varDirectory->isExist($certFile)) {
         $this->_createCertFile($certFile);
     }
     return $this->varDirectory->getAbsolutePath($certFile);
 }
Example #7
0
 /**
  * @param string $dbCode
  * @throws LocalizedException
  */
 protected function unpackDb($dbCode)
 {
     $this->archive->unpack($this->directory->getAbsolutePath($this->getDbArchiveFilePath($dbCode)), $this->directory->getAbsolutePath($this->database->getDbPath($dbCode)));
     if (!$this->directory->isExist($this->database->getDbPath($dbCode))) {
         throw new LocalizedException(__('Cannot unpack db file.'));
     }
 }
 /**
  * Get list of IP addresses effective for maintenance mode
  *
  * @return string[]
  */
 public function getAddressInfo()
 {
     if ($this->flagDir->isExist(self::IP_FILENAME)) {
         $temp = $this->flagDir->readFile(self::IP_FILENAME);
         return explode(',', trim($temp));
     } else {
         return [];
     }
 }
 /**
  * Check whether generation process has already locked
  *
  * @return bool
  */
 protected function isProcessLocked()
 {
     $lockFilePath = $this->config->getLessMaterializationRelativePath() . '/' . self::LOCK_FILE;
     if ($this->tmpDirectory->isExist($lockFilePath)) {
         $lockTime = time() - (int) $this->tmpDirectory->readFile($lockFilePath);
         if ($lockTime >= self::MAX_LOCK_TIME) {
             $this->tmpDirectory->delete($lockFilePath);
             return false;
         }
         return true;
     }
     return false;
 }
Example #10
0
 /**
  * Create flag in case when value is set to 'true', remove it if value is set to 'false'.
  *
  * @param string $pathToFlagFile
  * @param bool $value
  * @return $this
  */
 protected function setFlagValue($pathToFlagFile, $value)
 {
     if ($value) {
         try {
             $this->varReaderWriter->touch($pathToFlagFile);
         } catch (FileSystemException $e) {
             throw new \RuntimeException(sprintf('"%s" cannot be created.', $pathToFlagFile));
         }
     } else {
         if ($this->varReaderWriter->isExist($pathToFlagFile)) {
             $this->varReaderWriter->delete($pathToFlagFile);
         }
     }
     return $this;
 }
Example #11
0
 /**
  * @return string Path to config file
  * @throws \Exception
  */
 public function makeConfig()
 {
     if (!$this->directory->isExist($this->basePath)) {
         //$this->directory->delete($this->basePath);
         $this->directory->create($this->basePath);
         $this->directory->changePermissions($this->basePath, 0777);
     }
     $jsonData = [];
     $sphinxData = ['time' => date('d.m.Y H:i:s'), 'host' => $this->host, 'port' => $this->port, 'fallback_port' => $this->port - 1, 'logdir' => $this->directory->getAbsolutePath($this->basePath), 'sphinxdir' => $this->directory->getAbsolutePath($this->basePath), 'indexes' => '', 'localdir' => dirname(dirname(__FILE__)), 'custom' => $this->config->getAdditionalSearchdConfig()];
     $sphinxTemplate = $this->config->getSphinxConfigurationTemplate();
     $indexTemplate = $this->config->getSphinxIndexConfigurationTemplate();
     /** @var \Mirasvit\Search\Model\Index $index */
     foreach ($this->indexCollectionFactory->create() as $index) {
         foreach (array_keys($this->storeManager->getStores()) as $storeId) {
             $indexName = $index->getIndexInstance()->getIndexer()->getIndexName($storeId);
             $data = ['name' => $indexName, 'min_word_len' => 1, 'path' => $this->directory->getAbsolutePath($this->basePath) . '/' . $indexName, 'custom' => $this->config->getAdditionalIndexConfig()];
             $jsonAttributes = [];
             $attributes = [];
             foreach (array_keys($index->getIndexInstance()->getAttributes(true)) as $attribute) {
                 $attributes[] = "    rt_field = {$attribute}";
                 $jsonAttributes[] = $attribute;
                 if (count($attributes) > 250) {
                     break;
                 }
             }
             $attributes[] = "    rt_field = options";
             $jsonAttributes[] = "options";
             $data['attributes'] = implode(PHP_EOL, $attributes);
             $sphinxData['indexes'] .= $this->helper->filterTemplate($indexTemplate, $data);
             $jsonData[$indexName] = $jsonAttributes;
         }
     }
     $config = $this->helper->filterTemplate($sphinxTemplate, $sphinxData);
     if ($this->directory->isWritable($this->basePath)) {
         $this->directory->writeFile($this->configFilePath, $config);
         $this->directory->writeFile($this->configFilePath . '.attr', json_encode($jsonData));
     } else {
         if ($this->directory->isExist($this->configFilePath)) {
             throw new \Exception(__('File %1 does not writable', $this->configFilePath));
         } else {
             throw new \Exception(__('Directory %1 does not writable', $this->basePath));
         }
     }
     return $this->directory->getAbsolutePath($this->configFilePath);
 }
Example #12
0
 /**
  * Create preview image duplicate
  *
  * @param ThemeInterface $theme
  * @return bool
  */
 public function createPreviewImageCopy(ThemeInterface $theme)
 {
     $previewDir = $this->themeImagePath->getImagePreviewDirectory();
     $sourcePath = $theme->getThemeImage()->getPreviewImagePath();
     $sourceRelativePath = $this->rootDirectory->getRelativePath($sourcePath);
     if (!$theme->getPreviewImage() && !$this->mediaDirectory->isExist($sourceRelativePath)) {
         return false;
     }
     $isCopied = false;
     try {
         $destinationFileName = \Magento\Framework\File\Uploader::getNewFileName($sourcePath);
         $targetRelativePath = $this->mediaDirectory->getRelativePath($previewDir . '/' . $destinationFileName);
         $isCopied = $this->rootDirectory->copyFile($sourceRelativePath, $targetRelativePath, $this->mediaDirectory);
         $this->theme->setPreviewImage($destinationFileName);
     } catch (\Magento\Framework\Filesystem\FilesystemException $e) {
         $this->theme->setPreviewImage(null);
         $this->logger->critical($e);
     }
     return $isCopied;
 }
Example #13
0
    /**
     * Minify template file
     *
     * @param string $file
     * @return void
     */
    public function minify($file)
    {
        $dir = dirname($file);
        $fileName = basename($file);
        $content = preg_replace(
            '#(?<!]]>)\s+</#',
            '</',
            preg_replace(
                '#((?:<\?php\s+(?!echo|print|if|elseif|else)[^\?]*)\?>)\s+#',
                '$1 ',
                preg_replace(
                    '#(?<!' . implode('|', $this->inlineHtmlTags) . ')\> \<#',
                    '><',
                    preg_replace(
                        '#(?ix)(?>[^\S ]\s*|\s{2,})(?=(?:(?:[^<]++|<(?!/?(?:textarea|pre|script)\b))*+)'
                        . '(?:<(?>textarea|pre|script)\b|\z))#',
                        ' ',
                        preg_replace(
                            '#(?<!:|\\\\|\'|")//(?!\s*\<\!\[)(?!\s*]]\>)[^\n\r]*#',
                            '',
                            preg_replace(
                                '#(?<!:)//[^\n\r]*(\s\?\>)#',
                                '$1',
                                preg_replace(
                                    '#(?<!:)//[^\n\r]*(\<\?php)[^\n\r]*(\s\?\>)[^\n\r]*#',
                                    '',
                                    $this->readFactory->create($dir)->readFile($fileName)
                                )
                            )
                        )
                    )
                )
            )
        );

        if (!$this->htmlDirectory->isExist()) {
            $this->htmlDirectory->create();
        }
        $this->htmlDirectory->writeFile($this->getRelativeGeneratedPath($file), rtrim($content));
    }
Example #14
0
 /**
  * Get relative watermark file path
  * or false if file not found
  *
  * @return string | bool
  */
 protected function _getWatermarkFilePath()
 {
     $filePath = false;
     if (!($file = $this->getWatermarkFile())) {
         return $filePath;
     }
     $baseDir = $this->_catalogProductMediaConfig->getBaseMediaPath();
     $candidates = array($baseDir . '/watermark/stores/' . $this->_storeManager->getStore()->getId() . $file, $baseDir . '/watermark/websites/' . $this->_storeManager->getWebsite()->getId() . $file, $baseDir . '/watermark/default/' . $file, $baseDir . '/watermark/' . $file);
     foreach ($candidates as $candidate) {
         if ($this->_mediaDirectory->isExist($candidate)) {
             $filePath = $this->_mediaDirectory->getAbsolutePath($candidate);
             break;
         }
     }
     if (!$filePath) {
         $filePath = $this->_viewFileSystem->getStaticFileName($file);
     }
     return $filePath;
 }
Example #15
0
 /**
  * Clears contents of the log
  *
  * @return void
  */
 public function clear()
 {
     if ($this->directory->isExist($this->logFile)) {
         $this->directory->delete($this->logFile);
     }
 }
Example #16
0
 /**
  * Checks existence of install.log file
  *
  * @return bool
  */
 public function logfileExists()
 {
     return $this->directory->isExist($this->logFile);
 }
 /**
  * Checks if directory exists and is readable
  *
  * @param \Magento\Framework\Filesystem\Directory\WriteInterface $directory
  * @return bool
  */
 protected function isReadableDirectory($directory)
 {
     if (!$directory->isExist() || !$directory->isDirectory() || !$directory->isReadable()) {
         return false;
     }
     return true;
 }