From e6e441a538daadd6af86efc6a5ebad5dcf537819 Mon Sep 17 00:00:00 2001
From: Uma <uma.s@vtiger.com>
Date: Mon, 4 Nov 2019 14:15:49 +0530
Subject: [PATCH] Error free installation fix

---
 include/database/PearDatabase.php                      | 10 ++++++----
 include/fields/CurrencyField.php                       |  2 +-
 include/utils/EmailTemplate.php                        |  1 +
 modules/Calendar/models/Module.php                     |  2 +-
 modules/Migration/schema/660_to_700.php                |  2 +-
 modules/Migration/schema/701_to_710.php                |  2 +-
 modules/Migration/schema/711_to_720.php                |  6 +++++-
 modules/Users/actions/SystemSetupSave.php              |  2 +-
 modules/Users/views/UserSetup.php                      |  2 +-
 modules/Vtiger/models/Module.php                       |  6 ++++--
 modules/Vtiger/uitypes/Boolean.php                     |  2 +-
 modules/Vtiger/uitypes/Currency.php                    |  2 +-
 modules/Vtiger/uitypes/Datetime.php                    |  2 +-
 modules/Vtiger/uitypes/Email.php                       |  2 +-
 modules/Vtiger/uitypes/Owner.php                       |  2 +-
 modules/Vtiger/uitypes/Picklist.php                    |  2 +-
 modules/Vtiger/uitypes/Reference.php                   |  2 +-
 modules/Vtiger/uitypes/Text.php                        |  2 +-
 modules/Vtiger/uitypes/Time.php                        |  2 +-
 modules/Vtiger/uitypes/Url.php                         |  2 +-
 modules/Vtiger/views/IndexAjax.php                     |  2 +-
 modules/com_vtiger_workflow/VTWorkflowManager.inc      |  2 +-
 pkg/vtiger/modules/Assets/modules/Assets/Assets.php    |  6 +++---
 .../ModComments/modules/ModComments/models/Record.php  |  2 +-
 .../PBXManager/modules/PBXManager/models/Record.php    |  6 +++---
 25 files changed, 41 insertions(+), 32 deletions(-)

diff --git a/include/database/PearDatabase.php b/include/database/PearDatabase.php
index 0b7646c23..fa41139be 100644
--- a/include/database/PearDatabase.php
+++ b/include/database/PearDatabase.php
@@ -961,10 +961,12 @@ class PearDatabase{
 		$this->checkConnection();
 		$adoflds = $this->database->MetaColumns($tablename);
 		$i=0;
-		foreach($adoflds as $fld) {
-		    $colNames[$i] = $fld->name;
-		    $i++;
-		}
+        if(!empty($adoflds)){
+            foreach($adoflds as $fld) {
+                $colNames[$i] = $fld->name;
+                $i++;
+            }
+        }
 		return $colNames;
     }
 
