delete() 공개 메소드

Removes current record from database by primary key
public delete ( )
예제 #1
0
파일: Script.php 프로젝트: mheydt/scalr
 /**
  * Deletes this script
  *
  * @throws Scalr_Exception_Core
  * @throws Exception
  * @throws ModelException
  */
 public function delete()
 {
     // Check script usage
     $usage = [];
     $farmRolesCount = $this->db()->GetOne("SELECT COUNT(DISTINCT farm_roleid) FROM farm_role_scripts WHERE scriptid=?", array($this->id));
     if ($farmRolesCount > 0) {
         $message = [];
         foreach ($this->db()->GetCol("SELECT DISTINCT farm_roleid FROM farm_role_scripts WHERE scriptid = ? LIMIT 3", array($this->id)) as $id) {
             $dbFarmRole = \DBFarmRole::LoadByID($id);
             $message[] = $dbFarmRole->GetFarmObject()->Name . ' (' . $dbFarmRole->Alias . ')';
         }
         $usage[] = sprintf("%d farm roles: %s%s", $farmRolesCount, join(', ', $message), $farmRolesCount > 3 ? ' and others' : '');
     }
     $rolesCount = $this->db()->GetOne("SELECT COUNT(DISTINCT role_id) FROM role_scripts WHERE script_id=?", array($this->id));
     if ($rolesCount > 0) {
         $message = [];
         foreach ($this->db()->GetCol("SELECT DISTINCT role_id FROM role_scripts WHERE script_id = ? LIMIT 3", array($this->id)) as $id) {
             $dbRole = \DBRole::LoadByID($id);
             $message[] = $dbRole->name;
         }
         $usage[] = sprintf("%d roles: %s%s", $rolesCount, join(', ', $message), $rolesCount > 3 ? ' and others' : '');
     }
     $accountCount = $this->db()->GetOne("SELECT COUNT(*) FROM account_scripts WHERE script_id=?", array($this->id));
     if ($accountCount > 0) {
         $usage[] = sprintf("%d orchestration rule(s) on account level", $accountCount);
     }
     $taskCount = $this->db()->GetOne("SELECT COUNT(*) FROM scheduler WHERE script_id = ?", array($this->id));
     if ($taskCount > 0) {
         $usage[] = sprintf("%d scheduler task(s)", $taskCount);
     }
     if (count($usage)) {
         throw new Scalr_Exception_Core(sprintf('Script "%s" being used by %s, and can\'t be deleted', $this->name, join(', ', $usage)));
     }
     Tag::deleteTags(Tag::RESOURCE_SCRIPT, $this->id);
     parent::delete();
 }
예제 #2
0
파일: Client.php 프로젝트: scalr/scalr
 public function delete()
 {
     parent::delete();
     ReportEntity::deleteByAccountId($this->id);
     NotificationEntity::deleteByAccountId($this->id);
 }
예제 #3
0
 /**
  * {@inheritdoc}
  * @see \Scalr\Model\AbstractEntity::delete()
  */
 public function delete()
 {
     if (!$this->checkRemoval()) {
         //Archive it
         $this->archived = true;
         $this->save();
     } else {
         //Completely remove it
         parent::delete();
     }
 }
예제 #4
0
파일: Server.php 프로젝트: mheydt/scalr
 /**
  * {@inheritdoc}
  * @see AbstractEntity::delete()
  */
 public function delete()
 {
     $db = $this->db();
     try {
         $db->BeginTrans();
         // We need to perpetuate server_properties records for removed servers
         $db->Execute("DELETE FROM messages WHERE server_id=?", [$this->serverId]);
         $db->Execute("\n                UPDATE `dm_deployment_tasks` SET status=? WHERE server_id=?\n            ", [\Scalr_Dm_DeploymentTask::STATUS_ARCHIVED, $this->serverId]);
         $db->Execute("DELETE FROM `server_properties` WHERE `server_id` = ? AND `name` NOT IN (" . implode(", ", array_map([$db, "qstr"], self::getImportantPropertyList())) . ")", [$this->serverId]);
         $db->CommitTrans();
     } catch (Exception $e) {
         $db->RollbackTrans();
         throw $e;
     }
     parent::delete();
 }
예제 #5
0
 /**
  * {@inheritdoc}
  *
  * @see Scalr\Model\AbstractEntity::delete()
  *
  */
 public function delete()
 {
     $cnt = $this->db()->GetOne("SELECT COUNT(*) FROM apache_vhosts WHERE ssl_cert_id = ?", [$this->id]);
     if ($cnt > 0) {
         throw new ModelException(sprintf('Certificate "%s" is used by %s apache virtual host(s)', $this->name, $cnt));
     }
     parent::delete();
 }
예제 #6
0
 /**
  * {@inheritdoc}
  * @see AbstractEntity::delete()
  */
 public function delete()
 {
     parent::delete();
     if (ScalingMetric::METRIC_DATE_AND_TIME_ID === $this->metricId) {
         FarmRoleScalingTime::deleteByFarmRoleId($this->farmRoleId);
     }
 }
