コード例 #1
0
ファイル: EmailModel.php プロジェクト: HomeRefill/mautic
 /**
  * {@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);
         }
     }
 }
コード例 #2
0
ファイル: EmailModel.php プロジェクト: smotalima/mautic
 /**
  * {@inheritdoc}
  *
  * @param Email $entity
  * @param       $unlock
  *
  * @return mixed
  */
 public function saveEntity($entity, $unlock = true)
 {
     $now = new \DateTime();
     $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);
         //reset the variant hit and start date if there are any changes
         $changes = $entity->getChanges();
         if ($entity->isVariant() && !empty($changes) && empty($this->inConversion)) {
             $entity->setVariantSentCount(0);
             $entity->setVariantStartDate($now);
         }
     }
     parent::saveEntity($entity, $unlock);
     //also reset variants if applicable due to changes
     if (!empty($changes) && empty($this->inConversion)) {
         $parent = $entity->getVariantParent();
         $children = !empty($parent) ? $parent->getVariantChildren() : $entity->getVariantChildren();
         $variants = array();
         if (!empty($parent)) {
             $parent->setVariantSentCount(0);
             $parent->setVariantStartDate($now);
             $variants[] = $parent;
         }
         if (count($children)) {
             foreach ($children as $child) {
                 $child->setVariantSentCount(0);
                 $child->setVariantStartDate($now);
                 $variants[] = $child;
             }
         }
         //if the parent was changed, then that parent/children must also be reset
         if (isset($changes['variantParent'])) {
             $parent = $this->getEntity($changes['variantParent'][0]);
             if (!empty($parent)) {
                 $parent->setVariantSentCount(0);
                 $parent->setVariantStartDate($now);
                 $variants[] = $parent;
                 $children = $parent->getVariantChildren();
                 if (count($children)) {
                     foreach ($children as $child) {
                         $child->setVariantSentCount(0);
                         $child->setVariantStartDate($now);
                         $variants[] = $child;
                     }
                 }
             }
         }
         if (!empty($variants)) {
             $this->saveEntities($variants, false);
         }
     }
 }
コード例 #3
0
 /**
  * {@inheritDoc}
  */
 public function getChanges()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getChanges', array());
     return parent::getChanges();
 }