public function before()
 {
     // Lets render the template
     parent::before();
     // Check to see if the config exsists
     if (file_exists(APPPATH . 'config/production/db.php') === false) {
         Response::Redirect('install');
     }
     if (DBUtil::field_exists('urls', array('cached_preview')) === false && file_exists(APPPATH . 'classes/controller/upgrade.php')) {
         Response::Redirect(Uri::Create('upgrade'));
     }
     $real_base_url = Config::get('base_url');
     Config::set('base_url', str_replace('public/', '', $real_base_url));
     $base_url = Settings::get('different_short_url');
     if (empty($base_url) === false) {
         View::set_global(array('base_url' => $base_url), false, false);
     }
     if (trim(Uri::Base(), '/') == Settings::get('different_short_url')) {
         if (count(Uri::Segments()) == 2) {
             $route = Uri::to_assoc();
             if (isset($route) === true && $route['core'] == '404') {
                 // We are good!
             } else {
                 Response::Redirect(Settings::Get('base_url'));
             }
         } else {
             Response::Redirect(Settings::Get('base_url'));
         }
     }
     $data = null;
     if (Auth::Check()) {
         $user_id = Auth::get_user_id();
         static::$user_id = $user_id[1];
         $data['api_key'] = Auth::get('api_key');
         if (empty($data['api_key']) === true) {
             if (empty($data['api_key']) === true) {
                 $data['api_key'] = preg_replace('/\\+|\\/|\\=|\\?/', '', \Auth::instance()->hash_password(\Str::random()) . static::$user_id);
                 // invalidate the hash
                 \Auth::update_user(array('api_key' => $data['api_key']), Auth::get('username'));
             }
         }
     }
     // Lets set the default title , you can change it when calling the view
     $this->template->title = ucwords(str_replace('controller_', '', strtolower($this->request->route->controller)));
     try {
         Module::load('image');
         $this->template->image_js = true;
     } catch (Exception $e) {
     }
     // Lets get the header and footer and set a variable to use within the template
     $this->template->footer = View::forge('core/footer', $data);
     $this->template->header = View::forge('core/header');
 }
Example #2
0
 public function __construct($table = NULL)
 {
     if ($table) {
         // Set the inital table name
         $this->_table = $table;
     }
     if (\DBUtil::field_exists($table, array('updated_at'))) {
         $this->set(array('updated_at' => date('Y-m-d H;i;s')));
     }
     // Start the query with no SQL
     return parent::__construct('', \DB::UPDATE);
 }
Example #3
0
 public static function get_album_images($limit, $page = 1, $self_member_id = 0, $target_member_obj = null, $is_mypage = false, $params = array(), $is_return_array = false, $is_asc = false)
 {
     if (!is_array($params)) {
         $params = (array) $params;
     }
     if ($target_member_obj && !$target_member_obj instanceof \Model_Member) {
         throw new InvalidArgumentException('parameter target_member_obj is invalid.');
     }
     if (!empty($params['select']) && !\DBUtil::field_exists('album_image', $params['select'])) {
         throw new \ValidationFailedException();
     }
     $params = array_merge($params, array('where' => \Site_Model::get_where_params4list($target_member_obj ? $target_member_obj->id : 0, $self_member_id ?: 0, $is_mypage, !empty($params['where']) ? $params['where'] : array(), $target_member_obj ? 'album.member_id' : 'member_id'), 'limit' => $limit, 'order_by' => array('id' => $is_asc ? 'asc' : 'desc')));
     if ($target_member_obj) {
         $params['related'] = array('album');
     }
     $data = Model_AlbumImage::get_pager_list($params, $page, $is_return_array);
     $data['liked_album_image_ids'] = conf('like.isEnabled') && $self_member_id ? \Site_Model::get_liked_ids('album_image', $self_member_id, $data['list']) : array();
     return $data;
 }
 public function up()
 {
     $user = \DB::select('id')->from('users')->limit(1)->execute()->current();
     /*         * ********************************************************************************************
               update rack position
              * ********************************************************************************************* */
     $israck = \DBUtil::checkIfExist('rack');
     if ($israck) {
         if (!\DBUtil::field_exists('rack', array('position'))) {
             // Fields don't exist
             \DBUtil::add_fields('rack', array('position' => array('constraint' => 11, 'type' => 'int')));
         }
     }
     /*         * ********************************************************************************************
               add room height to settings
              * ********************************************************************************************* */
     $settings = \DB::select('value')->from('settings')->where('name', 'room_height')->as_object()->execute();
     if (!isset($settings[0])) {
         // insert default building
         list($set_id, $rows_affected) = \DB::insert('settings')->columns(array('id', 'name', 'value', 'meta_update_user'))->values(array('', 'room_height', '2500', $user['id']))->execute();
     }
     $settings = \DB::select('value')->from('settings')->where('name', 'tutorials')->as_object()->execute();
     if (!isset($settings[0])) {
         // insert default building
         list($set_id, $rows_affected) = \DB::insert('settings')->columns(array('id', 'name', 'value', 'meta_update_user'))->values(array('', 'tutorials', '0', $user['id']))->execute();
     }
     $settings = \DB::select('value')->from('settings')->where('name', 'background')->as_object()->execute();
     if (!isset($settings[0])) {
         // insert default building
         list($set_id, $rows_affected) = \DB::insert('settings')->columns(array('id', 'name', 'value', 'meta_update_user'))->values(array('', 'background', '2', $user['id']))->execute();
     }
     /*         * ********************************************************************************************
               fix zero position for racks into rooms
              * ********************************************************************************************* */
     $this->__update_rack_position();
 }
