listByFilter() публичный статический Метод

Gets a list of servers by filter
public static listByFilter ( array $filter = null ) : array
$filter array optional Filter value ['envId' => 'value']
Результат array Returns array of DBServer objects
Пример #1
0
 /**
  * {@inheritdoc}
  * @see Scalr_Model::delete()
  */
 public function delete($id = null)
 {
     $servers = \DBServer::listByFilter(['clientId' => $this->id]);
     foreach ($servers as $server) {
         /* @var $server \DBServer */
         $server->Remove();
     }
     try {
         $this->db->StartTrans();
         //TODO: Use models
         $this->db->Execute("\n                DELETE account_team_users FROM account_team_users, account_teams\n                WHERE account_teams.account_id = ?\n                AND account_team_users.team_id = account_teams.id\n            ", array($this->id));
         $this->db->Execute("DELETE FROM account_users WHERE account_id=?", array($this->id));
         $this->db->Execute("DELETE FROM account_teams WHERE account_id=?", array($this->id));
         $this->db->Execute("DELETE FROM account_limits WHERE account_id=?", array($this->id));
         /* @var $environment Environment */
         foreach (Environment::findByAccountId($this->id) as $environment) {
             $environment->delete(true);
         }
         CloudCredentials::deleteByAccountId($this->id);
         $this->db->Execute("\n                DELETE account_team_user_acls FROM account_team_user_acls, acl_account_roles\n                WHERE acl_account_roles.account_id = ?\n                AND account_team_user_acls.account_role_id = acl_account_roles.account_role_id\n            ", array($this->id));
         $this->db->Execute("DELETE FROM acl_account_roles WHERE account_id=?", array($this->id));
         $this->db->Execute("DELETE FROM ec2_ebs WHERE client_id=?", array($this->id));
         $this->db->Execute("DELETE FROM apache_vhosts WHERE client_id=?", array($this->id));
         $this->db->Execute("DELETE FROM scheduler WHERE account_id=?", array($this->id));
         foreach ($this->db->Execute("SELECT id FROM farms WHERE clientid=?", [$this->id]) as $farm) {
             $this->db->Execute("DELETE FROM farms WHERE id=?", array($farm["id"]));
             $this->db->Execute("DELETE FROM farm_roles WHERE farmid=?", array($farm["id"]));
             $this->db->Execute("DELETE FROM elastic_ips WHERE farmid=?", array($farm["id"]));
         }
         $roles = $this->db->GetAll("SELECT id FROM roles WHERE client_id = '{$this->id}'");
         foreach ($roles as $role) {
             $this->db->Execute("DELETE FROM roles WHERE id = ?", array($role['id']));
             $this->db->Execute("DELETE FROM role_behaviors WHERE role_id = ?", array($role['id']));
             $this->db->Execute("DELETE FROM role_images WHERE role_id = ?", array($role['id']));
             $this->db->Execute("DELETE FROM role_properties WHERE role_id = ?", array($role['id']));
             $this->db->Execute("DELETE FROM role_security_rules WHERE role_id = ?", array($role['id']));
         }
         //Removing cost centres and projects which are set up from this account
         $this->db->Execute("\n                DELETE project_properties FROM project_properties, projects\n                WHERE projects.project_id = project_properties.project_id\n                AND projects.account_id = ?\n            ", [$this->id]);
         $this->db->Execute("DELETE FROM projects WHERE account_id = ?", [$this->id]);
         $this->db->Execute("\n                DELETE cc_properties FROM cc_properties, ccs\n                WHERE ccs.cc_id = cc_properties.cc_id\n                AND ccs.account_id = ?\n            ", [$this->id]);
         $this->db->Execute("DELETE FROM ccs WHERE account_id = ?", [$this->id]);
         parent::delete();
         ReportEntity::deleteByAccountId($this->id);
         NotificationEntity::deleteByAccountId($this->id);
         $this->db->CompleteTrans();
     } catch (\Exception $e) {
         $this->db->RollbackTrans();
         throw $e;
     }
 }
Пример #2
0
 /**
  * {@inheritdoc}
  * @see Scalr_Model::delete()
  */
 public function delete($id = null)
 {
     if ($this->db->GetOne("SELECT COUNT(*) FROM farms WHERE env_id = ?", array($this->id))) {
         throw new Exception("Cannot remove environment. You need to remove all your farms first.");
     }
     if ($this->db->GetOne("SELECT COUNT(*) FROM client_environments WHERE client_id = ?", array($this->clientId)) < 2) {
         throw new Exception('At least one environment should be in account. You cannot remove the last one.');
     }
     parent::delete();
     try {
         $this->db->Execute("DELETE FROM client_environment_properties WHERE env_id=?", array($this->id));
         $this->db->Execute("DELETE FROM apache_vhosts WHERE env_id=?", array($this->id));
         $this->db->Execute("DELETE FROM autosnap_settings WHERE env_id=?", array($this->id));
         $this->db->Execute("DELETE FROM bundle_tasks WHERE env_id=?", array($this->id));
         $this->db->Execute("DELETE FROM dm_applications WHERE env_id=?", array($this->id));
         $this->db->Execute("DELETE FROM dm_deployment_tasks WHERE env_id=?", array($this->id));
         $this->db->Execute("DELETE FROM dm_sources WHERE env_id=?", array($this->id));
         $this->db->Execute("DELETE FROM dns_zones WHERE env_id=?", array($this->id));
         $this->db->Execute("DELETE FROM ec2_ebs WHERE env_id=?", array($this->id));
         $this->db->Execute("DELETE FROM elastic_ips WHERE env_id=?", array($this->id));
         $this->db->Execute("DELETE FROM farms WHERE env_id=?", array($this->id));
         $this->db->Execute("DELETE FROM roles WHERE env_id=?", array($this->id));
         $servers = \DBServer::listByFilter(['envId' => $this->id]);
         foreach ($servers as $server) {
             /* @var $server \DBServer */
             $server->Remove();
         }
         $this->db->Execute("DELETE FROM `account_team_envs` WHERE env_id = ?", array($this->id));
     } catch (Exception $e) {
         throw new Exception(sprintf(_("Cannot delete record. Error: %s"), $e->getMessage()), $e->getCode());
     }
 }
Пример #3
0
 /**
  * {@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());
     }
 }