Exemple #1
0
 /**
  * {@inheritdoc}
  *
  * @throws \Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
  */
 public function saveEntity($entity, $unlock = true)
 {
     if (!$entity instanceof User) {
         throw new MethodNotAllowedHttpException(array('User'), 'Entity must be of class User()');
     }
     parent::saveEntity($entity, $unlock);
 }
 /**
  * {@inheritdoc}
  *
  * @param       $entity
  * @param       $unlock
  * @return mixed
  */
 public function saveEntity($entity, $unlock = true)
 {
     $alias = $entity->getAlias();
     if (empty($alias)) {
         $alias = strtolower(InputHelper::alphanum($entity->getTitle(), false, '-'));
     } else {
         $alias = strtolower(InputHelper::alphanum($alias, false, '-'));
     }
     //make sure alias is not already taken
     $repo = $this->getRepository();
     $testAlias = $alias;
     $bundle = $entity->getBundle();
     $count = $repo->checkUniqueCategoryAlias($bundle, $testAlias, $entity);
     $aliasTag = $count;
     while ($count) {
         $testAlias = $alias . $aliasTag;
         $count = $repo->checkUniqueCategoryAlias($bundle, $testAlias, $entity);
         $aliasTag++;
     }
     if ($testAlias != $alias) {
         $alias = $testAlias;
     }
     $entity->setAlias($alias);
     parent::saveEntity($entity, $unlock);
 }
Exemple #3
0
 /**
  * {@inheritdoc}
  */
 public function saveEntity($entity, $unlock = true)
 {
     if (empty($this->inConversion)) {
         $alias = $entity->getAlias();
         if (empty($alias)) {
             $alias = strtolower(InputHelper::alphanum($entity->getTitle(), false, '-'));
         } else {
             $alias = strtolower(InputHelper::alphanum($alias, false, '-'));
         }
         //make sure alias is not already taken
         $repo = $this->getRepository();
         $testAlias = $alias;
         $count = $repo->checkUniqueAlias($testAlias, $entity);
         $aliasTag = $count;
         while ($count) {
             $testAlias = $alias . $aliasTag;
             $count = $repo->checkUniqueAlias($testAlias, $entity);
             $aliasTag++;
         }
         if ($testAlias != $alias) {
             $alias = $testAlias;
         }
         $entity->setAlias($alias);
     }
     //set the author for new asset
     if (!$entity->isNew()) {
         //increase the revision
         $revision = $entity->getRevision();
         $revision++;
         $entity->setRevision($revision);
     }
     parent::saveEntity($entity, $unlock);
 }
Exemple #4
0
 /**
  * {@inheritdoc}
  *
  * @throws \Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
  */
 public function saveEntity($entity, $unlock = true)
 {
     if (!$entity instanceof Role) {
         throw new MethodNotAllowedHttpException(['Role'], 'Entity must be of class Role()');
     }
     $isNew = $entity->getId() ? 0 : 1;
     if (!$isNew) {
         //delete all existing
         $this->em->getRepository('MauticUserBundle:Permission')->purgeRolePermissions($entity);
     }
     parent::saveEntity($entity, $unlock);
 }
 public function saveEntity($entity, $unlock = true)
 {
     if (!$entity instanceof Opportunity) {
         throw new \InvalidArgumentException('entity is not an instance of Opportunity');
     }
     if (!$entity->getOwnerUser()) {
         $entity->setOwnerUser($this->factory->getUser(true));
     }
     if ($leadId = $this->factory->getRequest()->get('leadId', false)) {
         $entity->setLead($this->factory->getModel('lead')->getEntity($leadId));
     }
     parent::saveEntity($entity);
 }
