/** * テーブル作成 * * @return boolean * @access private */ function _createTable() { $base_dir = $this->session->getParameter("base_dir"); if (!$this->installCompmain->getSessionDb($database, $dbhost, $dbusername, $dbpass, $dbname, $dbprefix, $dbpersist, $dsn)) { return false; } // // 共通テーブルCreate // $file_path = "/install/sql/" . $database . "/" . _SYS_TABLE_INI; if (!@file_exists(MODULE_DIR . $file_path)) { // mysqliならば、mysqlがあればそちらを使う if ($database != "mysqli") { return false; } $database = "mysql"; $file_path = "/install/sql/" . $database . "/" . _SYS_TABLE_INI; if (!@file_exists(MODULE_DIR . $file_path)) { return false; } } //モジュールに使用するテーブルあり // SQLファイルの読み込み $handle = fopen(MODULE_DIR . $file_path, 'r'); $sql_query = fread($handle, filesize(MODULE_DIR . $file_path)); fclose($handle); $sql_query = trim($sql_query); // SQLユーティリティクラスにて各クエリを配列に格納する $this->databaseSqlutility->splitMySqlFile($pieces, $sql_query); // // DB接続 // //include_once $base_dir.'/maple/nccore/db/DbObjectAdodb.class.php'; include_once BASE_DIR . '/maple/nccore/db/DbObjectAdodb.class.php'; $dbObject = new DbObjectAdodb(); $dbObject->setPrefix($dbprefix); $dbObject->setDsn($dsn); $conn_result = @$dbObject->connect(); if ($conn_result == false) { // DBが存在しない場合、CREATE DATABASE $this->res_arr[] = INSTALL_IMG_NO . sprintf(INSTALL_DBCHECK_NOT_CONNECT, $dbname) . "<div class=\"install_checkdb_createdb\">" . INSTALL_DBCHECK_NOT_FOUND . "</div>" . "<div class=\"install_checkdb_createdb bold\"> " . $dbname . "</div>" . "<div class=\"install_checkdb_createdb\">" . INSTALL_DBCHECK_CONFIRM_CREATE_DB . "</div>"; return false; } // DBが存在する場合 $result = true; foreach ($pieces as $piece) { // SQLユーティリティクラスにてテーブル名にプレフィックスをつける // 配列としてリターンされ、 // [0] プレフィックスをつけたクエリ // [4] プレフィックスをつけないテーブル名 // が格納されている $prefixed_query = $this->databaseSqlutility->prefixQuery($piece, $dbObject->getPrefix()); if (!$prefixed_query) { $this->res_arr[] = INSTALL_IMG_NO . sprintf(INSTALL_TBCREATE_FAILED_CREATE, $dbObject->getPrefix() . $prefixed_query[4]); $result = false; continue; } // 実行 if (!$dbObject->execute($prefixed_query[0])) { $this->res_arr[] = INSTALL_IMG_NO . sprintf(INSTALL_TBCREATE_FAILED_CREATE, $dbObject->getPrefix() . $prefixed_query[4]); $result = false; continue; } else { // 成功 $this->res_arr[] = INSTALL_IMG_YES . sprintf(INSTALL_TBCREATE_SUCCESS_CREATE, $dbObject->getPrefix() . $prefixed_query[4]); } } return $result; }
/** * SQLファイル実行 * param string $file_name * param string $type * * @access public */ function executeSqlFile($file_name, $type = "default") { $res_arr = array(); $result = false; $_lang = $this->_session->getParameter("_lang"); $base_dir = $this->_session->getParameter("base_dir"); $sitename = addslashes($this->_session->getParameter("sitename")); $modulesView =& $this->_container->getComponent("modulesView"); //$modules[$dir_name], $self_site_id, $private_room_name, $admin_user_id $self_site_id = $this->_session->getParameter("install_self_site_id"); $admin_user_id = $this->_session->getParameter("install_user_id"); $admin_login_id = $this->_session->getParameter("install_login_id"); $admin_handle = addslashes($this->_session->getParameter("install_handle")); $permalink = preg_replace(_PERMALINK_PROHIBITION, _PERMALINK_PROHIBITION_REPLACE, $admin_handle); $this->getSessionDb($database, $dbhost, $dbusername, $dbpass, $dbname, $dbprefix, $dbpersist, $dsn); // // DB接続 // //include_once $base_dir.'/maple/nccore/db/DbObjectAdodb.class.php'; include_once BASE_DIR . '/maple/nccore/db/DbObjectAdodb.class.php'; $dbObject = new DbObjectAdodb(); $dbObject->setPrefix($dbprefix); $dbObject->setDsn($dsn); $conn_result = @$dbObject->connect(); if ($conn_result == false) { // DB接続失敗 $res_arr[] = INSTALL_IMG_NO . sprintf(INSTALL_DBCHECK_NOT_CONNECT, $dbname); return array($result, $res_arr); } // $modules[$dir_name] $modules = $dbObject->execute("SELECT {modules}.* FROM {modules}", array(), null, null, true, array($this, "_fetchcallbackModules"), array($modulesView)); if ($modules === false) { // とりあえずDB接続失敗のエラーメッセージとする $res_arr[] = INSTALL_IMG_NO . sprintf(INSTALL_DBCHECK_NOT_CONNECT, $dbname); return array($result, $res_arr); } $databaseSqlutility =& $this->_container->getComponent("databaseSqlutility"); $config_db_kind = $database; $lang_file_path = $base_dir . '/webapp/modules/install/language/' . $_lang . '/' . $file_name; if (!@file_exists($lang_file_path)) { $_lang = "english"; $lang_file_path = $base_dir . '/webapp/modules/install/language/' . $_lang . '/' . $file_name; } include_once $lang_file_path; if (defined(strtoupper("INSTALL_CONF_ADD_PRIVATE_SPACE_NAME_" . $_lang))) { $private_room_name = str_replace("{X-HANDLE}", $admin_handle, constant(strtoupper('INSTALL_CONF_ADD_PRIVATE_SPACE_NAME_' . $_lang))); $this->_session->setParameter("install_private_room_name", $private_room_name); } else { $private_room_name = $this->_session->getParameter("install_private_room_name"); } $file_path = $base_dir . '/webapp/modules/install/sql/' . $database . '/' . $type . "/" . $file_name; if (!@file_exists($file_path) && $database == "mysqli") { $database = "mysql"; $file_path = $base_dir . '/webapp/modules/install/sql/' . $database . '/' . $type . "/" . $file_name; } $data = ""; include_once $file_path; if ($file_name == INSTALL_CONFIG_DATA_FILENAME) { $config_lang_sql = ''; $languages = array('japanese', 'english', 'chinese'); $items = explode(',', _MULTI_LANG_CONFIG_ITEMS); foreach ($languages as $lang_dirname) { include_once $base_dir . '/webapp/modules/install/language/' . $lang_dirname . '/' . $file_name; foreach ($items as $item) { if ($item == 'sitename') { $conf_value = $sitename; } else { if ($item == 'from') { $conf_value = 'netcommons'; } else { $conf_value = constant(strtoupper('INSTALL_CONF_' . $item . '_' . $lang_dirname)); } } $config_lang_sql .= "INSERT INTO `config_language` (`conf_name`, `lang_dirname`, `conf_value`) VALUES ('" . $item . "', '" . $lang_dirname . "', '" . $conf_value . "');"; } } $data .= $config_lang_sql; } $databaseSqlutility->splitMySqlFile($pieces, $data); $result = true; $config_success_count = 0; $config_failed_count = 0; $adodb =& $dbObject->getAdoDbObject(); $savetable_name = ""; foreach ($pieces as $piece) { // SQLユーティリティクラスにてテーブル名にプレフィックスをつける // 配列としてリターンされ、 // [0] プレフィックスをつけたクエリ // [4] プレフィックスをつけないテーブル名 // が格納されている $prefixed_query = $databaseSqlutility->prefixQuery($piece, $dbObject->getPrefix()); //$prefixed_query_result = true; if (!$prefixed_query) { //$prefixed_query_result = false; $result = false; $res_arr[] = INSTALL_IMG_NO . sprintf(INSTALL_INSERT_DATA_FAILED_INSERT, 1, "Unknown Table"); continue; } if ($savetable_name != $prefixed_query[4]) { // テーブルが変わった if ($savetable_name != "") { // メッセージ if ($config_success_count > 0) { // 成功 $res_arr[] = INSTALL_IMG_YES . sprintf(INSTALL_INSERT_DATA_SUCCESS_INSERT, $config_success_count, $savetable_name); } if ($config_failed_count > 0) { $result = false; $res_arr[] = INSTALL_IMG_NO . sprintf(INSTALL_INSERT_DATA_FAILED_INSERT, $config_failed_count, $savetable_name); } $config_success_count = 0; $config_failed_count = 0; } $savetable_name = $prefixed_query[4]; } // 実行 //$dbObject->executeはprefixの変換処理があるため使用しない if (!$adodb->Execute($prefixed_query[0])) { $config_failed_count++; $result = false; //continue; } else { // 成功 $config_success_count++; } } if ($savetable_name != "") { // メッセージ if ($config_success_count > 0) { // 成功 $res_arr[] = INSTALL_IMG_YES . sprintf(INSTALL_INSERT_DATA_SUCCESS_INSERT, $config_success_count, $savetable_name); } if ($config_failed_count > 0) { $result = false; $res_arr[] = INSTALL_IMG_NO . sprintf(INSTALL_INSERT_DATA_FAILED_INSERT, $config_failed_count, $savetable_name); } //$config_success_count = 0; //$config_failed_count = 0; } return array($result, $res_arr); }