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