Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  *
  * @param Email $entity
  * @param       $unlock
  *
  * @return mixed
  */
 public function saveEntity($entity, $unlock = true)
 {
     $now = new DateTimeHelper();
     $type = $entity->getEmailType();
     if (empty($type)) {
         // Just in case JS failed
         $entity->setEmailType('template');
     }
     // Ensure that list emails are published
     if ($entity->getEmailType() == 'list') {
         $entity->setIsPublished(true);
         $entity->setPublishDown(null);
         $entity->setPublishUp(null);
     }
     //set the author for new pages
     if (!$entity->isNew()) {
         //increase the revision
         $revision = $entity->getRevision();
         $revision++;
         $entity->setRevision($revision);
     }
     // Ensure links in template content don't have encoded ampersands
     if ($entity->getTemplate()) {
         $content = $entity->getContent();
         foreach ($content as $key => $value) {
             $content[$key] = $this->cleanUrlsInContent($value);
         }
         $entity->setContent($content);
     } else {
         // Ensure links in HTML don't have encoded ampersands
         $htmlContent = $this->cleanUrlsInContent($entity->getCustomHtml());
         $entity->setCustomHtml($htmlContent);
     }
     // Ensure links in PLAIN TEXT don't have encoded ampersands
     $plainContent = $this->cleanUrlsInContent($entity->getPlainText());
     $entity->setPlainText($plainContent);
     // Reset the variant hit and start date if there are any changes and if this is an A/B test
     // Do it here in addition to the blanket resetVariants call so that it's available to the event listeners
     $changes = $entity->getChanges();
     $parent = $entity->getVariantParent();
     if ($parent !== null && !empty($changes) && empty($this->inConversion)) {
         $entity->setVariantSentCount(0);
         $entity->setVariantReadCount(0);
         $entity->setVariantStartDate($now->getDateTime());
     }
     parent::saveEntity($entity, $unlock);
     // If parent, add this entity as a child of the parent so that it populates the list in the tab (due to Doctrine hanging on to entities in memory)
     if ($parent) {
         $parent->addVariantChild($entity);
     }
     // Reset associated variants if applicable due to changes
     if ($entity->isVariant() && !empty($changes) && empty($this->inConversion)) {
         $dateString = $now->toUtcString();
         $parentId = !empty($parent) ? $parent->getId() : $entity->getId();
         $this->getRepository()->resetVariants($parentId, $dateString);
         //if the parent was changed, then that parent/children must also be reset
         if (isset($changes['variantParent'])) {
             $this->getRepository()->resetVariants($changes['variantParent'][0], $dateString);
         }
     }
 }
 /**
  * {@inheritDoc}
  */
 public function setContent($content)
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'setContent', array($content));
     return parent::setContent($content);
 }