diff --git a/application/itopwebpage.class.inc.php b/application/itopwebpage.class.inc.php index cccc0ba8c..f07bad9f7 100644 --- a/application/itopwebpage.class.inc.php +++ b/application/itopwebpage.class.inc.php @@ -43,11 +43,13 @@ class iTopWebPage extends NiceWebPage implements iTabbedPage protected $sBreadCrumbEntryDescription; protected $sBreadCrumbEntryUrl; protected $sBreadCrumbEntryIcon; + protected $oCtx; public function __construct($sTitle, $bPrintable = false) { parent::__construct($sTitle, $bPrintable); $this->m_oTabs = new TabManager(); + $this->oCtx = new ContextTag('GUI:Console'); ApplicationContext::SetUrlMakerClass('iTopStandardURLMaker'); diff --git a/application/portalwebpage.class.inc.php b/application/portalwebpage.class.inc.php index 09471e7a2..05203c6f4 100644 --- a/application/portalwebpage.class.inc.php +++ b/application/portalwebpage.class.inc.php @@ -49,9 +49,12 @@ class PortalWebPage extends NiceWebPage */ protected $m_sWelcomeMsg; protected $m_aMenuButtons; + protected $m_oCtx; + public function __construct($sTitle, $sAlternateStyleSheet = '') { + $this->m_oCtx = new ContextTag('GUI:Portal'); $this->m_sWelcomeMsg = ''; $this->m_aMenuButtons = array(); parent::__construct($sTitle); diff --git a/application/startup.inc.php b/application/startup.inc.php index 0efbb5e3a..764e581c6 100644 --- a/application/startup.inc.php +++ b/application/startup.inc.php @@ -26,6 +26,7 @@ require_once(APPROOT.'/core/cmdbobject.class.inc.php'); require_once(APPROOT.'/application/utils.inc.php'); +require_once(APPROOT.'/core/contexttag.class.inc.php'); session_name('itop-'.md5(APPROOT)); session_start(); $sSwitchEnv = utils::ReadParam('switch_env', null); diff --git a/core/contexttag.class.inc.php b/core/contexttag.class.inc.php new file mode 100644 index 000000000..09b7f218a --- /dev/null +++ b/core/contexttag.class.inc.php @@ -0,0 +1,75 @@ + + + +/** + * Simple helper class for keeping track of the context inside the call stack + * + * To check (anywhere in the code) if a particular context tag is present + * in the call stack simply do: + * + * if (ContextTag::Check()) ... + * + * For example to know if the code is being executed in the context of a portal do: + * + * if (ContextTag::Check('GUI:Portal')) + * + * @copyright Copyright (C) 2016 Combodo SARL + * @license http://opensource.org/licenses/AGPL-3.0 + */ + +class ContextTag +{ + protected static $aStack; + + /** + * Store a context tag on the stack + * @param string $sTag + */ + public function __construct($sTag) + { + static::$aStack[] = $sTag; + } + + /** + * Cleanup the context stack + */ + public function __destruct() + { + array_pop(static::$aStack); + } + + /** + * Check if a given tag is present in the stack + * @param string $sTag + * @return bool + */ + public static function Check($sTag) + { + return in_array($sTag, static::$aStack); + } + + /** + * Get the whole stack as an array + * @return hash + */ + public static function GetStack() + { + return static::$aStack; + } +} \ No newline at end of file diff --git a/datamodels/2.x/itop-portal-base/portal/web/index.php b/datamodels/2.x/itop-portal-base/portal/web/index.php index 60c2ade74..a01b7e58f 100644 --- a/datamodels/2.x/itop-portal-base/portal/web/index.php +++ b/datamodels/2.x/itop-portal-base/portal/web/index.php @@ -49,6 +49,9 @@ if (UserRights::GetContactId() == 0) die(Dict::S('Portal:ErrorNoContactForThisUser')); } +$oCtx = new ContextTag('GUI:Portal'); +$oCtx2 = new ContextTag('Portal:'.PORTAL_MODULE_ID); + // Checking if debug param is on $bDebug = (isset($_REQUEST['debug']) && ($_REQUEST['debug'] === 'true') ); diff --git a/synchro/synchrodatasource.class.inc.php b/synchro/synchrodatasource.class.inc.php index ce6338e34..26304f2df 100644 --- a/synchro/synchrodatasource.class.inc.php +++ b/synchro/synchrodatasource.class.inc.php @@ -2244,7 +2244,9 @@ class SynchroExecution protected $m_aReconciliationKeys = array(); protected $m_aAttributes = array(); protected $m_iCountAllReplicas = 0; - + protected $m_oCtx; + protected $m_oCtx1; + /** * Constructor * @param SynchroDataSource $oDataSource Synchronization task @@ -2255,6 +2257,8 @@ class SynchroExecution { $this->m_oDataSource = $oDataSource; $this->m_oLastFullLoadStartDate = $oLastFullLoadStartDate; + $this->m_oCtx = new ContextTag('Synchro'); + $this->m_oCtx1 = new ContextTag('Synchro:'.$oDataSource->GetRawName()); // More precise context information } /** diff --git a/webservices/cron.php b/webservices/cron.php index 456b37a61..9ea73951b 100644 --- a/webservices/cron.php +++ b/webservices/cron.php @@ -39,7 +39,7 @@ if (!file_exists($sConfigFile)) require_once(APPROOT.'/application/startup.inc.php'); - +$oCtx = new ContextTag('CRON'); function ReadMandatoryParam($oP, $sParam, $sSanitizationFilter = 'parameter') { diff --git a/webservices/rest.php b/webservices/rest.php index 649b2972a..a307bd878 100644 --- a/webservices/rest.php +++ b/webservices/rest.php @@ -91,6 +91,7 @@ class RestResultListOperations extends RestResult // Main // $oP = new ajax_page('rest'); +$oCtx = new ContextTag('REST/JSON'); $sVersion = utils::ReadParam('version', null, false, 'raw_data'); $sOperation = utils::ReadParam('operation', null);