Deprecation: Deprecated since 3.0, to be removed in 4.0.
Example #1
0
 /**
  * Render the not found page if on frontend and http exception
  *
  * @param GetResponseForExceptionEvent $event
  */
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     $exception = $event->getException();
     if (!$exception instanceof HttpExceptionInterface || Zone::isBackend($event->getRequest())) {
         return;
     }
     if ($exception->getStatusCode() !== Response::HTTP_NOT_FOUND) {
         return;
     }
     // If $notFoundPage is referencing a template, render it and be done.
     if ($this->render->hasTemplate($this->notFoundPage)) {
         try {
             $this->renderNotFound($event, $this->notFoundPage, []);
         } catch (TwigErrorLoader $e) {
             // Template not found, fall though to see if we can render a
             // record, failing that let the exception handler take over
         }
     }
     // Next try for referencing DB content.
     $content = $this->storage->getContent($this->notFoundPage, ['returnsingle' => true]);
     if (!$content instanceof Content || empty($content->id)) {
         return;
     }
     $template = $this->templateChooser->record($content);
     $this->renderNotFound($event, $template, $content->getTemplateContext());
 }
Example #2
0
 /**
  * Render the not found page if on frontend and http exception
  *
  * @param GetResponseForExceptionEvent $event
  */
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     if (!$event->getException() instanceof HttpExceptionInterface || Zone::isBackend($event->getRequest())) {
         return;
     }
     $content = $this->storage->getContent($this->notFoundPage, ['returnsingle' => true]);
     if (!$content instanceof Content || empty($content->id)) {
         return;
     }
     $template = $this->templateChooser->record($content);
     $response = $this->render->render($template, $content->getTemplateContext());
     $event->setResponse($response);
 }
Example #3
0
 public function testGetNextChangeLogEntry()
 {
     $app = $this->getApp();
     $app['config']->set('general/changelog/enabled', true);
     $storage = new Storage($app);
     // To generate an extra changelog we fetch and save a content item
     // For now we need to mock the request object.
     $app['request'] = Request::create('/');
     $content = $storage->getContent('pages/1');
     $this->assertInstanceOf('\\Bolt\\Legacy\\Content', $content);
     $content->setValues(['status' => 'draft', 'ownerid' => 99]);
     $storage->saveContent($content, 'Test Suite Update');
     $content->setValues(['status' => 'published', 'ownerid' => 1]);
     $storage->saveContent($content, 'Test Suite Update');
     $log = $this->getLogChangeRepository()->getChangeLogEntry('pages', 1, 1, '>');
     $this->assertAttributeEquals(1, 'contentid', $log);
 }
Example #4
0
 protected function addSomeContent()
 {
     $app = $this->getApp();
     $app['request'] = Request::create('/');
     $app['config']->set('taxonomy/categories/options', ['news']);
     $prefillMock = new LoripsumMock();
     $app['prefill'] = $prefillMock;
     $storage = new Storage($app);
     $storage->prefill(['showcases', 'entries', 'pages']);
     // We also set some relations between showcases and entries
     $showcases = $storage->getContent('showcases');
     $randEntries = $storage->getContent('entries/random/2');
     foreach ($showcases as $show) {
         foreach (array_keys($randEntries) as $key) {
             $show->setRelation('entries', $key);
             $storage->saveContent($show);
         }
     }
 }
Example #5
0
 /**
  * Render the not found page if on frontend and http exception
  *
  * @param GetResponseForExceptionEvent $event
  */
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     if (!$event->getException() instanceof HttpExceptionInterface || Zone::isBackend($event->getRequest())) {
         return;
     }
     // If $notFoundPage is referencing a template, render it and be done.
     if ($this->render->hasTemplate($this->notFoundPage)) {
         $response = $this->render->render($this->notFoundPage);
         $event->setResponse($response);
         return;
     }
     // Next try for referencing DB content.
     $content = $this->storage->getContent($this->notFoundPage, ['returnsingle' => true]);
     if (!$content instanceof Content || empty($content->id)) {
         return;
     }
     $template = $this->templateChooser->record($content);
     $response = $this->render->render($template, [], $content->getTemplateContext());
     $event->setResponse($response);
 }