diff --git a/include/fields/CurrencyField.php b/include/fields/CurrencyField.php
index 5f475df09..44e9a735f 100644
--- a/include/fields/CurrencyField.php
+++ b/include/fields/CurrencyField.php
@@ -410,7 +410,7 @@ class CurrencyField {
     
 	public static function convertToDollar($amount, $conversionRate) {
 		if ($conversionRate == 0) return 0;
-		return $amount / $conversionRate;
+		return (float)$amount / (float)$conversionRate;
 	}
 	
 	public static function convertFromDollar($amount, $conversionRate) {
diff --git a/include/utils/EmailTemplate.php b/include/utils/EmailTemplate.php
index 4c4b1790c..8e57aaaa1 100644
--- a/include/utils/EmailTemplate.php
+++ b/include/utils/EmailTemplate.php
@@ -66,6 +66,7 @@ class EmailTemplate {
 	public function process($params) {
 		$module = $this->module;
 		$recordId = $this->recordId;
+        $variableList = array();
 		$variableList = $this->getTemplateVariableListForModule($module);
 		$handler = vtws_getModuleHandlerFromName($module, $this->user);
 		$meta = $handler->getMeta();
diff --git a/modules/Calendar/models/Module.php b/modules/Calendar/models/Module.php
index 4c79cd351..adfd7ed18 100644
--- a/modules/Calendar/models/Module.php
+++ b/modules/Calendar/models/Module.php
@@ -204,7 +204,7 @@ class Calendar_Module_Model extends Vtiger_Module_Model {
 	 * Function to get export query
 	 * @return <String> query;
 	 */
-	public function getExportQuery($where) {
+	public function getExportQuery($focus, $where) {
 		$currentUserModel = Users_Record_Model::getCurrentUserModel();
 		$userId = $currentUserModel->getId();
 		$userGroup = new GetUserGroups();
diff --git a/modules/Migration/schema/660_to_700.php b/modules/Migration/schema/660_to_700.php
index 0692a1924..bd78c8a2c 100644
--- a/modules/Migration/schema/660_to_700.php
+++ b/modules/Migration/schema/660_to_700.php
@@ -1226,7 +1226,7 @@ if(defined('VTIGER_UPGRADE')) {
 	}
 
 	$modules = array();
-	$ignoreModules = array('SMSNotifier', 'ModComments');
+	$ignoreModules = array('SMSNotifier', 'ModComments', 'PBXManager');
 	$result = $db->pquery('SELECT name FROM vtiger_tab WHERE isentitytype=? AND name NOT IN ('.generateQuestionMarks($ignoreModules).')', array(1, $ignoreModules));
 	while ($row = $db->fetchByAssoc($result)) {
 		$modules[] = $row['name'];
diff --git a/modules/Migration/schema/701_to_710.php b/modules/Migration/schema/701_to_710.php
index a5340d1ca..7562d9775 100644
--- a/modules/Migration/schema/701_to_710.php
+++ b/modules/Migration/schema/701_to_710.php
@@ -95,7 +95,7 @@ if (defined('VTIGER_UPGRADE')) {
             $customTableName = $customTable[0];
             $customTableId = $customTable[1];
             $customTableColumns = $db->getColumnNames($customTableName);
-            if (in_array($fieldName, $customTableColumns)) {
+            if (!empty($customTableColumns) && in_array($fieldName, $customTableColumns)) {
                 $fieldModel = Vtiger_Field_Model::getInstance($fieldName, $moduleModel);
                 $db->pquery("UPDATE vtiger_field SET tablename=? WHERE fieldid=?", array($baseTableName, $fieldModel->id));
                 $db->pquery("ALTER TABLE $baseTableName ADD COLUMN $fieldName VARCHAR(1)", array());
diff --git a/modules/Migration/schema/711_to_720.php b/modules/Migration/schema/711_to_720.php
index abf213419..8ef2b7b49 100644
--- a/modules/Migration/schema/711_to_720.php
+++ b/modules/Migration/schema/711_to_720.php
@@ -13,5 +13,9 @@ if (defined('VTIGER_UPGRADE')) {
 	$db = PearDatabase::getInstance();
 
 	// Added column storedname for vtiger_attachments to support reverse mapping.
-	$db->pquery('ALTER TABLE vtiger_attachments ADD COLUMN storedname varchar(255) NULL AFTER path', array());
+    $columns = $db->getColumnNames('vtiger_attachments');
+    $columnName = "storedname";
+    if(!in_array($columnName,$columns)) {
+        $db->pquery('ALTER TABLE vtiger_attachments ADD COLUMN storedname varchar(255) NULL AFTER path', array());
+    }
 }
diff --git a/modules/Users/actions/SystemSetupSave.php b/modules/Users/actions/SystemSetupSave.php
index e910c0b65..287de2fcc 100644
--- a/modules/Users/actions/SystemSetupSave.php
+++ b/modules/Users/actions/SystemSetupSave.php
@@ -19,7 +19,7 @@ class Users_SystemSetupSave_Action extends Users_Save_Action {
 	
 	public function process(Vtiger_Request $request) {
 		$moduleName = $request->getModule();
-		$packages = $request->get(packages);
+		$packages = $request->get('packages');
 		$userModuleModel = Users_Module_Model::getInstance($moduleName);
 		$userModuleModel::savePackagesInfo($packages);
 		header ('Location: index.php?module=Users&parent=Settings&view=UserSetup');
diff --git a/modules/Users/views/UserSetup.php b/modules/Users/views/UserSetup.php
index 03bca8c0e..a1b0421de 100644
--- a/modules/Users/views/UserSetup.php
+++ b/modules/Users/views/UserSetup.php
@@ -14,7 +14,7 @@ class Users_UserSetup_View extends Vtiger_Index_View {
 		return array();
 	}
     
-    public function preProcess(Vtiger_Request $request) {
+    public function preProcess(Vtiger_Request $request, $display=true) {
 		return true;
 	}
 
diff --git a/modules/Vtiger/models/Module.php b/modules/Vtiger/models/Module.php
index 5ee02638a..516803eab 100644
--- a/modules/Vtiger/models/Module.php
+++ b/modules/Vtiger/models/Module.php
@@ -889,8 +889,10 @@ class Vtiger_Module_Model extends Vtiger_Module {
 	 * @param <String> $where
 	 * @return <String> export query
 	 */
-	public function getExportQuery($where,$query=false) {
-		$focus = CRMEntity::getInstance($this->getName());
+	public function getExportQuery($focus, $where) {
+		if(!$focus) {
+			$focus = CRMEntity::getInstance($this->getName());
+        }
 		$query = $focus->create_export_query($where);
 		return $query;
 	}
diff --git a/modules/Vtiger/uitypes/Boolean.php b/modules/Vtiger/uitypes/Boolean.php
index bcd6e5d9b..e2f29f8f0 100644
--- a/modules/Vtiger/uitypes/Boolean.php
+++ b/modules/Vtiger/uitypes/Boolean.php
@@ -23,7 +23,7 @@ class Vtiger_Boolean_UIType extends Vtiger_Base_UIType {
 	 * @param <Object> $value
 	 * @return <Object>
 	 */
-	public function getDisplayValue($value) {
+	public function getDisplayValue($value, $record=false, $recordInstance=false) {
 		if($value == 1 || $value == '1' || strtolower($value) == 'on') {
 			return Vtiger_Language_Handler::getTranslatedString('LBL_YES', $this->get('field')->getModuleName());
 		}
diff --git a/modules/Vtiger/uitypes/Currency.php b/modules/Vtiger/uitypes/Currency.php
index acf655b9e..c39b03abe 100644
--- a/modules/Vtiger/uitypes/Currency.php
+++ b/modules/Vtiger/uitypes/Currency.php
@@ -23,7 +23,7 @@ class Vtiger_Currency_UIType extends Vtiger_Base_UIType {
 	 * @param <Object> $value
 	 * @return <Object>
 	 */
-	public function getDisplayValue($value, $skipConversion = false) {
+	public function getDisplayValue($value, $skipConversion = false, $recordInstance=false) {
 		$uiType = $this->get('field')->get('uitype');
 		if ($value) {
 			if ($uiType == 72) {
diff --git a/modules/Vtiger/uitypes/Datetime.php b/modules/Vtiger/uitypes/Datetime.php
index 1c1d8dd24..51a233043 100644
--- a/modules/Vtiger/uitypes/Datetime.php
+++ b/modules/Vtiger/uitypes/Datetime.php
@@ -23,7 +23,7 @@ class Vtiger_Datetime_UIType extends Vtiger_Date_UIType {
 	 * @param <Object> $value
 	 * @return <Object>
 	 */
-	public function getDisplayValue($value) {
+	public function getDisplayValue($value, $record=false, $recordInstance=false) {
 		$dateValue = '--';
 
 		if ($value != '') {
diff --git a/modules/Vtiger/uitypes/Email.php b/modules/Vtiger/uitypes/Email.php
index 3cf39170b..7dbab62b8 100644
--- a/modules/Vtiger/uitypes/Email.php
+++ b/modules/Vtiger/uitypes/Email.php
@@ -18,7 +18,7 @@ class Vtiger_Email_UIType extends Vtiger_Base_UIType {
 		return 'uitypes/Email.tpl';
 	}
 
-	public function getDisplayValue($value, $recordId) {
+	public function getDisplayValue($value, $recordId, $recordInstance=false) {
 		$currentUser = Users_Record_Model::getCurrentUserModel();
 		$internalMailer = $currentUser->get('internal_mailer');
 		if($value){
diff --git a/modules/Vtiger/uitypes/Owner.php b/modules/Vtiger/uitypes/Owner.php
index f62578842..9c9661a6d 100644
--- a/modules/Vtiger/uitypes/Owner.php
+++ b/modules/Vtiger/uitypes/Owner.php
@@ -23,7 +23,7 @@ class Vtiger_Owner_UIType extends Vtiger_Base_UIType {
 	 * @param <Object> $value
 	 * @return <Object>
 	 */
-	public function getDisplayValue($value) {
+	public function getDisplayValue($value, $record=false, $recordInstance=false) {
 		if (self::getOwnerType($value) === 'User') {
 			$userModel = Users_Record_Model::getCleanInstance('Users');
 			$userModel->set('id', $value);
diff --git a/modules/Vtiger/uitypes/Picklist.php b/modules/Vtiger/uitypes/Picklist.php
index 14eaa9847..8bf9e0568 100644
--- a/modules/Vtiger/uitypes/Picklist.php
+++ b/modules/Vtiger/uitypes/Picklist.php
@@ -23,7 +23,7 @@ class Vtiger_Picklist_UIType extends Vtiger_Base_UIType {
 	 * @param <Object> $value
 	 * @return <Object>
 	 */
-	public function getDisplayValue($value) {
+	public function getDisplayValue($value, $record=false, $recordInstance=false) {
 		return Vtiger_Language_Handler::getTranslatedString($value, $this->get('field')->getModuleName());
 	}
     
diff --git a/modules/Vtiger/uitypes/Reference.php b/modules/Vtiger/uitypes/Reference.php
index af07437e7..530e1aab5 100644
--- a/modules/Vtiger/uitypes/Reference.php
+++ b/modules/Vtiger/uitypes/Reference.php
@@ -40,7 +40,7 @@ class Vtiger_Reference_UIType extends Vtiger_Base_UIType {
 	 * @param <Integer> crmid of record
 	 * @return <String>
 	 */
-	public function getDisplayValue($value) {
+	public function getDisplayValue($value, $record=false, $recordInstance=false) {
 		$referenceModule = $this->getReferenceModule($value);
 		if($referenceModule && !empty($value)) {
 			$referenceModuleName = $referenceModule->get('name');
diff --git a/modules/Vtiger/uitypes/Text.php b/modules/Vtiger/uitypes/Text.php
index abca8ea22..074f19d29 100644
--- a/modules/Vtiger/uitypes/Text.php
+++ b/modules/Vtiger/uitypes/Text.php
@@ -15,7 +15,7 @@ class Vtiger_Text_UIType extends Vtiger_Base_UIType {
 	 * @param <Object> $value
 	 * @return <Object>
 	 */
-	public function getDisplayValue($value) {
+	public function getDisplayValue($value, $record=false, $recordInstance=false) {
 		return nl2br($value);
 	}
     
diff --git a/modules/Vtiger/uitypes/Time.php b/modules/Vtiger/uitypes/Time.php
index 801e65f9c..1f59d8156 100644
--- a/modules/Vtiger/uitypes/Time.php
+++ b/modules/Vtiger/uitypes/Time.php
@@ -23,7 +23,7 @@ class Vtiger_Time_UIType extends Vtiger_Base_UIType {
 	 * @param <String> time
 	 * @return <String> time
 	 */
-	public static function getDisplayTimeValue($time) {
+	public static function getDisplayTimeValue($time, $record=false, $recordInstance=false) {
 		$date = new DateTimeField($time);
 		return $date->getDisplayTime();
 	}
diff --git a/modules/Vtiger/uitypes/Url.php b/modules/Vtiger/uitypes/Url.php
index 8d0beebd0..5d30391ab 100644
--- a/modules/Vtiger/uitypes/Url.php
+++ b/modules/Vtiger/uitypes/Url.php
@@ -18,7 +18,7 @@ class Vtiger_Url_UIType extends Vtiger_Base_UIType {
 		return 'uitypes/Url.tpl';
 	}
 
-	public function getDisplayValue($value) {
+	public function getDisplayValue($value, $record=false, $recordInstance=false) {
 		$matchPattern = "^[\w]+:\/\/^";
 		preg_match($matchPattern, $value, $matches);
 		if(!empty ($matches[0])) {
diff --git a/modules/Vtiger/views/IndexAjax.php b/modules/Vtiger/views/IndexAjax.php
index f85075f52..cd8472df5 100644
--- a/modules/Vtiger/views/IndexAjax.php
+++ b/modules/Vtiger/views/IndexAjax.php
@@ -15,7 +15,7 @@ class Vtiger_IndexAjax_View extends Vtiger_Index_View {
 		$this->exposeMethod('showActiveRecords');
 	}
 
-	function preProcess(Vtiger_Request $request) {
+	function preProcess(Vtiger_Request $request, $display=true) {
 		return true;
 	}
 
diff --git a/modules/com_vtiger_workflow/VTWorkflowManager.inc b/modules/com_vtiger_workflow/VTWorkflowManager.inc
index eed587018..4d90b272a 100644
--- a/modules/com_vtiger_workflow/VTWorkflowManager.inc
+++ b/modules/com_vtiger_workflow/VTWorkflowManager.inc
@@ -122,7 +122,7 @@ class VTWorkflowManager{
 		} else {
 		//my changes
 		$result=$adb->getColumnNames("com_vtiger_workflows");
-		if(in_array(defaultworkflow,$result)){
+		if(in_array('defaultworkflow',$result)){
 			$result = $adb->pquery("select workflow_id, module_name, summary, test, execution_condition, defaultworkflow, type, filtersavedinnew
 								from com_vtiger_workflows where module_name=? and status=?",array($moduleName,1));
 		}
diff --git a/pkg/vtiger/modules/Assets/modules/Assets/Assets.php b/pkg/vtiger/modules/Assets/modules/Assets/Assets.php
index ba4c6b8e2..817ed1441 100644
--- a/pkg/vtiger/modules/Assets/modules/Assets/Assets.php
+++ b/pkg/vtiger/modules/Assets/modules/Assets/Assets.php
@@ -374,13 +374,13 @@ class Assets extends CRMEntity {
 			$assetLabel = 'Assets';
 
 			$accountInstance = Vtiger_Module::getInstance('Accounts');
-			$accountInstance->setRelatedlist($assetInstance,$assetLabel,array(ADD),'get_dependents_list');
+			$accountInstance->setRelatedlist($assetInstance,$assetLabel,array('ADD'),'get_dependents_list');
 
 			$productInstance = Vtiger_Module::getInstance('Products');
-			$productInstance->setRelatedlist($assetInstance,$assetLabel,array(ADD),'get_dependents_list');
+			$productInstance->setRelatedlist($assetInstance,$assetLabel,array('ADD'),'get_dependents_list');
 
 			$InvoiceInstance = Vtiger_Module::getInstance('Invoice');
-			$InvoiceInstance->setRelatedlist($assetInstance,$assetLabel,array(ADD),'get_dependents_list');
+			$InvoiceInstance->setRelatedlist($assetInstance,$assetLabel,array('ADD'),'get_dependents_list');
 
 			$result = $adb->pquery("SELECT 1 FROM vtiger_modentity_num WHERE semodule = ? AND active = 1", array($moduleName));
 			if (!($adb->num_rows($result))) {
diff --git a/pkg/vtiger/modules/ModComments/modules/ModComments/models/Record.php b/pkg/vtiger/modules/ModComments/modules/ModComments/models/Record.php
index 0a02da7f8..aee0a319d 100644
--- a/pkg/vtiger/modules/ModComments/modules/ModComments/models/Record.php
+++ b/pkg/vtiger/modules/ModComments/modules/ModComments/models/Record.php
@@ -139,7 +139,7 @@ class ModComments_Record_Model extends Vtiger_Record_Model {
 	 * @param <Integer> $record
 	 * @return ModComment_Record_Model
 	 */
-	public static function getInstanceById($record) {
+	public static function getInstanceById($record, $module=null) {
 		$db = PearDatabase::getInstance();
 		$result = $db->pquery('SELECT vtiger_modcomments.*, vtiger_crmentity.smownerid,
 					vtiger_crmentity.createdtime, vtiger_crmentity.modifiedtime FROM vtiger_modcomments
diff --git a/pkg/vtiger/modules/PBXManager/modules/PBXManager/models/Record.php b/pkg/vtiger/modules/PBXManager/modules/PBXManager/models/Record.php
index a84b38329..6c9a106c5 100644
--- a/pkg/vtiger/modules/PBXManager/modules/PBXManager/models/Record.php
+++ b/pkg/vtiger/modules/PBXManager/modules/PBXManager/models/Record.php
@@ -14,7 +14,7 @@ class PBXManager_Record_Model extends Vtiger_Record_Model{
     const lookuptableName = 'vtiger_pbxmanager_phonelookup';
     const entitytableName = 'vtiger_crmentity';
     
-    static function getCleanInstance(){
+    static function getCleanInstance($moduleName = ''){
         return new self;
     }
     
@@ -26,7 +26,7 @@ class PBXManager_Record_Model extends Vtiger_Record_Model{
         $db = PearDatabase::getInstance();
         $query = 'SELECT * FROM '.self::moduletableName.' AS module_table INNER JOIN '.self::entitytableName.' AS entity_table  WHERE module_table.callstatus IN(?,?) AND module_table.direction=? AND module_table.pbxmanagerid=entity_table.crmid AND entity_table.deleted=0';
         $result = $db->pquery($query,array('ringing','in-progress','inbound'));
-        $recordModels = array();
+        $recordModels = $recordIds = array();
         $rowCount =  $db->num_rows($result);
         for($i=0; $i<$rowCount; $i++) {
             $rowData = $db->query_result_rowdata($result, $i);
@@ -114,7 +114,7 @@ class PBXManager_Record_Model extends Vtiger_Record_Model{
         return true;
     }
     
-    public static function getInstanceById($phonecallsid){
+    public static function getInstanceById($phonecallsid, $module=null){
         $db = PearDatabase::getInstance();
         $record = new self();
         $query = 'SELECT * FROM '.self::moduletableName.' WHERE pbxmanagerid=?';
-- 
GitLab