private function onExtract()
 {
     $data = $this->request->data;
     if (!array_key_exists("item", $data)) {
         throw $this->invalidRequestException();
     }
     $overwrite = isset($data['overwrite']) ? $data['overwrite'] : FALSE;
     $archive = $this->item($data["item"]);
     $this->env->filesystem()->assertRights($archive, FilesystemController::PERMISSION_LEVEL_READ, "extract");
     $parent = NULL;
     if (isset($data["folder"])) {
         $this->item($data["folder"]);
     } else {
         $parent = $archive->parent();
     }
     $this->env->filesystem()->assertRights($parent, FilesystemController::PERMISSION_LEVEL_READWRITE, "extract");
     $name = str_replace(".", "_", basename($archive->internalPath()));
     $target = $parent->folderWithName($name);
     if ($target->exists() and !$overwrite) {
         throw new ServiceException("DIR_ALREADY_EXISTS", $target);
     }
     //$target = $parent->internalPath() . DIRECTORY_SEPARATOR . $name . DIRECTORY_SEPARATOR;
     $this->env->filesystem()->validateAction(FileEvent::CREATE_ITEM, $target);
     $this->env->filesystem()->triggerActionInterceptor(FileEvent::CREATE_ITEM, $target);
     if ($target->exists() and $overwrite) {
         $target->delete();
     }
     $this->env->filesystem()->createItem($target);
     $this->archiveManager()->extract($archive->internalPath(), $target->internalPath());
     $this->env->events()->onEvent(FileEvent::createItem($target));
     $this->response()->success(array());
 }
Ejemplo n.º 2
0
 public function createFile($parent, $name, $content = NULL, $size = 0)
 {
     Logging::logDebug('creating file [' . $parent->id() . '/' . $name . ']');
     $this->assertRights($parent, self::PERMISSION_LEVEL_READWRITE, "create file");
     $target = $parent->fileWithName($name);
     $this->validateAction(FileEvent::CREATE_ITEM, $target, array("size" => $size));
     if ($this->triggerActionInterceptor(FileEvent::CREATE_ITEM, $target, array("size" => $size))) {
         return NULL;
     }
     $new = $parent->createFile($name);
     if ($content != NULL) {
         $new->put($content);
     }
     $this->env->events()->onEvent(FileEvent::createItem($new));
     return $new;
 }