示例#1
0
 public function testGetDirectoryWrite()
 {
     /** @var \Magento\Framework\Filesystem\Directory\WriteInterface $dirWriteMock */
     $dirWriteMock = $this->getMock('Magento\\Framework\\Filesystem\\Directory\\WriteInterface');
     $this->_dirWriteFactoryMock->expects($this->once())->method('create')->will($this->returnValue($dirWriteMock));
     $this->assertEquals($dirWriteMock, $this->_filesystem->getDirectoryWrite(DirectoryList::ROOT));
 }
 /**
  * @magentoAppArea adminhtml
  * @magentoDbIsolation enabled
  * @magentoAppIsolation enabled
  * @magentoDataFixture Magento/Catalog/_files/product_simple.php
  */
 public function testExport()
 {
     $productRepository = $this->objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
     $index = 0;
     $ids = [];
     $origPricingData = [];
     while (isset($skus[$index])) {
         $ids[$index] = $productRepository->get($skus[$index])->getId();
         $origPricingData[$index] = $this->objectManager->create(\Magento\Catalog\Model\Product::class)->load($ids[$index])->getTierPrices();
         $index++;
     }
     $csvfile = uniqid('importexport_') . '.csv';
     $this->model->setWriter(\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\ImportExport\Model\Export\Adapter\Csv::class, ['fileSystem' => $this->fileSystem, 'destination' => $csvfile]));
     $this->assertNotEmpty($this->model->export());
     /** @var \Magento\AdvancedPricingImportExport\Model\Import\AdvancedPricing $importModel */
     $importModel = $this->objectManager->create(\Magento\AdvancedPricingImportExport\Model\Import\AdvancedPricing::class);
     $directory = $this->fileSystem->getDirectoryWrite(DirectoryList::VAR_DIR);
     $source = $this->objectManager->create(\Magento\ImportExport\Model\Import\Source\Csv::class, ['file' => $csvfile, 'directory' => $directory]);
     $errors = $importModel->setParameters(['behavior' => \Magento\ImportExport\Model\Import::BEHAVIOR_APPEND, 'entity' => 'advanced_pricing'])->setSource($source)->validateData();
     $this->assertTrue($errors->getErrorsCount() == 0, 'Advanced Pricing import error, imported from file:' . $csvfile);
     $importModel->importData();
     while ($index > 0) {
         $index--;
         $newPricingData = $this->objectManager->create(\Magento\Catalog\Model\Product::class)->load($ids[$index])->getTierPrices();
         $this->assertEquals(count($origPricingData[$index]), count($newPricingData));
         $this->assertEqualsOtherThanSkippedAttributes($origPricingData[$index], $newPricingData, []);
     }
 }
示例#3
0
 /**
  * Make sure the aggregated configuration is materialized
  *
  * By default write the file if it doesn't exist, but in developer mode always do it.
  *
  * @param string $relPath
  * @return void
  */
 private function ensureSourceFile($relPath)
 {
     $dir = $this->filesystem->getDirectoryWrite(DirectoryList::STATIC_VIEW);
     if ($this->appState->getMode() == \Magento\Framework\App\State::MODE_DEVELOPER || !$dir->isExist($relPath)) {
         $dir->writeFile($relPath, $this->config->getConfig());
     }
 }