Example #6
0
 public function getContent($textquery, $parameters = '', &$pager = [], $whereparameters = [])
 {
     $result = parent::getContent($textquery, $parameters, $pager, $whereparameters);
     if ($result) {
         $reflection = new \ReflectionClass($this);
         $prop = $reflection->getParentClass()->getProperty('app');
         $prop->setAccessible(true);
         $app = $prop->getValue($this);
         if (is_array($result)) {
             foreach ($result as &$record) {
                 $this->repeaterHydrate($record, $app);
             }
         } else {
             $this->repeaterHydrate($result, $app);
         }
     }
     return $result;
 }
Example #7
0
 protected function executeGetContentQueries($decoded)
 {
     $this->queries[] = $decoded;
     return parent::executeGetContentQueries($decoded);
 }
Example #8
0
 protected function addSomeContent()
 {
     $app = $this->getApp();
     $this->addDefaultUser($app);
     $app['config']->set('taxonomy/categories/options', ['news']);
     $prefillMock = new LoripsumMock();
     $app['prefill'] = $prefillMock;
     $storage = new Storage($app);
     $storage->prefill(['showcases', 'pages']);
 }
 /**
  * Delete a record.
  *
  * @param string  $contenttype
  * @param integer $id
  *
  * @throws \Bolt\Exception\StorageException
  *
  * @return integer The number of affected rows.
  */
 public function deleteContent($contenttype, $id)
 {
     if (empty($contenttype)) {
         $this->app['logger.system']->error('Contenttype is required for' . __FUNCTION__, ['event' => 'exception']);
         throw new StorageException('Contenttype is required for ' . __FUNCTION__);
     }
     $synced = false;
     if (is_string($contenttype)) {
         $ct = $this->getContentType($contenttype);
         $synced = $ct['blimp_mode'] === 'sync';
     } else {
         $synced = $contenttype['blimp_mode'] === 'sync';
         $contenttype = $contenttype['slug'];
     }
     $collection = $this->getContentTypeCollection($contenttype);
     // Test that the record exists in the database
     if ($synced) {
         $oldContent = parent::findContent(parent::getContenttypeTablename($contenttype), $id);
     } else {
         $oldContent = $this->findContent($collection, $id);
     }
     if (empty($oldContent)) {
         throw new StorageException('Attempted to delete a non-existent record');
     }
     $real_id = null;
     if ($synced) {
         if (!empty($oldContent['blimp_id'])) {
             $real_id = $oldContent['blimp_id'];
         }
     } else {
         $real_id = $id;
     }
     // Dispatch pre-delete event
     if (!$synced && $this->app['dispatcher']->hasListeners(StorageEvents::PRE_DELETE)) {
         $event = new StorageEvent($oldContent, ['contenttype' => $contenttype]);
         $this->app['dispatcher']->dispatch(StorageEvents::PRE_DELETE, $event);
     }
     $this->logDelete($contenttype, $id, $oldContent);
     if (!empty($real_id)) {
         $uri = $collection . '/' . $real_id;
         $res = $this->app['blimp_client.request']('DELETE', $uri);
         if ($res['status'] == 200 || $synced && $res['status'] == 404) {
             if ($synced) {
                 return $this->app['storage']->deleteContent($contenttype, $id);
             }
             if ($this->app['dispatcher']->hasListeners(StorageEvents::POST_DELETE)) {
                 $event = new StorageEvent($oldContent, ['contenttype' => $contenttype]);
                 $this->app['dispatcher']->dispatch(StorageEvents::POST_DELETE, $event);
             }
             return 1;
         }
     } else {
         return $this->app['storage']->deleteContent($contenttype, $id);
     }
     return 0;
 }
Example #10
0
 protected function addSomeContent()
 {
     $app = $this->getApp();
     $this->getService('config')->set('taxonomy/categories/options', ['news']);
     $prefillMock = new LoripsumMock();
     $this->setService('prefill', $prefillMock);
     $storage = new Storage($app);
     $storage->preFill(['pages']);
 }