From 52e5e543af5787350bf9d4e428249ae4cc8cc574 Mon Sep 17 00:00:00 2001
From: mcramer <m.cramer@pixcept.de>
Date: Wed, 07 Aug 2013 11:42:22 -0400
Subject: [PATCH] - Fixed: php compile fatal errors

---
 server/lib/classes/aps_installer.inc.php |   61 +++++++++++++++++++++++-------
 1 files changed, 46 insertions(+), 15 deletions(-)

diff --git a/server/lib/classes/aps_installer.inc.php b/server/lib/classes/aps_installer.inc.php
index 94d5ee0..6cb922f 100644
--- a/server/lib/classes/aps_installer.inc.php
+++ b/server/lib/classes/aps_installer.inc.php
@@ -257,7 +257,7 @@
         $this->document_root = $domain_res['document_root'];
         
         // Get the sub location
-        $location_res = $app->dbmaster->queryOneRecord("SELECT value FROM aps_instances_settings 
+        $location_res = $app->db->queryOneRecord("SELECT value FROM aps_instances_settings 
             WHERE name = 'main_location' AND instance_id = '".$app->db->quote($task['instance_id'])."';");
         $this->sublocation = $location_res['value'];
         
@@ -294,7 +294,8 @@
         $db_id = parent::getXPathValue($sxe, '//db:id');
         if(empty($db_id)) return; // No database needed
         
-		/*
+		/* WARNING: if this will ever be uncommented please check the updated prefix handling for user and db names!!!
+         * 
         // Set the database owner to the domain owner
         // ISPConfig identifies the owner by the sys_groupid (not sys_userid!)
         // so sys_userid can be set to any value
@@ -313,14 +314,14 @@
         
         $this->newdb_name = $dbname_prefix.$task['CustomerID'].'aps'.$task['InstanceID'];
         $this->newdb_user = $dbuser_prefix.$task['CustomerID'].'aps'.$task['InstanceID'];
-        $dbpw_res = $app->dbmaster->queryOneRecord("SELECT Value FROM aps_instances_settings  
+        $dbpw_res = $app->db->queryOneRecord("SELECT Value FROM aps_instances_settings  
             WHERE Name = 'main_database_password' AND InstanceID = '".$app->db->quote($task['InstanceID'])."';");
         $newdb_pw = $dbpw_res['Value'];
  
         // In any case delete an existing database (install and removal procedure)
         $app->db->query('DROP DATABASE IF EXISTS `'.$app->db->quote($this->newdb_name).'`;');
         // Delete an already existing database with this name
-        $app->dbmaster->query("DELETE FROM web_database WHERE database_name = '".$app->db->quote($this->newdb_name)."';");
+        $app->db->query("DELETE FROM web_database WHERE database_name = '".$app->db->quote($this->newdb_name)."';");
         
         
         // Create the new database and assign it to a user
@@ -333,7 +334,7 @@
         
             // Add the new database to the customer databases
             // Assumes: charset = utf8
-            $app->dbmaster->query('INSERT INTO web_database (sys_userid, sys_groupid, sys_perm_user, sys_perm_group, sys_perm_other, server_id, 
+            $app->db->query('INSERT INTO web_database (sys_userid, sys_groupid, sys_perm_user, sys_perm_group, sys_perm_other, server_id, 
                 type, database_name, database_user, database_password, database_charset, remote_access, remote_ips, active) 
                 VALUES ('.$task['sys_userid'].', '.$task['sys_groupid'].', "'.$task['sys_perm_user'].'", "'.$task['sys_perm_group'].'", 
                 "'.$task['sys_perm_other'].'", '.$app->db->quote($serverid).', "mysql", "'.$app->db->quote($this->newdb_name).'", 
@@ -344,16 +345,16 @@
         $mysqlver_res = $app->db->queryOneRecord('SELECT VERSION() as ver;');
         $mysqlver = $mysqlver_res['ver'];
 		
-		$tmp = $app->dbmaster->queryOneRecord("SELECT value FROM aps_instances_settings WHERE name = 'main_database_password' AND instance_id = '".$app->db->quote($task['instance_id'])."';");
+		$tmp = $app->db->queryOneRecord("SELECT value FROM aps_instances_settings WHERE name = 'main_database_password' AND instance_id = '".$app->db->quote($task['instance_id'])."';");
         $newdb_pw = $tmp['value'];
 		
-		$tmp = $app->dbmaster->queryOneRecord("SELECT value FROM aps_instances_settings WHERE name = 'main_database_host' AND instance_id = '".$app->db->quote($task['instance_id'])."';");
+		$tmp = $app->db->queryOneRecord("SELECT value FROM aps_instances_settings WHERE name = 'main_database_host' AND instance_id = '".$app->db->quote($task['instance_id'])."';");
         $newdb_host = $tmp['value'];
 		
-		$tmp = $app->dbmaster->queryOneRecord("SELECT value FROM aps_instances_settings WHERE name = 'main_database_name' AND instance_id = '".$app->db->quote($task['instance_id'])."';");
+		$tmp = $app->db->queryOneRecord("SELECT value FROM aps_instances_settings WHERE name = 'main_database_name' AND instance_id = '".$app->db->quote($task['instance_id'])."';");
         $newdb_name = $tmp['value'];
 		
-		$tmp = $app->dbmaster->queryOneRecord("SELECT value FROM aps_instances_settings WHERE name = 'main_database_login' AND instance_id = '".$app->db->quote($task['instance_id'])."';");
+		$tmp = $app->db->queryOneRecord("SELECT value FROM aps_instances_settings WHERE name = 'main_database_login' AND instance_id = '".$app->db->quote($task['instance_id'])."';");
         $newdb_login = $tmp['value'];
         
         $this->putenv[] = 'DB_'.$db_id.'_TYPE=mysql';
@@ -396,8 +397,28 @@
 
             // Now delete an existing folder (affects install and removal in the same way)
             @chdir($this->local_installpath);
-            if(file_exists($this->local_installpath)) exec("rm -Rf ".escapeshellarg($this->local_installpath).'*');
-            else mkdir($this->local_installpath, 0777, true);
+            if(file_exists($this->local_installpath)){
+				// make sure we don't delete error and stats folders
+				if($this->local_installpath == $this->document_root.'/'){
+					if(is_dir($this->document_root)){
+						$files = array_diff(scandir($this->document_root), array('.','..','error','stats'));
+						foreach($files as $file){
+							if(is_dir($this->document_root.'/'.$file)){
+								$app->file->removeDirectory($this->document_root.'/'.$file);
+							} else {
+								@unlink($this->document_root.'/'.$file);
+							}
+						}
+					} else {
+						@unlink($this->document_root);
+						mkdir($this->document_root, 0777, true);
+					}
+				} else {
+					exec("rm -Rf ".escapeshellarg($this->local_installpath).'*');
+				}
+			} else {
+				mkdir($this->local_installpath, 0777, true);
+			}
 
             if($this->handle_type == 'install')
             {            
@@ -424,6 +445,11 @@
                 $this->file_owner_user = $owner_res['system_user']; 
                 $this->file_owner_group = $owner_res['system_group'];
                 exec('chown -R '.$this->file_owner_user.':'.$this->file_owner_group.' '.escapeshellarg($this->local_installpath));
+				
+				//* Chown stats directory back
+				if(is_dir($this->local_installpath.'stats')) {
+					exec('chown -R root:root '.escapeshellarg($this->local_installpath.'stats'));
+				}
             }
         }
         catch(Exception $e)
@@ -446,7 +472,7 @@
     {
         global $app;
         
-        $userdata = $app->dbmaster->queryAllRecords("SELECT name, value FROM aps_instances_settings 
+        $userdata = $app->db->queryAllRecords("SELECT name, value FROM aps_instances_settings 
             WHERE instance_id = '".$app->db->quote($task['instance_id'])."';");
         if(empty($userdata)) return false;
         
@@ -557,6 +583,11 @@
             {
                 // The install succeeded, chown newly created files too
                 exec('chown -R '.$this->file_owner_user.':'.$this->file_owner_group.' '.escapeshellarg($this->local_installpath));
+				
+				//* Chown stats directory back
+				if(is_dir($this->local_installpath.'stats')) {
+					exec('chown -R root:root '.escapeshellarg($this->local_installpath.'stats'));
+				}
                 
                 $app->dbmaster->query('UPDATE aps_instances SET instance_status = "'.INSTANCE_SUCCESS.'" 
                     WHERE id = "'.$app->db->quote($task['instance_id']).'";');
@@ -613,7 +644,7 @@
         if(!isset($task['instance_id'])) $task['instance_id'] = $instanceid;
 		
 		// Download aps package
-		if(!file_exists($this->packages_dir.'/'.$task['path'])) {
+		if(!file_exists($this->packages_dir.'/'.$task['path']) || filesize($this->packages_dir.'/'.$task['path']) == 0) {
 			$ch = curl_init();
 			$fh = fopen($this->packages_dir.'/'.$task['path'], 'wb');
 			curl_setopt($ch, CURLOPT_FILE, $fh); 
@@ -679,8 +710,8 @@
         // Finally delete the instance entry + settings
         if($this->handle_type == 'delete')
         {
-            $app->dbmaster->query('DELETE FROM aps_instances WHERE id = "'.$app->db->quote($task['instance_id']).'";');
-            $app->dbmaster->query('DELETE FROM aps_instances_settings WHERE instance_id = "'.$app->db->quote($task['instance_id']).'";');
+            $app->db->query('DELETE FROM aps_instances WHERE id = "'.$app->db->quote($task['instance_id']).'";');
+            $app->db->query('DELETE FROM aps_instances_settings WHERE instance_id = "'.$app->db->quote($task['instance_id']).'";');
         }
         
         unset($sxe);

--
Gitblit v1.9.1