示例#4
0
 /**
  * @param \Magento\Framework\App\Helper\Context $context
  * @param \Magento\Framework\Filesystem $filesystem
  * @param \Magento\Backend\Model\Session $session
  * @param \Magento\Framework\View\Design\Theme\FlyweightFactory $themeFactory
  */
 public function __construct(\Magento\Framework\App\Helper\Context $context, \Magento\Framework\Filesystem $filesystem, \Magento\Backend\Model\Session $session, \Magento\Framework\View\Design\Theme\FlyweightFactory $themeFactory)
 {
     parent::__construct($context);
     $this->filesystem = $filesystem;
     $this->_session = $session;
     $this->_themeFactory = $themeFactory;
     $this->mediaDirectoryWrite = $this->filesystem->getDirectoryWrite(DirectoryList::MEDIA);
     $this->mediaDirectoryWrite->create($this->mediaDirectoryWrite->getRelativePath($this->getStorageRoot()));
 }
 /**
  * @param \Magento\Framework\Json\Encoder $encoder
  * @param \Magento\Framework\App\State $appState
  * @param \Psr\Log\LoggerInterface $logger
  * @param \Magento\Framework\Filesystem $filesystem
  */
 public function __construct(\Magento\Framework\Json\Encoder $encoder, \Magento\Framework\App\State $appState, \Psr\Log\LoggerInterface $logger, \Magento\Framework\Filesystem $filesystem)
 {
     $this->encoder = $encoder;
     $this->_appState = $appState;
     $this->_logger = $logger;
     $this->_filesystem = $filesystem;
     $this->directoryWrite = $this->_filesystem->getDirectoryWrite(DirectoryList::VAR_DIR);
     $this->registerShutdownFunction();
 }
示例#6
0
 /**
  * Publish the asset
  *
  * @param Asset\LocalInterface $asset
  * @return bool
  */
 private function publishAsset(Asset\LocalInterface $asset)
 {
     $targetDir = $this->filesystem->getDirectoryWrite(DirectoryList::STATIC_VIEW);
     $rootDir = $this->filesystem->getDirectoryWrite(DirectoryList::ROOT);
     $source = $rootDir->getRelativePath($asset->getSourceFile());
     $destination = $asset->getPath();
     $strategy = $this->materializationStrategyFactory->create($asset);
     return $strategy->publishFile($rootDir, $targetDir, $source, $destination);
 }
示例#7
0
 /**
  * constructor
  *
  * @param Filesystem $filesystem
  * @param Encoder $encoder
  */
 public function __construct(Filesystem $filesystem, Encoder $encoder)
 {
     $this->filesystem = $filesystem;
     $this->encoder = $encoder;
     $this->connectDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::VAR_DIR);
     $this->connectDirectory->create(Settings::VAR_DIR_NAME);
     $this->addTargetDir($this->connectDirectory->getAbsolutePath(Settings::VAR_DIR_NAME));
     $this->setCollectRecursively(false);
 }
 /**
  * @inheritdoc
  * @throws FileSystemException
  */
 public function lockProcess($lockName)
 {
     $this->tmpDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::VAR_DIR);
     $this->lockFilePath = $this->getFilePath($lockName);
     while ($this->isProcessLocked()) {
         sleep(1);
     }
     $this->tmpDirectory->writeFile($this->lockFilePath, time());
 }
 /**
  * @param Database $coreFileStorageDb
  * @param Storage $coreFileStorage
  * @param NotProtectedExtension $validator
  * @param Filesystem $filesystem
  * @param LinkConfig $linkConfig
  * @param SampleConfig $sampleConfig
  */
 public function __construct(Database $coreFileStorageDb, Storage $coreFileStorage, NotProtectedExtension $validator, Filesystem $filesystem, LinkConfig $linkConfig, SampleConfig $sampleConfig)
 {
     $this->_validator = $validator;
     $this->_coreFileStorage = $coreFileStorage;
     $this->_coreFileStorageDb = $coreFileStorageDb;
     $this->mediaDirectory = $filesystem->getDirectoryWrite(DirectoryList::MEDIA);
     $this->systemTmpDirectory = $filesystem->getDirectoryWrite(DirectoryList::SYS_TMP);
     $this->linkConfig = $linkConfig;
     $this->sampleConfig = $sampleConfig;
 }
示例#10
0
 /**
  * Publish the asset
  *
  * @param Asset\LocalInterface $asset
  * @return bool
  */
 private function publishAsset(Asset\LocalInterface $asset)
 {
     $targetDir = $this->filesystem->getDirectoryWrite(DirectoryList::STATIC_VIEW);
     $fullSource = $asset->getSourceFile();
     $source = basename($fullSource);
     $sourceDir = $this->writeFactory->create(dirname($fullSource));
     $destination = $asset->getPath();
     $strategy = $this->materializationStrategyFactory->create($asset);
     return $strategy->publishFile($sourceDir, $targetDir, $source, $destination);
 }
