public function action_index() { if (!\DBUtil::table_exists('blog') && !\DBUtil::table_exists('blog_comment')) { \Response::redirect('blog/installrequired'); } // list posts ----------------------------------------------------------------------------------------------------- $option['limit'] = \Model_Config::getval('content_items_perpage'); $option['offset'] = trim(\Input::get('page')) != null ? ((int) \Input::get('page') - 1) * $option['limit'] : 0; $list_items = \Blog\Model_Blog::listItems($option); // pagination config $config['pagination_url'] = \Uri::main() . \Uri::getCurrentQuerystrings(true, true, false); $config['total_items'] = $list_items['total']; $config['per_page'] = $option['limit']; $config['uri_segment'] = 'page'; $config['num_links'] = 3; $config['show_first'] = true; $config['show_last'] = true; $config['first-inactive'] = "\n\t\t<li class=\"disabled\">{link}</li>"; $config['first-inactive-link'] = '<a href="#">{page}</a>'; $config['first-marker'] = '«'; $config['last-inactive'] = "\n\t\t<li class=\"disabled\">{link}</li>"; $config['last-inactive-link'] = '<a href="#">{page}</a>'; $config['last-marker'] = '»'; $config['previous-marker'] = '‹'; $config['next-marker'] = '›'; $pagination = \Pagination::forge('viewlogins_pagination', $config); $output['list_items'] = $list_items; $output['pagination'] = $pagination; unset($config, $list_accounts, $option, $pagination); // <head> output ---------------------------------------------------------------------------------------------- $output['page_title'] = $this->generateTitle(\Lang::get('blog')); // <head> output ---------------------------------------------------------------------------------------------- return $this->generatePage('blog_v', $output, false); }
/** * create the sessions table * php oil r session:create */ public static function create() { // load session config \Config::load('session', true); if (\Config::get('session.driver') != 'db') { // prompt the user to confirm they want to remove the table. $continue = \Cli::prompt(\Cli::color('Your current driver type is not set db. Would you like to continue and add the sessions table anyway?', 'yellow'), array('y', 'n')); if ($continue === 'n') { return \Cli::color('Database sessions table was not created.', 'red'); } } if (\DBUtil::table_exists(\Config::get('session.db.table'))) { return \Cli::write('Session table already exists.'); } // create the session table using the table name from the config file \DBUtil::create_table(\Config::get('session.db.table'), array('session_id' => array('constraint' => 40, 'type' => 'varchar'), 'previous_id' => array('constraint' => 40, 'type' => 'varchar'), 'user_agent' => array('type' => 'text', 'null' => false), 'ip_hash' => array('constraint' => 32, 'type' => 'char'), 'created' => array('constraint' => 10, 'type' => 'int', 'unsigned' => true), 'updated' => array('constraint' => 10, 'type' => 'int', 'unsigned' => true), 'payload' => array('type' => 'longtext')), array('session_id'), false, 'InnoDB', \Config::get('db.default.charset')); // make previous_id a unique_key. speeds up query and prevents duplicate id's \DBUtil::create_index(\Config::get('session.db.table'), 'previous_id', 'previous_id', 'unique'); if (\Config::get('session.driver') === 'db') { // return success message. return \Cli::color('Success! Your session table has been created!', 'green'); } else { // return success message notifying that the driver is not db. return \Cli::color('Success! Your session table has been created! Your current session driver type is set to ' . \Config::get('session.driver') . '. In order to use the table you just created to manage your sessions, you will need to set your driver type to "db" in your session config file.', 'green'); } }
protected static function empty_table($table) { if (DBUtil::table_exists($table)) { DBUtil::truncate_table($table); } else { exit('No such table: ' . $table . PHP_EOL); } }
function up() { // only do this if it doesn't exist yet if (!\DBUtil::table_exists('users')) { // table users \DBUtil::create_table('users', array('id' => array('type' => 'integer primary key', 'autoincrement' => true), 'username' => array('type' => 'text'), 'password' => array('type' => 'text'), 'group' => array('type' => 'integer', 'default' => 1), 'email' => array('type' => 'text'), 'last_login' => array('type' => 'text'), 'login_hash' => array('type' => 'text'), 'profile_fields' => array('type' => 'text'), 'created_at' => array('type' => 'integer', 'default' => 0), 'updated_at' => array('type' => 'integer', 'default' => 0))); // add a unique index on username and email \DBUtil::create_index('users', array('username', 'email'), 'username', 'UNIQUE'); } }
public function action_uninstall() { if (\DBUtil::table_exists('blog')) { \DBUtil::drop_table('blog'); } if (\DBUtil::table_exists('blog_comment')) { \DBUtil::drop_table('blog_comment'); } echo 'Uninstall db tables for blog module completed.'; }
public function up() { if (\DBUtil::table_exists('task_queues')) { return; } // ------------------------- // task_queues // ------------------------- \DBUtil::create_table('task_queues', array('id' => array('type' => 'int', 'constraint' => 10, 'unsigned' => true, 'auto_increment' => true), 'method' => array('type' => 'varchar', 'constraint' => 255), 'options' => array('type' => 'varchar', 'constraint' => 255, 'comment' => 'json format'), 'duplicate_type' => array('type' => 'tinyint', 'default' => 0, 'comment' => '0:no limit setting, 1~:limit is refered from config file'), 'job_status' => array('type' => 'tinyint', 'default' => 0, 'comment' => '0:wait, 1:exec, 2:success, 3:error'), 'deleted' => array('type' => 'tinyint', 'default' => \Config::get('queue.logical_delete.not_deleted')), 'created_at' => array('type' => 'datetime', 'null' => true), 'updated_at' => array('type' => 'datetime', 'null' => true), 'timestamp' => array('type' => 'timestamp', 'default' => \DB::expr('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'))), array('id'), true, 'InnoDB', 'utf8'); }
public function actionAccountDeleteOnMultisiteTables($account_id = '', $args = '') { $test_table_name = 'testmultisiteaccount'; // get all sites from site table $sites_result = \DB::select('site_id')->as_object()->from('sites')->execute(); if ($sites_result != null) { foreach ($sites_result as $site) { if ($site->site_id == '1') { $test_table = 'testmultisiteaccount'; } else { $test_table = $site->site_id . '_testmultisiteaccount'; } if (\DBUtil::table_exists($test_table)) { \DB::delete($test_table)->where('account_id', $account_id)->execute(); } } } unset($site, $sites_result, $test_table, $test_table_name); }
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 run() { // create permission table. (user's permission) $sql = "CREATE TABLE IF NOT EXISTS `" . \DB::table_prefix('account_permission') . "` (\n `permission_id` int(11) NOT NULL AUTO_INCREMENT,\n `account_id` int(11) NOT NULL COMMENT 'refer to accounts.account_id',\n `permission_core` int(1) NOT NULL DEFAULT '0' COMMENT '1=core permission, 0=modules permission',\n `module_system_name` varchar(255) DEFAULT NULL COMMENT 'module system name',\n `permission_page` varchar(255) NOT NULL,\n `permission_action` varchar(255) DEFAULT NULL,\n PRIMARY KEY (`permission_id`),\n KEY `account_id` (`account_id`)\n ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='contain user''s permission for each admin page and action.' AUTO_INCREMENT=1 ;"; \DB::query($sql)->execute(); unset($sql); // loop sites to create permission table. $sites = \Model_Sites::find('all'); if ($sites != null) { foreach ($sites as $row) { $table_name = 'account_permission'; if ($row->site_id != '1') { $table_name = $row->site_id . '_' . $table_name; } if (!\DBUtil::table_exists($table_name)) { $sql = 'CREATE TABLE IF NOT EXISTS ' . \DB::table_prefix($table_name) . ' LIKE ' . \DB::table_prefix('account_permission'); \DB::query($sql)->execute(); unset($sql); } } } unset($row, $sites); return true; }
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'))); } }
/** * 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); }
/** * 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')); } }
public function action_accountMultisite() { $act = trim(\Input::post('act')); $output = []; if (strtolower(\Fuel\Core\Input::method()) == 'post') { if ($act == 'createmaintable') { $create_table = \Fuel\Core\DBUtil::create_table('testmultisiteaccount', ['id' => ['constraint' => 11, 'type' => 'int', 'auto_increment' => true], 'account_id' => ['constraint' => 11, 'type' => 'int', 'null' => true, 'comment' => 'refer to accounts.account_id'], 'actdate' => ['type' => 'bigint', 'null' => true, 'comment' => 'date/time of record date.']], ['id'], true); $output['create_table_result'] = $create_table; $output['result'] = true; } elseif ($act == 'insertdemodata') { // get accounts that is not guest $account_result = \DB::select('account_id')->as_object()->from('accounts')->where('account_id', '!=', '0')->execute(); // get all sites from site table $sites_result = \DB::select('site_id')->as_object()->from('sites')->execute(); $output['tables_data'] = []; if ($sites_result != null) { foreach ($sites_result as $site) { if ($site->site_id == '1') { $test_table = 'testmultisiteaccount'; } else { $test_table = $site->site_id . '_testmultisiteaccount'; } if (\DBUtil::table_exists($test_table)) { \DBUtil::truncate_table($test_table); if ($account_result != null) { foreach ($account_result as $account) { \DB::insert($test_table)->set(['account_id' => $account->account_id, 'actdate' => time()])->execute(); } // endforeach; $account_result } // endif; $account_result // finished insert get data from this table. $this_table_result = \DB::select()->as_object('stdClass')->from($test_table)->limit(10)->order_by('id', 'DESC')->execute()->as_array(); $output['tables_data'][$test_table] = $this_table_result; unset($this_table_result); } unset($test_table); } // endforeach; $sites_result $output['result'] = true; } // endif; $sites_result unset($account, $account_result, $site, $sites_result); } elseif ($act == 'loaddemodata') { // get all sites from site table $sites_result = \DB::select('site_id')->as_object()->from('sites')->execute(); $output['tables_data'] = []; if ($sites_result != null) { foreach ($sites_result as $site) { if ($site->site_id == '1') { $test_table = 'testmultisiteaccount'; } else { $test_table = $site->site_id . '_testmultisiteaccount'; } if (\DBUtil::table_exists($test_table)) { $this_table_result = \DB::select()->as_object('stdClass')->from($test_table)->limit(10)->order_by('id', 'DESC')->execute()->as_array(); $output['tables_data'][$test_table] = $this_table_result; unset($this_table_result); } } // endforeach; $sites_result $output['result'] = true; } // endif; $sites_result unset($site, $sites_result); } elseif ($act == 'droptable') { // get all sites from site table $sites_result = \DB::select('site_id')->as_object()->from('sites')->execute(); if ($sites_result != null) { foreach ($sites_result as $site) { if ($site->site_id == '1') { $test_table = 'testmultisiteaccount'; } else { $test_table = $site->site_id . '_testmultisiteaccount'; } if (\DBUtil::table_exists($test_table)) { \DBUtil::drop_table($test_table); } } // endforeach; $sites_result $output['result'] = true; } // endif; $sites_result unset($site, $sites_result); } // endif; $act if (\Input::is_ajax()) { $response = new \Response(); // no cache $response->set_header('Cache-Control', 'no-cache, no-store, max-age=0, must-revalidate'); $response->set_header('Cache-Control', 'post-check=0, pre-check=0', false); $response->set_header('Expires', 'Sat, 26 Jul 1997 05:00:00 GMT'); $response->set_header('Pragma', 'no-cache'); // content type $response->set_header('Content-Type', 'application/json'); // set body if ($output == null) { $output = []; } $response->body(json_encode($output)); return $response; } } // <head> output ------------------------------------------- $output['page_title'] = $this->generateTitle('Test module plugin'); // <head> output ------------------------------------------- // breadcrumb ------------------------------------------------------------------------------------------------- $page_breadcrumb = []; $page_breadcrumb[0] = ['name' => \Lang::get('admin_admin_home'), 'url' => \Uri::create('admin')]; $page_breadcrumb[1] = ['name' => 'Test module plugin', 'url' => \Uri::create('testmod/admin/index')]; $page_breadcrumb[2] = ['name' => 'Test delete account on multisite table', 'url' => \Uri::main()]; $output['page_breadcrumb'] = $page_breadcrumb; unset($page_breadcrumb); // breadcrumb ------------------------------------------------------------------------------------------------- return $this->generatePage('admin/templates/index/accountMultisite_v', $output, false); }
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')); }
public function action_index() { // check permission if (\Model_AccountLevelPermission::checkAdminPermission('blog_perm', 'blog_manage_perm') == false) { \Session::set_flash('form_status', array('form_status' => 'error', 'form_status_message' => \Lang::get('admin_permission_denied', array('page' => \Uri::string())))); \Response::redirect(\Uri::create('admin')); } // check table exists and link to install page. if (!\DBUtil::table_exists('blog') && !\DBUtil::table_exists('blog_comment')) { echo \Extension\Html::anchor('blog/admin/setup', 'Installation required'); exit; } // read flash message for display errors. $form_status = \Session::get_flash('form_status'); if (isset($form_status['form_status']) && isset($form_status['form_status_message'])) { $output['form_status'] = $form_status['form_status']; $output['form_status_message'] = $form_status['form_status_message']; } unset($form_status); // list posts ----------------------------------------------------------------------------------------------------- $option['limit'] = \Model_Config::getval('content_admin_items_perpage'); $option['offset'] = trim(\Input::get('page')) != null ? ((int) \Input::get('page') - 1) * $option['limit'] : 0; $list_items = \Blog\Model_Blog::listItems($option); // pagination config $config['pagination_url'] = \Uri::main() . \Uri::getCurrentQuerystrings(true, true, false); $config['total_items'] = $list_items['total']; $config['per_page'] = $option['limit']; $config['uri_segment'] = 'page'; $config['num_links'] = 3; $config['show_first'] = true; $config['show_last'] = true; $config['first-inactive'] = "\n\t\t<li class=\"disabled\">{link}</li>"; $config['first-inactive-link'] = '<a href="#">{page}</a>'; $config['first-marker'] = '«'; $config['last-inactive'] = "\n\t\t<li class=\"disabled\">{link}</li>"; $config['last-inactive-link'] = '<a href="#">{page}</a>'; $config['last-marker'] = '»'; $config['previous-marker'] = '‹'; $config['next-marker'] = '›'; $pagination = \Pagination::forge('viewlogins_pagination', $config); $output['list_items'] = $list_items; $output['pagination'] = $pagination; unset($config, $list_accounts, $option, $pagination); // <head> output ---------------------------------------------------------------------------------------------- $output['page_title'] = $this->generateTitle(\Lang::get('blog')); // <head> output ---------------------------------------------------------------------------------------------- return $this->generatePage('admin/blog_v', $output, false); }
public function action_table_exists($table = '') { if ($table == '') { $data['json'] = false; } else { $data['json'] = DBUtil::table_exists($table); } $this->template->content = View::forge('ajax/view', $data); }
public static function run() { //Drop tables is exists if (\DBUtil::table_exists('auctions')) { \DBUtil::drop_table('auctions'); } if (\DBUtil::table_exists('parts')) { \DBUtil::drop_table('parts'); } if (\DBUtil::table_exists('balances')) { \DBUtil::drop_table('balances'); } if (\DBUtil::table_exists('bidlogs')) { \DBUtil::drop_table('bidlogs'); } if (\DBUtil::table_exists('ships')) { \DBUtil::drop_table('ships'); } //Drop foreign key in imported db \DBUtil::drop_foreign_key('auction', 'auction_part'); //Drop index in imported db \DBUtil::drop_index('auction', 'auction_part'); //Rename tables \DBUtil::rename_table('auction', 'auctions'); \DBUtil::rename_table('part', 'parts'); \DBUtil::rename_table('balance', 'balances'); \DBUtil::rename_table('bidslog', 'bidlogs'); \DBUtil::rename_table('ship', 'ships'); // Modify and add fields in table auctions \DBUtil::modify_fields('auctions', ['auctionID' => ['constraint' => 10, 'type' => 'varchar', 'name' => 'auc_id'], 'description' => ['constraint' => 80, 'type' => 'varchar', 'name' => 'title'], 'groupId' => ['constraint' => 10, 'type' => 'int', 'name' => 'part_id', 'null' => true], 'itemCount' => ['constraint' => 3, 'type' => 'int', 'name' => 'item_count'], 'wonDate' => ['type' => 'datetime', 'name' => 'won_date'], 'vendor' => ['constraint' => 40, 'type' => 'varchar', 'name' => 'vendor_id'], 'memo' => ['constraint' => 60, 'type' => 'varchar', 'null' => true], 'wonUser' => ['constraint' => 20, 'type' => 'varchar', 'name' => 'won_user', 'null' => true]]); \DBUtil::add_fields('auctions', ['created_at' => ['constraint' => 11, 'type' => 'int', 'null' => true], 'updated_at' => ['constraint' => 11, 'type' => 'int', 'null' => true]]); // Modify and add fields in table parts \DBUtil::modify_fields('parts', ['groupId' => ['constraint' => 10, 'type' => 'int', 'auto_increment' => true, 'unsigned' => true, 'name' => 'id'], 'boxNumber' => ['constraint' => 3, 'type' => 'int', 'name' => 'box_number', 'null' => true], 'partPrice' => ['constraint' => 5, 'type' => 'int', 'name' => 'price'], 'partStatus' => ['constraint' => 3, 'type' => 'int', 'name' => 'status'], 'shipNumber' => ['constraint' => 5, 'type' => 'int', 'name' => 'ship_number', 'null' => true], 'trackNumber' => ['constraint' => 15, 'type' => 'varchar', 'name' => 'tracking', 'null' => true], 'memo' => ['constraint' => 60, 'type' => 'varchar', 'null' => true]]); \DBUtil::add_fields('parts', ['created_at' => ['constraint' => 11, 'type' => 'int', 'null' => true], 'updated_at' => ['constraint' => 11, 'type' => 'int', 'null' => true]]); // Modify and add fields in table vendors \DBUtil::modify_fields('vendors', ['vendor' => ['constraint' => 40, 'type' => 'varchar', 'name' => 'name'], 'byNow' => ['constraint' => 1, 'type' => 'int', 'name' => 'by_now'], 'postIndex' => ['constraint' => 20, 'type' => 'varchar', 'name' => 'post_index', 'null' => true], 'address' => ['constraint' => 80, 'type' => 'varchar', 'null' => true], 'color' => ['constraint' => 10, 'type' => 'varchar', 'null' => true], 'memo' => ['constraint' => 200, 'type' => 'varchar', 'null' => true]]); \DBUtil::add_fields('vendors', ['created_at' => ['constraint' => 11, 'type' => 'int', 'null' => true], 'updated_at' => ['constraint' => 11, 'type' => 'int', 'null' => true]]); // Replace vendor name to vendor id in auctions and add vendor if not exists try { $auctions = \DB::select_array(['id', 'vendor_id'])->from('auctions')->execute(); \DB::start_transaction(); foreach ($auctions as $auction) { $vendor = \DB::select('id')->from('vendors')->where('name', '=', $auction['vendor_id'])->execute()->as_array(); if (!empty($vendor)) { \DB::update('auctions')->value("vendor_id", $vendor[0]['id'])->where('id', '=', $auction['id'])->execute(); } else { $result = \DB::insert('vendors')->set(['name' => $auction['vendor_id']])->execute(); \DB::update('auctions')->value("vendor_id", $result[0])->where('id', '=', $auction['id'])->execute(); } } // Modify field type from varchat to int in auctions \DBUtil::modify_fields('auctions', ['vendor_id' => ['constraint' => 11, 'type' => 'int']]); \DB::commit_transaction(); } catch (\Exception $e) { \DB::rollback_transaction(); print "Replace vendor name to vendor id in auctions and add vendor if not exists was filed\n"; } // Replace won_user to user_id in auctions try { $users = \DB::select_array(['id', 'username'])->from('users')->execute(); \DB::start_transaction(); foreach ($users as $user) { \DB::update('auctions')->value('won_user', $user['id'])->where('won_user', '=', $user['username'])->execute(); } \DB::commit_transaction(); // Modify field type from varchat to int in auctions \DBUtil::modify_fields('auctions', ['won_user' => ['constraint' => 11, 'type' => 'int', 'name' => 'user_id']]); } catch (\Exception $e) { \DB::rollback_transaction(); print "Replace won_user to user_id in auctions was filed\n"; } // Add index to auctions and parts \DBUtil::create_index('auctions', 'part_id', 'part_id'); \DBUtil::create_index('auctions', 'won_date', 'won_date'); \DBUtil::create_index('parts', 'status', 'status'); \DBUtil::create_index('vendors', 'name', 'name'); // delete auc_id g143869725 !!!! print "Data base successfully converted\n"; }
/** * Generate MySQL Documentation for HTML. * * Usage (from command line): * * php oil refine mydoc:html <table_schema> <output_dir = "app/tmp/"> */ public static function html($table_schema = null, $dir = null) { if (empty($table_schema)) { static::help(); exit; } empty($dir) and $dir = APPPATH . 'tmp' . DS; $dir = rtrim($dir, DS) . DS . 'mydoc' . DS; /** * connect to db */ $ret = static::connect($table_schema); /** * delete and create mydoc dir */ if (file_exists($dir)) { if (!\Cli::option('f') and !\Cli::option('force')) { \Cli::write(realpath($dir) . ' already exist, please use -f option to force delete and generate.', 'red'); exit; } $ret = \File::delete_dir($dir); if ($ret === false) { \Cli::write("Could not delete directory \"{$dir}\"", 'red'); exit; } } $ret = mkdir($dir, 0777, true); if ($ret === false) { \Cli::write("Could not create directory \"{$dir}\"", 'red'); exit; } \File::copy_dir(__DIR__ . DS . '..' . DS . 'assets', $dir . 'assets'); /** * generate index.html */ $migration_table_name = \Config::get('migrations.table', 'migration'); $migration = array(); if (\DBUtil::table_exists($migration_table_name)) { $migration = \Db::select()->from($migration_table_name)->order_by('migration', 'desc')->limit(1)->execute()->as_array(); } $html = \View::forge('mydoc/index', array('migration' => $migration))->render(); \File::create($dir, 'index.html', $html); /** * get tables */ $tables = array_flip(\DB::list_tables()); /** * unset ignore tables */ foreach (\Config::get('mydoc.ignore_tables', array()) as $ignore_table_name) { if (isset($tables[$ignore_table_name])) { unset($tables[$ignore_table_name]); } } $ignore_table_regex = \Config::get('mydoc.ignore_table_regex'); foreach ($tables as $table_name => $tmp) { if (!empty($ignore_table_regex)) { if (preg_match($ignore_table_regex, $table_name)) { unset($tables[$table_name]); continue; } } $tables[$table_name] = array('indexes' => array(), 'foreign_keys' => array(), 'triggers' => array()); } /** * check table count */ if (count($tables) === 0) { \Cli::write("No tables in \"{$table_schema}\"", 'red'); exit; } /** * get foreign keys */ $sql = 'select distinct table_name, column_name, referenced_table_name, referenced_column_name from information_schema.key_column_usage where referenced_table_name is not null and referenced_column_name is not null and table_schema = :table_schema'; $foreign_keys = \Db::query($sql)->bind('table_schema', $table_schema)->execute()->as_array(); foreach ($foreign_keys as $foreign_key) { if (isset($tables[$foreign_key['table_name']])) { $tables[$foreign_key['table_name']]['foreign_keys'][$foreign_key['column_name']] = $foreign_key; } } /** * get indexes */ $sql = 'select distinct table_name, index_name, non_unique, column_name, comment from information_schema.statistics where table_schema = :table_schema'; $indexes = \Db::query($sql)->bind('table_schema', $table_schema)->execute()->as_array(); foreach ($indexes as $index) { if (isset($tables[$index['table_name']])) { $tables[$index['table_name']]['indexes'][$index['index_name']][$index['column_name']] = $index; } } /** * get triggers */ $sql = 'select distinct trigger_name, event_manipulation, event_object_table, action_statement, action_timing, definer from information_schema.triggers where trigger_schema = :trigger_schema'; $triggers = \Db::query($sql)->bind('trigger_schema', $table_schema)->execute()->as_array(); foreach ($triggers as $trigger) { if (isset($tables[$trigger['event_object_table']])) { $tables[$trigger['event_object_table']]['triggers'][] = $trigger; } } /** * generate tables.html */ $html = \View::forge('mydoc/tables', array('tables' => array_keys($tables)))->render(); \File::create($dir, 'tables.html', $html); /** * generate table_*.html */ foreach ($tables as $table_name => $infos) { $columns = \DB::list_columns($table_name); foreach ($columns as &$column) { // do we have a data_type defined? If not, use the generic type isset($column['data_type']) or $column['data_type'] = $column['type']; if ($column['data_type'] == 'enum') { $column['data_type'] .= "('" . implode("', '", $column['options']) . "')"; } $column['_length'] = null; foreach (array('length', 'character_maximum_length', 'display') as $idx) { // check if we have such a column, and filter out some default values if (isset($column[$idx]) and !in_array($column[$idx], array('65535', '16777215', '4294967295'))) { $column['_length'] = $column[$idx]; break; } } $column['_extras'] = array(); if (strpos(\Str::lower($column['key']), 'pri') !== false) { $column['_extras'][] = 'PK'; } if (strpos(\Str::lower($column['key']), 'uni') !== false) { $column['_extras'][] = 'UI'; } if (!empty($column['extra'])) { if (strpos($column['extra'], 'auto_increment') !== false) { $column['_extras'][] = 'AI'; } } $column['_foreign_key'] = null; if (!empty($infos['foreign_keys'])) { $foreign_key = \Arr::get($infos['foreign_keys'], $column['name'], array()); if (!empty($foreign_key)) { $column['_foreign_key'] = $foreign_key; $column['_extras'][] = 'FK'; } } if (!empty($column['_foreign_key'])) { $column['_parent_table_name'] = $column['_foreign_key']['referenced_table_name']; } else { $column['_foreign_key'] = array('referenced_table_name' => null, 'referenced_column_name' => null); if (0 < preg_match('/^.+_id$/', $column['name'])) { $parent_table_name = str_replace('_id', '', $column['name']); if (isset($tables[$parent_table_name = \Inflector::singularize($parent_table_name)])) { $column['_foreign_key'] = array('referenced_table_name' => $parent_table_name, 'referenced_column_name' => 'id'); } else { if (isset($tables[$parent_table_name = \Inflector::pluralize($parent_table_name)])) { $column['_foreign_key'] = array('referenced_table_name' => $parent_table_name, 'referenced_column_name' => 'id'); } } } } } $html = \View::forge('mydoc/table', array('table_name' => $table_name, 'columns' => $columns, 'infos' => $infos))->render(); \File::create($dir, 'table_' . $table_name . '.html', $html); } /** * generate indexes.html */ $html = \View::forge('mydoc/indexes', array('tables' => $tables))->render(); \File::create($dir, 'indexes.html', $html); /** * generate triggers.html */ $html = \View::forge('mydoc/triggers', array('tables' => $tables))->render(); \File::create($dir, 'triggers.html', $html); \Cli::write("Generated MySQL Documentation in \"{$dir}\"", 'green'); exit; }