Esempio n. 1
0
 /**
  * @param ContentEntity $content
  * @return ContentEntity|void
  */
 public function save(ContentEntity $content = null)
 {
     if (null === $content) {
         return;
     }
     $currentUser = $this->getUser();
     $newRecord = false;
     if ($content->getId() == null) {
         $content->setCreatedDate(new \DateTime());
         if ($content->getAuthor() == null) {
             $content->setAuthor($currentUser);
         }
         $newRecord = true;
     } else {
         $content->setLastModifiedAuthor($currentUser);
         $content->setModifiedDate(new \DateTime());
     }
     if ($content->getPublishDate() == null && $content->getStatus() == ContentPublishType::Published) {
         $content->setPublishDate(new \DateTime());
     }
     if ($content->getExpireDate() == null && $content->getStatus() == ContentPublishType::Expired) {
         $content->setExpireDate(new \DateTime());
     }
     $this->em()->persist($content);
     $this->em()->flush();
     if ($newRecord) {
         $this->admin()->addAudit(AuditLevelType::Normal, 'Content::' . $content->getType() . '::' . $content->getSchema(), AuditActionType::Add, $content->getId(), 'Added: ' . $content->getTitle());
     } else {
         $this->admin()->addAudit(AuditLevelType::Normal, 'Content::' . $content->getType() . '::' . $content->getSchema(), AuditActionType::Edit, $content->getId(), 'Edit: ' . $content->getTitle());
     }
     return $content;
 }