Exemplo n.º 1
0
 /**
  * update
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function update()
 {
     /** @var \Xpressengine\Http\Request $request */
     $request = app('request');
     $user = Auth::user();
     $id = $request->get('id');
     if ($id === null) {
         throw new RequiredValueException();
     }
     // 글 수정 시 게시판 설정이 아닌 글의 상태에 따른 처리가 되어야 한다.
     $item = $this->handler->get($id, $this->boardId);
     $doc = $item->getDocument();
     // 비회원이 작성 한 글 인증
     // 비회원이 작성 한 글일 때 인증페이지로 이동
     /** @var \Xpressengine\Plugins\Board\IdentifyManager $identifyManager */
     $identifyManager = app('xe.board.identify');
     if ($doc->isGuest() === true && $identifyManager->identified($item) === false && $user->getRating() != 'super') {
         $e = new InvalidIdentifyException();
         throw $e;
     }
     /** @var \Xpressengine\Plugins\Board\Validator $validator */
     $validator = app('xe.board.validator');
     $rules = $validator->makeRule($this->config);
     if ($user instanceof Guest) {
         $rules = array_merge($rules, $validator->guestUpdate());
     }
     $this->validate($request, $rules);
     $inputs = $request->all();
     // replace purifying content to origin content value
     $inputs['content'] = $request->originAll()['content'];
     foreach ($this->handler->documentFilter($inputs) as $name => $value) {
         $doc->{$name} = $value;
     }
     // 공지
     $doc->notice(false);
     if ($request->get('status') == 'notice' && $this->isManager) {
         $doc->notice(true);
     }
     $item->setDocument($doc);
     /** @var \Xpressengine\Storage\Storage $storage */
     if (($fileIds = $request->get('_files')) !== null) {
         $storage = app('xe.storage');
         $item->setFiles($storage->getsIn($fileIds));
     }
     // 암호 설정
     if ($doc->certifyKey != '') {
         $doc->certifyKey = $identifyManager->hash($doc->certifyKey);
     }
     // 비회원 글 수정시 비밀번호를 입력 안한 경우 원래 비밀번호로 설
     $origin = $doc->getOriginal();
     if ($origin['certifyKey'] != '' && $doc->certifyKey == '') {
         $doc->certifyKey = $origin['certifyKey'];
     }
     $item->setDocument($doc);
     XeDB::beginTransaction();
     $this->handler->put($item);
     $doc = $item->getDocument();
     // 비회원 비밀번호를 변경 한 경우 세션 변경
     if ($origin['certifyKey'] != '' && $origin['certifyKey'] != $doc->certifyKey) {
         $identifyManager->destroy($item);
         $identifyManager->create($item);
     }
     // 태그 등록
     /** @var \Xpressengine\Tag\TagHandler $tag */
     $tag = app('xe.tag');
     $hashTags = array_unique(Input::get('hashTags', []));
     $tag->set($this->boardId, $doc->id, $hashTags);
     XeDB::commit();
     return Redirect::to($this->urlHandler->getShow($item, $this->urlHandler->queryStringToArray(Input::get('queryString'))));
 }