/** * 문서 삭제 * * @param ItemEntity $item board item entity * @param ConfigEntity $config destination board config entity * @return int */ public function remove(ItemEntity $item, ConfigEntity $config) { $item = $this->get($item->id, $item->instanceId); // 덧글이 있다면 덧글들을 모두 휴지통으로 옯긴다. $count = 0; if ($config->get('recursiveDelete') === true) { $rows = $this->document->getRepository()->getReplies($item->getDocument()); foreach ($rows as $row) { $item = $this->get($row['id'], $row['instanceId']); $count = $this->document->remove($item->getDocument()); $this->slug->delete($item->getSlug()); /** @var \Xpressengine\Storage\File $file */ foreach ($this->storage->getsByTargetId($item->id) as $file) { $this->storage->unBind($item->id, $file, true); } } } else { $count = $this->document->remove($item->getDocument()); $this->slug->delete($item->getSlug()); /** @var \Xpressengine\Storage\File $file */ foreach ($this->storage->getsByTargetId($item->id) as $file) { $this->storage->unBind($item->id, $file, true); } } return $count; }
/** * 문서 삭제 * * @param Board $board board model * @param ConfigEntity $config board config entity * @return void * @throws \Exception */ public function remove(Board $board, ConfigEntity $config) { $board->getConnection()->beginTransaction(); // 덧글이 있다면 덧글들을 모두 삭제 if ($config->get('recursiveDelete') === true) { $query = Board::where('head', $board->head); if ($board->reply !== '' && $board->reply !== null) { $query->where('reply', 'like', $board->reply . '%'); } $items = $query->get(); foreach ($items as $item) { $this->setModelConfig($item, $config); if ($item->boardSlug !== null) { $item->boardSlug->delete(); } if ($item->boardCategory !== null) { $item->boardCategory->delete(); } $files = File::whereIn('id', $item->getFileIds())->get(); foreach ($files as $file) { $this->storage->unBind($item->id, $file, true); } $tags = Tag::getByTaggable($item->id); foreach ($tags as $tag) { $tag->delete(); } $item->delete(); } } else { if ($board->slug !== null) { $board->slug->delete(); } $files = File::whereIn('id', $board->getFileIds())->get(); foreach ($files as $file) { $this->storage->unBind($board->id, $file, true); } $tags = Tag::getByTaggable($board->id); foreach ($tags as $tag) { $tag->delete(); } $board->delete(); } $board->getConnection()->commit(); }
public function testUnBindNotRemovedFileWhenFlagFalse() { list($handler, $auth, $keygen, $distributor, $temps) = $this->getMocks(); $instance = new Storage($handler, $auth, $keygen, $distributor, $temps); $mockFile = m::mock('Xpressengine\\Storage\\File'); $mockConn = m::mock('stdClass'); $mockFile->shouldReceive('getConnection')->andReturn($mockConn); $mockFile->shouldReceive('getFileableTable')->andReturn('fileable_table'); $mockFile->shouldReceive('getKey')->andReturn('file-id'); $mockConn->shouldReceive('table')->once()->with('fileable_table')->andReturnSelf(); $mockConn->shouldReceive('where')->once()->with('fileId', 'file-id')->andReturnSelf(); $mockConn->shouldReceive('where')->once()->with('fileableId', 'fileable-id')->andReturnSelf(); $mockConn->shouldReceive('delete')->once()->andReturn(1); $mockFile->shouldReceive('getAttribute')->with('useCount')->andReturn(1); $mockFile->shouldReceive('setAttribute')->once()->with('useCount', 0)->andSet('useCount', 0); $mockFile->shouldReceive('save')->andReturn(true); $instance->unBind('fileable-id', $mockFile); }
public function testUnBindNotRemovedFileWhenFlagFalse() { list($handler, $repo, $auth, $keygen) = $this->getMocks(); $mockFile = m::mock('Xpressengine\\Storage\\File'); $mockFile->id = 'fileidstring'; $repo->shouldReceive('unRelating')->once()->with('targetidstring', 'fileidstring')->andReturnNull(); $instance = new Storage($handler, $repo, $auth, $keygen); $instance->unBind('targetidstring', $mockFile); }