[xoops-cvslog 5786] CVS update: xoops2jp/html/modules/legacy/admin/class

Back to archive index

Minahito minah****@users*****
2006年 11月 11日 (土) 17:37:38 JST


Index: xoops2jp/html/modules/legacy/admin/class/ModuleInstallUtils.class.php
diff -u xoops2jp/html/modules/legacy/admin/class/ModuleInstallUtils.class.php:1.1.2.5 xoops2jp/html/modules/legacy/admin/class/ModuleInstallUtils.class.php:1.1.2.6
--- xoops2jp/html/modules/legacy/admin/class/ModuleInstallUtils.class.php:1.1.2.5	Sat Nov 11 02:13:40 2006
+++ xoops2jp/html/modules/legacy/admin/class/ModuleInstallUtils.class.php	Sat Nov 11 17:37:37 2006
@@ -110,33 +110,85 @@
 			return;
 		}
 		
-		require_once XOOPS_MODULE_PATH . "/legacy/admin/class/Legacy_SQLScanner.class.php";
-		$scanner =& new Legacy_SQLScanner();
-		$scanner->setDB_PREFIX(XOOPS_DB_PREFIX);
-		
 		$sqlfile = $sqlfileInfo[XOOPS_DB_TYPE];
-		if (!$scanner->loadFile(XOOPS_MODULE_PATH . "/${dirname}/" . $sqlfile)) {
-			$log->addError(XCube_Utils::formatMessage(_AD_LEGACY_ERROR_SQL_FILE_NOT_FOUND, $sqlfile));
-			return false;
+		$sqlfilepath = XOOPS_MODULE_PATH . "/${dirname}/${sqlfile}";
+		
+		if (isset($module->modinfo['cube_style']) && $module->modinfo['cube_style'] == true) {
+			require_once XOOPS_MODULE_PATH . "/legacy/admin/class/Legacy_SQLScanner.class.php";
+			$scanner =& new Legacy_CubeStyleSQLScanner();
+			$scanner->setDB_PREFIX(XOOPS_DB_PREFIX);
+			$scanner->setDirname($module->get('dirname'));
+			
+			if (!$scanner->loadFile($sqlfilepath)) {
+				$log->addError(XCube_Utils::formatMessage(_AD_LEGACY_ERROR_SQL_FILE_NOT_FOUND, $sqlfile));
+				return false;
+			}
+	
+			$scanner->parse();
+			$sqls = $scanner->getSQL();
+			
+			$root =& XCube_Root::getSingleton();
+			$db =& $root->mController->getDB();
+			
+			//
+			// TODO The following variable exists for rollback, but it is not implemented.
+			//
+			foreach ($sqls as $sql) {
+				if (!$db->query($sql)) {
+					$log->addError($db->error());
+					return;
+				}
+			}
+			
+			$log->addReport(_AD_LEGACY_MESSAGE_DATABASE_SETUP_FINISHED);
 		}
+		else {
+			require_once XOOPS_ROOT_PATH.'/class/database/sqlutility.php';
+			
+			$reservedTables = array('avatar', 'avatar_users_link', 'block_module_link', 'xoopscomments', 'config', 'configcategory', 'configoption', 'image', 'imagebody', 'imagecategory', 'imgset', 'imgset_tplset_link', 'imgsetimg', 'groups','groups_users_link','group_permission', 'online', 'bannerclient', 'banner', 'bannerfinish', 'priv_msgs', 'ranks', 'session', 'smiles', 'users', 'newblocks', 'modules', 'tplfile', 'tplset', 'tplsource', 'xoopsnotifications', 'banner', 'bannerclient', 'bannerfinish');
 
-		$scanner->parse();
-		$sqls = $scanner->getSQL();
-		
-		$root =& XCube_Root::getSingleton();
-		$db =& $root->mController->getDB();
-		
-		//
-		// TODO The following variable exists for rollback, but it is not implemented.
-		//
-		foreach ($sqls as $sql) {
-			if (!$db->query($sql)) {
-				$log->addError($db->error());
-				return;
+			$root =& XCube_Root::getSingleton();
+			$db =& $root->mController->mDB;
+			
+			$sql_query = fread(fopen($sqlfilepath, 'r'), filesize($sqlfilepath));
+			$sql_query = trim($sql_query);
+			SqlUtility::splitMySqlFile($pieces, $sql_query);
+			$created_tables = array();
+			foreach ($pieces as $piece) {
+				// [0] contains the prefixed query
+				// [4] contains unprefixed table name
+				$prefixed_query = SqlUtility::prefixQuery($piece, $db->prefix());
+				if (!$prefixed_query) {
+					$log->addError("${piece} is not a valid SQL!");
+					return;
+				}
+				
+				// check if the table name is reserved
+				if (!in_array($prefixed_query[4], $reservedTables)) {
+					// not reserved, so try to create one
+					if (!$db->query($prefixed_query[0])) {
+						foreach ($db->error() as $error) {
+							$log->addError($error);
+						}
+						return;
+					}
+					else {
+						if (!in_array($prefixed_query[4], $created_tables)) {
+							$log->addReport('  Table ' . $db->prefix($prefixed_query[4]) . ' created.');
+							$created_tables[] = $prefixed_query[4];
+						}
+						else {
+							$log->addReport('  Data inserted to table ' . $db->prefix($prefixed_query[4]));
+						}
+					}
+				}
+				else {
+					// the table name is reserved, so halt the installation
+					$log->addError($prefixed_query[4] . " is a reserved table!");
+					return;
+				}
 			}
 		}
-		
-		$log->addReport(_AD_LEGACY_MESSAGE_DATABASE_SETUP_FINISHED);
 	}
 	
 	/**


xoops-cvslog メーリングリストの案内
Back to archive index