public function create($conn_asm, $conn_db, $id, $password) { global $error; $dg = DEFAULT_DG; $tablespace = $id; $drive = new Drive(); // Create Tablespace $result = $drive->create_tablespace($conn_db, $tablespace, $dg); if ($result === ERROR) { $error->set_msg("Failed to create Tablespace."); return(ERROR); } // Create User $result = self::exist_user($conn_db, $id); if ($result == TRUE) { $error->set_msg("User already exists."); return(ERROR); } $sql = "create user $id identified by $password default tablespace $tablespace quota " . DEFAULT_QUOTA . " on $tablespace"; $state_id = oci_parse($conn_db, $sql); $result = oci_execute($state_id); if ($result == FALSE) { $error->set_msg("Failed to create User. Failed SQL = '$sql'"); // Rollback $drive->delete_tablespace($conn_db, $tablespace); return(ERROR); } // Grant Role to User $sql = "grant " . CLOUD_USER . " to $id"; $state_id = oci_parse($conn_db, $sql); $result = oci_execute($state_id); if ($result == FALSE) { $error->set_msg("Failed to assign Role to User. Failed SQL = '$sql'"); // Rollback self::delete($conn_asm, $conn_db, $id); return(ERROR); } // Assign consumer group object privileges to Allow user to use this consumer group global $array_consumer_group; foreach ($array_consumer_group as $consumer_group) { $sql = "BEGIN dbms_resource_manager_privs.grant_switch_consumer_group(grantee_name => '$id',consumer_group => '$consumer_group',grant_option => FALSE);END;"; $state_id = oci_parse($conn_db, $sql); $result = oci_execute($state_id); if ($result == FALSE) { $error->set_msg("Failed to assign Consumer Group object privileges to User. Failed SQL = '$sql'"); // Rollback self::delete($conn_asm, $conn_db, $id); return(ERROR); } } // Assign default consumer group to user $result = self::update_consumer_group($conn_db, $id, DEFAULT_CONSUMER_GROUP); if ($result === ERROR) { $error->set_msg("Failed to assigne default Consumer Group to User"); // Rollback self::delete($conn_asm, $conn_db, $id); return(ERROR); } return(TRUE); }
public function create($conn_asm, $conn_db, $id, $password, $disk_type) { $dg = $id; $tablespace = $id; // Fetch Available Disk $drive = new Drive(); $available_disk = $drive->fetch_available_disk($conn_asm, $disk_type); if ($available_disk == FALSE ) { $this->err_msg = array_merge($this->err_msg, $drive->err_msg); array_push($this->err_msg, "新たなディスクの確保に失敗しました。"); return(FALSE); } if ($available_disk == NULL ) { array_push($this->err_msg, "利用可能なディスクがありません。"); return(FALSE); } // Create Diskgroup $available_disk["name"] = $dg . "_" . $disk_type; $result = $drive->create_dg($conn_asm, $dg, $available_disk); if ($result == FALSE) { $this->err_msg = array_merge($this->err_msg, $drive->err_msg); array_push($this->err_msg, "新たなディスクグループを作成出来ませんでした。"); return(FALSE); } // Mount Diskgroup $result = $drive->mount_dg($conn_asm, $dg); if ($result == FALSE) { $this->err_msg = array_merge($this->err_msg, $drive->err_msg); array_push($this->err_msg, "ディスクグループをマウント出来ませんでした。"); return(FALSE); } // Create Tablespace $result = $drive->create_tablespace($conn_db, $tablespace, $dg); if ($result == FALSE) { $this->err_msg = array_merge($this->err_msg, $drive->err_msg); array_push($this->err_msg, "新たな表領域を作成出来ませんでした。"); // Rollback $drive->delete_dg($conn_asm, $dg); return(FALSE); } // Create User $state_id = oci_parse($conn_db, "create user $id identified by $password default tablespace $tablespace quota unlimited on $tablespace"); $result = oci_execute($state_id); if ($result == FALSE) { array_push($this->err_msg, "新たなユーザーを作成出来ませんでした。"); // Rollback $drive->delete_tablespace($conn_db, $tablespace); $drive->delete_dg($conn_asm, $dg); return(FALSE); } // Grant Role to User $state_id = oci_parse($conn_db, "grant " . CLOUD_USER . " to $id"); $result = oci_execute($state_id); if ($result == FALSE) { array_push($this->err_msg, "ユーザーにロールを割り当て出来ませんでした。"); // Rollback self::delete($conn_asm, $conn_db, $id); return(FALSE); } global $array_consumer_group; foreach ($array_consumer_group as $consumer_group) { $state_id = oci_parse($conn_db, "BEGIN dbms_resource_manager_privs.grant_switch_consumer_group(grantee_name => '$id',consumer_group => '$consumer_group',grant_option => FALSE);END;"); $result = oci_execute($state_id); if ($result == FALSE) { array_push($this->err_msg, "ユーザーにコンシューマーグループオブジェクト権限を割り当て出来ませんでした。"); // Rollback self::delete($conn_asm, $conn_db, $id); return(FALSE); } } $result = self::update_consumer_group($conn_db, $id, DEFAULT_CONSUMER_GROUP); if ($result == FALSE) { array_push($this->err_msg, "コンシューマーグループマッピングを作成出来ませんでした。"); // Rollback self::delete($conn_asm, $conn_db, $id); return(FALSE); } return(TRUE); }