示例#1
0
 /**
  * {@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);
     }
 }