/**
  * @return HttpResponse
  */
 public function getAjaxRevisionControlBox()
 {
     $pageModel = new PageModel($this->db);
     $cmsPage = $pageModel->getPageByID($this->route->getParam(1));
     $elementModel = new ElementModel($this->db);
     $elementTree = $elementModel->getElementTree($cmsPage);
     $elementInstance = $elementModel->findElementIDInTree($elementTree, $this->route->getParam(0));
     try {
         $res = $elementInstance->generateRevisionBox($this, $cmsPage->getID());
     } catch (PHPException $e) {
         return $this->generateResponse(500, '<p><b>PHP Error:</b> ' . $e->getMessage() . ' in ' . $e->getFile() . ' (Line: ' . $e->getLine() . ')</p><pre>' . $e->getTraceAsString() . '</pre>');
     } catch (\Exception $e) {
         return $this->generateResponse(500, '<p>' . $e->getMessage() . '</p>');
     }
     return $this->generateResponse(200, $res);
 }
 public function index()
 {
     $oldReqUri = $_SERVER['REQUEST_URI'];
     $_SERVER['REQUEST_URI'] = '';
     $pageModel = new PageModel($this->indexer->getDB());
     $elementModel = new ElementModel($this->indexer->getDB());
     $searchModel = new SearchModel($this->indexer->getDB());
     $stmntPages = $this->indexer->getDB()->prepare("\n\t\t\tSELECT p.ID, p.language_codeFK lang, p.title, p.description, r.pattern, p.role\n\t\t\tFROM page p\n\t\t\tLEFT JOIN route r ON r.page_IDFK = p.ID\n\t\t\tWHERE r.ID IS NOT NULL\n\t\t");
     $resPages = $this->indexer->getDB()->select($stmntPages);
     $indexedPages = 0;
     foreach ($resPages as $p) {
         if ($p->role !== 'page') {
             echo "  Skipped page #" . $p->ID . ": reason -> unusable role: " . $p->role . PHP_EOL;
             continue;
         }
         $searchIndexInterface = $this->indexer->getIndex($p->lang);
         // Index page
         echo "  Indexing page #" . $p->ID . " into index \"" . $p->lang . "\": ";
         $cmsPage = $pageModel->getPageByID($p->ID);
         $elementTree = $elementModel->getElementTree($cmsPage);
         try {
             $searchableContent = $this->renderElementTreeRecursive($elementTree, $cmsPage->getLanguage());
         } catch (\Exception $e) {
             echo " Error -> " . $e->getMessage() . "\n";
             continue;
         }
         $searchDoc = new Document();
         $searchDoc->setInternalID($p->ID);
         $searchDoc->setLanguage($p->lang);
         $searchDoc->setTitle($p->title);
         $searchDoc->setDescription($searchableContent);
         $searchDoc->setPath($p->pattern);
         $searchDoc->setType('core_page');
         $docID = $searchModel->saveDocument($searchDoc);
         $luceneDocument = new \ZendSearch\Lucene\Document();
         $luceneDocument->addField(Field::keyword('ID', $docID));
         $luceneDocument->addField(Field::unStored('content', $searchableContent));
         $luceneDocument->addField(Field::unStored('description', $p->description));
         $searchIndexInterface->addDocument($luceneDocument);
         echo "done";
         echo "\n";
         ++$indexedPages;
     }
     $_SERVER['REQUEST_URI'] = $oldReqUri;
     echo "  Total indexed pages: " . $indexedPages . "\n";
 }
 /**
  * Generates an error page for a thrown exception which was not caught anywhere else in the code
  * 
  * @param \Exception $e The uncaught exception
  *
  * @return HttpResponse The HTTP response for sending back to the client (e.x. a nice styled error message)
  */
 public function generateErrorPage(\Exception $e)
 {
     $errorCode = 500;
     if ($e instanceof HttpException) {
         $errorCode = $e->getCode();
     }
     if ($e instanceof HttpException === false || $e->getCode() === 500) {
         $this->logger->error('An uncaught error occurred', $e);
     }
     $stmntErrorPage = $this->db->prepare("SELECT ID FROM page WHERE role = 'error' AND error_code = ?");
     $resErrorPage = $this->db->select($stmntErrorPage, array($errorCode));
     $env = $this->currentDomain->environment;
     if ($this->core->getSettings()->core->environments->{$env}->debug === true || count($resErrorPage) <= 0) {
         return parent::generateErrorPage($e);
     }
     $pageModel = new PageModel($this->db);
     $this->cmsPage = $pageModel->getPageByID($resErrorPage[0]->ID);
     return $this->generateCMSPage($pageModel);
 }