示例#1
0
 /**
  * Create yaml files from database data.
  *
  * Usage (from command line):
  *
  * php oil r dbfixt:generate [-n=5] [-o=/tmp] <table1> [<table2> [...]]
  *
  * @return string
  */
 public static function generate()
 {
     $num = Cli::option('n') ? (int) Cli::option('n') : 5;
     $dir = Cli::option('o');
     if (is_null($dir)) {
         $dir = APPPATH . 'tests/fixture';
         if (!is_dir($dir)) {
             mkdir($dir);
         }
     } else {
         if (!is_dir($dir)) {
             return Cli::color('No such directory: ' . $dir, 'red');
         }
     }
     $args = func_get_args();
     foreach ($args as $table) {
         if (DBUtil::table_exists($table)) {
             $result = DB::select('*')->from($table)->limit($num)->execute();
             $data = $result->as_array();
             static::setToYaml($dir, $data, $table);
         } elseif (Mongo_Db::instance()->get_collection($table)) {
             $mongo = Mongo_Db::instance();
             $data = $mongo->limit($num)->get($table);
             static::setToYaml($dir, $data, $table);
         } else {
             echo Cli::color('No such table: ' . $table, 'red') . PHP_EOL;
         }
     }
 }
示例#2
0
 public static function down_run($table_name)
 {
     $table_exists = DBUtil::table_exists($table_name);
     if (!$table_exists) {
         return false;
     }
     DBUtil::drop_table($table_name);
 }
示例#3
0
 public static function up()
 {
     $table_exists = DBUtil::table_exists(self::$_table_name);
     if ($table_exists) {
         return false;
     }
     DBUtil::create_table(self::$_table_name, ['product_id' => ['constraint' => 11, 'type' => 'int'], 'category_id' => ['constraint' => 11, 'type' => 'int']], ['product_id', 'category_id'], true, 'InnoDB', 'utf8_general_ci');
 }
示例#4
0
 public static function up()
 {
     $table_exists = DBUtil::table_exists(self::$_table_name);
     if ($table_exists) {
         return false;
     }
     DBUtil::create_table(self::$_table_name, ['id' => ['constraint' => 11, 'type' => 'int', 'auto_increment' => true], 'group_id' => ['constraint' => 50, 'type' => 'varchar'], 'group_name' => ['constraint' => 50, 'type' => 'varchar'], 'privacy' => ['constraint' => 255, 'type' => 'varchar'], 'created_at' => ['type' => 'timestamp', 'default' => DB::expr('CURRENT_TIMESTAMP')], 'updated_at' => ['type' => 'timestamp', 'default' => '0000-00-00 00:00:00']], ['id'], true, 'InnoDB', 'utf8_general_ci');
     DBUtil::create_index(self::$_table_name, 'group_id', 'group_id');
 }
示例#5
0
文件: config.php 项目: khoapld/wjshop
 public static function up()
 {
     $table_exists = DBUtil::table_exists(self::$_table_name);
     if ($table_exists) {
         return false;
     }
     DBUtil::create_table(self::$_table_name, ['id' => ['constraint' => 11, 'type' => 'int', 'auto_increment' => true], 'maintenance' => ['constraint' => 1, 'type' => 'tinyint', 'default' => 0], 'email' => ['constraint' => 255, 'type' => 'varchar', 'null' => true], 'telephone' => ['constraint' => 12, 'type' => 'varchar', 'null' => true], 'address' => ['constraint' => 255, 'type' => 'varchar', 'null' => true], 'fb_url' => ['constraint' => 255, 'type' => 'varchar', 'null' => true], 'shop_name' => ['constraint' => 255, 'type' => 'varchar', 'null' => true], 'created_at' => ['type' => 'timestamp', 'default' => DB::expr('CURRENT_TIMESTAMP')], 'updated_at' => ['type' => 'timestamp', 'default' => '0000-00-00 00:00:00']], ['id'], true, 'InnoDB', 'utf8_general_ci');
     DBUtil::create_index(self::$_table_name, 'maintenance', 'maintenance');
 }
