/** * 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; }
/** * 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)); } }
/** * 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; }