示例#11
0
 /**
  * Run application
  *
  * @return int
  */
 public function launch()
 {
     /* Clean reports */
     $directory = $this->filesystem->getDirectoryWrite(\Magento\Framework\App\Filesystem::ROOT_DIR);
     $path = $directory->getRelativePath($this->reportDir);
     if ($directory->isExist($path)) {
         $directory->delete($path);
     }
     /* Regenerate all indexers */
     $this->processor->reindexAll();
     return 0;
 }
示例#12
0
 /**
  * @inheritdoc
  * @throws FileSystemException
  */
 public function lockProcess($lockName)
 {
     if ($this->getState()->getMode() == State::MODE_PRODUCTION) {
         return;
     }
     $this->tmpDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::VAR_DIR);
     $this->lockFilePath = $this->getFilePath($lockName);
     while ($this->isProcessLocked()) {
         usleep(1000);
     }
     $this->tmpDirectory->writeFile($this->lockFilePath, time());
 }
示例#13
0
 /**
  * Run application
  *
  * @return \Magento\Framework\App\ResponseInterface
  */
 public function launch()
 {
     /* Clean reports */
     $directory = $this->filesystem->getDirectoryWrite(DirectoryList::ROOT);
     $path = $directory->getRelativePath($this->reportDir);
     if ($directory->isExist($path)) {
         $directory->delete($path);
     }
     /* Regenerate all indexers */
     $this->processor->reindexAll();
     $this->_response->setCode(0);
     return $this->_response;
 }
示例#14
0
 /**
  * @param Filesystem $filesystem
  * @param Filter $filter
  * @param MetadataProvider $metadataProvider
  * @param int $pageSize
  */
 public function __construct(Filesystem $filesystem, Filter $filter, MetadataProvider $metadataProvider, $pageSize = 200)
 {
     $this->filter = $filter;
     $this->directory = $filesystem->getDirectoryWrite(DirectoryList::VAR_DIR);
     $this->metadataProvider = $metadataProvider;
     $this->pageSize = $pageSize;
 }
 /**
  * Constructor
  *
  * @param MagentoComposerApplicationFactory $applicationFactory
  * @param \Magento\Framework\Filesystem $filesystem
  * @param ComposerInformation $composerInformation
  * @param ObjectManagerProvider $objectManagerProvider
  * @throws \Exception
  */
 public function __construct(MagentoComposerApplicationFactory $applicationFactory, Filesystem $filesystem, ComposerInformation $composerInformation, ObjectManagerProvider $objectManagerProvider)
 {
     $this->application = $applicationFactory->create();
     $this->directory = $filesystem->getDirectoryWrite(DirectoryList::VAR_DIR);
     $this->objectManager = $objectManagerProvider->get();
     $this->composerInformation = $composerInformation;
 }
示例#16
0
 /**
  * @param \Magento\Framework\Model\Context $context
  * @param \Magento\Framework\Registry $registry
  * @param \Magento\Store\Model\StoreManagerInterface $storeManager
  * @param \Magento\Framework\Filesystem $filesystem
  * @param \Magento\Framework\Image\Factory $imageFactory
  * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
  * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
  * @param array $data
  * @SuppressWarnings(PHPMD.ExcessiveParameterList)
  * @SuppressWarnings(PHPMD.UnusedLocalVariable)
  */
 public function __construct(\Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\Filesystem $filesystem, \Magento\Framework\Image\Factory $imageFactory, \Magento\Framework\ObjectManagerInterface $objectManager, array $data = [])
 {
     $this->_mediaDirectory = $filesystem->getDirectoryWrite(DirectoryList::MEDIA);
     $this->_imageFactory = $imageFactory;
     $this->_storeManager = $storeManager;
     $this->_objectManager = $objectManager;
 }