Exemple #6
0
 /**
  * {@inheritdoc}
  *
  * @param  \Mautic\PointBundle\Entity\Trigger $entity
  * @param  bool                               $unlock
  */
 public function saveEntity($entity, $unlock = true)
 {
     $isNew = $entity->getId() ? false : true;
     parent::saveEntity($entity, $unlock);
     //should we trigger for existing leads?
     if ($entity->getTriggerExistingLeads() && $entity->isPublished()) {
         $events = $entity->getEvents();
         $repo = $this->getEventRepository();
         $persist = array();
         $ipAddress = $this->factory->getIpAddress();
         foreach ($events as $event) {
             $dateTime = $this->factory->getDate($entity->getDateAdded());
             $filter = array('force' => array(array('column' => 'l.date_added', 'expr' => 'lte', 'value' => $dateTime->toUtcString()), array('column' => 'l.points', 'expr' => 'gte', 'value' => $entity->getPoints())));
             if (!$isNew) {
                 //get a list of leads that has already had this event applied
                 $leadIds = $repo->getLeadsForEvent($event->getId());
                 if (!empty($leadIds)) {
                     $filter['force'][] = array('column' => 'l.id', 'expr' => 'notIn', 'value' => $leadIds);
                 }
             }
             //get a list of leads that are before the trigger's date_added and trigger if not already done so
             /** @var \Mautic\LeadBundle\Model\LeadModel $leadModel */
             $leadModel = $this->factory->getModel('lead');
             $leads = $leadModel->getEntities(array('filter' => $filter));
             foreach ($leads as $l) {
                 if ($this->triggerEvent($event->convertToArray(), $l, true)) {
                     $log = new LeadTriggerLog();
                     $log->setIpAddress($ipAddress);
                     $log->setEvent($event);
                     $log->setLead($l);
                     $log->setDateFired(new \DateTime());
                     $event->addLog($log);
                     $persist[] = $event;
                 }
             }
         }
         if (!empty($persist)) {
             $repo->saveEntities($persist);
         }
     }
 }
Exemple #7
0
 /**
  * {@inheritdoc}
  *
  * @param   $entity
  * @param   $unlock
  *
  * @return mixed
  */
 public function saveEntity($entity, $unlock = true)
 {
     $alias = $entity->getAlias();
     if (empty($alias)) {
         $alias = $entity->getTitle();
     }
     $alias = $this->cleanAlias($alias, '', false, '-');
     //make sure alias is not already taken
     $repo = $this->getRepository();
     $testAlias = $alias;
     $bundle = $entity->getBundle();
     $count = $repo->checkUniqueCategoryAlias($bundle, $testAlias, $entity);
     $aliasTag = $count;
     while ($count) {
         $testAlias = $alias . $aliasTag;
         $count = $repo->checkUniqueCategoryAlias($bundle, $testAlias, $entity);
         ++$aliasTag;
     }
     if ($testAlias != $alias) {
         $alias = $testAlias;
     }
     $entity->setAlias($alias);
     parent::saveEntity($entity, $unlock);
 }
Exemple #8
0
 /**
  * {@inheritdoc}
  *
  * @param Lead $entity
  * @param bool   $unlock
  */
 public function saveEntity($entity, $unlock = true)
 {
     //check to see if we can glean information from ip address
     if (!$entity->imported && count($ips = $entity->getIpAddresses())) {
         $fields = $entity->getFields();
         $details = $ips->first()->getIpDetails();
         if (!empty($details['city']) && empty($fields['core']['city']['value'])) {
             $entity->addUpdatedField('city', $details['city']);
         }
         if (!empty($details['region']) && empty($fields['core']['state']['value'])) {
             $entity->addUpdatedField('state', $details['region']);
         }
         if (!empty($details['country']) && empty($fields['core']['country']['value'])) {
             $entity->addUpdatedField('country', $details['country']);
         }
         if (!empty($details['zipcode']) && empty($fields['core']['zipcode']['value'])) {
             $entity->addUpdatedField('zipcode', $details['zipcode']);
         }
     }
     parent::saveEntity($entity, $unlock);
 }
