Exemple #1
0
 /**
  * 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();
     }
     // }}}
 }
 public function down()
 {
     \DBUtil::truncate_table('location');
     \DBUtil::truncate_table('events');
     \DBUtil::truncate_table('agenda');
     \DBUtil::truncate_table('countries');
     \DBUtil::truncate_table('users');
 }
 protected static function empty_table($table)
 {
     if (DBUtil::table_exists($table)) {
         DBUtil::truncate_table($table);
     } else {
         exit('No such table: ' . $table . PHP_EOL);
     }
 }
Exemple #4
0
 public function action_openid_reset()
 {
     \DBUtil::truncate_table('users_openid');
     $auth = Auth::instance();
     echo '<p>' . $auth->create_user($group = 100) . '</p>';
     echo '<p>' . $auth->create_user($group = 1) . '</p>';
     echo '<p>' . $auth->create_user($group = 0) . '</p>';
     echo 'done';
 }
    public function up()
    {
        /*         * *********************************************************************************************
                  monitor_type
                 * ********************************************************************************************* */
        $monitor_type = \DBUtil::checkIfExist('monitor_type');
        if (!$monitor_type) {
            \DBUtil::create_table('monitor_type', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'name' => array('constraint' => 250, 'type' => 'varchar')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            \DBUtil::truncate_table('monitor_type');
            // insert default connector type
            list($insert_id, $rows_affected) = \DB::insert('monitor_type')->columns(array('id', 'name'))->values(array('1', 'Nagios'))->execute();
        }
        /*         * *********************************************************************************************
                  monitor_source
                 * ********************************************************************************************* */
        $monitor_source = \DBUtil::checkIfExist('monitor_source');
        if (!$monitor_source) {
            \DBUtil::create_table('monitor_source', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'typeID' => array('constraint' => 11, 'type' => 'int'), 'user' => array('constraint' => 250, 'type' => 'varchar'), 'pass' => array('constraint' => 250, 'type' => 'varchar'), 'content' => array('type' => 'text', 'null' => true), 'meta_update_time' => array('constraint' => 11, 'type' => 'int', 'default' => '0'), 'meta_update_user' => array('constraint' => 11, 'type' => 'int', 'default' => '0')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for wiki
            \DBUtil::create_index('monitor_source', 'typeID');
        }
        /*         * *********************************************************************************************
                  monitoring
                 * ********************************************************************************************* */
        $monitoring = \DBUtil::checkIfExist('monitoring');
        if (!$monitoring) {
            \DBUtil::create_table('monitoring', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'iconw' => array('constraint' => 11, 'type' => 'int'), 'iconu' => array('constraint' => 11, 'type' => 'int'), 'iconc' => array('constraint' => 11, 'type' => 'int'), 'osdw' => array('constraint' => 11, 'type' => 'int'), 'osdu' => array('constraint' => 11, 'type' => 'int'), 'osdc' => array('constraint' => 11, 'type' => 'int'), 'soundc' => array('constraint' => 11, 'type' => 'int'), 'soundw' => array('constraint' => 11, 'type' => 'int'), 'soundu' => array('constraint' => 11, 'type' => 'int'), 'meta_update_user' => array('constraint' => 11, 'type' => 'int', 'default' => '0')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for wiki
            //\DBUtil::create_index('vps', 'masterID');
            \DBUtil::truncate_table('monitoring');
            // insert default connector type
            list($insert_id, $rows_affected) = \DB::insert('monitoring')->columns(array('id', 'iconw', 'iconu', 'iconc', 'osdw', 'osdu', 'osdc', 'soundc', 'soundw', 'soundu', 'meta_update_user'))->values(array('1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1'))->execute();
        }
        /*         * *********************************************************************************************
                  FOREIGN KEYS
                 * ********************************************************************************************* */
        //monitor
        if (!$monitor_source) {
            $query = \DB::query('ALTER TABLE `monitor_source`
				ADD CONSTRAINT `monitor_ibfk_1` FOREIGN KEY (`typeID`) REFERENCES `monitor_type` (`id`) 
				ON DELETE CASCADE ON UPDATE CASCADE')->execute();
        }
        /*
         * UPDATE version 
         * 
         * */
        $now = time();
        list($insert_id, $rows_affected) = \DB::insert('version')->columns(array('value', 'meta_update_time'))->values(array('1.08', $now))->execute();
    }
 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');
         // 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');
     }
 }
 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);
 }