示例#17
0
 /**
  * Constructor
  * @param Filesystem $filesystem
  * @param string $logFile
  */
 public function __construct(Filesystem $filesystem, $logFile = null)
 {
     $this->directory = $filesystem->getDirectoryWrite(DirectoryList::LOG);
     if ($logFile) {
         $this->logFile = $logFile;
     }
 }
示例#18
0
 /**
  * @param \Magento\Backend\App\Action\Context $context
  * @param \Magento\Framework\App\Response\Http\FileFactory $fileFactory
  * @param \Magento\Framework\Controller\Result\RawFactory $resultRawFactory
  * @param \Magento\Framework\Filesystem $filesystem
  */
 public function __construct(\Magento\Backend\App\Action\Context $context, \Magento\Framework\App\Response\Http\FileFactory $fileFactory, \Magento\Framework\Controller\Result\RawFactory $resultRawFactory, \Magento\Framework\Filesystem $filesystem)
 {
     parent::__construct($context);
     $this->fileFactory = $fileFactory;
     $this->resultRawFactory = $resultRawFactory;
     $this->fileDirectory = $filesystem->getDirectoryWrite(DirectoryList::MODULES);
 }
示例#19
0
 /**
  * @param \Magento\Backend\Block\Context                      $context
  * @param \Magento\Framework\Filesystem                       $filesystem
  * @param \Magento\Framework\Filesystem\Directory\ReadFactory $directoryRead
  * @param \Magento\Framework\Stdlib\DateTime\DateTime         $coreDate
  * @param array                                               $data
  */
 public function __construct(\Magento\Backend\Block\Context $context, \Magento\Framework\Filesystem $filesystem, \Magento\Framework\Filesystem\Directory\ReadFactory $directoryRead, \Magento\Framework\Stdlib\DateTime\DateTime $coreDate, array $data = [])
 {
     parent::__construct($context, $data);
     $this->_ioRead = $filesystem->getDirectoryWrite(\Magento\Framework\App\Filesystem\DirectoryList::ROOT);
     $this->_coreDate = $coreDate;
     $this->_directoryRead = $directoryRead->create("");
 }
示例#20
0
 /**
  * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
  * @param \Magento\Framework\Filesystem $filesystem
  * @param \Magento\Framework\File\Size $fileSize
  * @param \Magento\Framework\HTTP\Adapter\FileTransferFactory $httpFactory
  * @throws \Magento\Framework\Exception\FileSystemException
  */
 public function __construct(\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Framework\Filesystem $filesystem, \Magento\Framework\File\Size $fileSize, \Magento\Framework\HTTP\Adapter\FileTransferFactory $httpFactory)
 {
     $this->mediaDirectory = $filesystem->getDirectoryWrite(DirectoryList::MEDIA);
     $this->filesystem = $filesystem;
     $this->httpFactory = $httpFactory;
     parent::__construct($scopeConfig, $filesystem, $fileSize);
 }
示例#21
0
 /**
  * Saves config
  *
  * @param array $data
  * @param bool $override
  * @return void
  */
 public function saveConfig(array $data, $override = false)
 {
     $paths = $this->configFilePool->getPaths();
     foreach ($data as $fileKey => $config) {
         if (isset($paths[$fileKey])) {
             if ($this->filesystem->getDirectoryWrite(DirectoryList::CONFIG)->isExist($paths[$fileKey])) {
                 $currentData = $this->reader->load($fileKey);
                 if ($override) {
                     $config = array_merge($currentData, $config);
                 } else {
                     $config = array_replace_recursive($currentData, $config);
                 }
             }
             $contents = $this->formatter->format($config);
             try {
                 $this->filesystem->getDirectoryWrite(DirectoryList::CONFIG)->writeFile($paths[$fileKey], $contents);
             } catch (FileSystemException $e) {
                 throw new FileSystemException(new Phrase('Deployment config file %1 is not writable.', [$paths[$fileKey]]));
             }
             if (function_exists('opcache_invalidate')) {
                 opcache_invalidate($this->filesystem->getDirectoryRead(DirectoryList::CONFIG)->getAbsolutePath($paths[$fileKey]));
             }
         }
     }
     $this->deploymentConfig->resetData();
 }
