Example #1
0
 /**
  * Class constructor
  *
  * @param  array   $config  Configuration [Optional]
  * @param  string  $id      Session id [Optional]
  */
 public function __construct(array $config = NULL, $id = NULL)
 {
     if (!isset($config['group'])) {
         // Use the default group
         $config['group'] = 'default';
     }
     // Load the database
     $this->_db = Database::instance($config['group']);
     if (isset($config['table'])) {
         // Set the table name
         $this->_table = (string) $config['table'];
     }
     if (isset($config['gc'])) {
         // Set the gc chance
         $this->_gc = (int) $config['gc'];
     }
     if (isset($config['columns'])) {
         // Overload column names
         $this->_columns = $config['columns'];
     }
     $this->_user_id = 0;
     parent::__construct($config, $id);
     if (mt_rand(0, $this->_gc) === $this->_gc) {
         // Run garbage collection
         // This will average out to run once every X requests
         $this->_gc();
     }
 }
Example #2
0
 /**
  * Constructs the model, taking a Database connection as the first and only
  * parameter
  *
  * @param Kohana_Database $db Database connection to use
  */
 public function __construct($db = NULL)
 {
     if ($db == NULL) {
         $db = \Gleez\Database\Database::instance(NULL);
     }
     $this->_db = $db;
     $this->_table = Config::get('migration.table', 'migrations');
 }
Example #3
0
 /**
  * Returns last executed query
  *
  * @return string
  */
 public function last_query()
 {
     return $this->_db->getLastQuery();
 }
Example #4
0
 /**
  * Load the active modules
  *
  * This is called at bootstrap time
  *
  * @param  boolean  $reset  Reset true to clear the cache.
  *
  * @uses   Cache::get
  * @uses   Log::add
  * @uses   Arr::merge
  */
 public static function load_modules($reset = TRUE)
 {
     self::$modules = array();
     self::$active = array();
     $kohana_modules = array();
     $cache = Cache::instance('modules');
     $data = $cache->get('load_modules', FALSE);
     if ($reset === FALSE and $data and isset($data['kohana_modules'])) {
         // db has to be initiated @todo fix this bug
         Database::instance(NULL);
         // use data from cache
         self::$modules = $data['modules'];
         self::$active = $data['active'];
         $kohana_modules = $data['kohana_modules'];
         unset($data);
     } else {
         $modules = ORM::factory('module')->order_by('weight', 'ASC')->order_by('name', 'ASC')->find_all();
         $_cache_modules = $_cache_active = array();
         foreach ($modules as $module) {
             self::$modules[$module->name] = $module;
             $_cache_modules[$module->name] = $module->as_array();
             if (!$module->active) {
                 continue;
             }
             //fix for old installations, where gleez exists in db
             if ($module->name != 'gleez') {
                 self::$active[$module->name] = $module;
                 $_cache_active[$module->name] = $module->as_array();
                 // try to get module path from db if it set
                 if (!empty($module->path) and is_dir($module->path)) {
                     $kohana_modules[$module->name] = $module->path;
                 } else {
                     $kohana_modules[$module->name] = MODPATH . $module->name;
                 }
             }
         }
         // set the cache for performance in production
         if (Kohana::$environment === Kohana::PRODUCTION) {
             $data = array();
             $data['modules'] = $_cache_modules;
             $data['active'] = $_cache_active;
             $data['kohana_modules'] = $kohana_modules;
             $cache->set('load_modules', $data, Date::DAY);
             unset($data, $_cache_modules, $_cache_active);
         }
     }
     Kohana::modules(Arr::merge($kohana_modules, Kohana::modules()));
 }
Example #5
0
 public static function prefix()
 {
     return Database::instance(NULL, self::$_config)->table_prefix();
 }
Example #6
0
 /**
  * Get data type.
  *
  * Returns a normalized array describing the SQL data type.
  * Example:<br>
  * <code>
  * $db->getDataType('char');
  * </code>
  *
  * @since  2.1.0
  *
  * @param  string $type SQL data type
  *
  * @return array
  */
 public function getDataType($type)
 {
     static $types = array('blob' => array('type' => 'string', 'binary' => TRUE, 'character_maximum_length' => '65535'), 'bool' => array('type' => 'bool'), 'bigint unsigned' => array('type' => 'int', 'min' => '0', 'max' => '18446744073709551615'), 'datetime' => array('type' => 'string'), 'decimal unsigned' => array('type' => 'float', 'exact' => TRUE, 'min' => '0'), 'double' => array('type' => 'float'), 'double precision unsigned' => array('type' => 'float', 'min' => '0'), 'double unsigned' => array('type' => 'float', 'min' => '0'), 'enum' => array('type' => 'string'), 'fixed' => array('type' => 'float', 'exact' => TRUE), 'fixed unsigned' => array('type' => 'float', 'exact' => TRUE, 'min' => '0'), 'float unsigned' => array('type' => 'float', 'min' => '0'), 'geometry' => array('type' => 'string', 'binary' => TRUE), 'int unsigned' => array('type' => 'int', 'min' => '0', 'max' => '4294967295'), 'integer unsigned' => array('type' => 'int', 'min' => '0', 'max' => '4294967295'), 'longblob' => array('type' => 'string', 'binary' => TRUE, 'character_maximum_length' => '4294967295'), 'longtext' => array('type' => 'string', 'character_maximum_length' => '4294967295'), 'mediumblob' => array('type' => 'string', 'binary' => TRUE, 'character_maximum_length' => '16777215'), 'mediumint' => array('type' => 'int', 'min' => '-8388608', 'max' => '8388607'), 'mediumint unsigned' => array('type' => 'int', 'min' => '0', 'max' => '16777215'), 'mediumtext' => array('type' => 'string', 'character_maximum_length' => '16777215'), 'national varchar' => array('type' => 'string'), 'numeric unsigned' => array('type' => 'float', 'exact' => TRUE, 'min' => '0'), 'nvarchar' => array('type' => 'string'), 'point' => array('type' => 'string', 'binary' => TRUE), 'real unsigned' => array('type' => 'float', 'min' => '0'), 'set' => array('type' => 'string'), 'smallint unsigned' => array('type' => 'int', 'min' => '0', 'max' => '65535'), 'text' => array('type' => 'string', 'character_maximum_length' => '65535'), 'tinyblob' => array('type' => 'string', 'binary' => TRUE, 'character_maximum_length' => '255'), 'tinyint' => array('type' => 'int', 'min' => '-128', 'max' => '127'), 'tinyint unsigned' => array('type' => 'int', 'min' => '0', 'max' => '255'), 'tinytext' => array('type' => 'string', 'character_maximum_length' => '255'), 'year' => array('type' => 'string'));
     $type = str_replace(' zerofill', '', $type);
     if (isset($types[$type])) {
         return $types[$type];
     }
     return parent::getDataType($type);
 }
Example #7
0
 public static function version()
 {
     return Database::instance(NULL, self::$_config)->version();
 }
Example #8
0
 /**
  * Gets a database connection for running the migrations
  *
  * @param  string $db_group Database connection group name
  * @return Database  Database connection
  */
 protected function _get_db_instance($db_group)
 {
     // If this isn't a dry run then just use a normal database connection
     if (!$this->_dry_run) {
         return Database::instance($db_group);
     }
     return Migration_Database::faux_instance($db_group);
 }