예제 #7
0
 /**
  * {@inheritdoc}
  * @see \Scalr\Model\AbstractEntity::delete()
  */
 public function delete()
 {
     if ($this->checkRemoval()) {
         //Completely remove it
         parent::delete();
         ReportEntity::deleteBy([['subjectId' => $this->projectId], ['subjectType' => ReportEntity::SUBJECT_TYPE_PROJECT]]);
         NotificationEntity::deleteBy([['subjectId' => $this->projectId], ['subjectType' => NotificationEntity::SUBJECT_TYPE_PROJECT]]);
     } else {
         //Archive it
         $this->archived = true;
         $this->save();
     }
 }
예제 #8
0
 /**
  * {@inheritdoc}
  * @see AbstractEntity::delete()
  */
 public function delete()
 {
     EnvironmentCloudCredentials::deleteByCloudCredentialsId($this->id);
     parent::delete();
 }
예제 #9
0
파일: Farm.php 프로젝트: mheydt/scalr
 /**
  * {@inheritdoc}
  * @see AbstractEntity::delete()
  */
 public function delete()
 {
     if ($this->status != FARM_STATUS::TERMINATED) {
         throw new FarmInUseException("Cannot delete a running farm, please terminate a farm before deleting it");
     }
     $servers = Server::find([['farmId' => $this->id], ['status' => ['$ne' => Server::STATUS_TERMINATED]]]);
     if (count($servers)) {
         throw new FarmInUseException(sprintf("Cannot delete a running farm, %s server%s still running on this farm", count($servers), count($servers) > 1 ? 's are' : ' is'));
     }
     $db = $this->db();
     try {
         $db->BeginTrans();
         foreach ($this->farmRoles as $farmRole) {
             $farmRole->delete();
         }
         $this->deleteScheduled();
         $db->Execute("DELETE FROM `logentries` WHERE `farmid` = ?", [$this->id]);
         $db->Execute("DELETE FROM `elastic_ips` WHERE `farmid` = ?", [$this->id]);
         $db->Execute("DELETE FROM `events` WHERE `farmid` = ?", [$this->id]);
         $db->Execute("DELETE FROM `ec2_ebs` WHERE `farm_id` = ?", [$this->id]);
         $db->Execute("DELETE FROM `farm_lease_requests` WHERE `farm_id` = ?", [$this->id]);
         foreach ($this->servers as $server) {
             $server->delete();
         }
         $db->Execute("UPDATE `dns_zones` SET `farm_id` = '0', `farm_roleid` ='0' WHERE `farm_id` = ?", [$this->id]);
         $db->Execute("UPDATE `apache_vhosts` SET `farm_id` = '0', `farm_roleid` ='0' WHERE `farm_id` = ?", [$this->id]);
         parent::delete();
         $db->CommitTrans();
     } catch (Exception $e) {
         $db->RollbackTrans();
         throw $e;
     }
     $db->Execute("DELETE FROM `scripting_log` WHERE `farmid` = ?", [$this->id]);
 }
예제 #10
0
파일: FarmRole.php 프로젝트: mheydt/scalr
 /**
  * {@inheritdoc}
  * @see AbstractEntity::delete()
  */
 public function delete()
 {
     $db = $this->db();
     try {
         $this->terminateServers();
         $db->BeginTrans();
         // Clear farm role options & scripts
         $db->Execute("DELETE FROM farm_role_service_config_presets WHERE farm_roleid=?", [$this->id]);
         $db->Execute("DELETE FROM farm_role_scaling_times WHERE farm_roleid=?", [$this->id]);
         $db->Execute("DELETE FROM farm_role_service_config_presets WHERE farm_roleid=?", [$this->id]);
         $db->Execute("DELETE FROM farm_role_scripting_targets WHERE `target`=? AND `target_type` = 'farmrole'", [$this->id]);
         $db->Execute("DELETE FROM ec2_ebs WHERE farm_roleid=?", [$this->id]);
         $db->Execute("DELETE FROM elastic_ips WHERE farm_roleid=?", [$this->id]);
         $db->Execute("DELETE FROM storage_volumes WHERE farm_roleid=?", [$this->id]);
         // Clear apache vhosts and update DNS zones
         $db->Execute("UPDATE apache_vhosts SET farm_roleid='0', farm_id='0' WHERE farm_roleid=?", [$this->id]);
         $db->Execute("UPDATE dns_zones SET farm_roleid='0' WHERE farm_roleid=?", [$this->id]);
         $this->deleteScheduled();
         $db->Execute("DELETE FROM farm_role_scripts WHERE farm_roleid=?", [$this->id]);
         parent::delete();
         $db->CommitTrans();
     } catch (Exception $e) {
         $db->RollbackTrans();
         throw $e;
     }
 }
