Exemplo n.º 1
0
 /**
  * Import directories to storage
  *
  * @param  array $dirs
  * @throws \Magento\Framework\Exception\LocalizedException
  * @return $this
  */
 public function importDirectories($dirs)
 {
     if (!is_array($dirs)) {
         return $this;
     }
     $dateSingleton = $this->_date;
     foreach ($dirs as $dir) {
         if (!is_array($dir) || !isset($dir['name']) || !strlen($dir['name'])) {
             continue;
         }
         try {
             $dir['path'] = ltrim($dir['path'], './');
             $directory = $this->_directoryFactory->create(['connectionName' => $this->getConnectionName()]);
             $directory->setPath($dir['path']);
             $parentId = $directory->getParentId();
             if ($parentId || $dir['path'] == '') {
                 $directory->setName($dir['name']);
                 $directory->setUploadTime($dateSingleton->date());
                 $directory->save();
             } else {
                 throw new \Magento\Framework\Exception\LocalizedException(__('Parent directory does not exist: %1', $dir['path']));
             }
         } catch (\Exception $e) {
             $this->_logger->critical($e);
         }
     }
     return $this;
 }
Exemplo n.º 2
0
 public function testGetDirsCollectionCreateSubDirectories()
 {
     $directoryName = 'test1';
     $this->coreFileStorageMock->expects($this->once())->method('checkDbUsage')->willReturn(true);
     $this->directoryCollectionMock->expects($this->once())->method('getSubdirectories')->with(self::STORAGE_ROOT_DIR)->willReturn([['name' => $directoryName]]);
     $this->directoryDatabaseFactoryMock->expects($this->once())->method('create')->willReturn($this->directoryCollectionMock);
     $this->directoryMock->expects($this->once())->method('create')->with(rtrim(self::STORAGE_ROOT_DIR, '/') . '/' . $directoryName);
     $this->generalTestGetDirsCollection(self::STORAGE_ROOT_DIR);
 }
Exemplo n.º 3
0
 /**
  * Recursively delete directory from storage
  *
  * @param string $path Target dir
  * @return void
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function deleteDirectory($path)
 {
     if ($this->_coreFileStorageDb->checkDbUsage()) {
         $this->_directoryDatabaseFactory->create()->deleteDirectory($path);
     }
     try {
         $this->_deleteByPath($path);
         $path = $this->getThumbnailRoot() . $this->_getRelativePathToRoot($path);
         $this->_deleteByPath($path);
     } catch (\Magento\Framework\Exception\FileSystemException $e) {
         throw new \Magento\Framework\Exception\LocalizedException(__('We cannot delete directory %1.', $path));
     }
 }
Exemplo n.º 4
0
 /**
  * Rename files in database
  *
  * @param  string $oldFilePath
  * @param  string $newFilePath
  * @return $this
  */
 public function renameFile($oldFilePath, $newFilePath)
 {
     $this->_getResource()->renameFile(basename($oldFilePath), dirname($oldFilePath), basename($newFilePath), dirname($newFilePath));
     $newPath = dirname($newFilePath);
     $directory = $this->_directoryFactory->create()->loadByPath($newPath);
     if (!$directory->getId()) {
         $directory = $this->getDirectoryModel()->createRecursive($newPath);
     }
     $this->loadByFilename($newFilePath);
     if ($this->getId()) {
         $this->setDirectoryId($directory->getId())->save();
     }
     return $this;
 }