Example #1
0
 /**
  * Set destination file path prefix
  *
  * @param string $path
  * @return bool
  */
 public function setDestDir($path)
 {
     if (is_string($path) && $this->_directory->isWritable($path)) {
         $this->_destDir = $path;
         return true;
     }
     return false;
 }
Example #2
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 #3
0
 /**
  * Disables all cache types by updating env.php.
  *
  * @return void
  */
 private function disableAllCacheTypes()
 {
     $envPath = $this->getEnvPath();
     if ($this->write->isWritable($this->write->getRelativePath($envPath))) {
         $envData = (include $envPath);
         if (isset($envData['cache_types'])) {
             $cacheTypes = array_keys($envData['cache_types']);
             foreach ($cacheTypes as $cacheType) {
                 $envData['cache_types'][$cacheType] = 0;
             }
             $formatter = new PhpFormatter();
             $contents = $formatter->format($envData);
             $this->write->writeFile($this->write->getRelativePath($envPath), $contents);
             if (function_exists('opcache_invalidate')) {
                 opcache_invalidate($this->write->getAbsolutePath($envPath));
             }
         }
     }
 }
Example #4
0
 /**
  * Goes to specified host/path and fetches reports from there.
  * Save reports to database.
  *
  * @param \Magento\Framework\Filesystem\Io\Sftp $connection
  * @return int Number of report rows that were fetched and saved successfully
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function fetchAndSave(\Magento\Framework\Filesystem\Io\Sftp $connection)
 {
     $fetched = 0;
     $listing = $this->_filterReportsList($connection->rawls());
     foreach ($listing as $filename => $attributes) {
         $localCsv = 'PayPal_STL_' . uniqid(\Magento\Framework\Math\Random::getRandomNumber()) . time() . '.csv';
         if ($connection->read($filename, $this->_tmpDirectory->getAbsolutePath($localCsv))) {
             if (!$this->_tmpDirectory->isWritable($localCsv)) {
                 throw new \Magento\Framework\Exception\LocalizedException(__('We cannot create a target file for reading reports.'));
             }
             $encoded = $this->_tmpDirectory->readFile($localCsv);
             $csvFormat = 'new';
             $fileEncoding = mb_detect_encoding($encoded);
             if (self::FILES_OUT_CHARSET != $fileEncoding) {
                 $decoded = @iconv($fileEncoding, self::FILES_OUT_CHARSET . '//IGNORE', $encoded);
                 $this->_tmpDirectory->writeFile($localCsv, $decoded);
                 $csvFormat = 'old';
             }
             // Set last modified date, this value will be overwritten during parsing
             if (isset($attributes['mtime'])) {
                 $date = new \DateTime();
                 $lastModified = $date->setTimestamp($attributes['mtime']);
                 $this->setReportLastModified($lastModified->format('Y-m-d H:i:s'));
             }
             $this->setReportDate($this->_fileNameToDate($filename))->setFilename($filename)->parseCsv($localCsv, $csvFormat);
             if ($this->getAccountId()) {
                 $this->save();
             }
             if ($this->_dataSaveAllowed) {
                 $fetched += count($this->_rows);
             }
             // clean object and remove parsed file
             $this->unsetData();
             $this->_tmpDirectory->delete($localCsv);
         }
     }
     return $fetched;
 }