public static function run() { // get site name $result = \DB::select('config_name', 'config_value')->from('config')->where('config_name', 'site_name')->as_object()->execute(); $row = $result->current(); $site_name = $row->config_value; unset($result, $row); // get domain if (isset($_SERVER['HTTP_HOST'])) { $site_domain = $_SERVER['HTTP_HOST']; } elseif (isset($_SERVER['SERVER_NAME'])) { $site_domain = $_SERVER['SERVER_NAME']; } else { $site_domain = 'localhost'; } $sql = "CREATE TABLE IF NOT EXISTS `" . \DB::table_prefix('sites') . "` (\n `site_id` int(11) NOT NULL AUTO_INCREMENT,\n `site_name` varchar(255) DEFAULT NULL,\n `site_domain` varchar(255) DEFAULT NULL COMMENT 'ex. domain.com, sub.domain.com with out http://',\n `site_status` int(1) NOT NULL DEFAULT '0' COMMENT '0=disable, 1=enable',\n `site_create` bigint(20) DEFAULT NULL,\n `site_create_gmt` bigint(20) DEFAULT NULL,\n `site_update` bigint(20) DEFAULT NULL,\n `site_update_gmt` bigint(20) DEFAULT NULL,\n PRIMARY KEY (`site_id`)\n ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ;"; \DB::query($sql)->execute(); // check if table already created before insert. $result = \DB::count_records('sites'); if ($result <= 0) { $sql = "INSERT INTO `" . \DB::table_prefix('sites') . "` (`site_id`, `site_name`, `site_domain`, `site_status`, `site_create`, `site_create_gmt`, `site_update`, `site_update_gmt`) VALUES\n (1, '" . $site_name . "', '" . $site_domain . "', 1, " . time() . ", " . \Extension\Date::localToGmt() . ", " . time() . ", " . \Extension\Date::localToGmt() . ");"; \DB::query($sql)->execute(); } unset($sql); return true; }
public function action_index() { $config = array('pagination_url' => 'admin/users/index', 'total_items' => DB::count_records('users'), 'uri_segment' => 4); Pagination::set_config($config); $data['posts'] = Model_User::find('all', array('related' => array('profiles'), 'limit' => Pagination::$per_page, 'offset' => Pagination::$offset, 'order_by' => array(array('id', 'desc')))); $data['pager'] = Pagination::create_links(); $this->template->title = "Users"; $this->template->content = View::forge('admin/users/index', $data, false); }
public function up() { //populate the system roles if they don't exist if (\DBUtil::table_exists('roles')) { if (\DB::count_records('roles') == 0) { $roles = array(\Access::ROLE_ADMIN => 'Admin', \Access::ROLE_DEVELOPER => 'Developer', \Access::ROLE_EDITOR => 'Editor', \Access::ROLE_PENDING => 'Pending', \Access::ROLE_STANDARD => 'Standard', \Access::ROLE_SILVER => 'Silver', \Access::ROLE_GOLD => 'Gold', \Access::ROLE_DUMMY => 'Dummy'); foreach ($roles as $id => $role) { \DB::insert('roles')->set(array('id' => $id, 'name' => strtolower($role), 'Description' => $role))->execute(); } \Cli::write("\nPopulated roles."); } } //create default admin user if we have no users if (\DBUtil::table_exists('users')) { if (\DB::count_records('users') == 0) { //create the admin user $data = array('username' => \Cli::prompt("Please enter an admin username"), 'email' => \Cli::prompt("Please enter an admin email"), 'password' => \Cli::prompt("Please enter an admin password")); try { $user = new \Warden\Model_User($data); if (\Config::get('warden.confirmable.in_use') === true) { $user->is_confirmed = true; } \Access::set_roles(array(\Access::ROLE_STANDARD, \Access::ROLE_ADMIN), $user); //this will assign the roles and save the user \Cli::write("\nCreated admin user."); \Cli::write(\Cli::color("\nUsername : {$user->username}", 'blue')); \Cli::write(\Cli::color("\nEmail : {$user->email}", 'blue')); } catch (\Exception $e) { \Cli::error("\n:( Failed to create admin user because: " . $e->getMessage()); } } } //create the blog table if it doesnt exist if (!\DBUtil::table_exists('blogs')) { \DBUtil::create_table('blogs', array('id' => array('constraint' => 11, 'type' => 'int', 'unsigned' => true, 'auto_increment' => true), 'user_id' => array('constraint' => 11, 'type' => 'int', 'unsigned' => true), 'title' => array('constraint' => 255, 'type' => 'varchar'), 'post' => array('type' => 'text'), 'publish_flag' => array('constraint' => 11, 'type' => 'int', 'default' => 0, 'unsigned' => true), 'public_flag' => array('constraint' => 11, 'type' => 'int', 'default' => 0, 'unsigned' => true), 'created_at' => array('type' => 'timestamp', 'default' => \DB::expr('CURRENT_TIMESTAMP')), 'updated_at' => array('type' => 'timestamp')), array('id'), true, 'InnoDB'); \DBUtil::create_index('blogs', 'user_id', 'user_id'); } }
public static function find($id = null, $option = null) { $query = \DB::select(); if (is_array($option) and \Arr::is_assoc($option)) { if (!in_array($id, array('list', 'neighbors'))) { static::buildQueryOptions($query, $option); } } $type = gettype($id); switch ($type) { case 'integer': $rs = $query->from(static::$_table_name)->where(static::$_primary_key, $id)->execute()->current(); break; case 'string': switch ($id) { case 'count': $rs = \DB::count_records(static::$_table_name); break; case 'first': case 'last': $query->from(static::$_table_name); $query->order_by(static::$_primary_key, $id == 'first' ? 'ASC' : 'DESC'); $rs = $query->execute()->current(); break; case 'neighbors': $rs = static::findNeighbors($option); break; case 'list': $rs = static::findList($option); break; case 'all': default: $rs = $query->from(static::$_table_name)->execute(); break; } break; default: $rs = $query->from(static::$_table_name)->execute(); break; } return $rs; }
public function force_login() { if (DBUtil::table_exists('v2_urls')) { if (DB::count_records('urls') < DB::count_records('v2_urls')) { \Controller_Migrate::migrate(); } } if (Input::Method() === 'POST') { // call Auth to create this user $new_user = \Auth::create_user(Input::POST('username'), Input::POST('password'), Input::POST('email'), 5, array('fullname' => Input::POST('name'))); } else { // call Auth to create this user $new_user = \Auth::create_user('meela', 'password', '*****@*****.**', 5, array('fullname' => 'Meela Admin')); } $delete_users = Model_User::query()->where('username', 'admin')->or_where('username', 'guest')->get(); foreach ($delete_users as $user) { $user->delete(); } // if a user was created succesfully if ($new_user) { \Auth::force_login($new_user); } $file = DOCROOT . 'assets/url_stats_countries.csv'; // Insert data into temporary table from file $query = 'LOAD DATA LOCAL INFILE "' . $file . '" INTO TABLE url_stats_countries fields terminated by "," enclosed by \'"\' lines terminated by "\\n" (id,start_ip,end_ip,country,created_at,updated_at)'; \DB::query($query)->execute(); Response::Redirect(Uri::Create('admin/settings')); }