remove() public method

delete document
public remove ( Document $doc ) : boolean
$doc Xpressengine\Document\Models\Document document model
return boolean
Beispiel #1
0
 /**
  * 문서 삭제
  *
  * @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;
 }
 /**
  * test remove
  *
  * @return void
  */
 public function testRemove()
 {
     $conn = $this->conn;
     $repo = $this->repo;
     $configHandler = $this->configHandler;
     $instanceManager = $this->instanceManager;
     $request = $this->request;
     $handler = new DocumentHandler($conn, $repo, $configHandler, $instanceManager, $request);
     $doc = $this->getDocumentEntity();
     $doc->instanceId = 'instanceId';
     $configHandler->shouldReceive('get')->andReturn(null);
     $configHandler->shouldReceive('getDefault')->andReturn($this->getConfigEntity());
     $repo->shouldReceive('delete')->andReturn(1);
     $result = $handler->remove($doc);
     $this->assertEquals(1, $result);
 }