/**
  * {@inheritdoc}
  */
 public function delete($object)
 {
     try {
         $this->manager->delete($object);
     } catch (DBALException $e) {
         throw new ModelManagerException('', 0, $e);
     } catch (\PDOException $e) {
         throw new ModelManagerException('', 0, $e);
     }
 }
Beispiel #2
0
 /**
  * Update the number of comment for a comment
  *
  * @param null|\Sonata\NewsBundle\Model\PostInterface $post
  *
  * @return void
  */
 public function updateCommentsCount(PostInterface $post = null)
 {
     $commentTableName = $this->getObjectManager()->getClassMetadata($this->getClass())->table['name'];
     $postTableName = $this->getObjectManager()->getClassMetadata($this->postManager->getClass())->table['name'];
     $this->getConnection()->beginTransaction();
     $this->getConnection()->query(sprintf('UPDATE %s p SET p.comments_count = 0', $postTableName));
     $this->getConnection()->query(sprintf('UPDATE %s p, (SELECT c.post_id, count(*) as total FROM %s as c WHERE c.status = 1 GROUP BY c.post_id) as count_comment
         SET p.comments_count = count_comment.total
         WHERE p.id = count_comment.post_id', $postTableName, $commentTableName));
     $this->getConnection()->commit();
 }
 /**
  * {@inheritdoc}
  */
 public function process(ConsumerEvent $event)
 {
     $media = $this->mediaManager->findOneBy(array('id' => $event->getMessage()->getValue('mediaId')));
     if (!$media) {
         throw new HandlingException(sprintf('Media not found - id: %s', $event->getMessage()->getValue('mediaId')));
     }
     // solve race condition between message queue and database transaction
     $media->setProviderReference($event->getMessage()->getValue('providerReference'));
     try {
         $this->getThumbnail($event)->generate($this->pool->getProvider($media->getProviderName()), $media);
     } catch (\LogicException $e) {
         throw new HandlingException(sprintf('Error while generating exception for media.id: %s', $event->getMessage()->getValue('mediaId')), 0, $e);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function load(BlockInterface $block)
 {
     $gallery = $block->getSetting('galleryId');
     if ($gallery) {
         $gallery = $this->galleryManager->findOneBy(array('id' => $gallery));
     }
     $block->setSetting('galleryId', $gallery);
 }
 /**
  * {@inheritdoc}
  */
 public function load(BlockInterface $block)
 {
     $media = $block->getSetting('mediaId', null);
     if (is_int($media)) {
         $media = $this->mediaManager->findOneBy(array('id' => $media));
     }
     $block->setSetting('mediaId', $media);
 }
 /**
  * Get the related Transaction.
  *
  * @param ConsumerEvent $event
  *
  * @throws \RuntimeException
  *
  * @return TransactionInterface
  */
 protected function getTransaction(ConsumerEvent $event)
 {
     $transactionId = $event->getMessage()->getValue('transaction_id');
     $transaction = $this->transactionManager->findOneBy(array('id' => $transactionId));
     if (!$transaction) {
         throw new \RuntimeException(sprintf('Unable to retrieve Transaction %d', $transactionId));
     }
     return $transaction;
 }
 /**
  * Update the number of comment for a comment.
  *
  * @param null|\Sonata\NewsBundle\Model\PostInterface $post
  */
 public function updateCommentsCount(PostInterface $post = null)
 {
     $commentTableName = $this->getObjectManager()->getClassMetadata($this->getClass())->table['name'];
     $postTableName = $this->getObjectManager()->getClassMetadata($this->postManager->getClass())->table['name'];
     $this->getConnection()->beginTransaction();
     $this->getConnection()->query($this->getCommentsCountResetQuery($postTableName));
     $this->getConnection()->query($this->getCommentsCountQuery($postTableName, $commentTableName));
     $this->getConnection()->commit();
 }
 /**
  * @param mixed $media
  *
  * @return MediaInterface|null|bool
  */
 private function getMedia($media)
 {
     if (!$media instanceof MediaInterface && strlen($media) > 0) {
         $media = $this->mediaManager->findOneBy(array('id' => $media));
     }
     if (!$media instanceof MediaInterface) {
         return false;
     }
     if ($media->getProviderStatus() !== MediaInterface::STATUS_OK) {
         return false;
     }
     return $media;
 }
Beispiel #9
0
 /**
  * Update the count comment
  */
 private function updateCountsComment()
 {
     $this->commentManager->updateCommentsCount();
 }
Beispiel #10
0
 /**
  * {@inheritdoc}
  */
 protected function configureFormFields(FormMapper $formMapper)
 {
     $commentClass = $this->commentManager->getClass();
     $formMapper->with('General')->add('enabled', null, array('required' => false))->add('author', 'sonata_type_model_list')->add('collection', 'sonata_type_model_list', array('required' => false))->add('title')->add('abstract', null, array('attr' => array('class' => 'span6', 'rows' => 5)))->add('content', 'sonata_formatter_type', array('event_dispatcher' => $formMapper->getFormBuilder()->getEventDispatcher(), 'format_field' => 'contentFormatter', 'source_field' => 'rawContent', 'source_field_options' => array('attr' => array('class' => 'span10', 'rows' => 20)), 'target_field' => 'content', 'listener' => true))->end()->with('Tags')->add('tags', 'sonata_type_model', array('required' => false, 'expanded' => true, 'multiple' => true))->end()->with('Options')->add('publicationDateStart')->add('commentsCloseAt')->add('commentsEnabled', null, array('required' => false))->add('commentsDefaultStatus', 'choice', array('choices' => $commentClass::getStatusList(), 'expanded' => true))->end();
 }
 /**
  * Deserialize object from its id.
  *
  * @param VisitorInterface $visitor
  * @param int              $data
  * @param array            $type
  *
  * @return null|object
  */
 public function deserializeObjectFromId(VisitorInterface $visitor, $data, array $type)
 {
     return $this->manager->findOneBy(array('id' => $data));
 }