/** * 게시판에 글 등록 시 핸들러를 통해서 처리 * Interception 을 통해 다양한 서드파티 기능이 추가될 수 있다. * * @param array $args arguments * @param UserInterface $user * @return Board */ public function add(array $args, UserInterface $user, ConfigEntity $config) { $model = $this->getModel($config); $model->getConnection()->beginTransaction(); $args['type'] = BoardModule::getId(); $args['userId'] = $user->getId(); if ($args['userId'] === null) { $args['userId'] = ''; } if (empty($args['writer'])) { $args['writer'] = $user->getDisplayName(); } if ($user instanceof Guest) { $args['userType'] = Board::USER_TYPE_GUEST; } if ($config->get('anonymity') === true) { $args['writer'] = $config->get('anonymityName'); $args['userType'] = Board::USER_TYPE_ANONYMITY; } // save Document $doc = $this->documentHandler->add($args); $model = $this->getModel($config); $board = $model->find($doc->id); $this->setModelConfig($board, $config); $this->saveSlug($board, $args); $this->saveCategory($board, $args); $this->setFiles($board, $args); $this->setTags($board, $args); $this->saveData($board, $args); $model->getConnection()->commit(); return $board; }
/** * insert a document * * @param ItemEntity $item board item entity * @param ConfigEntity $config board config entity * @return void */ public function add(ItemEntity $item, ConfigEntity $config) { $doc = $item->getDocument(); // board 의 function type 을 가져와 insert 실행 // if ($functionTypes = $config->get('functionType')) { // foreach ($functionTypes as $className) { // (new $className)->insert($doc); // } // } $this->document->getRepository()->connection()->beginTransaction(); // board 의 설정을 가져와서.. 어떤 글인가... 확인해야 겠다... // 그래서 어떤 insert 를 사용할 결정해야 겠어. $this->document->add($doc); $this->shortIdGenerator->make($item->id); $slugEntity = new SlugEntity(); $slugEntity->slug = $item->slug; $slugEntity->title = $item->title; $slugEntity->id = $item->id; $slugEntity->instanceId = $item->instanceId; $this->slug->insert($slugEntity); // interception 사용? // Todo 게시판에 files 라고 있는데.. 이게 업로드된 파일 id 정보이다. // 이걸 doc->id 와 매핑 시켜줘야 한다. /** @var \Xpressengine\Storage\File $file */ foreach ($item->getFiles() as $file) { $this->storage->bind($doc->id, $file); } $this->document->getRepository()->connection()->commit(); }
/** * test without writer information * * @expectedException \Xpressengine\Document\Exceptions\RequiredValueException * @return void */ public function testAddWithoutInstanceId() { $conn = $this->conn; $repo = $this->repo; $configHandler = $this->configHandler; $instanceManager = $this->instanceManager; $request = $this->request; $handler = new DocumentHandler($conn, $repo, $configHandler, $instanceManager, $request); $user = $this->getUser(); $user->shouldReceive('getId')->andReturn('userId'); $user->shouldReceive('getDisplayName')->andReturn('userName'); $doc = $this->getDocumentEntity(); $doc->shouldReceive('setAuthor'); $doc->shouldReceive('getAuthor')->andReturn($user); $doc->shouldReceive('setPureContent'); $handler->add($doc); }