예제 #11
0
파일: FarmRole.php 프로젝트: scalr/scalr
 /**
  * {@inheritdoc}
  * @see AbstractEntity::delete()
  */
 public function delete()
 {
     $db = $this->db();
     try {
         // we should set scaling to manual to prevent starting new instances while we are deleting FarmRole
         $frs = new FarmRoleSetting();
         $db->Execute("\n                 UPDATE {$frs->table()}\n                 SET {$frs->columnValue} = ?\n                 WHERE {$frs->columnFarmRoleId} = ?\n                 AND {$frs->columnName} = ?\n            ", [0, $this->id, FarmRoleSetting::SCALING_ENABLED]);
         $this->terminateServers();
         $db->BeginTrans();
         // Clear farm role options & scripts
         $db->Execute("DELETE FROM farm_role_service_config_presets WHERE farm_roleid=?", [$this->id]);
         $db->Execute("DELETE FROM farm_role_scaling_times WHERE farm_roleid=?", [$this->id]);
         $db->Execute("DELETE FROM farm_role_service_config_presets WHERE farm_roleid=?", [$this->id]);
         $db->Execute("DELETE FROM farm_role_scripting_targets WHERE `target`=? AND `target_type` = 'farmrole'", [$this->id]);
         $db->Execute("DELETE FROM ec2_ebs WHERE farm_roleid=?", [$this->id]);
         $db->Execute("DELETE FROM elastic_ips WHERE farm_roleid=?", [$this->id]);
         $db->Execute("DELETE FROM storage_volumes WHERE farm_roleid=?", [$this->id]);
         // Clear apache vhosts and update DNS zones
         $db->Execute("UPDATE apache_vhosts SET farm_roleid='0', farm_id='0' WHERE farm_roleid=?", [$this->id]);
         $db->Execute("UPDATE dns_zones SET farm_roleid='0' WHERE farm_roleid=?", [$this->id]);
         $this->deleteScheduled();
         $db->Execute("DELETE FROM farm_role_scripts WHERE farm_roleid=?", [$this->id]);
         parent::delete();
         $db->CommitTrans();
     } catch (Exception $e) {
         $db->RollbackTrans();
         throw $e;
     }
 }
예제 #12
0
파일: Server.php 프로젝트: scalr/scalr
 /**
  * {@inheritdoc}
  * @see AbstractEntity::delete()
  */
 public function delete()
 {
     $db = $this->db();
     try {
         $db->BeginTrans();
         // We need to perpetuate server_properties records for removed servers
         $db->Execute("DELETE FROM messages WHERE server_id=?", [$this->serverId]);
         $db->Execute("DELETE FROM `server_properties` WHERE `server_id` = ? AND `name` NOT IN (" . implode(", ", array_map([$db, "qstr"], self::getImportantPropertyList())) . ")", [$this->serverId]);
         $db->CommitTrans();
     } catch (Exception $e) {
         $db->RollbackTrans();
         throw $e;
     }
     parent::delete();
 }
예제 #13
0
파일: Team.php 프로젝트: scalr/scalr
 /**
  * {@inheritdoc}
  * @see AbstractEntity::delete()
  */
 public function delete()
 {
     parent::delete();
     TeamEnvs::deleteByTeamId($this->id);
     TeamUser::deleteByTeamId($this->id);
 }
예제 #14
0
파일: Environment.php 프로젝트: scalr/scalr
 /**
  * {@inheritdoc}
  * @see AbstractEntity::delete()
  *
  * @param   bool    $force Delete ignoring restrictions
  */
 public function delete($force = false)
 {
     $db = $this->db();
     if (!$force) {
         if ($db->GetOne("SELECT 1 FROM `farms` WHERE `env_id` = ? LIMIT 1", [$this->id])) {
             throw new ObjectInUseException('Cannot remove environment. You need to remove all your farms first.');
         }
         if ($db->GetOne("SELECT COUNT(*) FROM client_environments WHERE client_id = ?", [$this->accountId]) < 2) {
             throw new ObjectInUseException('At least one environment should be in account. You cannot remove the last one.');
         }
     }
     parent::delete();
     try {
         $db->Execute("DELETE FROM client_environment_properties WHERE env_id=?", [$this->id]);
         $db->Execute("DELETE FROM apache_vhosts WHERE env_id=?", [$this->id]);
         $db->Execute("DELETE FROM autosnap_settings WHERE env_id=?", [$this->id]);
         $db->Execute("DELETE FROM bundle_tasks WHERE env_id=?", [$this->id]);
         $db->Execute("DELETE FROM dns_zones WHERE env_id=?", [$this->id]);
         $db->Execute("DELETE FROM ec2_ebs WHERE env_id=?", [$this->id]);
         $db->Execute("DELETE FROM elastic_ips WHERE env_id=?", [$this->id]);
         $db->Execute("DELETE FROM farms WHERE env_id=?", [$this->id]);
         $db->Execute("DELETE FROM roles WHERE env_id=?", [$this->id]);
         $servers = \DBServer::listByFilter(['envId' => $this->id]);
         foreach ($servers as $server) {
             /* @var $server \DBServer */
             $server->Remove();
         }
         Entity\EnvironmentCloudCredentials::deleteByEnvId($this->id);
         Entity\CloudCredentials::deleteByEnvId($this->id);
         TeamEnvs::deleteByEnvId($this->id);
     } catch (Exception $e) {
         throw new Exception(sprintf(_("Cannot delete record. Error: %s"), $e->getMessage()), $e->getCode());
     }
 }