Beispiel #1
0
 /**
  * {@inheritdoc}
  * @see \Scalr\Model\AbstractEntity::save()
  */
 public function save()
 {
     //Checks data integrity.
     $criteria = [['name' => $this->name]];
     if ($this->ccId) {
         $criteria[] = ['ccId' => ['$ne' => $this->ccId]];
     }
     //The name of the cost centre should be unique withing the global
     $item = CostCentreEntity::findOne($criteria);
     if ($item) {
         throw new AnalyticsException(sprintf('A Cost Center with this name already exists. Please choose another name.'));
     }
     parent::save();
     if ($this->ccId && \Scalr::getContainer()->analytics->enabled) {
         \Scalr::getContainer()->analytics->tags->syncValue($this->accountId ?: 0, \Scalr\Stats\CostAnalytics\Entity\TagEntity::TAG_ID_COST_CENTRE, $this->ccId, $this->name);
     }
 }