Example #5
0
 function up()
 {
     //check for address field as integer
     if (!\DBUtil::field_exists('network_ip_ports', array('addrint'))) {
         //\Fuel\Core\Module::load('basic');
         //add field
         \DBUtil::add_fields('network_ip_ports', array('addrint' => array('type' => 'double')));
         $ports = \DB::select('id', 'ipv4')->from('network_ip_ports')->as_object()->execute();
         foreach ($ports as $port) {
             $result = \DB::update('network_ip_ports')->value("addrint", $this->IPv4_dotquadA_to_intA($port->ipv4))->where('id', '=', $port->id)->execute();
         }
         /*
          $ips = \Basic\Model_Network_Ip::find('all');
         
         
         
         
          foreach($ips as $ip){
          $ip->addrint=$this->IPv4_dotquadA_to_intA($ip->ipv4);
          $ip->save();
          }
         */
     }
 }
Example #6
0
 protected static function usertable()
 {
     if (!\DBUtil::table_exists(static::$data['ormauth_table'])) {
         if (!\DBUtil::table_exists(static::$data['simpleauth_table'])) {
             // table users
             \DBUtil::create_table(static::$data['ormauth_table'], array('id' => array('type' => 'int', 'constraint' => 11, 'auto_increment' => true), 'username' => array('type' => 'varchar', 'constraint' => 50), 'password' => array('type' => 'varchar', 'constraint' => 255), 'group_id' => array('type' => 'int', 'constraint' => 11, 'default' => 1), 'email' => array('type' => 'varchar', 'constraint' => 255), 'last_login' => array('type' => 'varchar', 'constraint' => 25), 'previous_login' => array('type' => 'varchar', 'constraint' => 25, 'default' => 0), 'login_hash' => array('type' => 'varchar', 'constraint' => 255), 'user_id' => array('type' => 'int', 'constraint' => 11, 'default' => 0), 'created_at' => array('type' => 'int', 'constraint' => 11, 'default' => 0), 'updated_at' => array('type' => 'int', 'constraint' => 11, 'default' => 0)), array('id'));
             // add a unique index on username and email
             \DBUtil::create_index(static::$data['ormauth_table'], array('username', 'email'), 'username', 'UNIQUE');
         } else {
             \DBUtil::rename_table(static::$data['simpleauth_table'], static::$data['ormauth_table']);
         }
     }
     // run a check on required fields, and deal with missing ones. we might be migrating from simpleauth
     if (\DBUtil::field_exists(static::$data['ormauth_table'], 'group')) {
         \DBUtil::modify_fields(static::$data['ormauth_table'], array('group' => array('name' => 'group_id', 'type' => 'int', 'constraint' => 11)));
     }
     if (!\DBUtil::field_exists(static::$data['ormauth_table'], 'group_id')) {
         \DBUtil::add_fields(static::$data['ormauth_table'], array('group_id' => array('type' => 'int', 'constraint' => 11, 'default' => 1, 'after' => 'password')));
     }
     if (!\DBUtil::field_exists(static::$data['ormauth_table'], 'previous_login')) {
         \DBUtil::add_fields(static::$data['ormauth_table'], array('previous_login' => array('type' => 'varchar', 'constraint' => 25, 'default' => 0, 'after' => 'last_login')));
     }
     if (!\DBUtil::field_exists(static::$data['ormauth_table'], 'user_id')) {
         \DBUtil::add_fields(static::$data['ormauth_table'], array('user_id' => array('type' => 'int', 'constraint' => 11, 'default' => 0, 'after' => 'login_hash')));
     }
     if (\DBUtil::field_exists(static::$data['ormauth_table'], 'created')) {
         \DBUtil::modify_fields(static::$data['ormauth_table'], array('created' => array('name' => 'created_at', 'type' => 'int', 'constraint' => 11)));
     }
     if (!\DBUtil::field_exists(static::$data['ormauth_table'], 'created_at')) {
         \DBUtil::add_fields(static::$data['ormauth_table'], array('created_at' => array('type' => 'int', 'constraint' => 11, 'default' => 0, 'after' => 'user_id')));
     }
     if (\DBUtil::field_exists(static::$data['ormauth_table'], 'updated')) {
         \DBUtil::modify_fields(static::$data['ormauth_table'], array('updated' => array('name' => 'updated_at', 'type' => 'int', 'constraint' => 11)));
     }
     if (!\DBUtil::field_exists(static::$data['ormauth_table'], 'updated_at')) {
         \DBUtil::add_fields(static::$data['ormauth_table'], array('updated_at' => array('type' => 'int', 'constraint' => 11, 'default' => 0, 'after' => 'created_at')));
     }
 }
