View Single Post
  #2  
Old 20th March 2013, 18:52
abdi abdi is offline
Senior Member
 
Join Date: Sep 2012
Posts: 118
Thanks: 0
Thanked 10 Times in 6 Posts
Lightbulb Complete

Hello Till,

Here is the backup download / restore API function. I have tested it and it works. You may however advice on the code formats and if any suggestions especially in the area of reporting errors.

Code:
	//* Backup download and restoration by Abdi Joseph
	public function sites_web_domain_backup($session_id, $backup_id, $params)
    {
		global $app;
		
		//*Set variables
		$action_type	=	$params['action_type'];		
		$backup_record 	= 	$app->db->queryOneRecord("SELECT * FROM `web_backup` WHERE `backup_id`='$backup_id'");		
		$server_id		=	$backup_record['server_id'];

		//*Set default action state
		$action_state	=	"pending";		
		$tstamp			=	time();
		
		//* Basic validation of variables
		if ($server_id <= 0) return "Invalid or non existant backup_id $backup_id";
		if ($action_type != 'backup_download' and $action_type != 'backup_restore') return "Invalid action_type $action_type";
		
		//* Validate instance
		$instance_record	=	$app->db->queryOneRecord("SELECT * FROM `sys_remoteaction` WHERE `action_param`='$backup_id' and `action_type`='$action_type' and `action_state`='pending'");	
		if ($instance_record['action_id'] >= 1) return "There is already a pending $action_type action";
		
		//* Save the record
		if ($app->db->query("INSERT INTO `sys_remoteaction` SET 
			`server_id`		=	'$server_id',
			`tstamp`		=	'$tstamp',
 	 		`action_type`	=	'$action_type',
 	 		`action_param`	=	'$backup_id',
			`action_state`	=	'$action_state'")) return true;
		else return false;
	}
To test drive it you can use the following:

Code:
try 
{ 
	$session_id = $client->login($username,$password);
	
	//* Set the function parameters.
	$backup_id 		= 	2;
	$action_type	=	"backup_restore";
	$params = array(
			'action_type' 	=> $action_type
			);
	
	print_r($client->sites_web_domain_backup($session_id, $backup_id, $params));
} catch (SoapFault $e) { echo $client->__getLastResponse(); die('SOAP Error: '.$e->getMessage()); }
If everything is fine, let me so that I can work on the documentation as well ...

I will attach the finel remoting.inc.php file on your approval.
Reply With Quote