Exemple #8
0
 public function action_delete_log($account_id = '')
 {
     // clear redirect referrer
     \Session::delete('submitted_redirect');
     // set redirect url
     $redirect = $this->getAndSetSubmitRedirection();
     // check permission
     if (\Model_AccountLevelPermission::checkAdminPermission('account_perm', 'account_deletelogin_log_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($redirect);
     }
     if (!is_numeric($account_id)) {
         \Response::redirect($redirect);
     }
     // load language
     \Lang::load('account');
     \Lang::load('accountlogins');
     $act = trim(\Input::post('act'));
     if (\Extension\NoCsrf::check()) {
         // if actions
         if ($act == 'del') {
             \Model_AccountLogins::query()->where('account_id', $account_id)->delete();
         } elseif ($act == 'truncate') {
             \DBUtil::truncate_table('account_logins');
         }
     }
     // go back
     \Response::redirect($redirect);
 }
 public function down()
 {
     \DBUtil::truncate_table($this->table_name);
 }
Exemple #10
0
    function up()
    {
        $user = \DB::select('id')->from('users')->limit(1)->execute()->current();
        /*         * *********************************************************************************************
                  building
                 * ********************************************************************************************* */
        $building = \DBUtil::checkIfExist('building');
        if (!$building) {
            \DBUtil::create_table('building', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'name' => array('constraint' => 250, 'type' => 'varchar'), 'name_short' => array('constraint' => 250, 'type' => 'varchar', 'null' => true), 'notes' => array('type' => 'text', 'null' => true), 'meta_default_data' => array('constraint' => 11, 'type' => 'int', 'null' => true, 'default' => '0'), 'meta_update_time' => array('constraint' => 11, 'type' => 'int', 'default' => '0'), 'meta_update_user' => array('constraint' => 11, 'type' => 'int', 'default' => '0')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            // insert default building
            list($building_id, $rows_affected) = \DB::insert('building')->columns(array('id', 'name', 'name_short', 'notes', 'meta_default_data', 'meta_update_time', 'meta_update_user'))->values(array('1', 'Building Demo', '', '', '', time(), $user['id']))->execute();
        }
        /*         * *********************************************************************************************
                  cables
                 * ********************************************************************************************* */
        $cables = \DBUtil::checkIfExist('cables');
        if (!$cables) {
            \DBUtil::create_table('cables', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'dev1' => array('constraint' => 11, 'type' => 'int'), 'port1' => array('constraint' => 11, 'type' => 'int'), 'name1' => array('constraint' => 4, 'type' => 'int'), 'dev2' => array('constraint' => 11, 'type' => 'int'), 'port2' => array('constraint' => 11, 'type' => 'int'), 'name2' => array('constraint' => 4, 'type' => 'int'), 'type' => array('constraint' => 11, 'type' => 'int'), 'meta_update_time' => array('constraint' => 11, 'type' => 'int', 'default' => '0'), 'meta_update_user' => array('constraint' => 11, 'type' => 'int', 'default' => '0')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for cable devices
            \DBUtil::create_index('cables', 'dev1');
            \DBUtil::create_index('cables', 'dev2');
        }
        /*         * *********************************************************************************************
                  connector speed
                 * ********************************************************************************************* */
        $connector_speed = \DBUtil::checkIfExist('connector_speed');
        if (!$connector_speed) {
            \DBUtil::create_table('connector_speed', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'name' => array('constraint' => 250, 'type' => 'varchar')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            \DBUtil::truncate_table('connector_speed');
            // insert default connector speed
            list($insert_id, $rows_affected) = \DB::insert('connector_speed')->columns(array('id', 'name'))->values(array('1', '10 MBs'), array('2', '10/100 MBs'), array('3', '1 GBs'), array('4', '10 GBs'))->execute();
        }
        /*         * *********************************************************************************************
                  connector type
                 * ********************************************************************************************* */
        $connector_type = \DBUtil::checkIfExist('connector_type');
        if (!$connector_type) {
            \DBUtil::create_table('connector_type', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'name' => array('constraint' => 250, 'type' => 'varchar')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            \DBUtil::truncate_table('connector_type');
            // insert default connector type
            list($insert_id, $rows_affected) = \DB::insert('connector_type')->columns(array('id', 'name'))->values(array('1', 'RJ45'), array('2', 'Fiber LC'))->execute();
        }
        /*         * *********************************************************************************************
                  device
                 * ********************************************************************************************* */
        $device = \DBUtil::checkIfExist('device');
        if (!$device) {
            \DBUtil::create_table('device', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'hostname' => array('constraint' => 250, 'type' => 'varchar'), 'type' => array('constraint' => 11, 'type' => 'int'), 'cat' => array('constraint' => 11, 'type' => 'int'), 'rack' => array('constraint' => 11, 'type' => 'int'), 'rack_pos' => array('constraint' => 11, 'type' => 'int', 'default' => '0'), 'rack_units' => array('constraint' => 11, 'type' => 'int', 'default' => '1'), 'parent_device' => array('constraint' => 11, 'type' => 'int', 'default' => '0'), 'meta_default_data' => array('constraint' => 11, 'type' => 'int', 'default' => '0'), 'meta_update_time' => array('constraint' => 11, 'type' => 'int', 'default' => '0'), 'meta_update_user' => array('constraint' => 11, 'type' => 'int', 'default' => '0')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for device
            \DBUtil::create_index('device', 'type');
            \DBUtil::create_index('device', 'cat');
            \DBUtil::create_index('device', 'rack');
        }
        /*         * *********************************************************************************************
                  device category
                 * ********************************************************************************************* */
        $device_category = \DBUtil::checkIfExist('device_category');
        if (!$device_category) {
            \DBUtil::create_table('device_category', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'name' => array('constraint' => 250, 'type' => 'varchar')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            \DBUtil::truncate_table('device_category');
            // insert default connector type
            list($insert_id, $rows_affected) = \DB::insert('device_category')->columns(array('id', 'name'))->values(array('1', 'Server'), array('2', 'Switch'), array('3', 'Router'), array('4', 'PDU'), array('5', 'Patch Panel'), array('6', 'KVM Switch'), array('7', 'APC ATS'), array('8', 'FC Switch'), array('9', 'Human Interface'), array('10', 'UPS'))->execute();
        }
        /*         * *********************************************************************************************
                  device fieldset
                 * ********************************************************************************************* */
        $device_fieldset = \DBUtil::checkIfExist('device_fieldset');
        if (!$device_fieldset) {
            \DBUtil::create_table('device_fieldset', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'name' => array('constraint' => 250, 'type' => 'varchar'), 'type' => array('constraint' => 250, 'type' => 'varchar'), 'deviceID' => array('constraint' => 11, 'type' => 'int'), 'tab' => array('constraint' => 11, 'type' => 'int'), 'value' => array('type' => 'text', 'null' => true), 'extra' => array('constraint' => 250, 'type' => 'varchar', 'null' => true), 'static' => array('constraint' => 1, 'type' => 'int')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for device
            \DBUtil::create_index('device_fieldset', 'deviceID');
            //\DBUtil::create_index('device_fieldset',array('name','type','deviceID'),'un_key_field','unique');
        }
        /*         * *********************************************************************************************
                  device KVM
                 * ********************************************************************************************* */
        $device_kvm = \DBUtil::checkIfExist('device_kvm');
        if (!$device_kvm) {
            \DBUtil::create_table('device_kvm', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'fieldsetID' => array('constraint' => 11, 'type' => 'int'), 'deviceID' => array('constraint' => 11, 'type' => 'int'), 'input' => array('constraint' => 11, 'type' => 'int'), 'output' => array('constraint' => 11, 'type' => 'int'), 'type' => array('constraint' => 11, 'type' => 'int')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for device kvm
            \DBUtil::create_index('device_kvm', 'fieldsetID');
            \DBUtil::create_index('device_kvm', 'deviceID');
        }
        /*         * *********************************************************************************************
                  device KVM socket
                 * ********************************************************************************************* */
        $device_kvm_socket = \DBUtil::checkIfExist('device_kvm_socket');
        if (!$device_kvm_socket) {
            \DBUtil::create_table('device_kvm_socket', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'kvmID' => array('constraint' => 11, 'type' => 'int'), 'conn_type' => array('constraint' => 11, 'type' => 'int'), 'type' => array('constraint' => 11, 'type' => 'int')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for device kvm socket
            \DBUtil::create_index('device_kvm_socket', 'kvmID');
        }
        /*         * *********************************************************************************************
                  device network
                 * ********************************************************************************************* */
        $device_network = \DBUtil::checkIfExist('device_network');
        if (!$device_network) {
            \DBUtil::create_table('device_network', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'fieldsetID' => array('constraint' => 11, 'type' => 'int'), 'deviceID' => array('constraint' => 11, 'type' => 'int'), 'nics' => array('constraint' => 11, 'type' => 'int'), 'vports' => array('constraint' => 11, 'type' => 'int'), 'ports' => array('constraint' => 11, 'type' => 'int'), 'uplinks' => array('constraint' => 11, 'type' => 'int'), 'config_data' => array('type' => 'text'), 'type' => array('constraint' => 11, 'type' => 'int')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for device network
            \DBUtil::create_index('device_network', 'fieldsetID');
            \DBUtil::create_index('device_network', 'deviceID');
        }
        /*         * *********************************************************************************************
                  device Power
                 * ********************************************************************************************* */
        $device_power = \DBUtil::checkIfExist('device_power');
        if (!$device_power) {
            \DBUtil::create_table('device_power', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'fieldsetID' => array('constraint' => 11, 'type' => 'int'), 'deviceID' => array('constraint' => 11, 'type' => 'int'), 'input' => array('constraint' => 11, 'type' => 'int'), 'output' => array('constraint' => 11, 'type' => 'int'), 'current' => array('constraint' => 11, 'type' => 'int'), 'ru' => array('constraint' => 11, 'type' => 'int'), 'pos' => array('constraint' => 11, 'type' => 'int'), 'type' => array('constraint' => 11, 'type' => 'int')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for device kvm
            \DBUtil::create_index('device_power', 'fieldsetID');
            \DBUtil::create_index('device_power', 'deviceID');
        }
        /*         * *********************************************************************************************
                  device Power socket
                 * ********************************************************************************************* */
        $device_power_socket = \DBUtil::checkIfExist('device_power_socket');
        if (!$device_power_socket) {
            \DBUtil::create_table('device_power_socket', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'powerID' => array('constraint' => 11, 'type' => 'int'), 'conn_type' => array('constraint' => 11, 'type' => 'int'), 'type' => array('constraint' => 11, 'type' => 'int')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for device kvm socket
            \DBUtil::create_index('device_power_socket', 'powerID');
        }
        /*         * *********************************************************************************************
                  device template
                 * ********************************************************************************************* */
        $device_template = \DBUtil::checkIfExist('device_template');
        if (!$device_template) {
            \DBUtil::create_table('device_template', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'name' => array('constraint' => 250, 'type' => 'varchar'), 'categoryID' => array('constraint' => 11, 'type' => 'int'), 'hidden' => array('constraint' => 11, 'type' => 'int', 'default' => '0'), 'meta_update_user' => array('constraint' => 11, 'type' => 'int'), 'rack_unit' => array('constraint' => 11, 'type' => 'int')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for device template
            \DBUtil::create_index('device_template', 'categoryID');
            \DBUtil::create_index('device_template', 'meta_update_user');
        }
        /*         * *********************************************************************************************
                  device template field
                 * ********************************************************************************************* */
        $device_temp_field = \DBUtil::checkIfExist('device_temp_field');
        if (!$device_temp_field) {
            \DBUtil::create_table('device_temp_field', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'templateID' => array('constraint' => 11, 'type' => 'int'), 'tab' => array('constraint' => 2, 'type' => 'int'), 'name' => array('constraint' => 250, 'type' => 'varchar'), 'type' => array('constraint' => 250, 'type' => 'varchar'), 'static' => array('constraint' => 1, 'type' => 'int'), 'extra' => array('constraint' => 250, 'type' => 'varchar', 'null' => true), 'value' => array('constraint' => 250, 'type' => 'varchar', 'null' => true)), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for device template field
            \DBUtil::create_index('device_temp_field', 'templateID');
        }
        /*         * *********************************************************************************************
                  device template KVM
                 * ********************************************************************************************* */
        $device_temp_kvm = \DBUtil::checkIfExist('device_temp_kvm');
        if (!$device_temp_kvm) {
            \DBUtil::create_table('device_temp_kvm', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'fieldsetID' => array('constraint' => 11, 'type' => 'int'), 'templateID' => array('constraint' => 11, 'type' => 'int'), 'input' => array('constraint' => 11, 'type' => 'int'), 'output' => array('constraint' => 11, 'type' => 'int'), 'type' => array('constraint' => 11, 'type' => 'int')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for device template kvm
            \DBUtil::create_index('device_temp_kvm', 'fieldsetID');
            \DBUtil::create_index('device_temp_kvm', 'templateID');
        }
        /*         * *********************************************************************************************
                  device template KVM socket
                 * ********************************************************************************************* */
        $device_temp_kvm_socket = \DBUtil::checkIfExist('device_temp_kvm_socket');
        if (!$device_temp_kvm_socket) {
            \DBUtil::create_table('device_temp_kvm_socket', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'kvmID' => array('constraint' => 11, 'type' => 'int'), 'conn_type' => array('constraint' => 11, 'type' => 'int'), 'type' => array('constraint' => 11, 'type' => 'int')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for device kvm socket
            \DBUtil::create_index('device_temp_kvm_socket', 'kvmID');
        }
        /*         * *********************************************************************************************
                  device template network
                 * ********************************************************************************************* */
        $device_temp_network = \DBUtil::checkIfExist('device_temp_network');
        if (!$device_temp_network) {
            \DBUtil::create_table('device_temp_network', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'fieldID' => array('constraint' => 11, 'type' => 'int'), 'templateID' => array('constraint' => 11, 'type' => 'int'), 'nics' => array('constraint' => 11, 'type' => 'int'), 'vports' => array('constraint' => 11, 'type' => 'int'), 'ports' => array('constraint' => 11, 'type' => 'int'), 'uplinks' => array('constraint' => 11, 'type' => 'int'), 'config_data' => array('type' => 'text'), 'type' => array('constraint' => 11, 'type' => 'int')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for device network
            \DBUtil::create_index('device_temp_network', 'fieldID');
            \DBUtil::create_index('device_temp_network', 'templateID');
        }
        /*         * *********************************************************************************************
                  device template Power
                 * ********************************************************************************************* */
        $device_temp_power = \DBUtil::checkIfExist('device_temp_power');
        if (!$device_temp_power) {
            \DBUtil::create_table('device_temp_power', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'fieldsetID' => array('constraint' => 11, 'type' => 'int'), 'templateID' => array('constraint' => 11, 'type' => 'int'), 'input' => array('constraint' => 11, 'type' => 'int'), 'output' => array('constraint' => 11, 'type' => 'int'), 'current' => array('constraint' => 11, 'type' => 'int'), 'ru' => array('constraint' => 11, 'type' => 'int'), 'pos' => array('constraint' => 11, 'type' => 'int'), 'type' => array('constraint' => 11, 'type' => 'int')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for device template power
            \DBUtil::create_index('device_temp_power', 'fieldsetID');
            \DBUtil::create_index('device_temp_power', 'templateID');
        }
        /*         * *********************************************************************************************
                  device template Power socket
                 * ********************************************************************************************* */
        $device_temp_power_socket = \DBUtil::checkIfExist('device_temp_power_socket');
        if (!$device_temp_power_socket) {
            \DBUtil::create_table('device_temp_power_socket', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'powerID' => array('constraint' => 11, 'type' => 'int'), 'conn_type' => array('constraint' => 11, 'type' => 'int'), 'type' => array('constraint' => 11, 'type' => 'int')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for device kvm socket
            \DBUtil::create_index('device_temp_power_socket', 'powerID');
        }
        /*         * *********************************************************************************************
                  floor
                 * ********************************************************************************************* */
        $floor = \DBUtil::checkIfExist('floor');
        if (!$floor) {
            \DBUtil::create_table('floor', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'name' => array('constraint' => 250, 'type' => 'varchar'), 'building' => array('constraint' => 11, 'type' => 'int'), 'has_rooms' => array('constraint' => 11, 'type' => 'int', 'default' => '0', 'null' => true), 'notes' => array('type' => 'text', 'null' => true), 'meta_default_data' => array('constraint' => 11, 'type' => 'int', 'default' => '0', 'null' => true), 'meta_update_time' => array('constraint' => 11, 'type' => 'int', 'default' => '0'), 'meta_update_user' => array('constraint' => 11, 'type' => 'int', 'default' => '0')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for floor
            \DBUtil::create_index('floor', 'building');
            // insert default building
            list($floor_id, $rows_affected) = \DB::insert('floor')->columns(array('id', 'name', 'building', 'has_rooms', 'notes', 'meta_default_data', 'meta_update_time', 'meta_update_user'))->values(array('1', 'Floor 1', $building_id[0], '', '', '', time(), $user['id']))->execute();
        }
        /*         * *********************************************************************************************
                  hardware raid
                 * ********************************************************************************************* */
        $hardware_raid = \DBUtil::checkIfExist('hardware_raid');
        if (!$hardware_raid) {
            \DBUtil::create_table('hardware_raid', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'fieldsetID' => array('constraint' => 11, 'type' => 'int', 'null' => true), 'raid_type' => array('constraint' => 11, 'type' => 'int', 'null' => true), 'size' => array('constraint' => 250, 'type' => 'varchar', 'null' => true), 'total' => array('constraint' => 11, 'type' => 'int', 'null' => true), 'meta_update_time' => array('constraint' => 11, 'type' => 'int', 'default' => '0'), 'meta_update_user' => array('constraint' => 11, 'type' => 'int', 'default' => '0'), 'tempfieldID' => array('constraint' => 11, 'type' => 'int', 'null' => true)), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for hardware raid
            \DBUtil::create_index('hardware_raid', 'raid_type');
            //\DBUtil::create_index('hardware_raid', 'fieldsetID');
        }
        /*         * *********************************************************************************************
                  hardware raid data
                 * ********************************************************************************************* */
        $hardware_raid_data = \DBUtil::checkIfExist('hardware_raid_data');
        if (!$hardware_raid_data) {
            \DBUtil::create_table('hardware_raid_data', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'hardware_raid' => array('constraint' => 11, 'type' => 'int'), 'model' => array('constraint' => 250, 'type' => 'varchar'), 'size' => array('constraint' => 250, 'type' => 'varchar', 'null' => true), 'vport' => array('constraint' => 250, 'type' => 'varchar'), 'meta_update_time' => array('constraint' => 11, 'type' => 'int', 'default' => '0'), 'meta_update_user' => array('constraint' => 11, 'type' => 'int', 'default' => '0'), 'serial_number' => array('constraint' => 250, 'type' => 'varchar')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for hardware raid
            \DBUtil::create_index('hardware_raid_data', 'hardware_raid');
        }
        /*         * *********************************************************************************************
                  hardware ram
                 * ********************************************************************************************* */
        $hardware_ram = \DBUtil::checkIfExist('hardware_ram');
        if (!$hardware_ram) {
            \DBUtil::create_table('hardware_ram', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'fieldsetID' => array('constraint' => 11, 'type' => 'int', 'null' => true), 'ram_type' => array('constraint' => 11, 'type' => 'int', 'null' => true), 'size' => array('constraint' => 250, 'type' => 'varchar', 'null' => true), 'total' => array('constraint' => 11, 'type' => 'int', 'null' => true), 'meta_update_time' => array('constraint' => 11, 'type' => 'int', 'default' => '0'), 'meta_update_user' => array('constraint' => 11, 'type' => 'int', 'default' => '0'), 'tempfieldID' => array('constraint' => 11, 'type' => 'int', 'null' => true)), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for hardware raid
            \DBUtil::create_index('hardware_ram', 'ram_type');
            //\DBUtil::create_index('hardware_ram', 'fieldsetID');
        }
        /*         * *********************************************************************************************
                  hardware ram data
                 * ********************************************************************************************* */
        $hardware_ram_data = \DBUtil::checkIfExist('hardware_ram_data');
        if (!$hardware_ram_data) {
            \DBUtil::create_table('hardware_ram_data', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'hardware_ram' => array('constraint' => 11, 'type' => 'int'), 'model' => array('constraint' => 250, 'type' => 'varchar'), 'size' => array('constraint' => 250, 'type' => 'varchar'), 'port' => array('constraint' => 250, 'type' => 'varchar'), 'meta_update_time' => array('constraint' => 11, 'type' => 'int', 'default' => '0'), 'meta_update_user' => array('constraint' => 11, 'type' => 'int', 'default' => '0'), 'serial_number' => array('constraint' => 250, 'type' => 'varchar')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for hardware ram
            \DBUtil::create_index('hardware_ram_data', 'hardware_ram');
        }
        /*         * *********************************************************************************************
                  images
                 * ********************************************************************************************* */
        $images = \DBUtil::checkIfExist('images');
        if (!$images) {
            \DBUtil::create_table('images', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'name' => array('constraint' => 250, 'type' => 'varchar'), 'elementID' => array('constraint' => 11, 'type' => 'int'), 'type' => array('constraint' => 1, 'type' => 'varchar'), 'width' => array('constraint' => 11, 'type' => 'int'), 'height' => array('constraint' => 11, 'type' => 'int')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for images
            \DBUtil::create_index('images', 'elementID');
        }
        /*         * *********************************************************************************************
                  network ip ports
                 * ********************************************************************************************* */
        $network_ip_ports = \DBUtil::checkIfExist('network_ip_ports');
        if (!$network_ip_ports) {
            \DBUtil::create_table('network_ip_ports', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'networkID' => array('constraint' => 11, 'type' => 'int'), 'nic_name' => array('constraint' => 250, 'type' => 'varchar'), 'ipv4' => array('constraint' => 15, 'type' => 'varchar'), 'ipv6' => array('constraint' => 42, 'type' => 'varchar'), 'conn_type' => array('constraint' => 11, 'type' => 'int'), 'conn_speed' => array('constraint' => 11, 'type' => 'int'), 'type' => array('constraint' => 11, 'type' => 'int')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for network ip ports
            \DBUtil::create_index('network_ip_ports', 'networkID');
            \DBUtil::create_index('network_ip_ports', 'conn_type');
            \DBUtil::create_index('network_ip_ports', 'conn_speed');
        }
        /*         * *********************************************************************************************
                  network mac ports
                 * ********************************************************************************************* */
        $network_mac_ports = \DBUtil::checkIfExist('network_mac_ports');
        if (!$network_mac_ports) {
            \DBUtil::create_table('network_mac_ports', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'networkID' => array('constraint' => 11, 'type' => 'int'), 'mac_address' => array('constraint' => 18, 'type' => 'varchar'), 'conn_device' => array('constraint' => 11, 'type' => 'int'), 'vlan' => array('constraint' => 11, 'type' => 'int', 'null' => true), 'type' => array('constraint' => 2, 'type' => 'int')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for network mac ports
            \DBUtil::create_index('network_mac_ports', 'networkID');
            \DBUtil::create_index('network_mac_ports', 'conn_device');
            \DBUtil::create_index('network_mac_ports', 'vlan');
        }
        /*         * *********************************************************************************************
                  network vlans
                 * ********************************************************************************************* */
        $network_vlans = \DBUtil::checkIfExist('network_vlans');
        if (!$network_vlans) {
            \DBUtil::create_table('network_vlans', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'networkID' => array('constraint' => 11, 'type' => 'int'), 'name' => array('constraint' => 250, 'type' => 'varchar')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for network mac ports
            \DBUtil::create_index('network_vlans', 'networkID');
        }
        /*         * *********************************************************************************************
                  notes
                 * ********************************************************************************************* */
        $notes = \DBUtil::checkIfExist('notes');
        if (!$notes) {
            \DBUtil::create_table('notes', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'deviceID' => array('constraint' => 11, 'type' => 'int'), 'txt' => array('type' => 'text'), 'meta_update_time' => array('constraint' => 11, 'type' => 'int', 'default' => '0'), 'meta_update_user' => array('constraint' => 11, 'type' => 'int', 'default' => '0')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for notes
            \DBUtil::create_index('notes', 'deviceID');
        }
        /*         * *********************************************************************************************
                  RAID type
                 * ********************************************************************************************* */
        $raid_type = \DBUtil::checkIfExist('raid_type');
        if (!$raid_type) {
            \DBUtil::create_table('raid_type', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'name' => array('constraint' => 250, 'type' => 'varchar')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            \DBUtil::truncate_table('raid_type');
            // insert default raid type
            list($insert_id, $rows_affected) = \DB::insert('raid_type')->columns(array('id', 'name'))->values(array('1', 'none'), array('2', 'RAID 0'), array('3', 'RAID 1'), array('4', 'RAID 2'), array('5', 'RAID 3'), array('6', 'RAID 4'), array('7', 'RAID 5'), array('8', 'RAID 6'), array('9', 'RAID 7'), array('10', 'RAID 10'), array('11', 'RAID S (parity RAID)'), array('12', 'RAID-DP'), array('13', 'Matrix RAID'), array('14', 'RAID-K'), array('15', 'RAID-Z'), array('16', 'RAID 1.5'), array('17', 'RAIDn'), array('18', 'Linux MD RAID 10'), array('19', 'IBM ServeRAID 1E'), array('20', 'ineo Complex RAID'), array('21', 'Drobo BeyondRAID'), array('22', 'nunRAID'))->execute();
        }
        /*         * *********************************************************************************************
                  RAM type
                 * ********************************************************************************************* */
        $ram_type = \DBUtil::checkIfExist('ram_type');
        if (!$ram_type) {
            \DBUtil::create_table('ram_type', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'name' => array('constraint' => 250, 'type' => 'varchar')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            \DBUtil::truncate_table('ram_type');
            // insert default ram type
            list($insert_id, $rows_affected) = \DB::insert('ram_type')->columns(array('id', 'name'))->values(array('1', 'none'), array('2', 'SDRAM'), array('3', 'RDRAM'), array('4', 'DDR1'), array('5', 'DDR2'), array('6', 'DDR3'), array('7', 'DDR4'))->execute();
        }
        /*         * *********************************************************************************************
                  room
                 * ********************************************************************************************* */
        $room = \DBUtil::checkIfExist('room');
        if (!$room) {
            \DBUtil::create_table('room', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'name' => array('constraint' => 250, 'type' => 'varchar'), 'floor' => array('constraint' => 11, 'type' => 'int'), 'has_racks' => array('constraint' => 11, 'type' => 'int', 'default' => '0', 'null' => true), 'notes' => array('type' => 'text', 'null' => true), 'meta_default_data' => array('constraint' => 11, 'type' => 'int', 'default' => '0', 'null' => true), 'meta_update_time' => array('constraint' => 11, 'type' => 'int', 'default' => '0'), 'meta_update_user' => array('constraint' => 11, 'type' => 'int', 'default' => '0')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for network mac ports
            \DBUtil::create_index('room', 'floor');
            //insert default room
            list($room_id, $rows_affected) = \DB::insert('room')->columns(array('id', 'name', 'floor', 'has_racks', 'notes', 'meta_default_data', 'meta_update_time', 'meta_update_user'))->values(array('1', 'Room A', $floor_id[0], '', '', '0', time(), $user['id']))->execute();
        }
        /*         * *********************************************************************************************
                  rack
                 * ********************************************************************************************* */
        $rack = \DBUtil::checkIfExist('rack');
        if (!$rack) {
            \DBUtil::create_table('rack', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'name' => array('constraint' => 250, 'type' => 'varchar'), 'room' => array('constraint' => 11, 'type' => 'int'), 'room_pos' => array('constraint' => 11, 'type' => 'int', 'default' => '0'), 'hidden_rack' => array('constraint' => 11, 'type' => 'int', 'default' => '0'), 'size' => array('constraint' => 11, 'type' => 'int', 'default' => '42'), 'numbering_direction' => array('constraint' => 11, 'type' => 'int', 'default' => '0'), 'notes' => array('type' => 'text', 'null' => true), 'meta_default_data' => array('constraint' => 11, 'type' => 'int', 'default' => '0'), 'meta_update_time' => array('constraint' => 11, 'type' => 'int', 'default' => '0'), 'meta_update_user' => array('constraint' => 11, 'type' => 'int', 'default' => '0')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for network mac ports
            \DBUtil::create_index('rack', 'room');
            // insert default rack
            list($rack_id, $rows_affected) = \DB::insert('rack')->columns(array('id', 'name', 'room', 'room_pos', 'hidden_rack', 'size', 'numbering_direction', 'notes', 'meta_default_data', 'meta_update_time', 'meta_update_user'))->values(array('1', 'Default Rack', $room_id[0], 0, 0, 42, 0, '', '0', time(), $user['id']))->execute();
        }
        /*         * *********************************************************************************************
                  template network ip ports
                 * ********************************************************************************************* */
        $temp_network_ip_ports = \DBUtil::checkIfExist('temp_network_ip_ports');
        if (!$temp_network_ip_ports) {
            \DBUtil::create_table('temp_network_ip_ports', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'tempnetID' => array('constraint' => 11, 'type' => 'int'), 'nic_name' => array('constraint' => 250, 'type' => 'varchar', 'null' => true), 'ipv4' => array('constraint' => 15, 'type' => 'varchar', 'null' => true), 'ipv6' => array('constraint' => 42, 'type' => 'varchar', 'null' => true), 'conn_type' => array('constraint' => 11, 'type' => 'int', 'null' => true), 'conn_speed' => array('constraint' => 11, 'type' => 'int', 'null' => true), 'type' => array('constraint' => 11, 'type' => 'int')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for network ip ports
            \DBUtil::create_index('temp_network_ip_ports', 'tempnetID');
            \DBUtil::create_index('temp_network_ip_ports', 'conn_type');
            \DBUtil::create_index('temp_network_ip_ports', 'conn_speed');
        }
        /*         * *********************************************************************************************
                  template network mac ports
                 * ********************************************************************************************* */
        $temp_network_mac_ports = \DBUtil::checkIfExist('temp_network_mac_ports');
        if (!$temp_network_mac_ports) {
            \DBUtil::create_table('temp_network_mac_ports', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'tempnetID' => array('constraint' => 11, 'type' => 'int'), 'mac_address' => array('constraint' => 18, 'type' => 'varchar'), 'conn_device' => array('constraint' => 11, 'type' => 'int'), 'vlan' => array('constraint' => 11, 'type' => 'int', 'null' => true), 'type' => array('constraint' => 2, 'type' => 'int')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for network mac ports
            \DBUtil::create_index('temp_network_mac_ports', 'tempnetID');
            \DBUtil::create_index('temp_network_mac_ports', 'conn_device');
            \DBUtil::create_index('temp_network_mac_ports', 'vlan');
        }
        /*         * *********************************************************************************************
                  template network vlans
                 * ********************************************************************************************* */
        $temp_network_vlans = \DBUtil::checkIfExist('temp_network_vlans');
        if (!$temp_network_vlans) {
            \DBUtil::create_table('temp_network_vlans', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'tempnetID' => array('constraint' => 11, 'type' => 'int'), 'name' => array('constraint' => 250, 'type' => 'varchar')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for network mac ports
            \DBUtil::create_index('temp_network_vlans', 'tempnetID');
        }
        /*         * *********************************************************************************************
                  template images
                 * ********************************************************************************************* */
        $temp_images = \DBUtil::checkIfExist('temp_images');
        if (!$temp_images) {
            \DBUtil::create_table('temp_images', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'name' => array('constraint' => 250, 'type' => 'varchar'), 'elementID' => array('constraint' => 11, 'type' => 'int'), 'type' => array('constraint' => 1, 'type' => 'varchar'), 'width' => array('constraint' => 11, 'type' => 'int'), 'height' => array('constraint' => 11, 'type' => 'int')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for images
            \DBUtil::create_index('temp_images', 'elementID');
        }
        /*         * *********************************************************************************************
                  wiki category
                 * ********************************************************************************************* */
        $wiki_categories = \DBUtil::checkIfExist('wiki_categories');
        if (!$wiki_categories) {
            \DBUtil::create_table('wiki_categories', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'name' => array('constraint' => 250, 'type' => 'varchar')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            \DBUtil::truncate_table('wiki_categories');
            // insert default connector type
            list($insert_id, $rows_affected) = \DB::insert('wiki_categories')->columns(array('id', 'name'))->values(array('1', 'General'), array('2', 'Installation'), array('3', 'Devices'), array('4', 'Maintenance'))->execute();
        }
        /*         * *********************************************************************************************
                  wiki
                 * ********************************************************************************************* */
        $wiki = \DBUtil::checkIfExist('wiki');
        if (!$wiki) {
            \DBUtil::create_table('wiki', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'catID' => array('constraint' => 11, 'type' => 'int'), 'title' => array('constraint' => 250, 'type' => 'varchar'), 'content' => array('type' => 'text', 'null' => true), 'meta_update_time' => array('constraint' => 11, 'type' => 'int', 'default' => '0'), 'meta_update_user' => array('constraint' => 11, 'type' => 'int', 'default' => '0')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for wiki
            \DBUtil::create_index('wiki', 'catID');
        }
        /*         * *********************************************************************************************
                  vps
                 * ********************************************************************************************* */
        $vps = \DBUtil::checkIfExist('vps');
        if (!$vps) {
            \DBUtil::create_table('vps', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'masterID' => array('constraint' => 11, 'type' => 'int'), 'hostname' => array('constraint' => 250, 'type' => 'varchar'), 'cpu' => array('constraint' => 11, 'type' => 'int'), 'ram' => array('constraint' => 11, 'type' => 'int'), 'storage' => array('constraint' => 11, 'type' => 'int')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for wiki
            \DBUtil::create_index('vps', 'masterID');
        }
        /*         * *********************************************************************************************
                  vps
                 * ********************************************************************************************* */
        /*
         $vps_ip_ports = \DBUtil::checkIfExist('vps_ip_ports');
         if (!$vps_ip_ports) {
         \DBUtil::create_table('vps_ip_ports', array(
         'id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true),
         'vpsID' => array('constraint' => 11, 'type' => 'int'),
         'data' => array('constraint' => 250, 'type' => 'varchar')
         ), array('id'), true, 'InnoDB', 'utf8_unicode_ci'
         );
        
         //create indexes for wiki
         \DBUtil::create_index('vps_ip_ports', 'vpsID');
         }
        */
        /*         * *********************************************************************************************
                  FOREIGN KEYS
                 * ********************************************************************************************* */
        if (!$cables) {
            $query = \DB::query('ALTER TABLE `cables`
		ADD CONSTRAINT `cables_ibfk_1` FOREIGN KEY (`dev1`) REFERENCES `device` (`id`) 
		ON DELETE CASCADE ON UPDATE CASCADE')->execute();
            $query = \DB::query('ALTER TABLE `cables`
  		ADD CONSTRAINT `cables_ibfk_2` FOREIGN KEY (`dev2`) REFERENCES `device` (`id`) 
		ON DELETE CASCADE ON UPDATE CASCADE')->execute();
        }
        if (!$device) {
            $query = \DB::query('ALTER TABLE `device`
		ADD CONSTRAINT `device_ibfk_2` FOREIGN KEY (`rack`) REFERENCES `rack` (`id`)
			ON DELETE CASCADE ON UPDATE CASCADE')->execute();
        }
        if (!$device_fieldset) {
            $query = \DB::query('ALTER TABLE `device_fieldset` ADD CONSTRAINT `device_fieldset_ibfk_1`
		FOREIGN KEY (`deviceID`) REFERENCES `device` (`id`) 
		ON DELETE CASCADE ON UPDATE CASCADE')->execute();
        }
        if (!$device_kvm) {
            $query = \DB::query('ALTER TABLE `device_kvm`
  			ADD CONSTRAINT `device_kvm_ibfk_1` FOREIGN KEY (`fieldsetID`) 
			REFERENCES `device_fieldset` (`id`) ON DELETE CASCADE ON UPDATE CASCADE')->execute();
        }
        if (!$device_kvm_socket) {
            $query = \DB::query('ALTER TABLE `device_kvm_socket`
  			ADD CONSTRAINT `device_kvm_socket_ibfk_1` FOREIGN KEY (`kvmID`) 
			REFERENCES `device_kvm` (`id`) ON DELETE CASCADE ON UPDATE CASCADE')->execute();
        }
        if (!$device_network) {
            $query = \DB::query('ALTER TABLE `device_network` ADD CONSTRAINT `device_network_ibfk_2`
		FOREIGN KEY (`fieldsetID`) REFERENCES `device_fieldset` (`id`) 
		ON DELETE  CASCADE ON UPDATE CASCADE;')->execute();
        }
        if (!$device_power) {
            $query = \DB::query('ALTER TABLE `device_power`
  			ADD CONSTRAINT `device_power_ibfk_1` FOREIGN KEY (`fieldsetID`) 
			REFERENCES `device_fieldset` (`id`) ON DELETE CASCADE ON UPDATE CASCADE')->execute();
        }
        if (!$device_power_socket) {
            $query = \DB::query('ALTER TABLE `device_power_socket`
  			ADD CONSTRAINT `device_power_socket_ibfk_1` FOREIGN KEY (`powerID`) 
			REFERENCES `device_power` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;')->execute();
        }
        if (!$device_template) {
            $query = \DB::query('ALTER TABLE `device_template` ADD CONSTRAINT `device_template_ibfk_1`
		FOREIGN KEY (`categoryID`) REFERENCES `device_category` (`id`) 
		ON DELETE CASCADE ON UPDATE CASCADE;')->execute();
        }
        if (!$device_temp_field) {
            $query = \DB::query('ALTER TABLE `device_temp_field` ADD CONSTRAINT `device_temp_field_ibfk_2`
		FOREIGN KEY (`templateID`) REFERENCES `device_template` (`id`) 
		ON DELETE CASCADE ON UPDATE CASCADE;')->execute();
        }
        if (!$device_temp_kvm) {
            $query = \DB::query('ALTER TABLE `device_temp_kvm`
  		ADD CONSTRAINT `device_temp_kvm_ibfk_1` FOREIGN KEY (`fieldsetID`) 
		REFERENCES `device_temp_field` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;')->execute();
        }
        if (!$device_temp_kvm_socket) {
            $query = \DB::query('ALTER TABLE `device_temp_kvm_socket`
  		ADD CONSTRAINT `device_temp_kvm_socket_ibfk_1` FOREIGN KEY (`kvmID`) 
		REFERENCES `device_temp_kvm` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;')->execute();
        }
        if (!$device_temp_network) {
            $query = \DB::query('ALTER TABLE `device_temp_network`
  		ADD CONSTRAINT `device_temp_network_ibfk_1` FOREIGN KEY (`fieldID`) 
		REFERENCES `device_temp_field` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;')->execute();
        }
        if (!$device_temp_power) {
            $query = \DB::query('ALTER TABLE `device_temp_power`
  		ADD CONSTRAINT `device_temp_power_ibfk_1` FOREIGN KEY (`fieldsetID`) 
		REFERENCES `device_temp_field` (`id`) ON DELETE CASCADE ON UPDATE CASCADE')->execute();
        }
        if (!$device_temp_power_socket) {
            $query = \DB::query('ALTER TABLE `device_temp_power_socket`
  		ADD CONSTRAINT `device_temp_power_socket_ibfk_1` FOREIGN KEY (`powerID`) 
		REFERENCES `device_temp_power` (`id`) ON DELETE CASCADE ON UPDATE CASCADE')->execute();
        }
        if (!$floor) {
            $query = \DB::query('ALTER TABLE `floor` ADD CONSTRAINT `floor_ibfk_4`
		FOREIGN KEY (`building`) REFERENCES `building` (`id`) 
		ON DELETE CASCADE ON UPDATE CASCADE;')->execute();
        }
        if (!$hardware_raid) {
            $query = \DB::query('ALTER TABLE `hardware_raid`  ADD CONSTRAINT `hardware_raid_ibfk_2`
		FOREIGN KEY (`raid_type`) REFERENCES `raid_type` (`id`);')->execute();
        }
        if (!$hardware_raid_data) {
            $query = \DB::query('ALTER TABLE `hardware_raid_data` ADD CONSTRAINT `hardware_raid_data_ibfk_2`
		FOREIGN KEY (`hardware_raid`) REFERENCES `hardware_raid` (`id`) 
		ON DELETE CASCADE ON UPDATE CASCADE;')->execute();
        }
        if (!$images) {
            $query = \DB::query('ALTER TABLE `images` ADD CONSTRAINT `images_ibfk_2`
		FOREIGN KEY (`elementID`) REFERENCES `device_fieldset` (`id`) 
		ON DELETE CASCADE ON UPDATE CASCADE;')->execute();
        }
        if (!$network_ip_ports) {
            $query = \DB::query('ALTER TABLE `network_ip_ports` ADD CONSTRAINT `network_ip_ports_ibfk_4`
		FOREIGN KEY (`networkID`) REFERENCES `device_network` (`id`) 
		ON DELETE CASCADE ON UPDATE CASCADE;')->execute();
        }
        if (!$network_mac_ports) {
            $query = \DB::query('ALTER TABLE `network_mac_ports` ADD CONSTRAINT `network_mac_ports_ibfk_1`
		FOREIGN KEY (`networkID`) REFERENCES `device_network` (`id`) 
		ON DELETE CASCADE ON UPDATE CASCADE;')->execute();
        }
        if (!$network_vlans) {
            $query = \DB::query('ALTER TABLE `network_vlans` ADD CONSTRAINT `network_vlans_ibfk_3`
		FOREIGN KEY (`networkID`) REFERENCES `device_network` (`id`) 
		ON DELETE CASCADE ON UPDATE CASCADE;')->execute();
        }
        if (!$notes) {
            $query = \DB::query('ALTER TABLE `notes` ADD CONSTRAINT `notes_ibfk_1`
		FOREIGN KEY (`deviceID`) REFERENCES `device` (`id`) 
		ON DELETE CASCADE ON UPDATE CASCADE;')->execute();
        }
        if (!$rack) {
            $query = \DB::query('ALTER TABLE `rack` ADD CONSTRAINT `rack_ibfk_2`
		FOREIGN KEY (`room`) REFERENCES `room` (`id`) 
		ON DELETE CASCADE ON UPDATE CASCADE;')->execute();
        }
        if (!$room) {
            $query = \DB::query('ALTER TABLE `room` ADD CONSTRAINT `room_ibfk_2`
		FOREIGN KEY (`floor`) REFERENCES `floor` (`id`) 
		ON DELETE CASCADE ON UPDATE CASCADE;')->execute();
        }
        if (!$temp_network_ip_ports) {
            $query = \DB::query('ALTER TABLE `temp_network_ip_ports` ADD CONSTRAINT `temp_network_ip_ports_ibfk_4`
		FOREIGN KEY (`tempnetID`) REFERENCES `device_temp_network` (`id`)
		ON DELETE CASCADE ON UPDATE CASCADE;')->execute();
        }
        if (!$temp_network_mac_ports) {
            $query = \DB::query('ALTER TABLE `temp_network_mac_ports` ADD CONSTRAINT `temp_network_mac_ports_ibfk_1`
		FOREIGN KEY (`tempnetID`) REFERENCES `device_temp_network` (`id`)
		ON DELETE CASCADE ON UPDATE CASCADE;')->execute();
        }
        if (!$temp_network_vlans) {
            $query = \DB::query('ALTER TABLE `temp_network_vlans` ADD CONSTRAINT `temp_network_vlans_ibfk_3`
		FOREIGN KEY (`tempnetID`) REFERENCES `device_temp_network` (`id`)
		ON DELETE CASCADE ON UPDATE CASCADE;')->execute();
        }
        //wiki
        if (!$wiki) {
            $query = \DB::query('ALTER TABLE `wiki`
				ADD CONSTRAINT `wiki_ibfk_1` FOREIGN KEY (`catID`) REFERENCES `wiki_categories` (`id`)
				ON DELETE CASCADE ON UPDATE CASCADE')->execute();
        }
        //virtual private server
        if (!$vps) {
            $query = \DB::query('ALTER TABLE `vps`
					ADD CONSTRAINT `vps_ibfk_1` FOREIGN KEY (`masterID`) REFERENCES `device` (`id`)
					ON DELETE CASCADE ON UPDATE CASCADE')->execute();
        }
        /*
                  //ips of vps
                  if (!$vps_ip_ports) {
                  $query = \DB::query('ALTER TABLE `vps_ip_ports`
                  ADD CONSTRAINT `vps_ip_ibfk_1` FOREIGN KEY (`vpsID`) REFERENCES `vps` (`id`)
                  ON DELETE CASCADE ON UPDATE CASCADE')->execute();
                  }
        */
    }
 public function down()
 {
     \DBUtil::truncate_table('clients');
 }
Exemple #12
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);
 }
 public static function truncate()
 {
     try {
         return \DBUtil::truncate_table(static::$_table_name);
     } catch (\Database_Exception $e) {
         return false;
     }
 }
 public function down()
 {
     \DBUtil::truncate_table(\Config::get('sentry.table.users'));
     \DBUtil::truncate_table(\Config::get('sentry.table.groups'));
 }
    public function up()
    {
        /*         * *********************************************************************************************
                  graphing
                 * ********************************************************************************************* */
        $graphing = \DBUtil::checkIfExist('graphing');
        if (!$graphing) {
            \DBUtil::create_table('graphing', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'name' => array('constraint' => 250, 'type' => 'varchar'), 'value' => array('constraint' => 250, 'type' => 'varchar'), 'meta_update_user' => array('constraint' => 11, 'type' => 'int', 'default' => '0')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            \DBUtil::truncate_table('graphing');
            // insert default connector type
            list($insert_id, $rows_affected) = \DB::insert('graphing')->columns(array('id', 'name', 'value', 'meta_update_user'))->values(array('1', 'cacti_size', '1', '1'))->execute();
        }
        /*         * *********************************************************************************************
                  graphing_type
                 * ********************************************************************************************* */
        $graphing_type = \DBUtil::checkIfExist('graphing_type');
        if (!$graphing_type) {
            \DBUtil::create_table('graphing_type', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'name' => array('constraint' => 250, 'type' => 'varchar')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            \DBUtil::truncate_table('graphing_type');
            // insert default connector type
            list($insert_id, $rows_affected) = \DB::insert('graphing_type')->columns(array('id', 'name'))->values(array('1', 'Cacti'))->execute();
        }
        /*         * *********************************************************************************************
                  graphing_source
                 * ********************************************************************************************* */
        $graphing_source = \DBUtil::checkIfExist('graphing_source');
        if (!$graphing_source) {
            \DBUtil::create_table('graphing_source', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'typeID' => array('constraint' => 11, 'type' => 'int'), 'user' => array('constraint' => 250, 'type' => 'varchar'), 'pass' => array('constraint' => 250, 'type' => 'varchar'), 'content' => array('type' => 'text', 'null' => true), 'meta_update_time' => array('constraint' => 11, 'type' => 'int', 'default' => '0'), 'meta_update_user' => array('constraint' => 11, 'type' => 'int', 'default' => '0')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for graphing
            \DBUtil::create_index('graphing_source', 'typeID');
        }
        /*         * *********************************************************************************************
                  graphing_cacti
                 * ********************************************************************************************* */
        $graphing_cacti = \DBUtil::checkIfExist('graphing_cacti');
        if (!$graphing_cacti) {
            \DBUtil::create_table('graphing_cacti', array('id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true), 'sourceID' => array('constraint' => 11, 'type' => 'int'), 'name' => array('constraint' => 250, 'type' => 'varchar'), 'num' => array('constraint' => 250, 'type' => 'varchar'), 'macID' => array('constraint' => 11, 'type' => 'int'), 'graphID' => array('constraint' => 11, 'type' => 'int'), 'meta_update_time' => array('constraint' => 11, 'type' => 'int', 'default' => '0'), 'meta_update_user' => array('constraint' => 11, 'type' => 'int', 'default' => '0'), 'deviceID' => array('constraint' => 11, 'type' => 'int')), array('id'), true, 'InnoDB', 'utf8_unicode_ci');
            //create indexes for graphing
            \DBUtil::create_index('graphing_cacti', 'deviceID');
            \DBUtil::create_index('graphing_cacti', 'sourceID');
            \DBUtil::create_index('graphing_cacti', 'macID');
        }
        /*         * *********************************************************************************************
                  FOREIGN KEYS
                 * ********************************************************************************************* */
        //graphing
        if (!$graphing_source) {
            $query = \DB::query('ALTER TABLE `graphing_source`
					ADD CONSTRAINT `graphing_ibfk_1` FOREIGN KEY (`typeID`) REFERENCES `graphing_type` (`id`)
					ON DELETE CASCADE ON UPDATE CASCADE')->execute();
        }
        //graphing_cacti
        if (!$graphing_cacti) {
            $query = \DB::query('ALTER TABLE `graphing_cacti`
					ADD CONSTRAINT `graphing_cacti_ibfk_1` FOREIGN KEY (`sourceID`) REFERENCES `graphing_source` (`id`)
					ON DELETE CASCADE ON UPDATE CASCADE')->execute();
            /*
             $query = \DB::query('ALTER TABLE `graphing_cacti`
             ADD CONSTRAINT `graphing_cacti_ibfk_2` FOREIGN KEY (`macID`) REFERENCES `network_mac_ports` (`id`)
             ON DELETE CASCADE ON UPDATE CASCADE')->execute();
            */
            $query = \DB::query('ALTER TABLE `graphing_cacti`
					ADD CONSTRAINT `graphing_cacti_ibfk_3` FOREIGN KEY (`deviceID`) REFERENCES `device` (`id`)
					ON DELETE CASCADE ON UPDATE CASCADE')->execute();
        }
        /*
         * UPDATE version
         *
         * */
        $now = time();
        list($insert_id, $rows_affected) = \DB::insert('version')->columns(array('value', 'meta_update_time'))->values(array('1.09', $now))->execute();
    }
 /**
  * reset permission
  *
  * @param null|integer $core
  * @return boolean
  */
 public static function resetPermission($core = '')
 {
     if ($core == null) {
         // reset all permissions
         \DBUtil::truncate_table(static::$_table_name);
         return true;
     } elseif ($core === 1) {
         // reset core permissions
         \DB::delete(static::$_table_name)->where('permission_core', '1')->execute();
         return true;
     } elseif ($core === 0) {
         // reset modules permissions
         \DB::delete(static::$_table_name)->where('permission_core', '0')->execute();
         return true;
     }
     // clear cache
     \Extension\Cache::deleteCache('model.accountLevelPermission-checkLevelPermission-' . \Model_Sites::getSiteId(false));
     return false;
 }
Exemple #17
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');
             }
         }
     }
 }
Exemple #18
0
 /**
  * clear the sessions table
  * php oil r session:clear
  */
 public static function clear()
 {
     // load session config
     \Config::load('session', true);
     // prompt the user to confirm they want to clear the table.
     $iamsure = \Cli::prompt('Are you sure you want to clear the sessions table?', array('y', 'n'));
     // if they are sure, then let's drop it
     if ($iamsure === 'y') {
         \DBUtil::truncate_table(\Config::get('session.db.table'));
         return \Cli::color('Session database table successfully truncated.', 'green');
     }
     // if we made it to here, than that means the user said no.
     return \Cli::color('Session database table was not cleared.', 'red');
 }
 public function down()
 {
     \DBUtil::truncate_table('lookups');
 }