19 declare(strict_types=1);
44 $existing_handler = $this->handler_factory->getHandlerForResource($resource);
45 $existing_path = $this->filesystem_base_path .
'/' . $existing_handler->getFullContainerPath(
49 $new_handler = $this->handler_factory->getHandlerForStorageId($to_handler_id);
50 $destination_path = $this->filesystem_base_path .
'/' . $new_handler->getFullContainerPath(
54 if (!file_exists($existing_path)) {
56 $this->resource_builder->remove($resource);
60 if (!is_dir(dirname($destination_path)) && !mkdir(dirname($destination_path), 0777,
true)) {
63 if (file_exists($destination_path)) {
67 $result = rename($existing_path, $destination_path);
72 "UPDATE il_resource SET storage_id = %s WHERE rid = %s LIMIT 1",
78 if ($this->clean_up) {
79 $existing_handler->cleanUpContainer($resource);
90 foreach (glob($path . DIRECTORY_SEPARATOR .
"*") as $file) {
93 return $empty && rmdir($path);
96 private function mergeDirectories(
string $path_to_source_dir,
string $path_to_destination_dir): bool
98 $dir = opendir($path_to_source_dir);
100 while (($name = readdir($dir)) !==
false) {
104 if ($name ===
'..') {
107 $src_path = $path_to_source_dir .
'/' . $name;
108 $dest_path = $path_to_destination_dir .
'/' . $name;
110 if (is_dir($src_path)) {
112 if (!file_exists($dest_path)) {
113 mkdir($dest_path, 0777,
true);
116 } elseif (file_exists($dest_path)) {
118 rename($src_path, $dest_path);
119 } elseif (!file_exists($dest_path)) {
120 rename($src_path, $dest_path);
migrate(StorableResource $resource, string $to_handler_id)
__construct(private StorageHandlerFactory $handler_factory, protected ResourceBuilder $resource_builder, private \ilDBInterface $database, protected string $filesystem_base_path)
Migrator constructor.
Interface StorageResource.
mergeDirectories(string $path_to_source_dir, string $path_to_destination_dir)
removeEmptySubFolders(string $path)
Class StorageHandlerFactory.