예제 #1
0
파일: Tree.php 프로젝트: aiesh/magento2
 /**
  * Json tree builder
  *
  * @return string
  */
 public function getTreeJson()
 {
     $storageRoot = $this->_cmsWysiwygImages->getStorageRoot();
     $collection = $this->_coreRegistry->registry('storage')->getDirsCollection($this->_cmsWysiwygImages->getCurrentPath());
     $jsonArray = array();
     foreach ($collection as $item) {
         $jsonArray[] = array('text' => $this->_cmsWysiwygImages->getShortFilename($item->getBasename(), 20), 'id' => $this->_cmsWysiwygImages->convertPathToId($item->getFilename()), 'path' => substr($item->getFilename(), strlen($storageRoot)), 'cls' => 'folder');
     }
     return \Zend_Json::encode($jsonArray);
 }
예제 #2
0
 /**
  * Create new directory in storage
  *
  * @param string $name New directory name
  * @param string $path Parent directory path
  * @return array New directory info
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function createDirectory($name, $path)
 {
     if (!preg_match(self::DIRECTORY_NAME_REGEXP, $name)) {
         throw new \Magento\Framework\Exception\LocalizedException(__('Please rename the folder using only letters, numbers, underscores and dashes.'));
     }
     $relativePath = $this->_directory->getRelativePath($path);
     if (!$this->_directory->isDirectory($relativePath) || !$this->_directory->isWritable($relativePath)) {
         $path = $this->_cmsWysiwygImages->getStorageRoot();
     }
     $newPath = $path . '/' . $name;
     $relativeNewPath = $this->_directory->getRelativePath($newPath);
     if ($this->_directory->isDirectory($relativeNewPath)) {
         throw new \Magento\Framework\Exception\LocalizedException(__('We found a directory with the same name. Please try another folder name.'));
     }
     $this->_directory->create($relativeNewPath);
     try {
         if ($this->_coreFileStorageDb->checkDbUsage()) {
             $relativePath = $this->_coreFileStorageDb->getMediaRelativePath($newPath);
             $this->_directoryDatabaseFactory->create()->createRecursive($relativePath);
         }
         $result = ['name' => $name, 'short_name' => $this->_cmsWysiwygImages->getShortFilename($name), 'path' => $newPath, 'id' => $this->_cmsWysiwygImages->convertPathToId($newPath)];
         return $result;
     } catch (\Magento\Framework\Exception\FileSystemException $e) {
         throw new \Magento\Framework\Exception\LocalizedException(__('We cannot create a new directory.'));
     }
 }
예제 #3
0
 /**
  * @param string $fileName
  * @param string $expectedFilename
  * @dataProvider providerShortFilenameDefaultMaxLength
  */
 public function testGetShortFilenameDefaultMaxLength($fileName, $expectedFilename)
 {
     $this->assertEquals($expectedFilename, $this->imagesHelper->getShortFilename($fileName));
 }