From f20d227905f9cd220915c93a6a8b948c9931dde1 Mon Sep 17 00:00:00 2001
From: Adrien <af@brain-networks.fr>
Date: Mon, 31 Dec 2018 17:20:51 +0100
Subject: [PATCH] Webservice PHP 7 compatibility

---
 include/Webservices/QueryParser.php               | 12 ++++++++++--
 include/Webservices/SessionManager.php            | 11 +++++++++--
 include/Webservices/State.php                     |  9 ++++++++-
 include/Webservices/VtigerCRMActorMeta.php        |  9 ++++++++-
 include/Webservices/VtigerCRMObject.php           | 10 ++++++++--
 include/Webservices/VtigerCRMObjectMeta.php       |  9 ++++++++-
 include/Webservices/VtigerModuleOperation.php     |  9 ++++++++-
 include/Webservices/VtigerWebserviceObject.php    | 10 +++++++++-
 include/Webservices/WebServiceError.php           | 10 ++++++++--
 include/Webservices/WebserviceEntityOperation.php |  9 ++++++++-
 10 files changed, 84 insertions(+), 14 deletions(-)

diff --git a/include/Webservices/QueryParser.php b/include/Webservices/QueryParser.php
index 1cbca970e..7333463d4 100644
--- a/include/Webservices/QueryParser.php
+++ b/include/Webservices/QueryParser.php
@@ -19,11 +19,19 @@
 		private $hasError ;
 		private $error ;
 		private $user; 
