/** * {@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); } } }
/** * {@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} * * @param Email $entity * @param $unlock * * @return mixed */ public function saveEntity($entity, $unlock = true) { $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); // Ensure that this email has the same lists assigned as the translated parent if applicable /** @var Email $translationParent */ if ($translationParent = $entity->getTranslationParent()) { $parentLists = $translationParent->getLists()->toArray(); $entity->setLists($parentLists); } } if (!$this->updatingTranslationChildren) { if (!$entity->isNew()) { //increase the revision $revision = $entity->getRevision(); $revision++; $entity->setRevision($revision); } // Reset a/b test if applicable if ($isVariant = $entity->isVariant()) { $variantStartDate = new \DateTime(); $resetVariants = $this->preVariantSaveEntity($entity, ['setVariantSentCount', 'setVariantReadCount'], $variantStartDate); } parent::saveEntity($entity, $unlock); if ($isVariant) { $emailIds = $entity->getRelatedEntityIds(); $this->postVariantSaveEntity($entity, $resetVariants, $emailIds, $variantStartDate); } $this->postTranslationEntitySave($entity); // Force translations for this entity to use the same segments if ($entity->getEmailType() == 'list' && $entity->hasTranslations()) { $translations = $entity->getTranslationChildren()->toArray(); $this->updatingTranslationChildren = true; foreach ($translations as $translation) { $this->saveEntity($translation); } $this->updatingTranslationChildren = false; } } else { parent::saveEntity($entity, false); } }
/** * {@inheritDoc} */ public function getEmailType() { $this->__initializer__ && $this->__initializer__->__invoke($this, 'getEmailType', array()); return parent::getEmailType(); }