コード例 #1
0
ファイル: ConfigTest.php プロジェクト: aiesh/magento2
 public static function setUpBeforeClass()
 {
     /** @var \Magento\Framework\App\Filesystem $filesystem */
     $filesystem = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Framework\\App\\Filesystem');
     self::$_varDirectory = $filesystem->getDirectoryWrite(\Magento\Framework\App\Filesystem::VAR_DIR);
     self::$_tmpDir = self::$_varDirectory->getAbsolutePath('ConfigTest');
     self::$_varDirectory->create(self::$_varDirectory->getRelativePath(self::$_tmpDir));
 }
コード例 #2
0
ファイル: Collection.php プロジェクト: Atlis/docker-magento2
 /**
  * Set base dir
  *
  * @param \Magento\Core\Model\EntityFactory $entityFactory
  * @param \Magento\Framework\App\Filesystem $filesystem
  */
 public function __construct(\Magento\Core\Model\EntityFactory $entityFactory, \Magento\Framework\App\Filesystem $filesystem)
 {
     parent::__construct($entityFactory);
     $this->filesystem = $filesystem;
     $this->connectDirectory = $this->filesystem->getDirectoryWrite(\Magento\Framework\App\Filesystem::VAR_DIR);
     $this->connectDirectory->create('connect');
     $this->addTargetDir($this->connectDirectory->getAbsolutePath('connect'));
 }
コード例 #3
0
ファイル: Storage.php プロジェクト: pradeep-wagento/magento2
 /**
  * @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()));
 }
コード例 #4
0
 /**
  * Log information about fatal error.
  *
  * @param string $reportData
  * @return string
  */
 protected function _saveFatalErrorReport($reportData)
 {
     $this->directoryWrite->create('report/api');
     $reportId = abs(intval(microtime(true) * rand(100, 1000)));
     $this->directoryWrite->writeFile('report/api/' . $reportId, serialize($reportData));
     return $reportId;
 }
コード例 #5
0
 /**
  * Check var/generation read and write access
  *
  * @return bool
  */
 public function check()
 {
     $initParams = $this->serviceManager->get(InitParamListener::BOOTSTRAP_PARAM);
     $filesystemDirPaths = isset($initParams[Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS]) ? $initParams[Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS] : [];
     $directoryList = new DirectoryList(BP, $filesystemDirPaths);
     $generationDirectoryPath = $directoryList->getPath(DirectoryList::GENERATION);
     $driverPool = new DriverPool();
     $fileWriteFactory = new WriteFactory($driverPool);
     /** @var \Magento\Framework\Filesystem\DriverInterface $driver */
     $driver = $driverPool->getDriver(DriverPool::FILE);
     $directoryWrite = new Write($fileWriteFactory, $driver, $generationDirectoryPath);
     if ($directoryWrite->isExist()) {
         if ($directoryWrite->isDirectory() || $directoryWrite->isReadable()) {
             try {
                 $probeFilePath = $generationDirectoryPath . DIRECTORY_SEPARATOR . uniqid(mt_rand()) . 'tmp';
                 $fileWriteFactory->create($probeFilePath, DriverPool::FILE, 'w');
                 $driver->deleteFile($probeFilePath);
             } catch (\Exception $e) {
                 return false;
             }
         } else {
             return false;
         }
     } else {
         try {
             $directoryWrite->create();
         } catch (\Exception $e) {
             return false;
         }
     }
     return true;
 }
コード例 #6
0
ファイル: Storage.php プロジェクト: tingyeeh/magento2
 /**
  * Create thumbnail for image and save it to thumbnails directory
  *
  * @param string $source Image path to be resized
  * @param bool $keepRation Keep aspect ratio or not
  * @return bool|string Resized filepath or false if errors were occurred
  */
 public function resizeFile($source, $keepRation = true)
 {
     $realPath = $this->_directory->getRelativePath($source);
     if (!$this->_directory->isFile($realPath) || !$this->_directory->isExist($realPath)) {
         return false;
     }
     $targetDir = $this->getThumbsPath($source);
     $pathTargetDir = $this->_directory->getRelativePath($targetDir);
     if (!$this->_directory->isExist($pathTargetDir)) {
         $this->_directory->create($pathTargetDir);
     }
     if (!$this->_directory->isExist($pathTargetDir)) {
         return false;
     }
     $image = $this->_imageFactory->create();
     $image->open($source);
     $image->keepAspectRatio($keepRation);
     $image->resize($this->_resizeParameters['width'], $this->_resizeParameters['height']);
     $dest = $targetDir . '/' . pathinfo($source, PATHINFO_BASENAME);
     $image->save($dest);
     if ($this->_directory->isFile($this->_directory->getRelativePath($dest))) {
         return $dest;
     }
     return false;
 }
