Commit cc0ea0ba5fd11ae75734081d9ed0576d4cb5c8bc

Authored by Megan Watson
1 parent 8b26c067

KTS-4246. Added a check to stop the plugin from being registered on every page load.

Committed by: Megan Watson
Reviewed by: Kevin Fourie
lib/plugins/plugin.inc.php
... ... @@ -334,6 +334,11 @@ class KTPlugin {
334 334 $sql = "SELECT id FROM plugin_helper WHERE namespace = '{$sNamespace}' AND classtype = '{$type}'";
335 335 $res = DBUtil::getOneResult($sql);
336 336  
  337 + // if record exists - ignore it.
  338 + if(!empty($res)){
  339 + return true;
  340 + }
  341 +
337 342 $aValues = array();
338 343 $aValues['namespace'] = $sNamespace;
339 344 $aValues['plugin'] = (!empty($this->sNamespace)) ? $this->sNamespace : $sNamespace;
... ... @@ -343,16 +348,6 @@ class KTPlugin {
343 348 $aValues['viewtype'] = $view;
344 349 $aValues['classtype'] = $type;
345 350  
346   - // if record exists - update it.
347   - if(!empty($res)){
348   - $id = $res['id'];
349   - $updateRes = DBUtil::autoUpdate('plugin_helper', $aValues, $id);
350   - if(PEAR::isError($updateRes)){
351   - return $updateRes;
352   - }
353   - return true;
354   - }
355   -
356 351 // Insert into DB
357 352 $res = DBUtil::autoInsert('plugin_helper', $aValues);
358 353 if(PEAR::isError($res)){
... ... @@ -426,6 +421,7 @@ class KTPlugin {
426 421 if(!$res){
427 422 return false;
428 423 }
  424 + return true;
429 425  
430 426 // Get actions, portlets, etc, create arrays as part of plugin
431 427 $query = "SELECT * FROM plugin_helper h WHERE plugin = '{$this->sNamespace}'";
... ...
lib/plugins/pluginregistry.inc.php
... ... @@ -60,8 +60,15 @@ class KTPluginRegistry {
60 60 $sFilename = (!empty($sFilename)) ? KTPlugin::_fixFilename($sFilename) : '';
61 61 $this->_aPluginDetails[$sNamespace] = array($sClassName, $sNamespace, $sFilename);
62 62  
63   - $object = $sClassName.'|'.$sNamespace.'|'.$sFilename;
64   - KTPlugin::registerPluginHelper($sNamespace, $sClassName, $sFilename, $object, 'general', 'plugin');
  63 + /*
  64 + Check whether the system is registering or not. If true, register the plugin in plugin_helper.
  65 + If false, skip.
  66 + This check has been put in place to prevent the plugin being registered on every page load.
  67 + */
  68 + if(isset($_SESSION['plugins_registerplugins']) && $_SESSION['plugins_registerplugins']){
  69 + $object = $sClassName.'|'.$sNamespace.'|'.$sFilename;
  70 + KTPlugin::registerPluginHelper($sNamespace, $sClassName, $sFilename, $object, 'general', 'plugin');
  71 + }
65 72 }
66 73  
67 74 function &getPlugin($sNamespace) {
... ...
lib/plugins/pluginutil.inc.php
... ... @@ -161,7 +161,6 @@ class KTPluginUtil {
161 161 if($sType != 'dashboard'){
162 162 $sType = 'general';
163 163 }
164   - $GLOBALS['_KT_PLUGIN'] = array();
165 164  
166 165 $aPlugins = array();
167 166 $aPluginHelpers = array();
... ... @@ -573,13 +572,15 @@ class KTPluginUtil {
573 572 /* Sort the plugins by priority */
574 573 asort($plugins);
575 574  
  575 + /*
  576 + Add a check to indicate that plugin registration is occuring.
  577 + This check has been put in place to prevent the plugin being registered on every page load.
  578 + */
  579 + $_SESSION['plugins_registerplugins'] = true;
576 580 foreach($plugins as $sFile => $priority) {
577 581 require_once($sFile);
578 582 }
579   -
580   -
581   -
582   -
  583 + $_SESSION['plugins_registerplugins'] = false;
583 584  
584 585 $oRegistry =& KTPluginRegistry::getSingleton();
585 586 $aRegistryList = $oRegistry->getPlugins();
... ...