Example #7
0
 /**
  * installs or upgrades the migration table to the current schema
  *
  * @return	void
  *
  * @deprecated	Remove upgrade check in 1.4
  */
 protected static function table_version_check()
 {
     // set connection
     static::$connection === null or \DBUtil::set_connection(static::$connection);
     // if table does not exist
     if (!\DBUtil::table_exists(static::$table)) {
         // create table
         \DBUtil::create_table(static::$table, static::$table_definition);
     } elseif (!\DBUtil::field_exists(static::$table, array('migration'))) {
         // get the current migration status
         $current = \DB::select()->from(static::$table)->order_by('type', 'ASC')->order_by('name', 'ASC')->execute(static::$connection)->as_array();
         // drop the existing table, and recreate it in the new layout
         \DBUtil::drop_table(static::$table);
         \DBUtil::create_table(static::$table, static::$table_definition);
         // check if we had a current migration status
         if (!empty($current)) {
             // do we need to migrate from a v1.0 migration environment?
             if (isset($current[0]['current'])) {
                 // convert the current result into a v1.1. migration environment structure
                 $current = array(0 => array('name' => 'default', 'type' => 'app', 'version' => $current[0]['current']));
             }
             // build a new config structure
             $configs = array();
             // convert the v1.1 structure to the v1.2 structure
             foreach ($current as $migration) {
                 // find the migrations for this entry
                 $migrations = static::find_migrations($migration['name'], $migration['type'], null, $migration['version']);
                 // array to keep track of the migrations already run
                 $config = array();
                 // add the individual migrations found
                 foreach ($migrations as $file) {
                     $file = pathinfo($file['path']);
                     // add this migration to the table
                     \DB::insert(static::$table)->set(array('name' => $migration['name'], 'type' => $migration['type'], 'migration' => $file['filename']))->execute(static::$connection);
                     // and to the config
                     $config[] = $file['filename'];
                 }
                 // create a config entry for this name and type if needed
                 isset($configs[$migration['type']]) or $configs[$migration['type']] = array();
                 $configs[$migration['type']][$migration['name']] = $config;
             }
             // write the updated migrations config back
             \Config::set('migrations.version', $configs);
             \Config::save(\Fuel::$env . DS . 'migrations', 'migrations');
         }
         // delete any old migration config file that may exist
         is_file(APPPATH . 'config' . DS . 'migrations.php') and unlink(APPPATH . 'config' . DS . 'migrations.php');
     }
     // set connection to default
     static::$connection === null or \DBUtil::set_connection(null);
 }