示例#22
0
 /**
  * Save customized DOM of view configuration
  *
  * @param \DOMDocument $config
  * @return $this
  */
 protected function _saveViewConfiguration(\DOMDocument $config)
 {
     $targetPath = $this->_theme->getCustomization()->getCustomViewConfigPath();
     $directory = $this->_filesystem->getDirectoryWrite(DirectoryList::ROOT);
     $directory->writeFile($directory->getRelativePath($targetPath), $config->saveXML());
     return $this;
 }
示例#23
0
 /**
  * @param \Magento\Framework\Filesystem $filesystem
  * @param \Magento\MediaStorage\Helper\File\Storage\Database $fileStorageDatabase
  * @param \Magento\MediaStorage\Model\File\Storage\DatabaseFactory $storageDatabaseFactory
  * @param \Magento\Framework\App\Response\Http\FileFactory $fileFactory
  */
 public function __construct(\Magento\Framework\Filesystem $filesystem, \Magento\MediaStorage\Helper\File\Storage\Database $fileStorageDatabase, \Magento\MediaStorage\Model\File\Storage\DatabaseFactory $storageDatabaseFactory, \Magento\Framework\App\Response\Http\FileFactory $fileFactory)
 {
     $this->_rootDir = $filesystem->getDirectoryWrite(DirectoryList::ROOT);
     $this->_fileStorageDatabase = $fileStorageDatabase;
     $this->_storageDatabaseFactory = $storageDatabaseFactory;
     $this->_fileFactory = $fileFactory;
 }
 /**
  * {@inheritdoc}
  * @throws \InvalidArgumentException
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $locale = $input->getOption(self::LOCALE_OPTION);
     if (!$this->validator->isValid($locale)) {
         throw new \InvalidArgumentException($locale . ' argument has invalid value, please run info:language:list for list of available locales');
     }
     $area = $input->getOption(self::AREA_OPTION);
     $theme = $input->getOption(self::THEME_OPTION);
     $type = $input->getArgument(self::TYPE_ARGUMENT);
     $this->state->setAreaCode($area);
     $this->objectManager->configure($this->configLoader->load($area));
     $sourceFileGenerator = $this->sourceFileGeneratorPool->create($type);
     foreach ($input->getArgument(self::FILE_ARGUMENT) as $file) {
         $file .= '.' . $type;
         $output->writeln("<info>Gathering {$file} sources.</info>");
         $asset = $this->assetRepo->createAsset($file, ['area' => $area, 'theme' => $theme, 'locale' => $locale]);
         $rootDir = $this->filesystem->getDirectoryWrite(DirectoryList::ROOT);
         $sourceFile = $this->assetSource->findSource($asset);
         $relativePath = $rootDir->getRelativePath($sourceFile);
         $content = $rootDir->readFile($relativePath);
         $chain = $this->chainFactory->create(['asset' => $asset, 'origContent' => $content, 'origContentType' => $asset->getContentType(), 'origAssetPath' => $relativePath]);
         $processedCoreFile = $sourceFileGenerator->generateFileTree($chain);
         $targetDir = $this->filesystem->getDirectoryWrite(DirectoryList::STATIC_VIEW);
         $source = $rootDir->getRelativePath($processedCoreFile);
         $destination = $asset->getPath();
         $rootDir->copyFile($source, $destination, $targetDir);
         $output->writeln("<info>Successfully processed dynamic stylesheet into CSS</info>");
     }
 }
示例#25
0
 /**
  * @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate
  * @param \Psr\Log\LoggerInterface $logger
  * @param \Magento\Framework\Locale\ResolverInterface $localeResolver
  * @param \Magento\Framework\Url\EncoderInterface $urlEncoder
  * @param \Magento\MediaStorage\Model\File\Validator\NotProtectedExtension $fileValidator
  * @param \Magento\Framework\Filesystem $filesystem
  * @codeCoverageIgnore
  */
 public function __construct(\Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate, \Psr\Log\LoggerInterface $logger, \Magento\Framework\Locale\ResolverInterface $localeResolver, \Magento\Framework\Url\EncoderInterface $urlEncoder, \Magento\MediaStorage\Model\File\Validator\NotProtectedExtension $fileValidator, \Magento\Framework\Filesystem $filesystem)
 {
     parent::__construct($localeDate, $logger, $localeResolver);
     $this->urlEncoder = $urlEncoder;
     $this->_fileValidator = $fileValidator;
     $this->_directory = $filesystem->getDirectoryWrite(DirectoryList::MEDIA);
 }
 /**
  * @param Context $context
  * @param StoreManagerInterface $storeManager
  * @param Filesystem $filesystem
  * @param string $imageDir
  */
 public function __construct(Context $context, StoreManagerInterface $storeManager, Filesystem $filesystem, $imageDir = 'design/image')
 {
     parent::__construct($context);
     $this->storeManager = $storeManager;
     $this->mediaDirectory = $filesystem->getDirectoryWrite(DirectoryList::MEDIA);
     $this->imageDir = $imageDir;
 }
 /**
  * Constructor
  *
  * @param MagentoComposerApplicationFactory $applicationFactory
  * @param \Magento\Framework\Filesystem $filesystem
  * @param \Magento\Framework\Stdlib\DateTime $dateTime
  * @param ComposerInformation $composerInformation
  * @throws \Exception
  */
 public function __construct(MagentoComposerApplicationFactory $applicationFactory, Filesystem $filesystem, DateTime $dateTime, ComposerInformation $composerInformation)
 {
     $this->application = $applicationFactory->create();
     $this->directory = $filesystem->getDirectoryWrite(DirectoryList::VAR_DIR);
     $this->dateTime = $dateTime;
     $this->composerInformation = $composerInformation;
 }