Exemple #9
0
 /**
  * {@inheritdoc}
  *
  * @param Lead $entity
  * @param bool $unlock
  */
 public function saveEntity($entity, $unlock = true)
 {
     $companyFieldMatches = [];
     $fields = $entity->getFields();
     $updatedFields = $entity->getUpdatedFields();
     $company = null;
     if (isset($updatedFields['company'])) {
         $companyFieldMatches['company'] = $updatedFields['company'];
     }
     //check to see if we can glean information from ip address
     if (!$entity->imported && count($ips = $entity->getIpAddresses())) {
         $details = $ips->first()->getIpDetails();
         if (!empty($details['city']) && empty($fields['core']['city']['value'])) {
             $entity->addUpdatedField('city', $details['city']);
             $companyFieldMatches['city'] = $details['city'];
         }
         if (!empty($details['region']) && empty($fields['core']['state']['value'])) {
             $entity->addUpdatedField('state', $details['region']);
             $companyFieldMatches['state'] = $details['region'];
         }
         if (!empty($details['country']) && empty($fields['core']['country']['value'])) {
             $entity->addUpdatedField('country', $details['country']);
             $companyFieldMatches['country'] = $details['country'];
         }
         if (!empty($details['zipcode']) && empty($fields['core']['zipcode']['value'])) {
             $entity->addUpdatedField('zipcode', $details['zipcode']);
         }
     }
     if (!empty($companyFieldMatches)) {
         list($company, $leadAdded) = IdentifyCompanyHelper::identifyLeadsCompany($companyFieldMatches, $entity, $this->companyModel);
         if ($leadAdded) {
             $entity->addCompanyChangeLogEntry('form', 'Identify Company', 'Lead added to the company, ' . $company['companyname'], $company['id']);
         }
         unset($updatedFields['company']);
     }
     parent::saveEntity($entity, $unlock);
     if (!empty($company)) {
         // Save after the lead in for new leads created through the API and maybe other places
         $this->companyModel->addLeadToCompany($company['id'], $entity, true);
     }
 }
Exemple #10
0
 /**
  * {@inheritdoc}
  */
 public function saveEntity($entity, $unlock = true)
 {
     $isNew = $entity->getId() ? false : true;
     if ($isNew && !$entity->getAlias()) {
         $alias = $this->cleanAlias($entity->getName(), '', 10);
         $entity->setAlias($alias);
     }
     //save the form so that the ID is available for the form html
     parent::saveEntity($entity, $unlock);
     //now build the form table
     if ($entity->getId()) {
         $this->createTableSchema($entity, $isNew);
     }
     $this->generateHtml($entity);
 }
Exemple #11
0
 /**
  * {@inheritdoc}
  *
  * @param Page $entity
  * @param bool $unlock
  */
 public function saveEntity($entity, $unlock = true)
 {
     if (empty($this->inConversion)) {
         $alias = $entity->getAlias();
         if (empty($alias)) {
             $alias = $entity->getTitle();
         }
         $alias = $this->cleanAlias($alias, '', false, '-');
         //make sure alias is not already taken
         $repo = $this->getRepository();
         $testAlias = $alias;
         $count = $repo->checkUniqueAlias($testAlias, $entity);
         $aliasTag = $count;
         while ($count) {
             $testAlias = $alias . $aliasTag;
             $count = $repo->checkUniqueAlias($testAlias, $entity);
             $aliasTag++;
         }
         if ($testAlias != $alias) {
             $alias = $testAlias;
         }
         $entity->setAlias($alias);
     }
     $now = new DateTimeHelper();
     //set the author for new pages
     $isNew = $entity->isNew();
     if (!$isNew) {
         //increase the revision
         $revision = $entity->getRevision();
         $revision++;
         $entity->setRevision($revision);
     }
     // 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->setVariantHits(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);
     }
     if ($translationParent = $entity->getTranslationParent()) {
         $translationParent->addTranslationChild($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);
         }
     }
 }
