unBind() public method

set the target be not have a file
public unBind ( string $fileableId, File $file, boolean $remove = false ) : void
$fileableId string fileable identifier
$file File file instance
$remove boolean remove file when given true
return void
Exemplo n.º 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;
 }
Exemplo n.º 2
0
 /**
  * 문서 삭제
  *
  * @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();
 }
Exemplo n.º 3
0
 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);
 }
Exemplo n.º 4
0
 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);
 }