public function __construct($parent)
 {
     parent::__construct($parent);
     $this->middleware('Auth');
     $this->middleware('Admin');
     $load = new Database();
     $this->db = $load->conn();
 }
 public function __construct($parent)
 {
     parent::__construct($parent);
     if (file_exists(APP_PATH . 'install/lock')) {
         exit('App is Installed.');
     }
     $load = new Database();
     $this->db = $load->conn();
 }
Beispiel #3
0
 public static function get_driver_name($db_ident = null)
 {
     if (is_null($db_ident)) {
         $db_ident = self::get_default_ident();
     }
     if (\System\Database::exists($db_ident)) {
         return cfg('database', 'list', $db_ident, 'driver');
     } else {
         throw new \System\Error\Database(sprintf('Database %s does not exist', $db_ident));
     }
 }
Beispiel #4
0
 public static function cmd_database()
 {
     \System\Init::full();
     $db_list = \System\Settings::get('database', 'list');
     foreach ($db_list as $db_ident => $db_cfg) {
         $size = \System\Database::query("\n\t\t\t\t\tSELECT\n\t\t\t\t\t\t\tsum(data_length + index_length) 'size',\n\t\t\t\t\t\t\tsum( data_free ) 'free'\n\t\t\t\t\t\tFROM information_schema.TABLES\n\t\t\t\t\t\tWHERE table_schema = '" . $db_cfg['database'] . "'\n\t\t\t\t\t\tGROUP BY table_schema;\n\t\t\t\t")->fetch();
         $mlast_date = false;
         $mcount = 0;
         try {
             $mig = \System\Database\Migration::get_new();
             $mcount = count($mig);
             $stat = "Ok";
             $mlast = \System\Database\Migration::get_first()->where(array("status" => 'ok'))->sort_by("updated_at DESC")->fetch();
             if ($mlast) {
                 $mlast_date = $mlast->updated_at;
             }
         } catch (System\Error $e) {
             $stat = "Migrating database is necessary.";
         }
         \Helper\Cli::out('Database ' . $db_ident);
         \Helper\Cli::sep();
         \Helper\Cli::out_flist(array("list" => array("Driver" => $db_cfg['driver'], "Host name" => $db_cfg['host'], "Database name" => $db_cfg['database'], "User" => $db_cfg['username'], "Used charset" => $db_cfg['charset'], "Lazy driver" => $db_cfg['lazy'] ? 'yes' : 'no', "Size" => \System\Template::convert_value('information', $size['size']), "Free space" => \System\Template::convert_value('information', $size['free']), "Structure" => $stat, "Last migrated" => $mlast_date ? $mlast_date->format('Y-m-d H:i:s') : 'never', "New migrations" => $mcount)));
     }
 }
Beispiel #5
0
<?php

\System\Database::init();
if (Godmode\Router::entered($request)) {
    Godmode\Router::init();
    if ($request->logged_in()) {
        if (!\Godmode\Gatekeeper::canAccessGodmode($request->user)) {
            throw new \System\Error\AccessDenied();
        }
    } else {
        $url_login = \System\Router::get_url($request->host, 'god_login');
        if ($request->path != $url_login) {
            redirect_now($url_login);
        }
    }
}
Beispiel #6
0
 public function query($query)
 {
     return \System\Database::query($query, $this->ident);
 }
Beispiel #7
0
 /**
  * Récupération de PDO
  */
 function __CONSTRUCT()
 {
     $this->pdo = Database::getInstance();
 }
Beispiel #8
0
 private function sql($query)
 {
     try {
         return \System\Database::query($query);
     } catch (\System\Error $e) {
         $this->status = 'failed';
         $this->errors[] = $e->getMessage();
     }
 }