Exemple #12
0
 /**
  * {@inheritdoc}
  *
  * @param Page $entity
  * @param bool $unlock
  */
 public function saveEntity($entity, $unlock = true)
 {
     if (empty($this->inConversion)) {
         $alias = $entity->getAlias();
         if (empty($alias)) {
             $alias = $entity->getTitle();
         }
         $alias = $this->cleanAlias($alias, '', false, '-');
         //make sure alias is not already taken
         $repo = $this->getRepository();
         $testAlias = $alias;
         $count = $repo->checkUniqueAlias($testAlias, $entity);
         $aliasTag = $count;
         while ($count) {
             $testAlias = $alias . $aliasTag;
             $count = $repo->checkUniqueAlias($testAlias, $entity);
             $aliasTag++;
         }
         if ($testAlias != $alias) {
             $alias = $testAlias;
         }
         $entity->setAlias($alias);
     }
     $now = new \DateTime();
     //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();
         $isVariant = $entity->getVariantStartDate();
         if ($isVariant !== null && !empty($changes) && empty($this->inConversion)) {
             $entity->setVariantHits(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->setVariantHits(0);
             $parent->setVariantStartDate($now);
             $variants[] = $parent;
         }
         if (count($children)) {
             foreach ($children as $child) {
                 $child->setVariantHits(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->setVariantHits(0);
                 $parent->setVariantStartDate($now);
                 $variants[] = $parent;
                 $children = $parent->getVariantChildren();
                 if (count($children)) {
                     foreach ($children as $child) {
                         $child->setVariantHits(0);
                         $child->setVariantStartDate($now);
                         $variants[] = $child;
                     }
                 }
             }
         }
         if (!empty($variants)) {
             $this->saveEntities($variants, false);
         }
     }
 }
Exemple #13
0
 /**
  * {@inheritdoc}
  *
  * @param object $entity
  * @param bool   $unlock
  */
 public function saveEntity($entity, $unlock = true)
 {
     parent::saveEntity($entity, $unlock);
     $this->postTranslationEntitySave($entity);
 }
Exemple #14
0
 /**
  * {@inheritdoc}
  *
  * @var \MauticPlugin\MauticSocialBundle\Entity\Monitoring
  */
 public function saveEntity($monitoringEntity, $unlock = true)
 {
     // we're editing an existing record
     if (!$monitoringEntity->isNew()) {
         //increase the revision
         $revision = $monitoringEntity->getRevision();
         ++$revision;
         $monitoringEntity->setRevision($revision);
     } else {
         $now = new \DateTime();
         $monitoringEntity->setDateAdded($now);
     }
     parent::saveEntity($monitoringEntity, $unlock);
 }
Exemple #15
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);
     }
 }
Exemple #16
0
 /**
  * {@inheritdoc}
  */
 public function saveEntity($entity, $unlock = true)
 {
     $isNew = $entity->getId() ? false : true;
     if ($isNew) {
         $alias = substr(strtolower(InputHelper::alphanum($entity->getName())), 0, 10);
         $entity->setAlias($alias);
     }
     //save the form so that the ID is available for the form html
     parent::saveEntity($entity, $unlock);
     //now build the form table
     if ($entity->getId()) {
         $this->createTableSchema($entity, $isNew);
     }
     $this->generateHtml($entity);
 }
Exemple #17
0
 /**
  * Create/edit entity
  *
  * @param object $entity
  * @param bool   $unlock
  */
 public function saveEntity($entity, $unlock = true)
 {
     // Set widget name from widget type if empty
     if (!$entity->getName()) {
         $entity->setName($this->translator->trans('mautic.widget.' . $entity->getType()));
     }
     parent::saveEntity($entity, $unlock);
 }