示例#6
0
 public static function up()
 {
     $table_exists = DBUtil::table_exists(self::$_table_name);
     if ($table_exists) {
         return false;
     }
     DBUtil::create_table(self::$_table_name, ['id' => ['constraint' => 11, 'type' => 'int', 'auto_increment' => true], 'parent_id' => ['constraint' => 11, 'type' => 'int'], 'provider' => ['constraint' => 255, 'type' => 'varchar'], 'uid' => ['constraint' => 50, 'type' => 'varchar'], 'secret' => ['constraint' => 255, 'type' => 'varchar', 'null' => true], 'access_token' => ['constraint' => 255, 'type' => 'varchar', 'default' => ''], 'expires' => ['constraint' => 11, 'type' => 'int', 'default' => 0], 'refresh_token' => ['constraint' => 255, 'type' => 'varchar', 'null' => true], 'created_at' => ['constraint' => 11, 'type' => 'int', 'default' => 0]], ['id'], true, 'InnoDB', 'utf8_general_ci');
     DBUtil::create_index(self::$_table_name, 'parent_id', 'parent_id');
 }
示例#7
0
 public static function up()
 {
     $table_exists = DBUtil::table_exists(self::$_table_name);
     if ($table_exists) {
         return false;
     }
     DBUtil::create_table(self::$_table_name, ['order_item_id' => ['constraint' => 11, 'type' => 'int', 'auto_increment' => true], 'order_id' => ['constraint' => 11, 'type' => 'int'], 'product_id' => ['constraint' => 11, 'type' => 'int'], 'product_price' => ['constraint' => 11, 'type' => 'int'], 'quantity' => ['constraint' => 11, 'type' => 'int'], 'created_at' => ['type' => 'timestamp', 'default' => DB::expr('CURRENT_TIMESTAMP')]], ['order_item_id'], true, 'InnoDB', 'utf8_general_ci');
     DBUtil::create_index(self::$_table_name, 'order_id', 'order_id');
     DBUtil::create_index(self::$_table_name, 'product_id', 'product_id');
 }
示例#8
0
 public static function up()
 {
     $table_exists = DBUtil::table_exists(self::$_table_name);
     if ($table_exists) {
         return false;
     }
     DBUtil::create_table(self::$_table_name, ['id' => ['constraint' => 11, 'type' => 'int', 'auto_increment' => true], 'code' => ['constraint' => 50, 'type' => 'varchar'], 'product_name' => ['type' => 'text'], 'product_description' => ['type' => 'text', 'null' => true], 'product_info' => ['type' => 'text', 'null' => true], 'note' => ['type' => 'text', 'null' => true], 'product_photo' => ['constraint' => 50, 'type' => 'varchar', 'null' => true], 'status' => ['constraint' => 1, 'type' => 'tinyint', 'default' => 2], 'highlight' => ['constraint' => 1, 'type' => 'tinyint', 'default' => 0], 'created_at' => ['type' => 'timestamp', 'default' => DB::expr('CURRENT_TIMESTAMP')], 'updated_at' => ['type' => 'timestamp', 'default' => '0000-00-00 00:00:00']], ['id'], true, 'InnoDB', 'utf8_general_ci');
     DBUtil::create_index(self::$_table_name, 'code', 'code');
     DBUtil::create_index(self::$_table_name, 'status', 'status');
     DBUtil::create_index(self::$_table_name, 'highlight', 'highlight');
 }
