/** * Index question * * @todo do this via runLater * * @return object $this */ protected function addToSearchIndex() { IndexerFactory::factory($this->Registry)->indexQuestion($this->Question); return $this; }
/** * * Set the value of $this->Resource, set resource i_status * to value of 2 (posted), adds the name and uid of moderator * who approved the item, * update the user account of item author to increase their * count of approved items * * @param int $id * @param string $type emun 'q', 'a' * * @throws \Lampcms\DevException if $id is not numeric or $type is not enum 'q', 'a' * @throws \Lampcms\Exception if question/answer is deleted or not found by $id * @return object $this */ public function approveResource($id, $type = 'q') { /** * First check that Viewer is a moderator * only moderator can approve a pending resource * If Viewer does not have permission then AccessException will be thrown */ $this->checkAccessPermission('approve_pending'); if (!is_numeric($id)) { throw new DevException('Value of $id was not numeric. Passed value was: ' . $id); } if ($type !== 'q' && $type !== 'a') { throw new DevException('Unknown resource type. Can only be "a" or "q". Passed value was: ' . $type); } if ('q' === $type) { $a = $this->Registry->Mongo->QUESTIONS->findOne(array(ResourceSchema::PRIMARY => (int) $id)); } else { $a = $this->Registry->Mongo->ANSWERS->findOne(array(ResourceSchema::PRIMARY => (int) $id)); } if (empty($a)) { throw new \Lampcms\Exception('@@Question not found@@'); } if (!empty($a[ResourceSchema::DELETED_TIMESTAMP])) { throw new \Lampcms\Exception('@@This item was deleted on@@ ' . date('r', $a[ResourceSchema::DELETED_TIMESTAMP])); } if ('q' === $type) { $this->Question = $this->Resource = new Question($this->Registry, $a); } else { $this->Resource = new Answer($this->Registry, $a); $this->Question = $this->getQuestion($this->Resource->getQuestionId()); } if (true === ($res = $this->Resource->setApprovedStatus($this->Registry->Viewer))) { $this->updatePoster(); $this->updateCategory($type); if ('q' === $type) { $this->addTags()->addUnansweredTags()->addRelatedTags(); try { IndexerFactory::factory($this->Registry)->indexQuestion($this->Resource); } catch (\Exception $e) { $err = 'Exception: ' . get_class($e) . ' Unable to add question to search index because: ' . $e->getMessage() . ' Error Code: ' . $e->getCode() . ' trace: ' . $e->getTraceAsString(); d($err); } $this->Registry->Dispatcher->post($this->Resource, 'onApprovedQuestion'); } else { /** * Need update etag of Question otherwise * upon page reload the browser will show cached * version of question with this answer still showing * with the "pending" notice */ $this->updateQuestion(); $this->Registry->Dispatcher->post($this->Resource, 'onApprovedAnswer', array('question' => $this->Question)); } d('Approval complete for resource type ' . $type . ' id: ' . $id); } else { d('Item was already approved'); } return $this; }
/** * Remove data from search index * if question is deleted * * @todo later if we also index Answers, then * run removeAnswer() if resource is answer. * * @return object $this */ protected function removeFromIndex() { if ($this->Resource instanceof \Lampcms\Question) { IndexerFactory::factory($this->Registry)->removeQuestion($this->Resource); } return $this; }
/** * Index question * * @todo do this via runLater * * @return object $this */ protected function addToSearchIndex() { /** * Do NOT add 'PENDING' question to search index * Only add question with status 'POSTED' */ if ($this->Question[Schema::RESOURCE_STATUS_ID] === Schema::POSTED) { IndexerFactory::factory($this->Registry)->indexQuestion($this->Question); } return $this; }