コード例 #7
0
 /**
  * Copy file to tmp theme customization path
  *
  * @param string $sourceFile
  * @return string
  */
 protected function _copyFileToTmpCustomizationPath($sourceFile)
 {
     $targetFile = $this->_helperStorage->getStorageRoot() . '/' . basename($sourceFile);
     $this->directoryTmp->create(pathinfo($targetFile, PATHINFO_DIRNAME));
     $this->directoryVar->copyFile($this->directoryVar->getRelativePath($sourceFile), $this->directoryTmp->getRelativePath($targetFile), $this->directoryTmp);
     return $targetFile;
 }
コード例 #8
0
ファイル: Extension.php プロジェクト: Atlis/docker-magento2
 /**
  * Create package file compatible with previous version of Magento Connect Manager
  *
  * @return boolean
  */
 public function createPackageV1x()
 {
     try {
         $this->writeDirectory->create('pear/');
     } catch (\Magento\Framework\Filesystem\FilesystemException $e) {
         $this->logger->addStreamLog(\Magento\Framework\Logger::LOGGER_EXCEPTION);
         $this->logger->log($e->getMessage());
         return false;
     }
     if (!$this->getPackageXml()) {
         $this->generatePackageXml();
     }
     $this->getPackage()->saveV1x($this->writeDirectory->getAbsolutePath('pear/'));
     return true;
 }
コード例 #9
0
 /**
  * Create folder
  *
  * @param string $name
  * @param string $path
  * @return array
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function createFolder($name, $path)
 {
     if (!preg_match(self::DIRECTORY_NAME_REGEXP, $name)) {
         throw new \Magento\Framework\Exception\LocalizedException(__('Use only standard alphanumeric, dashes and underscores.'));
     }
     if (!$this->mediaWriteDirectory->isWritable($path)) {
         $path = $this->_helper->getStorageRoot();
     }
     $newPath = $path . '/' . $name;
     if ($this->mediaWriteDirectory->isExist($newPath)) {
         throw new \Magento\Framework\Exception\LocalizedException(__('We found a directory with the same name.'));
     }
     $this->mediaWriteDirectory->create($newPath);
     $result = ['name' => $name, 'short_name' => $this->_helper->getShortFilename($name), 'path' => str_replace($this->_helper->getStorageRoot(), '', $newPath), 'id' => $this->_helper->convertPathToId($newPath)];
     return $result;
 }
コード例 #10
0
ファイル: Images.php プロジェクト: pavelnovitsky/magento2
 /**
  * Return path of the current selected directory or root directory for startup
  * Try to create target directory if it doesn't exist
  *
  * @return string
  * @throws \Magento\Framework\Model\Exception
  */
 public function getCurrentPath()
 {
     if (!$this->_currentPath) {
         $currentPath = $this->_directory->getAbsolutePath() . \Magento\Cms\Model\Wysiwyg\Config::IMAGE_DIRECTORY;
         $path = $this->_getRequest()->getParam($this->getTreeNodeName());
         if ($path) {
             $path = $this->convertIdToPath($path);
             if ($this->_directory->isDirectory($this->_directory->getRelativePath($path))) {
                 $currentPath = $path;
             }
         }
         try {
             $currentDir = $this->_directory->getRelativePath($currentPath);
             if (!$this->_directory->isExist($currentDir)) {
                 $this->_directory->create($currentDir);
             }
         } catch (\Magento\Framework\Filesystem\FilesystemException $e) {
             $message = __('The directory %1 is not writable by server.', $currentPath);
             throw new \Magento\Framework\Model\Exception($message);
         }
         $this->_currentPath = $currentPath;
     }
     return $this->_currentPath;
 }
コード例 #11
0
 /**
  * Create destination folder if not exists and return full file path
  *
  * @param string $destination
  * @param string $newName
  * @return string
  * @throws \Exception
  */
 protected function _prepareDestination($destination = null, $newName = null)
 {
     if (empty($destination)) {
         $destination = $this->_fileSrcPath;
     } else {
         if (empty($newName)) {
             $info = pathinfo($destination);
             $newName = $info['basename'];
             $destination = $info['dirname'];
         }
     }
     if (empty($newName)) {
         $newFileName = $this->_fileSrcName;
     } else {
         $newFileName = $newName;
     }
     $fileName = $destination . '/' . $newFileName;
     if (!is_writable($destination)) {
         try {
             $this->directoryWrite->create($this->directoryWrite->getRelativePath($destination));
         } catch (\Magento\Framework\Filesystem\FilesystemException $e) {
             $this->logger->addStreamLog(\Magento\Framework\Logger::LOGGER_SYSTEM);
             $this->logger->log($e->getMessage());
             throw new \Exception('Unable to write file into directory ' . $destination . '. Access forbidden.');
         }
     }
     return $fileName;
 }
コード例 #12
0
 public function testCreate()
 {
     $this->driver->expects($this->once())->method('isDirectory')->will($this->returnValue(false));
     $this->driver->expects($this->once())->method('createDirectory')->will($this->returnValue(true));
     $this->assertTrue($this->write->create('correct-path'));
 }