public function move($item, $to) { Logging::logDebug('moving ' . $item->id() . "[" . $item->path() . '] to [' . $to . ']'); if ($item->isRoot()) { throw new ServiceException("INSUFFICIENT_PERMISSIONS", "Cannot move root folders"); } if ($to->isFile()) { throw new ServiceException("NOT_A_DIR", $to->path()); } if ($item->parent()->id() == $to->id()) { if ($item->isFile()) { throw new ServiceException("FILE_ALREADY_EXISTS"); } else { throw new ServiceException("DIR_ALREADY_EXISTS"); } } $this->assertRights($item, self::PERMISSION_LEVEL_READ, "move"); $this->assertRights($to, self::PERMISSION_LEVEL_READWRITE, "move"); $overwrite = $this->env->request()->hasData("overwrite") ? $this->env->request()->data("overwrite") == 1 : FALSE; $version = ($this->env->plugins()->hasPlugin("History") and $this->env->plugins()->getPlugin("History")->isItemActionVersioned($item, FileEvent::MOVE, array("to" => $to))); $replace = ($overwrite or $version); if ($item->isFile()) { if ($to->fileExists($item->name())) { if (!$replace) { throw new ServiceException("FILE_ALREADY_EXISTS"); } else { $this->assertRights($to->fileWithName($item->name()), self::PERMISSION_LEVEL_READWRITEDELETE); } } } else { if ($to->folderExists($item->name())) { throw new ServiceException("DIR_ALREADY_EXISTS"); } } $this->validateAction(FileEvent::MOVE, $item, array("to" => $to, "replace" => $replace)); if ($this->triggerActionInterceptor(FileEvent::MOVE, $item, array("to" => $to, "replace" => $replace))) { return; } if ($item->isFile() and $to->fileExists($item->name())) { if ($overwrite) { Logging::logDebug("File exists, overwriting"); $target = $to->fileWithName($item->name()); $this->doDeleteItem($target); // "hard-delete", remove also meta-data } } $moved = $item->move($to); if (!$version) { $this->env->events()->onEvent(FileEvent::move($item, $moved, $replace)); $this->idProvider->move($item, $moved); } else { //when versioning, "move" only created metadata and remove original item's other data $target = $to->fileWithName($item->name()); $meta = $this->getCreatedMetadataInfo($item, TRUE); if ($meta != NULL) { $this->setCreatedMetadata($target, $meta["at"], $meta["by"]); } $this->doDeleteItem($item, TRUE, TRUE, FALSE); // "hard-delete", remove also meta-data } }
public function move($item, $to) { Logging::logDebug('moving ' . $item->id() . "[" . $item->path() . '] to [' . $to . ']'); if ($item->isRoot()) { throw new ServiceException("INSUFFICIENT_PERMISSIONS", "Cannot move root folders"); } if ($to->isFile()) { throw new ServiceException("NOT_A_DIR", $to->path()); } $this->assertRights($item, self::PERMISSION_LEVEL_READ, "move"); $this->assertRights($to, self::PERMISSION_LEVEL_READWRITE, "move"); $to = $item->move($to); $this->env->events()->onEvent(FileEvent::move($item, $to)); $this->idProvider->move($item, $to); }