save() публичный Метод

Saves current entity to database
public save ( )
Пример #1
0
 /**
  * {@inheritdoc}
  * @see AbstractEntity::save()
  */
 public function save()
 {
     parent::save();
     if (!empty($this->_settings)) {
         $this->_settings->save();
     }
 }
Пример #2
0
 /**
  * {@inheritdoc}
  * @see \Scalr\Model\AbstractEntity::save()
  */
 public function save()
 {
     if (empty($this->emails)) {
         throw new AnalyticsException(sprintf("Email must be set for the %s.", get_class($this)));
     }
     parent::save();
 }
Пример #3
0
 /**
  * {@inheritdoc}
  * @see \Scalr\Model\AbstractEntity::save()
  */
 public function save()
 {
     if ($this->{static::ENTITY_VALUE_FIELD_NAME} === null) {
         $this->delete();
     } else {
         parent::save();
     }
 }
 /**
  * {@inheritdoc}
  * @see \Scalr\Model\AbstractEntity::save()
  */
 public function save()
 {
     if (empty($this->eventId)) {
         throw new ModelException(sprintf("eventId must be set for %s before saving.", get_class($this)));
     } else {
         if (empty($this->ccId)) {
             throw new ModelException(sprintf("ccId must be set for %s before saving.", get_class($this)));
         }
     }
     parent::save();
 }
Пример #5
0
 /**
  * {@inheritdoc}
  * @see AbstractEntity::save()
  */
 public function save()
 {
     parent::save();
     foreach ($this->_properties as $property) {
         if ($property->value == false) {
             $property->delete();
         } else {
             $property->save();
         }
     }
 }
Пример #6
0
 public function save()
 {
     $this->variables = [];
     $matches = [];
     $text = preg_replace('/(\\\\%)/si', '$$scalr$$', $this->content);
     preg_match_all("/\\%([^\\%\\s]+)\\%/si", $text, $matches);
     $builtin = array_keys(\Scalr_Scripting_Manager::getScriptingBuiltinVariables());
     foreach ($matches[1] as $var) {
         if (!in_array($var, $builtin)) {
             $this->variables[$var] = ucwords(str_replace("_", " ", $var));
         }
     }
     parent::save();
 }
Пример #7
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);
     }
 }
Пример #8
0
 /**
  * {@inheritdoc}
  * @see AbstractEntity::save()
  */
 public function save()
 {
     $this->setupScalingTimes();
     parent::save();
 }
Пример #9
0
 /**
  * {@inheritdoc}
  * @see AbstractEntity::save()
  */
 public function save()
 {
     $this->changed = microtime();
     if (empty($this->id)) {
         $this->createdById = $this->changedById;
         $this->added = new DateTime();
         $this->status = FARM_STATUS::TERMINATED;
         if (empty($this->settings[FarmSetting::TIMEZONE])) {
             $this->settings[FarmSetting::TIMEZONE] = date_default_timezone_get();
         }
         $this->settings[FarmSetting::CRYPTO_KEY] = \Scalr::GenerateRandomKey(40);
         /* @var $governance Governance */
         $governance = Governance::findPk($this->envId, Governance::CATEGORY_GENERAL, Governance::GENERAL_LEASE);
         if (!empty($governance) && $governance->enabled) {
             $this->settings[FarmSetting::LEASE_STATUS] = 'Active';
         }
         //TODO: unused field
         $this->region = Aws::REGION_US_EAST_1;
     }
     parent::save();
     if (!empty($this->_settings)) {
         $this->_settings->save();
     }
 }
Пример #10
0
 public function save()
 {
     $this->db()->BeginTrans();
     try {
         parent::save();
         $this->db()->Execute("DELETE FROM `role_behaviors` WHERE `role_id` = ?", [$this->id]);
         $sql = $args = [];
         foreach ($this->getBehaviors() as $behavior) {
             $sql[] = '(?, ?)';
             $args = array_merge($args, [$this->id, $behavior]);
         }
         if (count($sql)) {
             $this->db()->Execute("INSERT INTO `role_behaviors` (`role_id`, `behavior`) VALUES " . join(', ', $sql), $args);
         }
         $this->db()->CommitTrans();
     } catch (\Exception $e) {
         $this->db()->RollbackTrans();
         throw $e;
     }
 }
Пример #11
0
 /**
  * {@inheritdoc}
  * @see AbstractEntity::save()
  */
 public function save()
 {
     $this->setupRole();
     $this->setupAlias();
     $this->setupScaling();
     $this->setupBehaviors();
     $this->setupPolling();
     parent::save();
     $this->setupAnalytics();
     if (!empty($this->_settings)) {
         $this->_settings->save();
     }
 }