-		function Parser($user, $q){
+		function __construct($user, $q)
+		{
 			$this->query = $q;
 			$this->out = array();
 			$this->hasError = false;
-			$this->user = $user; 
+			$this->user = $user;
+		}
+
+		function Parser($user, $q){
+			// PHP4-style constructor.
+			// This will NOT be invoked, unless a sub-class that extends `foo` calls it.
+			// In that case, call the new-style constructor to keep compatibility.
+			self::__construct($user, $q);
 		}
 		
 		function parse(){
diff --git a/include/Webservices/SessionManager.php b/include/Webservices/SessionManager.php
index fff4e25cb..e325d9914 100644
--- a/include/Webservices/SessionManager.php
+++ b/include/Webservices/SessionManager.php
@@ -26,8 +26,8 @@
 		private $sessionVar = "__SessionExists";
 		private $error ;
 		
-		function SessionManager(){
-			
+		function __construct()
+		{
 			global $maxWebServiceSessionLifeSpan, $maxWebServiceSessionIdleTime;
 			
 			$now = time();
@@ -42,6 +42,13 @@
 			//otherwise it subtracts the time from previous time
 			HTTP_Session2::setIdle($this->idleLife, true);
 		}
+		function SessionManager(){
+			// PHP4-style constructor.
+			// This will NOT be invoked, unless a sub-class that extends `foo` calls it.
+			// In that case, call the new-style constructor to keep compatibility.
+			self::__construct();
+			
+		}
 		
 		function isValid(){
 			
diff --git a/include/Webservices/State.php b/include/Webservices/State.php
index c5c162174..a91c95218 100644
--- a/include/Webservices/State.php
+++ b/include/Webservices/State.php
@@ -14,11 +14,18 @@
 		var $result ;
 		var $error;
 		
-		function State(){
+		function __construct()
+		{
 			$this->success = false;
 			$this->result = array();
 			$this->error = array();
 		}
+		function State(){
+			// PHP4-style constructor.
+			// This will NOT be invoked, unless a sub-class that extends `foo` calls it.
+			// In that case, call the new-style constructor to keep compatibility.
+			self::__construct();
+		}
 		
 		
 	}
diff --git a/include/Webservices/VtigerCRMActorMeta.php b/include/Webservices/VtigerCRMActorMeta.php
index cab7a7c92..962af7092 100644
--- a/include/Webservices/VtigerCRMActorMeta.php
+++ b/include/Webservices/VtigerCRMActorMeta.php
@@ -13,7 +13,8 @@ class VtigerCRMActorMeta extends EntityMeta {
 	protected static $fieldTypeMapping = array();
 	protected static $referenceTypeMapping = array();
 	
-	function VtigerCRMActorMeta($tableName,$webserviceObject,$adb,$user){
+	function __construct($tableName,$webserviceObject,$adb,$user)
+	{
 		parent::__construct($webserviceObject,$user);
 		$this->baseTable = $tableName;
 		$this->idColumn = null;
@@ -23,6 +24,12 @@ class VtigerCRMActorMeta extends EntityMeta {
 		$this->tableIndexList = null;
 		$this->defaultTableList = array();
 	}
+	function VtigerCRMActorMeta($tableName,$webserviceObject,$adb,$user){
+		// PHP4-style constructor.
+		// This will NOT be invoked, unless a sub-class that extends `foo` calls it.
+		// In that case, call the new-style constructor to keep compatibility.
+		self::__construct($tableName,$webserviceObject,$adb,$user);
+	}
     
     public function getIdColumn() {
         if($this->idColumn === null) {
diff --git a/include/Webservices/VtigerCRMObject.php b/include/Webservices/VtigerCRMObject.php
index 033ffd683..45f472ca0 100644
--- a/include/Webservices/VtigerCRMObject.php
+++ b/include/Webservices/VtigerCRMObject.php
@@ -13,8 +13,8 @@ class VtigerCRMObject{
 	private $moduleName ;
 	private $moduleId ;
 	private $instance ;
-	
-	function VtigerCRMObject($moduleCredential, $isId=false){
+	function __construct($moduleCredential, $isId=false)
+	{
 		
 		if($isId){
 			$this->moduleId = $moduleCredential;
@@ -26,6 +26,12 @@ class VtigerCRMObject{
 		$this->instance = null;
 		$this->getInstance();
 	}
+	function VtigerCRMObject($moduleCredential, $isId=false){
+		// PHP4-style constructor.
+		// This will NOT be invoked, unless a sub-class that extends `foo` calls it.
+		// In that case, call the new-style constructor to keep compatibility.
+		self::__construct($moduleCredential, $isId);
+	}
 	
 	public function getModuleName(){
 		return $this->moduleName;
diff --git a/include/Webservices/VtigerCRMObjectMeta.php b/include/Webservices/VtigerCRMObjectMeta.php
index dc4afcb3d..d0941fd81 100644
--- a/include/Webservices/VtigerCRMObjectMeta.php
+++ b/include/Webservices/VtigerCRMObjectMeta.php
@@ -21,7 +21,8 @@ class VtigerCRMObjectMeta extends EntityMeta {
 	private $hasDeleteAccess;
 	private $assignUsers;
 	
-	function VtigerCRMObjectMeta($webserviceObject,$user){
+	function __construct($webserviceObject,$user)
+	{
 		
 		parent::__construct($webserviceObject,$user);
 		
@@ -50,6 +51,12 @@ class VtigerCRMObjectMeta extends EntityMeta {
 		}
 		$this->tabId = null;
 	}
+	function VtigerCRMObjectMeta($webserviceObject,$user){
+		// PHP4-style constructor.
+		// This will NOT be invoked, unless a sub-class that extends `foo` calls it.
+		// In that case, call the new-style constructor to keep compatibility.
+		self::__construct($webserviceObject,$user);
+	}
 
 	/**
 	 * returns tabid of the current object.
diff --git a/include/Webservices/VtigerModuleOperation.php b/include/Webservices/VtigerModuleOperation.php
index 675b67ff8..284b9b098 100644
--- a/include/Webservices/VtigerModuleOperation.php
+++ b/include/Webservices/VtigerModuleOperation.php
@@ -13,11 +13,18 @@ class VtigerModuleOperation extends WebserviceEntityOperation {
 	protected $isEntity = true;
 	protected $partialDescribeFields = null;
 	
-	public function VtigerModuleOperation($webserviceObject,$user,$adb,$log){
+	public function __construct($webserviceObject,$user,$adb,$log)
+	{
 		parent::__construct($webserviceObject,$user,$adb,$log);
 		$this->meta = $this->getMetaInstance();
 		$this->tabId = $this->meta->getTabId();
 	}
+	public function VtigerModuleOperation($webserviceObject,$user,$adb,$log){
+		// PHP4-style constructor.
+		// This will NOT be invoked, unless a sub-class that extends `foo` calls it.
+		// In that case, call the new-style constructor to keep compatibility.
+		self::__construct($webserviceObject,$user,$adb,$log);
+	}
 	
 	protected function getMetaInstance(){
 		if(empty(WebserviceEntityOperation::$metaCache[$this->webserviceObject->getEntityName()][$this->user->id])){
diff --git a/include/Webservices/VtigerWebserviceObject.php b/include/Webservices/VtigerWebserviceObject.php
index 23783a98f..73581148a 100644
--- a/include/Webservices/VtigerWebserviceObject.php
+++ b/include/Webservices/VtigerWebserviceObject.php
@@ -15,7 +15,8 @@ class VtigerWebserviceObject{
 	private $handlerPath;
 	private $handlerClass;
 	
-	private function VtigerWebserviceObject($entityId,$entityName,$handler_path,$handler_class){
+	private function __construct($entityId,$entityName,$handler_path,$handler_class)
+	{
 		$this->id = $entityId;
 		$this->name = $entityName;
 		// Quick Fix to override default Actor class & path (good to update DB itself)
@@ -28,6 +29,13 @@ class VtigerWebserviceObject{
 		$this->handlerClass = $handler_class;
 	}
 	
+	private function VtigerWebserviceObject($entityId,$entityName,$handler_path,$handler_class){
+		// PHP4-style constructor.
+		// This will NOT be invoked, unless a sub-class that extends `foo` calls it.
+		// In that case, call the new-style constructor to keep compatibility.
+		self::__construct($entityId,$entityName,$handler_path,$handler_class);
+	}
+	
 	// Cache variables to enable result re-use
 	private static $_fromNameCache = array();
 		
diff --git a/include/Webservices/WebServiceError.php b/include/Webservices/WebServiceError.php
index 13725b7b3..9f8009aba 100644
--- a/include/Webservices/WebServiceError.php
+++ b/include/Webservices/WebServiceError.php
@@ -13,11 +13,17 @@
 		
 		public $code;
 		public $message;
-		
-		function WebServiceException($errCode,$msg){
+		function __construct($errCode,$msg)
+		{
 			$this->code = $errCode;
 			$this->message = $msg;
 		}
+		function WebServiceException($errCode,$msg){
+			// PHP4-style constructor.
+			// This will NOT be invoked, unless a sub-class that extends `foo` calls it.
+			// In that case, call the new-style constructor to keep compatibility.
+			self::__construct($errCode,$msg);
+		}
 		
 	}
 	
diff --git a/include/Webservices/WebserviceEntityOperation.php b/include/Webservices/WebserviceEntityOperation.php
index d53176a5d..876d2d45d 100644
--- a/include/Webservices/WebserviceEntityOperation.php
+++ b/include/Webservices/WebserviceEntityOperation.php
@@ -21,12 +21,19 @@ abstract class WebserviceEntityOperation{
 	
 	protected static $metaCache = array();
 	
-	protected function WebserviceEntityOperation($webserviceObject,$user,$adb,$log){
+	protected function __construct($webserviceObject,$user,$adb,$log)
+	{
 		$this->user = $user;
 		$this->log = $log;
 		$this->webserviceObject = $webserviceObject;
 		$this->pearDB = $adb;
 	}
+	protected function WebserviceEntityOperation($webserviceObject,$user,$adb,$log){
+		// PHP4-style constructor.
+		// This will NOT be invoked, unless a sub-class that extends `foo` calls it.
+		// In that case, call the new-style constructor to keep compatibility.
+		self::__construct($webserviceObject,$user,$adb,$log);
+	}
 	
 	public function create($elementType,$element){
 		throw new WebServiceException(WebServiceErrorCode::$OPERATIONNOTSUPPORTED,
-- 
GitLab