/** * Get a table to match the one with the given name in the database * @param string $name * @param Database $database */ public function __construct($name, Database $database) { $this->name = $name; $this->database = $database; $this->driver = $database->getDriver(); parent::__construct($this); }
/** * Set up the database tables, views, etc. * */ protected function finalDatabaseSetup() { $this->db = $this->finalDatabasePrimary(); // Let's iterate through the SQL files and run them all $driver = $this->db->getDriver(); $files = \Airship\list_all_files(ROOT . '/Installer/sql/' . $driver, 'sql'); \sort($files); foreach ($files as $file) { $query = \file_get_contents($file); try { $this->db->exec($query); } catch (\PDOException $e) { var_dump($e->getMessage()); var_dump($query); exit(1); } } switch ($driver) { case 'pgsql': $this->databaseFinalPgsql(); break; default: die('Unsupported primary database driver'); } }
/** * Is this user a super user? Do they belong in a superuser group? * * @param int $user_id - User ID * @param bool $ignore_groups - Don't look at their groups * @return bool */ public function isSuperUser(int $user_id = 0, bool $ignore_groups = false) : bool { if (empty($user_id)) { // We can short-circuit this for guests... return false; } $statements = ['check_user' => \Airship\queryStringRoot('security.permissions.is_superuser_user', $this->db->getDriver()), 'check_groups' => \Airship\queryStringRoot('security.permissions.is_superuser_group', $this->db->getDriver())]; if ($this->db->cell($statements['check_user'], $user_id) > 0) { return true; } elseif (!$ignore_groups) { return $this->db->cell($statements['check_groups'], $user_id) > 0; } return false; }
/** * ILIKE condition * * @access public * @param string $column * @param mixed $value */ public function ilike($column, $value) { $this->addCondition($this->db->escapeIdentifier($column) . ' ' . $this->db->getDriver()->getOperator('ILIKE') . ' ?'); $this->values[] = $value; }