Пример #12
0
 /**
  * {@inheritdoc}
  * @see AbstractEntity::save()
  */
 public function save()
 {
     $this->changed = microtime();
     $db = $this->db();
     try {
         $db->BeginTrans();
         if (empty($this->id)) {
             $this->ownerId = $this->changedById;
             $this->settings[FarmSetting::CREATED_BY_ID] = $this->ownerId;
             $this->settings[FarmSetting::CREATED_BY_EMAIL] = User::findPk($this->ownerId)->email;
             $this->added = new DateTime();
             $this->status = FARM_STATUS::TERMINATED;
             if (empty($this->settings[FarmSetting::TIMEZONE])) {
                 $this->settings[FarmSetting::TIMEZONE] = date_default_timezone_get();
             }
             $this->settings[FarmSetting::CRYPTO_KEY] = \Scalr::GenerateRandomKey(40);
             /* @var $governance Governance */
             $governance = Governance::findPk($this->envId, Governance::CATEGORY_GENERAL, Governance::GENERAL_LEASE);
             if (!empty($governance) && $governance->enabled) {
                 $this->settings[FarmSetting::LEASE_STATUS] = 'Active';
             }
             //TODO: unused field
             $this->region = Aws::REGION_US_EAST_1;
         }
         parent::save();
         if (!empty($this->_settings)) {
             $this->_settings->save();
         }
         if (isset($this->_teamsChanged)) {
             $this->saveTeams($this->_teams);
             $this->_teamsChanged = false;
         }
         $db->CommitTrans();
     } catch (Exception $e) {
         $db->RollbackTrans();
         throw $e;
     }
 }
Пример #13
0
 /**
  * {@inheritdoc}
  * @see AbstractEntity::save()
  */
 public function save()
 {
     parent::save();
     if (!empty($this->_properties)) {
         $this->_properties->save();
     }
 }
Пример #14
0
 public function save()
 {
     if ($this->platform == \SERVER_PLATFORMS::GCE || $this->platform == \SERVER_PLATFORMS::AZURE) {
         $this->cloudLocation = '';
     }
     // image on GCE or Azure doesn't require cloudLocation
     $hash = self::calculateHash($this->envId, $this->id, $this->platform, $this->cloudLocation);
     if (!$this->hash) {
         $this->hash = $hash;
     } else {
         if ($this->hash != $hash) {
             throw new Exception('Hash are mismatched in entity Image');
         }
     }
     parent::save();
 }
Пример #15
0
 /**
  * Creates and save entity to DB^ keep entity to delete after test
  *
  * @param AbstractEntity $entity
  * @param array          $data
  *
  * @return AbstractEntity
  */
 public function createEntity(AbstractEntity $entity, array $data)
 {
     foreach ($entity->getIterator() as $property => $_) {
         if (isset($data[$property])) {
             $entity->{$property} = $data[$property];
         }
     }
     $entity->save();
     $key = [];
     foreach ($entity->getIterator()->getPrimaryKey() as $position => $property) {
         $key[$position] = $entity->{$property};
     }
     static::$testData[get_class($entity)][] = $key;
     return $entity;
 }
Пример #16
0
 /**
  * {@inheritdoc}
  * @see AbstractEntity::save()
  */
 public function save()
 {
     try {
         $this->db()->BeginTrans();
         parent::save();
         if (!empty($this->_properties)) {
             $this->_properties->save();
         }
         $this->db()->CommitTrans();
     } catch (Exception $e) {
         $this->db()->RollbackTrans();
         throw $e;
     }
 }
Пример #17
0
 /**
  * Saves changes, if script already exists, or saves new script
  *
  * @throws ModelException
  */
 public function save()
 {
     $id = $this->id;
     $this->dtChanged = new \DateTime();
     parent::save();
     if (!$id) {
         // we should create first version
         $version = new ScriptVersion();
         $version->scriptId = $this->id;
         $version->version = 1;
         $version->content = '';
         $version->changedById = $this->createdById;
         $version->changedByEmail = $this->createdByEmail;
         $version->save();
     }
 }
Пример #18
0
 public function save()
 {
     $this->variables = [];
     $variables = Script::fetchVariables($this->content);
     if (!empty($variables)) {
         $builtin = array_keys(\Scalr_Scripting_Manager::getScriptingBuiltinVariables());
         foreach ($variables as $var) {
             if (!in_array($var, $builtin)) {
                 $this->variables[$var] = ucwords(str_replace("_", " ", $var));
             }
         }
     }
     parent::save();
 }
Пример #19
0
 public function save()
 {
     if ($this->platform == \SERVER_PLATFORMS::GCE || $this->platform == \SERVER_PLATFORMS::AZURE) {
         $this->cloudLocation = '';
     }
     // image on GCE or Azure doesn't require cloudLocation
     parent::save();
 }
Пример #20
0
 /**
  * Creates and save entity to DB, keeps entity to delete after test
  *
  * @param AbstractEntity $entity
  * @param array          $data
  * @param int            $priority
  *
  * @return AbstractEntity
  * @throws \Scalr\Exception\ModelException
  */
 public static function createEntity(AbstractEntity $entity, array $data, $priority = 0)
 {
     foreach ($entity->getIterator() as $property => $_) {
         if (isset($data[$property])) {
             $entity->{$property} = $data[$property];
         }
     }
     $entity->save();
     $key = [];
     foreach ($entity->getIterator()->getPrimaryKey() as $position => $property) {
         $key[$position] = $entity->{$property};
     }
     static::toDelete(get_class($entity), $key, $priority);
     return $entity;
 }