From 33f4bf428c8da92af134b8d1eabbe315e49ce933 Mon Sep 17 00:00:00 2001
From: yogeshwar <yogeshwar.g@vtigersolutions.com>
Date: Mon, 29 Apr 2024 14:41:42 +0530
Subject: [PATCH] Fixes #1802:Handled initializeListViewContents being called
 twice on each list

---
 modules/Portal/views/List.php                              | 6 ++++--
 modules/Reports/views/List.php                             | 7 ++++---
 modules/Settings/Vtiger/views/List.php                     | 7 ++++---
 modules/Vtiger/views/FindDuplicates.php                    | 7 ++++---
 modules/Vtiger/views/List.php                              | 7 ++++---
 .../EmailTemplates/modules/EmailTemplates/views/List.php   | 7 ++++---
 .../modules/RecycleBin/modules/RecycleBin/views/List.php   | 7 ++++---
 7 files changed, 28 insertions(+), 20 deletions(-)

diff --git a/modules/Portal/views/List.php b/modules/Portal/views/List.php
index 2e0bef6cf..bda02b40f 100644
--- a/modules/Portal/views/List.php
+++ b/modules/Portal/views/List.php
@@ -40,7 +40,10 @@ class Portal_List_View extends Vtiger_Index_View {
 
 	public function initializeListViewContents(Vtiger_Request $request, Vtiger_Viewer $viewer) {
 
-	if($this->listviewinitcalled == false){
+	if($this->listviewinitcalled){
+		return;
+	}
+
 		$moduleName = $request->getModule();
 		$pageNumber = $request->get('page');
 		$orderBy = $request->get('orderby');
@@ -132,7 +135,6 @@ class Portal_List_View extends Vtiger_Index_View {
 
 		$this->listviewinitcalled = true;
 	}
-	}
 	function getHeaderScripts(Vtiger_Request $request) {
 		$headerScriptInstances = parent::getHeaderScripts($request);
 		$moduleName = $request->getModule();
diff --git a/modules/Reports/views/List.php b/modules/Reports/views/List.php
index 5eac8e4fd..9d4a01e02 100644
--- a/modules/Reports/views/List.php
+++ b/modules/Reports/views/List.php
@@ -100,7 +100,9 @@ class Reports_List_View extends Vtiger_Index_View {
 
 	public function initializeListViewContents(Vtiger_Request $request) {
 
-		if($this->listviewinitcalled == false){
+		if($this->listviewinitcalled){
+			return;
+		}
 			$moduleName = $request->getModule();
 			$viewer = $this->getViewer($request);
 			$moduleModel = Vtiger_Module_Model::getInstance($moduleName);
@@ -238,8 +240,7 @@ class Reports_List_View extends Vtiger_Index_View {
 		}
 		$viewer->assign('DASHBOARD_TABS', $activeTabs);
 
-		$this->listviewinitcalled=true;
-	}
+		$this->listviewinitcalled=true;  // to make a early exit if it is called more than once
 }
 
 	/**
diff --git a/modules/Settings/Vtiger/views/List.php b/modules/Settings/Vtiger/views/List.php
index 234d1ca02..b4a265c19 100644
--- a/modules/Settings/Vtiger/views/List.php
+++ b/modules/Settings/Vtiger/views/List.php
@@ -38,7 +38,9 @@ class Settings_Vtiger_List_View extends Settings_Vtiger_Index_View {
 	 */
 	public function initializeListViewContents(Vtiger_Request $request, Vtiger_Viewer $viewer) {
 
-		if($this->listviewinitcalled ==false){
+		if($this->listviewinitcalled){
+			return;
+		}
 			$moduleName = $request->getModule();
 			$qualifiedModuleName = $request->getModule(false);
 			$pageNumber = $request->get('page');
@@ -139,9 +141,8 @@ class Settings_Vtiger_List_View extends Settings_Vtiger_Index_View {
 			$viewer->assign('LISTVIEW_COUNT', $totalCount);
 		}
 
-		$this->listviewinitcalled =true;
+		$this->listviewinitcalled =true; // to make a early exit if it is called more than once
 	}
-}
     
     public function postProcess(Vtiger_Request $request) {
         $viewer = $this->getViewer($request);
diff --git a/modules/Vtiger/views/FindDuplicates.php b/modules/Vtiger/views/FindDuplicates.php
index c03bb6af8..8fd57af1f 100644
--- a/modules/Vtiger/views/FindDuplicates.php
+++ b/modules/Vtiger/views/FindDuplicates.php
@@ -58,7 +58,9 @@ class Vtiger_FindDuplicates_View extends Vtiger_List_View {
 	 */
 	public function initializeListViewContents(Vtiger_Request $request, Vtiger_Viewer $viewer) {
 
-		if($this->listviewinitcalled == false){
+		if($this->listviewinitcalled){
+			return;
+		}
 			$currentUser = vglobal('current_user');
 			$viewer = $this->getViewer ($request);
 			$module = $request->getModule();
@@ -124,9 +126,8 @@ class Vtiger_FindDuplicates_View extends Vtiger_List_View {
 		$customViewModel = CustomView_Record_Model::getAllFilterByModule($module);
 		$viewer->assign('VIEW_NAME', $customViewModel->getId());
 
-		$this->listviewinitcalled = true;
+		$this->listviewinitcalled = true; // to make a early exit if it is called more than once
 	}
-}
 
 	/**
 	 * Function returns the number of records for the current filter
diff --git a/modules/Vtiger/views/List.php b/modules/Vtiger/views/List.php
index 9a37df8b5..09045baa0 100644
--- a/modules/Vtiger/views/List.php
+++ b/modules/Vtiger/views/List.php
@@ -161,7 +161,9 @@ class Vtiger_List_View extends Vtiger_Index_View {
 	 */
 	public function initializeListViewContents(Vtiger_Request $request, Vtiger_Viewer $viewer) {
 
-		if($this->listviewinitcalled == false){
+		if($this->listviewinitcalled){
+			return;
+		}
 			$moduleName = $request->getModule();
 			$cvId = $this->viewName;
 			$pageNumber = $request->get('page');
@@ -439,9 +441,8 @@ class Vtiger_List_View extends Vtiger_Index_View {
 		$picklistDependencyDatasource = Vtiger_DependencyPicklist::getPicklistDependencyDatasource($moduleName);
 		$viewer->assign('PICKIST_DEPENDENCY_DATASOURCE',Zend_Json::encode($picklistDependencyDatasource));
 
-		$this->listviewinitcalled = true;
+		$this->listviewinitcalled = true; // to make a early exit if it is called more than once
 	}
-}
 
 	protected function assignCustomViews(Vtiger_Request $request, Vtiger_Viewer $viewer) {
 		$allCustomViews = CustomView_Record_Model::getAllByGroup($request->getModule());
diff --git a/pkg/vtiger/modules/EmailTemplates/modules/EmailTemplates/views/List.php b/pkg/vtiger/modules/EmailTemplates/modules/EmailTemplates/views/List.php
index 9acf159c8..caa1b09bf 100644
--- a/pkg/vtiger/modules/EmailTemplates/modules/EmailTemplates/views/List.php
+++ b/pkg/vtiger/modules/EmailTemplates/modules/EmailTemplates/views/List.php
@@ -87,7 +87,9 @@ class EmailTemplates_List_View extends Vtiger_Index_View {
 	 */
 	public function initializeListViewContents(Vtiger_Request $request, Vtiger_Viewer $viewer) {
 
-		if($this->listviewinitcalled == false){
+		if($this->listviewinitcalled){
+			return;
+		}
 			$moduleName = $request->getModule();
 			$cvId = $request->get('viewname');
 			$viewType = $request->get('viewType');
@@ -226,9 +228,8 @@ class EmailTemplates_List_View extends Vtiger_Index_View {
 		$viewer->assign('IS_MODULE_EDITABLE', $listViewModel->getModule()->isPermitted('EditView'));
 		$viewer->assign('IS_MODULE_DELETABLE', $listViewModel->getModule()->isPermitted('Delete'));
 
-		$this->listviewinitcalled = true;
+		$this->listviewinitcalled = true; // to make a early exit if it is called more than once
 	}
-}
 
 	/**
 	 * Function returns the number of records for the current filter
diff --git a/pkg/vtiger/modules/RecycleBin/modules/RecycleBin/views/List.php b/pkg/vtiger/modules/RecycleBin/modules/RecycleBin/views/List.php
index 5b61b4e0f..435a61ce0 100644
--- a/pkg/vtiger/modules/RecycleBin/modules/RecycleBin/views/List.php
+++ b/pkg/vtiger/modules/RecycleBin/modules/RecycleBin/views/List.php
@@ -71,7 +71,9 @@ class RecycleBin_List_View extends Vtiger_Index_View {
 	 */
 	public function initializeListViewContents(Vtiger_Request $request, Vtiger_Viewer $viewer) {
 
-		if($this-> listviewinitcalled == false){
+		if($this-> listviewinitcalled){
+			return;
+		}
 			$moduleName = $request->getModule();
 			$sourceModule = $request->get('sourceModule');
 
@@ -222,10 +224,9 @@ class RecycleBin_List_View extends Vtiger_Index_View {
 		}
 		$viewer->assign('IS_MODULE_DELETABLE', $listViewModel->getModule()->isPermitted('Delete'));
 
-		$this-> listviewinitcalled = true;
+		$this-> listviewinitcalled = true; // to make a early exit if it is called more than once
 
 	}
-}
 
 	/**
 	 * Function to get the list of Script models to be included
-- 
GitLab