From 83cf9857f40b89787fa3552bbc1587e2cc46a5cb Mon Sep 17 00:00:00 2001
From: llaffont <llaffont@git-test.afi-sa.fr>
Date: Fri, 6 Sep 2013 09:33:44 +0000
Subject: [PATCH] =?UTF-8?q?Le=20profiling=20XHProf=20est=20param=C3=A9trab?=
 =?UTF-8?q?le?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../ZendAfi/Controller/Plugin/XHProfile.php   | 24 +++++++++++++++----
 library/startup.php                           |  7 +++++-
 2 files changed, 25 insertions(+), 6 deletions(-)

diff --git a/library/ZendAfi/Controller/Plugin/XHProfile.php b/library/ZendAfi/Controller/Plugin/XHProfile.php
index 120d66867b2..880367751ed 100644
--- a/library/ZendAfi/Controller/Plugin/XHProfile.php
+++ b/library/ZendAfi/Controller/Plugin/XHProfile.php
@@ -20,7 +20,22 @@
  */
 
 class ZendAfi_Controller_Plugin_XHProfile extends Zend_Controller_Plugin_Abstract {
-	protected $_enabled = false;
+	protected 
+		$_enabled = false,
+		$_root_path = './xhprof',
+		$_root_url = '/xhprof';
+
+	public function setWebappRootPath($path) {
+		$this->_root_path = $path;
+		return $this;
+	}
+
+
+	public function setRootUrl($url) {
+		$this->_root_url = $url;
+		return $this;
+	}
+
 
 	public function preDispatch(Zend_Controller_Request_Abstract  $request) {
 		if (!Class_Users::isCurrentUserSuperAdmin())
@@ -46,14 +61,13 @@ class ZendAfi_Controller_Plugin_XHProfile extends Zend_Controller_Plugin_Abstrac
 			return;
 
 		$xhprof_data = xhprof_disable();
-		$XHPROF_ROOT = "/usr/share/webapps/xhprof";
-		include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_lib.php";
-		include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_runs.php";
+		require_once $this->_root_path . "/xhprof_lib/utils/xhprof_lib.php";
+		require_once $this->_root_path . "/xhprof_lib/utils/xhprof_runs.php";
 		$xhprof_runs = new XHProfRuns_Default();
 		$run_id = $xhprof_runs->save_run($xhprof_data, "xhprof_testing");
 
 		$this->_response
-			->setRedirect("http://localhost/xhprof/index.php?run={$run_id}&source=xhprof_testing\n")
+			->setRedirect('http://localhost'.$this->_root_url."/index.php?run={$run_id}&source=xhprof_testing\n")
 			->clearBody();
 	}
 }
diff --git a/library/startup.php b/library/startup.php
index bdef801b2c4..23517b67d5a 100644
--- a/library/startup.php
+++ b/library/startup.php
@@ -109,6 +109,8 @@ function setupConstants() {
 	defineConstant('MEMCACHED_ENABLE', false);
 	defineConstant('MEMCACHED_HOST', 'localhost');
 	defineConstant('MEMCACHED_PORT', '11211');
+	defineConstant('XHPROF_ROOT_PATH', '/usr/share/webapps/xhprof');
+	defineConstant('XHPROF_ROOT_URL', '/xhprof');
 }
 
 
@@ -277,7 +279,6 @@ function setupFrontController($cfg) {
 		->registerPlugin(new ZendAfi_Controller_Plugin_InitModule())
 		->registerPlugin(new ZendAfi_Controller_Plugin_SelectionBib())
 		->registerPlugin(new ZendAfi_Controller_Plugin_System())
-		->registerPlugin(new ZendAfi_Controller_Plugin_XHProfile())
 		->registerPlugin(new ZendAfi_Controller_Plugin_Popup())
 		->setParam('useDefaultControllerAlways', true);
 
@@ -287,6 +288,10 @@ function setupFrontController($cfg) {
 	if (!Class_Users::isCurrentUserSuperAdmin())
 		return $front_controller;
 
+	$front_controller->registerPlugin((new ZendAfi_Controller_Plugin_XHProfile())
+																		->setWebappRootPath(XHPROF_ROOT_PATH)
+																		->setRootUrl(XHPROF_ROOT_URL));
+
 	set_include_path(get_include_path() . PATH_SEPARATOR . ROOT_PATH.'library/ZFDebug/library');
 	return $front_controller
 		->registerPlugin(new ZFDebug_Controller_Plugin_Debug(['plugins' => 
-- 
GitLab