Beispiel #1
0
 /**
  * Parses common criteria
  *
  * @param     array    $criteria array of the query search criteria
  * @param     string   $join     joins
  * @param     string   $where    where part of the statement
  */
 private function parseFindCriteria($criteria, &$join, &$where)
 {
     if (isset($criteria['accountId'])) {
         $join .= " JOIN account_ccs ac ON ac.cc_id = c.cc_id ";
         $where .= "\n                AND ac.account_id = " . $this->db->escape($criteria['accountId']) . "\n                AND EXISTS (\n                    SELECT 1 FROM projects p WHERE p.cc_id = c.cc_id\n                    AND p.shared = " . ProjectEntity::SHARED_WITHIN_ACCOUNT . "\n                    AND p.account_id = " . $this->db->escape($criteria['accountId']) . "\n               )\n           ";
     }
 }
Beispiel #2
0
 /**
  * Checks if user has permissions to project in environment or account scope
  *
  * @param string $projectId     Identifier of the project
  * @param array $criteria       ['envId' => '', 'clientid' => '']
  * @return bool|mixed
  */
 public function checkPermission($projectId, array $criteria)
 {
     $and = '';
     foreach ($criteria as $name => $value) {
         $field = 'f.' . \Scalr::decamelize($name);
         $and .= " AND " . $field . "=" . $this->db->escape($value);
     }
     $projectEntity = new ProjectEntity();
     $projectId = $projectEntity->type('projectId')->toDb($projectId);
     $where = " WHERE p.project_id = UNHEX('" . $projectId . "') AND EXISTS (\n                SELECT * FROM farms f\n                LEFT JOIN farm_settings fs ON f.id = fs.farmid\n                WHERE fs.name = '" . Entity\FarmSetting::PROJECT_ID . "'\n                AND REPLACE(fs.value, '-', '') = HEX(p.project_id)\n                {$and})";
     $sql = "SELECT " . $projectEntity->fields('p') . "\n                FROM " . $projectEntity->table('p') . $where;
     return $this->db->GetOne($sql);
 }
Beispiel #3
0
 /**
  * Finds farms by key
  * It searches by name
  *
  * @param   int       $envId     Current enviroment id
  * @param   string    $key       optional Search key
  * @return  ArrayCollection Returns collection of the farm objects
  */
 public function findFarmsByKey($envId, $key = null)
 {
     $statement = "\n            SELECT *\n            FROM farms f\n            WHERE f.env_id = " . intval($envId) . "\n        ";
     if (!is_null($key) && $key !== '') {
         $statement .= "\n                AND f.name LIKE '%" . $this->db->escape($key) . "%'\n            ";
     }
     $collection = new ArrayCollection();
     $rs = $this->db->Execute($statement);
     while ($rec = $rs->FetchRow()) {
         $item = DBFarm::loadFields($rec);
         $collection->append($item);
     }
     return $collection;
 }
Beispiel #4
0
 /**
  * {@inheritdoc}
  * @see Scalr\Upgrade.UpdateInterface::hasTable()
  */
 public function hasTable($table, $database = null)
 {
     $ret = $this->db->getOne("SHOW TABLES " . ($database ? "FROM `" . $this->db->escape($database) . "` " : "") . "LIKE ?", array($table));
     return $ret ? true : false;
 }