Exemple #18
0
 /**
  * {@inheritdoc}
  *
  * @param Page $entity
  * @param bool $unlock
  */
 public function saveEntity($entity, $unlock = true)
 {
     $pageIds = $entity->getRelatedEntityIds();
     if (empty($this->inConversion)) {
         $alias = $entity->getAlias();
         if (empty($alias)) {
             $alias = $entity->getTitle();
         }
         $alias = $this->cleanAlias($alias, '', false, '-');
         //make sure alias is not already taken
         $repo = $this->getRepository();
         $testAlias = $alias;
         $count = $repo->checkPageUniqueAlias($testAlias, $pageIds);
         $aliasTag = 1;
         while ($count) {
             $testAlias = $alias . $aliasTag;
             $count = $repo->checkPageUniqueAlias($testAlias, $pageIds);
             ++$aliasTag;
         }
         if ($testAlias != $alias) {
             $alias = $testAlias;
         }
         $entity->setAlias($alias);
     }
     // Set the author for new pages
     $isNew = $entity->isNew();
     if (!$isNew) {
         //increase the revision
         $revision = $entity->getRevision();
         ++$revision;
         $entity->setRevision($revision);
     }
     // Reset a/b test if applicable
     $variantStartDate = new \DateTime();
     $resetVariants = $this->preVariantSaveEntity($entity, ['setVariantHits'], $variantStartDate);
     parent::saveEntity($entity, $unlock);
     $this->postVariantSaveEntity($entity, $resetVariants, $pageIds, $variantStartDate);
     $this->postTranslationEntitySave($entity);
 }
Exemple #19
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);
         }
     }
 }
Exemple #20
0
 /**
  * {@inheritdoc}
  *
  * @param \Mautic\PointBundle\Entity\Trigger $entity
  * @param bool                               $unlock
  */
 public function saveEntity($entity, $unlock = true)
 {
     $isNew = $entity->getId() ? false : true;
     parent::saveEntity($entity, $unlock);
     //should we trigger for existing leads?
     if ($entity->getTriggerExistingLeads() && $entity->isPublished()) {
         $events = $entity->getEvents();
         $repo = $this->getEventRepository();
         $persist = [];
         $ipAddress = $this->ipLookupHelper->getIpAddress();
         foreach ($events as $event) {
             $filter = ['force' => [['column' => 'l.date_added', 'expr' => 'lte', 'value' => (new DateTimeHelper($entity->getDateAdded()))->toUtcString()], ['column' => 'l.points', 'expr' => 'gte', 'value' => $entity->getPoints()]]];
             if (!$isNew) {
                 //get a list of leads that has already had this event applied
                 $leadIds = $repo->getLeadsForEvent($event->getId());
                 if (!empty($leadIds)) {
                     $filter['force'][] = ['column' => 'l.id', 'expr' => 'notIn', 'value' => $leadIds];
                 }
             }
             //get a list of leads that are before the trigger's date_added and trigger if not already done so
             $leads = $this->leadModel->getEntities(['filter' => $filter]);
             foreach ($leads as $l) {
                 if ($this->triggerEvent($event->convertToArray(), $l, true)) {
                     $log = new LeadTriggerLog();
                     $log->setIpAddress($ipAddress);
                     $log->setEvent($event);
                     $log->setLead($l);
                     $log->setDateFired(new \DateTime());
                     $event->addLog($log);
                     $persist[] = $event;
                 }
             }
         }
         if (!empty($persist)) {
             $repo->saveEntities($persist);
         }
     }
 }
Exemple #21
0
 /**
  * {@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);
         }
     }
 }
Exemple #22
0
 /**
  * {@inheritdoc}
  *
  * @param Focus      $entity
  * @param bool|false $unlock
  */
 public function saveEntity($entity, $unlock = true)
 {
     parent::saveEntity($entity, $unlock);
     // Generate cache after save to have ID available
     $content = $this->generateJavascript($entity);
     $entity->setCache($content);
     $this->getRepository()->saveEntity($entity);
 }