示例#28
0
 public function __construct(\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Framework\Filesystem $filesystem, \Magento\Framework\Filesystem\File\ReadFactory $readFactory)
 {
     $this->_scopeConfig = $scopeConfig;
     $this->_filesystem = $filesystem;
     $this->_directory = $filesystem->getDirectoryWrite(DirectoryList::ROOT);
     $this->_readFactory = $readFactory;
 }
示例#29
0
 /**
  * @param \Magento\Framework\Model\Context $context
  * @param \Magento\Framework\Registry $registry
  * @param \Magento\Framework\Filesystem $filesystem
  * @param \Magento\Store\Model\StoreManagerInterface $storeManager
  * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
  * @param \Magento\Framework\Model\Resource\AbstractResource $resource
  * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
  * @param array $data
  */
 public function __construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Filesystem $filesystem, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Framework\Model\Resource\AbstractResource $resource = null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, array $data = [])
 {
     $this->_tmpDirectory = $filesystem->getDirectoryWrite(DirectoryList::SYS_TMP);
     $this->_storeManager = $storeManager;
     $this->_scopeConfig = $scopeConfig;
     parent::__construct($context, $registry, $resource, $resourceCollection, $data);
 }
 /**
  * @param \Magento\Captcha\Helper\Data $helper
  * @param \Magento\Captcha\Helper\Adminhtml\Data $adminHelper
  * @param \Magento\Framework\Filesystem $filesystem
  * @param \Magento\Store\Model\StoreManager $storeManager
  */
 public function __construct(\Magento\Captcha\Helper\Data $helper, \Magento\Captcha\Helper\Adminhtml\Data $adminHelper, \Magento\Framework\Filesystem $filesystem, \Magento\Store\Model\StoreManager $storeManager)
 {
     $this->_helper = $helper;
     $this->_adminHelper = $adminHelper;
     $this->_mediaDirectory = $filesystem->getDirectoryWrite(DirectoryList::MEDIA);
     $this->_storeManager = $storeManager;
 }