Pārlūkot izejas kodu

Module Prerequisites Checking Added and Installer Changes

own3mall 8 gadi atpakaļ
vecāks
revīzija
a44aebb1e1

+ 7 - 0
includes/functions.php

@@ -829,4 +829,11 @@ function utf8ize($d, $htmlEntities = true) {
     }
     return $d;
 }
+
+function preReqInstalled($prereq){
+	if (($prereq['type'] === "f" && function_exists($prereq['value'])) || ($prereq['type'] === "c" && class_exists($prereq['value'])) || ($prereq['type'] === "x" && extension_loaded($prereq['value']))){
+		return true;
+	}
+	return false;
+}
 ?>

+ 11 - 19
install.php

@@ -249,16 +249,12 @@ function install() {
         echo "<h3>".get_lang('checking_required_modules')."</h3>\n<table class='install'>";
 
         foreach ( $properties_to_check as $propertie ) {
-            if ( ( $propertie['type'] === "f" && function_exists($propertie['value']) ) ||
-                ( $propertie['type'] === "c" && class_exists($propertie['value']) ) ||
-				( $propertie['type'] === "x" && extension_loaded($propertie['value']) ) ) {
-                    echo "<tr><td>".$propertie['name']."</td>
-                        <td><span class='success'>".get_lang('found')."</span></td></tr>";
-                } else {
-					echo "<tr><td>".$propertie['name']."</td>
-							<td><span class='failure'>".get_lang('not_found')."</span></td></tr>";
-					$failed = true;
-                }
+			if(preReqInstalled($propertie)){
+				echo "<tr><td>".$propertie['name']."</td><td><span class='success'>".get_lang('found')."</span></td></tr>";
+			}else{
+				echo "<tr><td>".$propertie['name']."</td><td><span class='failure'>".get_lang('not_found')."</span></td></tr>";
+				$failed = true;
+			}
         }
 
         echo "<tr><td>Pear XXTEA</td><td>";
@@ -335,17 +331,13 @@ function install() {
         echo "<h3>".get_lang('checking_optional_modules')."</h3>\n<table class='install'>";
         
         foreach ( $optional_properties_to_check as $propertie ) {
-            if ( ( $propertie['type'] === "f" && function_exists($propertie['value']) ) ||
-                ( $propertie['type'] === "c" && class_exists($propertie['value']) ) ||
-				( $propertie['type'] === "x" && extension_loaded($propertie['value']) ) ) {
-					
-				echo "<tr><td>".$propertie['name']."</td>
-                        <td><span class='success'>".get_lang('found')."</span></td></tr>";
+			if(preReqInstalled($propertie)){
+				echo "<tr><td>".$propertie['name']."</td><td><span class='success'>".get_lang('found')."</span></td></tr>";
 			}else{
-				echo "<tr><td>".$propertie['name']."</td>
-							<td><span class='warning'>".get_lang('not_found')."</span></td></tr>";
+				echo "<tr><td>".$propertie['name']."</td><td><span class='warning'>".get_lang('not_found')."</span></td></tr>";
+				$failed = true;
 			}
-		}
+        }
 		
 		echo "</table>\n";
 

+ 2 - 1
lang/English/modules/modulemanager.php

@@ -52,4 +52,5 @@ define('OGP_LANG_failed_del_db', "Failed to delete module from database.");
 define('OGP_LANG_updated_module', "Updated module: '%s'.");
 define('OGP_LANG_updating_modules', "Updating Modules");
 define('OGP_LANG_updating_finished', "Updating Finished");
-?>
+define('OGP_LANG_prereqs_missing', "Prerequisites of %s must be installed on the server before %s can be installed.");
+?>

+ 24 - 1
modules/modulemanager/module_handling.php

@@ -33,7 +33,7 @@ function list_available_modules()
 /// \return 1 If module installation was successfull.
 /// \return 2 If module installation was optional and module was not installed.
 function install_module($db, $module, $install_if_optional = TRUE)
-{
+{	
     // each module must have module.php file which contains the required variables.
     /// \todo We might want to turn this to XML file.
     if ( !is_file("modules/".$module."/module.php") )
@@ -52,6 +52,29 @@ function install_module($db, $module, $install_if_optional = TRUE)
 
     if ( $db->isModuleInstalled($module) )
         return 0;
+        
+    // Prerequisites checking
+    if(isset($module_prereqs) && is_array($module_prereqs) && count($module_prereqs)){
+		$prereqPass = true;
+		$missingPrereqs = "";
+		$i = 0;
+		foreach($module_prereqs as $prereq){
+			if(!preReqInstalled($prereq)){
+				if($i == 0){
+					$missingPrereqs .= $prereq["name"];
+				}else{
+					$missingPrereqs .= ", " . $prereq["name"];
+				}
+				$prereqPass = false;
+			}
+			$i++;
+		}
+		
+		if(!$prereqPass){
+			print_failure(get_lang_f("prereqs_missing", $missingPrereqs, $module_title));
+			return -2;
+		}
+	}
 
     // Check if the module should be installed or not.
     if ( $install_if_optional == FALSE && $module_required == FALSE )