Beispiel #1
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();
 }