Beispiel #9
0
 public function get_filter_cond($filter, $table_alias)
 {
     $pass = null;
     $type = $filter['type'];
     $value = $filter[$type];
     $value = \System\Database::escape($value);
     $value_soft = \System\Database::escape_soft($filter[$type]);
     if (!empty($filter['self'])) {
         $value = $value_soft;
     }
     if ($filter['attr'] == 'id' && $this->assoc_with_model) {
         $model = $this->assoc_with_model;
         $filter['attr'] = $model::get_id_col();
     }
     switch ($type) {
         case 'in':
         case 'exact':
             if (is_array($value)) {
                 $value = implode(',', $value);
                 $pass = "******" . $filter['attr'] . "` IN (" . $value . ")";
             } else {
                 $pass = "******" . $filter['attr'] . "` = '" . $value . "'";
             }
             break;
         case 'is_null':
             def($filter['is_null'], true);
             $pass = '******' . $filter['attr'] . '` ' . ($filter['is_null'] ? 'IS' : 'IS NOT') . ' NULL';
             break;
         case 'iexact':
             $pass = "******" . $filter['attr'] . "`) = LOWER(" . $value . ")";
             break;
         case 'contains':
             $pass = "******" . $filter['attr'] . "` LIKE '%" . $value_soft . "%'";
             break;
         case 'icontains':
             $pass = "******" . $filter['attr'] . "`) LIKE LOWER('%" . $value_soft . "%')";
             break;
         case 'starts_with':
             $pass = "******" . $filter['attr'] . "` LIKE '" . $value_soft . "%'";
             break;
         case 'istarts_with':
             $pass = "******" . $filter['attr'] . "`) LIKE LOWER('" . $value_soft . "%')";
             break;
         case 'ends_with':
             $pass = "******" . $filter['attr'] . "` LIKE '%" . $value_soft . "'";
             break;
         case 'iends_with':
             $pass = "******" . $filter['attr'] . "`) LIKE LOWER('%" . $value_soft . "')";
             break;
         case 'gt':
         case 'gte':
         case 'lt':
         case 'lte':
             if ($type == 'gt') {
                 $pass = "******" . $filter['attr'] . "` > " . $value . "";
             } else {
                 if ($type == 'gte') {
                     $pass = "******" . $filter['attr'] . "` >= " . $value . "";
                 } else {
                     if ($type == 'lt') {
                         $pass = "******" . $filter['attr'] . "` < " . $value . "";
                     } else {
                         if ($type == 'lte') {
                             $pass = "******" . $filter['attr'] . "` <= " . $value . "";
                         }
                     }
                 }
             }
             break;
         default:
             throw new \System\Error\Argument('Unknown filter', $type);
     }
     return $pass;
 }
Beispiel #10
0
 /**
  * Create a new database query instance
  *
  * @param string
  * @param object Connector
  */
 public function __construct($table, $connection = null)
 {
     if (is_null($connection)) {
         $connection = DB::connection();
     }
     $this->table = $table;
     $this->connection = $connection;
 }
Beispiel #11
0
 public function to_sql()
 {
     $data = array($this->lat(), $this->lng());
     return 'GeomFromText(\'POINT(' . \System\Database::escape($data[0]) . ' ' . \System\Database::escape($data[1]) . ')\')';
 }
Beispiel #12
0
 /**
  * Create or update object in database
  *
  * @return System\Model\Database
  */
 public function save()
 {
     $this->run_tasks(\System\Model\Callback::BEFORE_SAVE);
     $model = get_model($this);
     if ($this->update_check()) {
         if (isset($model::$attrs['pass'])) {
             foreach ($model::$attrs['pass'] as $attr) {
                 $old_attr = $attr . '_old';
                 if (any($this->__get($old_attr)) && $this->{$attr} != $this->{$old_attr}) {
                     $this->{$attr} = hash_passwd($this->{$attr});
                 }
             }
         }
         $data = $this->get_data_raw();
         if (!$this->is_new() && !$this->is_new_object) {
             \System\Database::simple_update($model::get_table(), $model::get_id_col(), $this->id, $data);
         } else {
             $id = \System\Database::simple_insert($model::get_table(), $data);
             if ($id) {
                 $this->id = $id;
             } else {
                 throw new \System\Error\Database(sprintf('Could not save model "%s".', $model));
             }
         }
     }
     $this->save_relations();
     $this->run_tasks(\System\Model\Callback::AFTER_SAVE);
     return $this;
 }
Beispiel #13
0
 public static function cmd_seed(array $params = array())
 {
     \System\Init::full();
     \Helper\Cli::out('Seeding initial system data ..');
     \System\Database::seed_initial_data();
     $data = \System\Settings::read(\System\Database::DIR_INITIAL_DATA, true);
     if ($data) {
         \Helper\Cli::out("Injecting initial data ..");
         foreach ($data as $data_set_name => $data_set_models) {
             self::seed_data($data_set_name, $data_set_models);
         }
     }
 }