public function destroy() { $ids = Input::get('id'); $files = $this->storage->getsIn($ids); foreach ($files as $file) { $this->storage->remove($file); } if (Input::get('redirect') != null) { return redirect(Input::get('redirect')); } else { return redirect()->route('manage.storage.index'); } }
/** * 회원의 프로필 이미지를 등록한다. * * @param UserInterface $user 프로필 이미지를 등록할 회원 * @param UploadedFile $profileFile 프로필 이미지 파일 * * @return string 등록한 프로필이미지 ID */ public function updateUserProfileImage(UserInterface $user, UploadedFile $profileFile) { $disk = array_get($this->profileImgConfig, 'storage.disk'); $path = array_get($this->profileImgConfig, 'storage.path'); $size = array_get($this->profileImgConfig, 'size'); // make fitted image /** @var ImageManager $imageManager */ $imageManager = call_user_func($this->imageManagerResolver); $image = $imageManager->make($profileFile->getRealPath()); $image = $image->fit($size['width'], $size['height']); // remove old profile image if (!empty($user->profileImageId)) { $file = File::find($user->profileImageId); if ($file !== null) { try { $this->storage->remove($file); } catch (\Exception $e) { } } } // save image to storage $id = $user->getId(); $file = $this->storage->create($image->encode()->getEncoded(), $path . "/{$id}", $id, $disk); return $file->id; }
/** * 회원의 프로필 이미지를 등록한다. * * @param MemberEntityInterface $member 프로필 이미지를 등록할 회원 * @param UploadedFile $profileFile 프로필 이미지 파일 * * @return string 등록한 프로필이미지 ID */ public function updateMemberProfileImage(MemberEntityInterface $member, UploadedFile $profileFile) { $disk = array_get($this->profileImgConfig, 'storage.disk'); $path = array_get($this->profileImgConfig, 'storage.path'); $size = array_get($this->profileImgConfig, 'size'); // make fitted imageg /** @var ImageManager $imageManager */ $imageManager = call_user_func($this->imageManagerResolver); $image = $imageManager->make($profileFile->getRealPath()); $image = $image->fit($size['width'], $size['height']); // remove old profile image if ($member->profileImageId !== null && $member->profileImageId !== "") { $file = $this->storage->get($member->profileImageId); $this->storage->remove($file); } $id = $member->getId(); // save image to storage $file = $this->storage->create($image->encode()->getEncoded(), $path . "/{$id}", $id, $disk); return $file->getId(); }
/** * 미디어 삭제 * * @param Media $media media instance * @return bool */ public function remove(Media $media) { $this->metaRemove($media); return $this->storage->remove($media); }
/** * file destory * * @param Storage $storage * @param string $instanceId * @param string $id * @return RendererInterface */ public function fileDestroy(Storage $storage, $instanceId, $id) { if (empty($id) || !($file = File::find($id))) { throw new InvalidArgumentException(); } if ($file->userId !== Auth::id()) { throw new AccessDeniedHttpException(); } try { $result = $storage->remove($file); } catch (\Exception $e) { $result = false; } return XePresenter::makeApi(['deleted' => $result]); }
public function testRemove() { list($handler, $auth, $keygen, $distributor, $temps) = $this->getMocks(); $instance = new Storage($handler, $auth, $keygen, $distributor, $temps); $mockFile = m::mock('Xpressengine\\Storage\\File'); $mockFile->shouldReceive('getAttribute')->with('id')->andReturn('foo'); $mockFile->shouldReceive('getAttribute')->with('originId')->andReturnNull(); $mockChild = m::mock('Xpressengine\\Storage\\File'); $mockChild->shouldReceive('getAttribute')->with('id')->andReturn('bar'); $mockChild->shouldReceive('getAttribute')->with('originId')->andReturn('foo'); $mockFile->shouldReceive('getRawDerives')->andReturn([$mockChild]); $conn = m::mock('stdClass'); $conn->shouldReceive('table')->andReturnSelf(); $conn->shouldReceive('where')->once()->with('fileId', 'foo')->andReturnSelf(); $conn->shouldReceive('where')->once()->with('fileId', 'bar')->andReturnSelf(); $conn->shouldReceive('delete')->twice(); $mockFile->shouldReceive('getConnection')->andReturn($conn); $mockFile->shouldReceive('getFileableTable')->andReturn('fileableTable'); $mockChild->shouldReceive('getConnection')->andReturn($conn); $mockChild->shouldReceive('getFileableTable')->andReturn('fileableTable'); $handler->shouldReceive('delete')->once()->with($mockChild)->andReturnNull(); $handler->shouldReceive('delete')->once()->with($mockFile)->andReturnNull(); $mockFile->shouldReceive('delete')->once()->andReturn(true); $mockChild->shouldReceive('delete')->once()->andReturn(true); $result = $instance->remove($mockFile); $this->assertTrue($result); }
public function testRemove() { list($handler, $repo, $auth, $keygen) = $this->getMocks(); $mockFile = m::mock('Xpressengine\\Storage\\File'); $mockFile->id = 'fileidentifier'; $mockChild = m::mock('Xpressengine\\Storage\\File'); $mockChild->id = 'filechildidentifier'; $mockChild->parentId = 'fileidentifier'; $repo->shouldReceive('fetch')->once()->with(['parentId' => 'fileidentifier'])->andReturn([$mockChild]); $handler->shouldReceive('delete')->once()->with($mockChild)->andReturnNull(); $repo->shouldReceive('delete')->once()->with($mockChild)->andReturnNull(); $handler->shouldReceive('delete')->once()->with($mockFile)->andReturnNull(); $repo->shouldReceive('delete')->once()->with($mockFile)->andReturnNull(); $instance = new Storage($handler, $repo, $auth, $keygen); $instance->remove($mockFile); }
public function testRemove() { list($handler, $auth, $keygen, $distributor, $temps) = $this->getMocks(); $instance = new Storage($handler, $auth, $keygen, $distributor, $temps); $mockFile = m::mock('Xpressengine\\Storage\\File'); $mockFile->shouldReceive('getAttribute')->with('originId')->andReturnNull(); $mockChild = m::mock('Xpressengine\\Storage\\File'); $mockChild->shouldReceive('getAttribute')->with('originId')->andReturn('origin-id'); $mockFile->shouldReceive('getRawDerives')->andReturn([$mockChild]); $handler->shouldReceive('delete')->once()->with($mockChild)->andReturnNull(); $handler->shouldReceive('delete')->once()->with($mockFile)->andReturnNull(); $mockFile->shouldReceive('delete')->once()->andReturn(true); $mockChild->shouldReceive('delete')->once()->andReturn(true); $result = $instance->remove($mockFile); $this->assertTrue($result); }