Example #8
0
 /**
  * Installs or upgrades migration table
  *
  * @return  void
  * @deprecated	Remove upgrade check in 1.2
  */
 private static function table_check()
 {
     // if table does not exist
     if (!\DBUtil::table_exists(static::$table)) {
         // create table
         \DBUtil::create_table(static::$table, static::$table_definition);
     } elseif (!\DBUtil::field_exists(static::$table, array('name', 'type'))) {
         $current = \DB::select('current')->from(static::$table)->limit(1)->execute()->get('current');
         \DBUtil::drop_table(static::$table);
         \DBUtil::create_table(static::$table, static::$table_definition);
         \DB::insert(static::$table)->set(array('name' => 'default', 'type' => 'app', 'version' => (int) $current))->execute();
     }
 }
 function up()
 {
     // get the driver used
     \Config::load('auth', true);
     $drivers = \Config::get('auth.driver', array());
     is_array($drivers) or $drivers = array($drivers);
     if (in_array('Simpleauth', $drivers)) {
         // get the tablename
         \Config::load('simpleauth', true);
         $table = \Config::get('simpleauth.table_name', 'users');
         // only do this if it doesn't exist yet
         if (!\DBUtil::table_exists($table)) {
             // table users
             \DBUtil::create_table($table, array('id' => array('type' => 'int', 'constraint' => 11, 'auto_increment' => true), 'username' => array('type' => 'varchar', 'constraint' => 50), 'password' => array('type' => 'varchar', 'constraint' => 255), 'group' => array('type' => 'int', 'constraint' => 11, 'default' => 1), 'email' => array('type' => 'varchar', 'constraint' => 255), 'last_login' => array('type' => 'varchar', 'constraint' => 25), 'login_hash' => array('type' => 'varchar', 'constraint' => 255), 'profile_fields' => array('type' => 'text'), 'created_at' => array('type' => 'int', 'constraint' => 11, 'default' => 0), 'updated_at' => array('type' => 'int', 'constraint' => 11, 'default' => 0)), array('id'));
             // add a unique index on username and email
             \DBUtil::create_index($table, array('username', 'email'), 'username', 'UNIQUE');
         }
     } elseif (in_array('Ormauth', $drivers)) {
         // get the tablename
         \Config::load('ormauth', true);
         $table = \Config::get('ormauth.table_name', 'users');
         if (!\DBUtil::table_exists($table)) {
             // get the simpleauth tablename, maybe that exists
             \Config::load('simpleauth', true);
             $simpletable = \Config::get('simpleauth.table_name', 'users');
             if (!\DBUtil::table_exists($simpletable)) {
                 // table users
                 \DBUtil::create_table($table, array('id' => array('type' => 'int', 'constraint' => 11, 'auto_increment' => true), 'username' => array('type' => 'varchar', 'constraint' => 50), 'password' => array('type' => 'varchar', 'constraint' => 255), 'group_id' => array('type' => 'int', 'constraint' => 11, 'default' => 1), 'email' => array('type' => 'varchar', 'constraint' => 255), 'last_login' => array('type' => 'varchar', 'constraint' => 25), 'previous_login' => array('type' => 'varchar', 'constraint' => 25, 'default' => 0), 'login_hash' => array('type' => 'varchar', 'constraint' => 255), 'user_id' => array('type' => 'int', 'constraint' => 11, 'default' => 0), 'created_at' => array('type' => 'int', 'constraint' => 11, 'default' => 0), 'updated_at' => array('type' => 'int', 'constraint' => 11, 'default' => 0)), array('id'));
                 // add a unique index on username and email
                 \DBUtil::create_index($table, array('username', 'email'), 'username', 'UNIQUE');
             } else {
                 \DBUtil::rename_table($simpletable, $table);
             }
         }
         // run a check on required fields, and deal with missing ones. we might be migrating from simpleauth
         if (\DBUtil::field_exists($table, 'group')) {
             \DBUtil::modify_fields($table, array('group' => array('name' => 'group_id', 'type' => 'int', 'constraint' => 11)));
         }
         if (!\DBUtil::field_exists($table, 'group_id')) {
             \DBUtil::add_fields($table, array('group_id' => array('type' => 'int', 'constraint' => 11, 'default' => 1, 'after' => 'password')));
         }
         if (!\DBUtil::field_exists($table, 'previous_login')) {
             \DBUtil::add_fields($table, array('previous_login' => array('type' => 'varchar', 'constraint' => 25, 'default' => 0, 'after' => 'last_login')));
         }
         if (!\DBUtil::field_exists($table, 'user_id')) {
             \DBUtil::add_fields($table, array('user_id' => array('type' => 'int', 'constraint' => 11, 'default' => 0, 'after' => 'login_hash')));
         }
         if (\DBUtil::field_exists($table, 'created')) {
             \DBUtil::modify_fields($table, array('created' => array('name' => 'created_at', 'type' => 'int', 'constraint' => 11)));
         }
         if (!\DBUtil::field_exists($table, 'created_at')) {
             \DBUtil::add_fields($table, array('created_at' => array('type' => 'int', 'constraint' => 11, 'default' => 0, 'after' => 'user_id')));
         }
         if (\DBUtil::field_exists($table, 'updated')) {
             \DBUtil::modify_fields($table, array('updated' => array('name' => 'updated_at', 'type' => 'int', 'constraint' => 11)));
         }
         if (!\DBUtil::field_exists($table, 'updated_at')) {
             \DBUtil::add_fields($table, array('updated_at' => array('type' => 'int', 'constraint' => 11, 'default' => 0, 'after' => 'created_at')));
         }
         // table users_meta
         \DBUtil::create_table($table . '_metadata', array('id' => array('type' => 'int', 'constraint' => 11, 'auto_increment' => true), 'parent_id' => array('type' => 'int', 'constraint' => 11, 'default' => 0), 'key' => array('type' => 'varchar', 'constraint' => 20), 'value' => array('type' => 'varchar', 'constraint' => 100), 'user_id' => array('type' => 'int', 'constraint' => 11, 'default' => 0), 'created_at' => array('type' => 'int', 'constraint' => 11, 'default' => 0), 'updated_at' => array('type' => 'int', 'constraint' => 11, 'default' => 0)), array('id'));
         // convert profile fields to metadata, and drop the column
         if (\DBUtil::field_exists($table, 'profile_fields')) {
             $result = \DB::select('id', 'profile_fields')->from($table)->execute();
             foreach ($result as $row) {
                 $profile_fields = empty($row['profile_fields']) ? array() : unserialize($row['profile_fields']);
                 foreach ($profile_fields as $field => $value) {
                     if (!is_numeric($field)) {
                         \DB::insert($table . '_metadata')->set(array('parent_id' => $row['id'], 'key' => $field, 'value' => $value))->execute();
                     }
                 }
             }
             \DBUtil::drop_fields($table, array('profile_fields'));
         }
         // table users_user_role
         \DBUtil::create_table($table . '_user_roles', array('user_id' => array('type' => 'int', 'constraint' => 11), 'role_id' => array('type' => 'int', 'constraint' => 11)), array('user_id', 'role_id'));
         // table users_user_perms
         \DBUtil::create_table($table . '_user_permissions', array('user_id' => array('type' => 'int', 'constraint' => 11), 'perms_id' => array('type' => 'int', 'constraint' => 11)), array('user_id', 'perms_id'));
     }
 }
