Пример #1
0
 /**
  * Import directories to storage
  *
  * @param  array $dirs
  * @throws \Magento\Framework\Model\Exception
  * @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\Model\Exception(__('Parent directory does not exist: %1', $dir['path']));
             }
         } catch (\Exception $e) {
             $this->_logger->critical($e);
         }
     }
     return $this;
 }
Пример #2
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;
 }
Пример #3
0
 /**
  * Recursively delete directory from storage
  *
  * @param string $path Target dir
  * @return void
  * @throws \Magento\Framework\Model\Exception
  */
 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\Filesystem\FilesystemException $e) {
         throw new \Magento\Framework\Model\Exception(__('We cannot delete directory %1.', $path));
     }
 }