From a548e7d1a781d0f07524eb7a1b9fedb4274ef266 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dominik=20M=C3=BCller?= <info@profi-webdesign.net>
Date: Wed, 2 Sep 2015 21:27:57 +0200
Subject: [PATCH] fixed problem with not working aps-crawler over remote (must
 use interface mode) added possibility to change package-status over remote

---
 interface/lib/classes/remote.d/aps.inc.php | 38 +++++++++++++++++++---
 interface/web/sites/lib/remote.conf.php    |  2 +-
 2 files changed, 35 insertions(+), 5 deletions(-)

diff --git a/interface/lib/classes/remote.d/aps.inc.php b/interface/lib/classes/remote.d/aps.inc.php
index b626f1b7ab..8d232f4d75 100644
--- a/interface/lib/classes/remote.d/aps.inc.php
+++ b/interface/lib/classes/remote.d/aps.inc.php
@@ -39,13 +39,15 @@ class remoting_aps extends remoting {
 	{
 		global $app;
 	
-		if(!$this->checkPerm($session_id, 'sites_aps_update_package')) {
+		if(!$this->checkPerm($session_id, 'sites_aps_update_package_list')) {
 			$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
 			return false;
 		}
-	
+		
+		require_once '../../../lib/config.inc.php';
 		$app->load('aps_crawler');
-		$aps = new ApsCrawler($app, false); // true = Interface mode, false = Server mode
+		
+		$aps = new ApsCrawler($app, true); // true = Interface mode, false = Server mode
 		$aps->startCrawler();
 		$aps->parseFolderToDB();
 		$aps->fixURLs();
@@ -53,7 +55,7 @@ class remoting_aps extends remoting {
 		return true;
 	}
 	
-	public function sites_aps_available_packages_list($session_id, $params)
+	public function sites_aps_available_packages_list($session_id, $params = array())
 	{
 		global $app;
 	
@@ -198,6 +200,34 @@ class remoting_aps extends remoting {
 		return $settings;
 	}
 	
+	public function sites_aps_change_package_status($session_id, $primary_id, $params)
+	{
+		global $app;
+	
+		if(!$this->checkPerm($session_id, 'sites_aps_change_package_status')) {
+			$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
+			return false;
+		}
+		
+		$app->load('aps_base');
+		$app->load('aps_guicontroller');
+		$gui = new ApsGUIController($app);
+		
+		// Make sure an integer ID is given
+		if (!isset($primary_id) || !$gui->isValidPackageID($primary_id, true)) {// always adminflag
+			$this->server->fault('package_error', 'The given Package ID is not valid.');
+			return false;
+		}
+		
+		if(!isset($params['package_status']) || (($params['package_status'] != PACKAGE_ENABLED) && ($params['package_status'] != PACKAGE_LOCKED))) {
+			$this->server->fault('package_error', 'Wrong new status: '.$params['package_status']);
+			return false;
+		}
+		
+		$app->db->query("UPDATE aps_packages SET package_status = ".$params['package_status']." WHERE id = '".$app->functions->intval($primary_id)."';");
+		return true;
+	}
+	
 	public function sites_aps_install_package($session_id, $primary_id, $params)
 	{
 		global $app;
diff --git a/interface/web/sites/lib/remote.conf.php b/interface/web/sites/lib/remote.conf.php
index 6548ef02c9..a9ef3236b7 100644
--- a/interface/web/sites/lib/remote.conf.php
+++ b/interface/web/sites/lib/remote.conf.php
@@ -8,5 +8,5 @@ $function_list['sites_web_domain_get,sites_web_domain_add,sites_web_domain_updat
 $function_list['sites_web_domain_backup'] = 'Sites Backup functions';
 $function_list['sites_web_aliasdomain_get,sites_web_aliasdomain_add,sites_web_aliasdomain_update,sites_web_aliasdomain_delete'] = 'Sites Aliasdomain functions';
 $function_list['sites_web_subdomain_get,sites_web_subdomain_add,sites_web_subdomain_update,sites_web_subdomain_delete'] = 'Sites Subdomain functions';
-$function_list['sites_aps_update_package_list,sites_aps_available_packages_list,sites_aps_install_package,sites_aps_get_package_details,sites_aps_get_package_file,sites_aps_get_package_settings,sites_aps_instance_get,sites_aps_instance_delete'] = 'Sites APS functions';
+$function_list['sites_aps_update_package_list,sites_aps_available_packages_list,sites_aps_change_package_status,sites_aps_install_package,sites_aps_get_package_details,sites_aps_get_package_file,sites_aps_get_package_settings,sites_aps_instance_get,sites_aps_instance_delete'] = 'Sites APS functions';
 ?>
-- 
GitLab