Example #10
0
 /**
  * old version < 1.09 is without modules.. erase old table and set new
  */
 private function __erase_old_migration()
 {
     \Config::load('install', true);
     $version = \Config::get('install.version');
     $table = \DBUtil::checkIfExist('version');
     if ($table) {
         if (!DBUtil::field_exists('version', array('mode'))) {
             // Fields dont exist
             \DBUtil::truncate_table('version');
             \DBUtil::add_fields('version', array('lastcheck' => array('constraint' => 11, 'type' => 'int', 'default' => '0'), 'mode' => array('constraint' => 22, 'type' => 'varchar'), 'master' => array('constraint' => 22, 'type' => 'varchar'), 'quiet' => array('constraint' => 2, 'type' => 'int', 'default' => '0')));
             $now = time();
             /*  
                            \Config::load('update', true);
                             $master = \Config::get('update.version');
             */
             $master = '1.1';
             list($insert_id, $rows_affected) = \DB::insert('version')->columns(array('id', 'value', 'meta_update_time', 'lastcheck', 'mode', 'master', 'quiet'))->values(array('1', $master, $now, $now, $master, $master, 0))->execute();
             $table = \DBUtil::checkIfExist('simple_log');
             if (!$table) {
                 \DBUtil::create_table('simple_log', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'name' => array('constraint' => 200, 'type' => 'varchar'), 'value' => array('type' => 'text')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
             }
         }
     }
 }
 public function create_tables()
 {
     if (file_exists(APPPATH . 'config/production/db.php') == true) {
         Log::error('shit worked!');
     }
     // DBUtil::set_connection(null);
     if (DBUtil::table_exists('urls')) {
         if (DBUtil::field_exists('urls', array('time'))) {
             // Upgrade Me
             try {
                 DBUtil::rename_table('urls', 'v2_urls');
                 DBUtil::rename_table('stats', 'v2_stats');
                 DBUtil::rename_table('settings', 'v2_settings');
             } catch (\Database_Exception $e) {
                 Log::error($e);
             }
             Controller_Install::create_tables();
         } else {
             // Already Installed
         }
     } else {
         $oil_path = str_replace('public/', '', DOCROOT);
         try {
             @Migrate::current('default', 'app');
             @Migrate::current('auth', 'package');
         } catch (\Database_exception $e) {
             Debug::Dump('PLEASE REVISIT THIS /install (DONT RELOAD) THAT SHOULD INSTALL THE SCRIPT FOR YOU IF NOT THEN: Access has been denied for the database user , go to fuel/app/config/production/db.php , and edit your username and password!');
             die;
         }
         try {
             \DBUtil::create_index('urls', 'short_url');
         } catch (\Database_exception $e) {
             Log::error($e);
         }
         try {
             \DBUtil::create_index('urls', 'user_id');
         } catch (\Database_exception $e) {
             Log::error($e);
         }
         try {
             \DBUtil::create_index('urls', array('id', 'short_url'));
         } catch (\Database_exception $e) {
             Log::error($e);
         }
         try {
             \DBUtil::create_index('urls', array('id', 'user_id'));
         } catch (\Database_exception $e) {
             Log::error($e);
         }
         try {
             \DBUtil::create_index('urls', array('id', 'short_url', 'user_id'));
         } catch (\Database_exception $e) {
             Log::error($e);
         }
         try {
             \DBUtil::create_index('url_stats', 'url_id');
         } catch (\Database_exception $e) {
             Log::error($e);
         }
         try {
             \DBUtil::create_index('url_stats', 'country');
         } catch (\Database_exception $e) {
             Log::error($e);
         }
         try {
             \DBUtil::create_index('url_stats', array('id', 'url_id'));
         } catch (\Database_exception $e) {
             Log::error($e);
         }
         try {
             \DBUtil::create_index('url_stats_countries', 'start_ip');
         } catch (\Database_exception $e) {
             Log::error($e);
         }
         try {
             \DBUtil::create_index('url_stats_countries', 'end_ip');
         } catch (\Database_exception $e) {
             Log::error($e);
         }
         try {
             \DBUtil::create_index('url_stats_countries', 'country');
         } catch (\Database_exception $e) {
             Log::error($e);
         }
         try {
             \DBUtil::create_index('url_stats_countries', array('start_ip', 'end_ip'));
         } catch (\Database_exception $e) {
             Log::error($e);
         }
         try {
             \DBUtil::create_index('url_stats_countries', array('start_ip', 'end_ip', 'country'));
         } catch (\Database_exception $e) {
             Log::error($e);
         }
         try {
             \DBUtil::modify_fields('urls', array('url' => array('constraint' => 255, 'type' => 'varchar')));
         } catch (\Database_exception $e) {
             Log::error($e);
         }
     }
     return true;
 }