public function copy($item, $to, $name = NULL) { Logging::logDebug('copying ' . $item->id() . "[" . $item->internalPath() . '] to ' . $to->id() . "[" . $to->internalPath() . '] ' . $name); if ($to->isFile()) { throw new ServiceException("NOT_A_DIR", $to->path()); } if ($item->isFile()) { $target = $to->fileWithName($name != NULL ? $name : $item->name()); } else { $target = $to->folderWithName($name != NULL ? $name : $item->name()); } $this->assertRights($item, self::PERMISSION_LEVEL_READ, "copy"); $this->assertRights($to, self::PERMISSION_LEVEL_READWRITE, "copy"); $overwrite = $this->env->request()->hasData("overwrite") ? $this->env->request()->data("overwrite") == 1 : FALSE; $replace = ($overwrite or $this->env->plugins()->hasPlugin("History") and $this->env->plugins()->getPlugin("History")->isItemActionVersioned($item, FileEvent::COPY, array("to" => $to, "target" => $target))); if ($target->exists()) { if (!$item->isFile()) { // cannot overwrite folder throw new ServiceException("DIR_ALREADY_EXISTS"); } if (!$replace) { throw new ServiceException("FILE_ALREADY_EXISTS"); } $this->assertRights($target, self::PERMISSION_LEVEL_READWRITE, "copy"); } $this->validateAction(FileEvent::COPY, $item, array("to" => $to, "target" => $target, "replace" => $replace)); if ($this->triggerActionInterceptor(FileEvent::COPY, $item, array("to" => $to, "target" => $target, "replace" => $replace))) { return; } if ($item->isFile() and $target->exists()) { if ($overwrite) { Logging::logDebug("File exists, overwriting"); $target->delete(); //"soft-delete", just remove content, no events that remove meta-data //TODO update content instead of delete©?? } } $target = $item->copy($target); $this->env->events()->onEvent(FileEvent::copy($item, $target, $replace)); }
public function copy($item, $to) { Logging::logDebug('copying ' . $item->id() . "[" . $item->internalPath() . '] to ' . $to->id() . "[" . $to->internalPath() . ']'); if ($item->isFile() and !$to->isFile()) { $to = $to->createFile($item->name()); } if (!$item->isFile() and $to->isFile()) { throw new ServiceException("NOT_A_DIR", $to->path()); } $this->assertRights($item, self::PERMISSION_LEVEL_READ, "copy"); $this->assertRights($to->parent(), self::PERMISSION_LEVEL_READWRITE, "copy"); $to = $item->copy($to); $this->env->events()->onEvent(FileEvent::copy($item, $to)); }