/**
  * Handles PRE_SAVE storage event
  *
  * @param StorageEvent $event
  */
 public function onPreSave(StorageEvent $event)
 {
     $contenttype = $event->getContentType();
     // record contenttype
     $record = $event->getContent();
     // record itself
     $created = $event->isCreate();
     // if record was created, updated or deleted, for more information see the page in the documentation
     // Do whatever you want with this data
     // See page in the documentation for a logging example
 }
Example #2
0
 /**
  * It should detect already hashed passwords.
  *
  * @dataProvider providePreSaveAlreadyHashed
  */
 public function testOnPreSavePasswordAlreadyHashed($hash)
 {
     $this->storageEvent->getContent()->willReturn($this->user->reveal());
     $this->user->getPassword()->willReturn($hash);
     $this->passwordFactory->createHash(Argument::cetera())->shouldNotBeCalled();
     $this->user->setPassword($hash)->shouldBeCalled();
     $this->listener->onUserEntityPreSave($this->storageEvent->reveal());
 }
Example #3
0
 /**
  * Pre-save storage event.
  *
  * @param StorageEvent $event
  */
 public function onPreSave(StorageEvent $event)
 {
     /** @var Entity\Entity $entityRecord */
     $entityRecord = $event->getContent();
     if ($entityRecord instanceof Entity\Users) {
         $this->passwordHash($entityRecord);
     }
 }
Example #4
0
 public function testSetupWithRecord()
 {
     $app = $this->getApp();
     $content = new Content($app, 'pages');
     $content->setValue('id', 5);
     $event = new StorageEvent($content);
     $this->assertEquals(5, $event->getId());
     $this->assertEquals('pages', $event->getContentType());
 }
 /**
  * Encode array fields as json string just before save it in the storage.
  *
  * @param StorageEvent $event
  */
 public function arrayToJson(StorageEvent $event)
 {
     $content = $event->getContent();
     foreach ($content->contenttype['fields'] as $key => $options) {
         if ($options['type'] == 'array') {
             $content->values[$key] = json_encode(array_values($content->values[$key]));
         }
     }
 }
 /**
  * Remove sessions & authtokens when a user is deleted.
  *
  * @param StorageEvent $event
  */
 public function onStorageEventPreDelete(StorageEvent $event)
 {
     /** @var Entity\Users $userEntity */
     $userEntity = $event->getContent();
     if (!$userEntity instanceof \Bolt\Storage\Entity\Users) {
         return;
     }
     $this->deleteAuthtokens($userEntity);
     $this->deleteSessions($userEntity);
 }
Example #7
0
 public function testIsCreate()
 {
     $app = $this->getApp();
     $content = new Content($app, 'pages');
     $content->setValue('id', 5);
     $event = new StorageEvent($content);
     $event->setArgument('create', true);
     $this->assertTrue($event->isCreate());
     $event->setArgument('create', false);
     $this->assertFalse($event->isCreate());
 }
 /**
  * Handles PRE_SAVE storage event
  *
  * @param StorageEvent $event
  */
 public function onPreSave(StorageEvent $event)
 {
     // The ContentType of the record being saved
     $contenttype = $event->getContentType();
     // The record being saved
     $record = $event->getContent();
     // A flag to tell if the record was created, updated or deleted,
     // for more information see the page in the documentation
     $created = $event->isCreate();
     // Do whatever you want with this data
     // See page in the documentation for a logging example
 }
Example #9
0
 /**
  * Post-save testing event.
  *
  * @param StorageEvent $event
  */
 public function eventPostSave(StorageEvent $event)
 {
     $contenttype = $event->getContentType();
     if ($contenttype === 'pages') {
         $repo = $this->app['storage']->getRepository($contenttype);
         $record = $event->getContent();
         $values = $record->serialize();
         if ($event->isCreate()) {
             // Add a unique paragraph to the end of the body
             $record->setBody($values['body'] . '<p>Snuck in to body during POST_SAVE on create: ' . date('Y-m-d H:i:s') . '</p>');
         } else {
             // Add a unique paragraph to the end of the body
             $record->setBody($values['body'] . '<p>Added to body during POST_SAVE on save: ' . date('Y-m-d H:i:s') . '</p>');
         }
         // Save the changes to the database
         $repo->save($record, true);
     }
 }
Example #10
0
 /**
  * Dispatch the event to IFTTT channel
  *
  * Only control if the content belongs to allowed content-types to broadcast.
  */
 public function dispatchToChannel(\Bolt\Events\StorageEvent $event)
 {
     $id = $event->getId();
     $contenttype = $event->getContentType();
     $content = $event->getContent();
     // Only allowed content types in published state.
     if (!in_array($contenttype, $this->config['content_types'])) {
         return;
     }
     // Payload
     $payload = array('value1' => $content->get('title'), 'value2' => $this->app['resources']->getUrl('hosturl') . $content->link());
     $event_name = $this->config['event_name'];
     try {
         $this->sendRequest($event_name, $payload);
         $this->log("Channel notified with event '{$event_name}' for {$contenttype}#{$id}");
     } catch (\Guzzle\Http\Exception\BadResponseException $e) {
         $code = $e->getResponse()->getStatusCode();
         $message = $e->getMessage();
         $this->log("Error : HTTP/{$code} - {$message}", "error");
     }
 }
 /**
  * Handles POST_DELETE storage event
  *
  * @param StorageEvent $event
  */
 public function onPostDelete(StorageEvent $event)
 {
     $id = $event->getId();
     // $contenttype = $event->getContentType();
     $record = $event->getContent();
 }
 /**
  * Replace shortcodes with actual tweet content
  *
  * @uses  getEmbed()
  * @param StorageEvent $event
  */
 function preSave(StorageEvent $event)
 {
     $record = $event->getContent();
     $newbody = preg_replace_callback($this->regex, array($this, 'getEmbed'), $record->get('body'));
     $record->setValue('body', $newbody);
 }
Example #13
0
 /**
  * postDeleteCallback.
  *
  * This callback takes care of deleting all translations,
  * associated with the deleted content.
  */
 public function postDeleteCallback(StorageEvent $event)
 {
     $subject = $event->getSubject();
     $query = 'DELETE FROM ' . $prefix . 'translation where content_type = ? and content_type_id = ?';
     $stmt = $this->app['db']->prepare($query);
     $stmt->bindValue(1, $event->getArgument('contenttype'));
     $stmt->bindValue(2, $subject['id']);
     $stmt->execute();
 }
 /**
  * StorageEvents::POST_SAVE event callback.
  *
  * @param StorageEvent $event
  */
 public function postSave(StorageEvent $event)
 {
     $request = $this->requestStack->getCurrentRequest();
     if ($request === null) {
         return;
     }
     $localeSlug = $request->get('_locale');
     $subject = $event->getSubject();
     if (!$subject instanceof Content) {
         return;
     }
     if (!isset($subject[$localeSlug . 'data'])) {
         return;
     }
     $localeData = json_decode($subject[$localeSlug . 'data']);
     foreach ($localeData as $key => $value) {
         $subject->set($key, $value);
     }
 }