function down() { // get the drivers defined $drivers = normalize_driver_types(); if (in_array('Simpleauth', $drivers)) { // get the tablename \Config::load('simpleauth', true); $basetable = \Config::get('simpleauth.table_name', 'users'); // make sure the configured DB is used \DBUtil::set_connection(\Config::get('simpleauth.db_connection', null)); } elseif (in_array('Ormauth', $drivers)) { // get the tablename \Config::load('ormauth', true); $basetable = \Config::get('ormauth.table_name', 'users'); // make sure the configured DB is used \DBUtil::set_connection(\Config::get('ormauth.db_connection', null)); } else { $basetable = 'users'; } \DBUtil::drop_table($basetable . '_sessionscopes'); \DBUtil::drop_table($basetable . '_sessions'); \DBUtil::drop_table($basetable . '_scopes'); \DBUtil::drop_table($basetable . '_clients'); // reset any DBUtil connection set \DBUtil::set_connection(null); }
/** * This method gets ran when a valid method name is not used in the command. * * Usage (from command line): * * php oil r setuptables:index "arguments" * * @return string */ public function index($args = NULL) { echo "\n==========================================="; echo "\nRunning task [Setuptables:Index]"; echo "\n-------------------------------------------\n\n"; /*************************** Put in TASK DETAILS HERE **************************/ // 初期ユーザー定義 $init_users = array(array('name' => 'codex', 'password' => '1234', 'group' => 6)); // データベース接続 \DBUtil::set_connection(null); // {{{ トランケート $truncates = array('', '_permissions', '_metadata', '_user_permissions', '_group_permissions', '_role_permissions'); foreach ($truncates as $truncate) { \DBUtil::truncate_table('users' . $truncate); } // }}} // {{{ 初期ユーザー追加 foreach ($init_users as $init_user) { // ユーザー名 $key = $init_user['name']; // パスワード $password = $init_user['password']; // メールアドレス $email = $key . '@xenophy.com'; // グループ $group = $init_user['group']; // 追加 $user = \Auth\Model\Auth_User::forge()->find(\Auth::create_user($key, $password, $email, $group)); // 保存 $user->save(); } // }}} }
function down() { // 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') . '_providers'; // make sure the configured DB is used \DBUtil::set_connection(\Config::get('simpleauth.db_connection', null)); } elseif (in_array('Ormauth', $drivers)) { // get the tablename \Config::load('ormauth', true); $table = \Config::get('ormauth.table_name', 'users') . '_providers'; // make sure the configured DB is used \DBUtil::set_connection(\Config::get('ormauth.db_connection', null)); } if (isset($table)) { // drop the users remote table \DBUtil::drop_table($table); } // reset any DBUtil connection set \DBUtil::set_connection(null); }
public static function delete_timeline4id($timeline_id) { $delete_target_notice_cache_member_ids = array(); $writable_connection = \MyOrm\Model::connection(true); \DBUtil::set_connection($writable_connection); \DB::start_transaction(); if (is_enabled('notice')) { \Notice\Site_NoOrmModel::delete_member_watch_content_multiple4foreign_data('timeline', $timeline_id); $notice_ids = \Notice\Site_NoOrmModel::get_notice_ids4foreign_data('timeline', $timeline_id); $delete_target_notice_cache_member_ids = \Notice\Site_NoOrmModel::get_notice_status_member_ids4notice_ids($notice_ids); \Notice\Site_NoOrmModel::delete_notice_multiple4ids($notice_ids); } if (!\DB::delete('timeline')->where('id', $timeline_id)->execute()) { throw new \FuelException('Failed to delete timeline. id:' . $timeline_id); } \DB::commit_transaction(); \DBUtil::set_connection(null); // delete caches if ($delete_target_notice_cache_member_ids) { foreach ($delete_target_notice_cache_member_ids as $member_id) { \Notice\Site_Util::delete_unread_count_cache($member_id); } } Site_Util::delete_cache($timeline_id); }
function down() { // get the drivers defined $drivers = normalize_driver_types(); if (in_array('Ormauth', $drivers)) { // get the tablename \Config::load('ormauth', true); $table = \Config::get('ormauth.table_name', 'users'); // make sure the configured DB is used \DBUtil::set_connection(\Config::get('ormauth.db_connection', null)); // drop the admin_users_perms table \DBUtil::drop_table($table . '_permissions'); } // reset any DBUtil connection set \DBUtil::set_connection(null); }
function down() { // get the drivers defined $drivers = normalize_driver_types(); if (in_array('Ormauth', $drivers)) { // get the tablename \Config::load('ormauth', true); $table = \Config::get('ormauth.table_name', 'users'); // make sure the configured DB is used \DBUtil::set_connection($connection = \Config::get('ormauth.db_connection', null)); // modify the filter field to add the 'remove' filter \DB::update($table . '_roles')->set(array('filter' => 'D'))->where('filter', '=', 'R')->execute($connection); \DBUtil::modify_fields($table . '_roles', array('filter' => array('type' => 'enum', 'constraint' => "'', 'A', 'D'", 'default' => ''))); } // reset any DBUtil connection set \DBUtil::set_connection(null); }
public static function delete_album_image_multiple4ids($album_image_ids = array(), $with_delete_timeline = false) { if (!is_array($album_image_ids)) { $album_image_ids = (array) $album_image_ids; } $delete_target_notice_cache_member_ids = array(); $delete_target_timeline_ids = array(); $writable_connection = \MyOrm\Model::connection(true); \DBUtil::set_connection($writable_connection); \DB::start_transaction(); foreach ($album_image_ids as $album_image_id) { if (is_enabled('notice')) { \Notice\Site_NoOrmModel::delete_member_watch_content_multiple4foreign_data('album_image', $album_image_id); $notice_ids = \Notice\Site_NoOrmModel::get_notice_ids4foreign_data('album_image', $album_image_id); $delete_target_notice_cache_member_ids += \Notice\Site_NoOrmModel::get_notice_status_member_ids4notice_ids($notice_ids); \Notice\Site_NoOrmModel::delete_notice_multiple4ids($notice_ids); } if (is_enabled('timeline') && $with_delete_timeline) { $delete_target_timeline_ids += \timeline\site_noormmodel::delete_timeline_multiple4foreign_data('album_image', $album_image_id); } } $file_names = \Util_Orm::conv_col2array(Model_AlbumImage::get4ids($album_image_ids), 'file_name'); \DB::delete('album_image')->where('id', 'in', $album_image_ids)->execute(); \DB::commit_transaction(); \DBUtil::set_connection(null); \DB::start_transaction(); if ($files = \Model_File::get4names($file_names)) { foreach ($files as $file) { $file->delete(); } } \DB::commit_transaction(); // delete caches if ($delete_target_notice_cache_member_ids) { foreach ($delete_target_notice_cache_member_ids as $member_id) { \Notice\Site_Util::delete_unread_count_cache($member_id); } } if ($delete_target_timeline_ids) { foreach ($delete_target_timeline_ids as $timeline_id) { \Timeline\Site_Util::delete_cache($timeline_id); } } }
function down() { // get the drivers defined $drivers = normalize_driver_types(); if (in_array('Ormauth', $drivers)) { // get the tablename \Config::load('ormauth', true); $table = \Config::get('ormauth.table_name', 'users'); // make sure the configured DB is used \DBUtil::set_connection(\Config::get('ormauth.db_connection', null)); // empty the user, group and role tables \DBUtil::truncate_table($table); \DBUtil::truncate_table($table . '_groups'); \DBUtil::truncate_table($table . '_roles'); \DBUtil::truncate_table($table . '_group_roles'); } // reset any DBUtil connection set \DBUtil::set_connection(null); }
function down() { // get the driver used \Config::load('auth', true); $drivers = \Config::get('auth.driver', array()); is_array($drivers) or $drivers = array($drivers); if (in_array('Ormauth', $drivers)) { // get the tablename \Config::load('ormauth', true); $table = \Config::get('ormauth.table_name', 'users'); // make sure the configured DB is used \DBUtil::set_connection(\Config::get('ormauth.db_connection', null)); // drop the admin_users_role table \DBUtil::drop_table($table . '_roles'); // drop the admin_users_role_perms table \DBUtil::drop_table($table . '_role_permissions'); } // reset any DBUtil connection set \DBUtil::set_connection(null); }
function down() { // get the driver used \Config::load('auth', true); $drivers = \Config::get('auth.driver', array()); is_array($drivers) or $drivers = array($drivers); if (in_array('Ormauth', $drivers)) { // get the tablename \Config::load('ormauth', true); $basetable = \Config::get('ormauth.table_name', 'users'); // make sure the configured DB is used \DBUtil::set_connection(\Config::get('ormauth.db_connection', null)); \DBUtil::drop_fields($basetable . '_user_permissions', array('id')); \DBUtil::create_index($basetable . '_user_permissions', array('user_id', 'perms_id'), '', 'PRIMARY'); \DBUtil::drop_fields($basetable . '_group_permissions', array('id')); \DBUtil::create_index($basetable . '_group_permissions', array('group_id', 'perms_id'), '', 'PRIMARY'); \DBUtil::drop_fields($basetable . '_role_permissions', array('id')); \DBUtil::create_index($basetable . '_role_permissions', array('role_id', 'perms_id'), '', 'PRIMARY'); } // reset any DBUtil connection set \DBUtil::set_connection(null); }
/** * 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); }