示例#9
0
文件: order.php 项目: khoapld/wjshop
 public static function up()
 {
     $table_exists = DBUtil::table_exists(self::$_table_name);
     if ($table_exists) {
         return false;
     }
     DBUtil::create_table(self::$_table_name, ['order_id' => ['constraint' => 11, 'type' => 'int', 'auto_increment' => true], 'user_id' => ['constraint' => 11, 'type' => 'int'], 'message' => ['type' => 'text', 'null' => true], 'order_email' => ['type' => 'text', 'null' => true], 'order_gender' => ['type' => 'text', 'null' => true], 'order_last_name' => ['type' => 'text', 'null' => true], 'order_first_name' => ['type' => 'text', 'null' => true], 'order_last_name_kana' => ['type' => 'text', 'null' => true], 'order_first_name_kana' => ['type' => 'text', 'null' => true], 'order_tel' => ['type' => 'text', 'null' => true], 'order_fax' => ['type' => 'text', 'null' => true], 'order_zip' => ['type' => 'text', 'null' => true], 'order_addr' => ['type' => 'text', 'null' => true], 'payment_total' => ['constraint' => 11, 'type' => 'int'], 'payment_method' => ['constraint' => 1, 'type' => 'int'], 'payment_status' => ['constraint' => 1, 'type' => 'int', 'default' => 1], 'payment_date' => ['type' => 'timestamp', 'default' => '0000-00-00 00:00:00'], 'del_flg' => ['constraint' => 1, 'type' => 'tinyint', 'default' => 0], 'created_at' => ['type' => 'timestamp', 'default' => DB::expr('CURRENT_TIMESTAMP')], 'updated_at' => ['type' => 'timestamp', 'default' => '0000-00-00 00:00:00']], ['order_id'], true, 'InnoDB', 'utf8_general_ci');
     DBUtil::create_index(self::$_table_name, 'user_id', 'user_id');
     DBUtil::create_index(self::$_table_name, 'payment_method', 'payment_method');
     DBUtil::create_index(self::$_table_name, 'payment_status', 'payment_status');
     DBUtil::create_index(self::$_table_name, 'del_flg', 'del_flg');
 }
示例#10
0
文件: user.php 项目: khoapld/wjshop
 public static function up()
 {
     $table_exists = DBUtil::table_exists(self::$_table_name);
     if ($table_exists) {
         return false;
     }
     DBUtil::create_table(self::$_table_name, ['id' => ['constraint' => 11, 'type' => 'int', 'auto_increment' => true], 'username' => ['constraint' => 32, 'type' => 'varchar'], 'email' => ['constraint' => 255, 'type' => 'varchar'], 'password' => ['constraint' => 255, 'type' => 'varchar'], 'login_hash' => ['constraint' => 255, 'type' => 'varchar', 'null' => true], 'last_login' => ['constraint' => 11, 'type' => 'int', 'default' => 0], 'group' => ['constraint' => 11, 'type' => 'int', 'default' => 1], 'password_code' => ['constraint' => 32, 'type' => 'varchar', 'null' => true], 'full_name' => ['constraint' => 255, 'type' => 'varchar', 'null' => true], 'gender' => ['constraint' => 1, 'type' => 'int', 'default' => 0], 'birthday' => ['constraint' => 10, 'type' => 'varchar', 'null' => true], 'address' => ['constraint' => 255, 'type' => 'varchar', 'null' => true], 'telephone' => ['constraint' => 12, 'type' => 'varchar', 'null' => true], 'user_photo' => ['constraint' => 50, 'type' => 'varchar', 'null' => true], 'created_at' => ['type' => 'timestamp', 'default' => DB::expr('CURRENT_TIMESTAMP')], 'updated_at' => ['type' => 'timestamp', 'default' => '0000-00-00 00:00:00']], ['id'], true, 'InnoDB', 'utf8_general_ci');
     DBUtil::create_index(self::$_table_name, 'username', 'username');
     DBUtil::create_index(self::$_table_name, 'email', 'email');
     DBUtil::create_index(self::$_table_name, 'password', 'password');
     DBUtil::create_index(self::$_table_name, 'login_hash', 'login_hash');
     DBUtil::create_index(self::$_table_name, 'group', 'group');
 }
示例#11
0
 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);
 }