Commit 450d20e46c330cf2fc63f3b13a60992661acc894

Authored by donald_jackson
1 parent ff362cb4

"Fatal error after having updated and reread the plugins a few times on Windows …

…XP and Windows Vista."
KTC-649
Implemented basic priority mechanism to force load of ktcore, ktstandard and i18n plugins before others.

Committed by: Donald Jackson
Reviewed by: Kevin Fourie

git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/branches/RB_3.5.4a@9658 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing 1 changed file with 32 additions and 2 deletions
lib/plugins/pluginutil.inc.php
@@ -525,6 +525,22 @@ class KTPluginUtil { @@ -525,6 +525,22 @@ class KTPluginUtil {
525 } 525 }
526 return false; 526 return false;
527 } 527 }
  528 +
  529 + /* Get the priority of the plugin */
  530 + function getPluginPriority($sFile) {
  531 + $defaultPriority = 10;
  532 + $priority = array(
  533 + "ktcore" => 1,
  534 + "ktstandard" => 2,
  535 + "i18n" => 3
  536 + );
  537 + foreach($priority as $pattern => $priority) {
  538 + if(ereg($pattern, $sFile)) {
  539 + return $priority;
  540 + }
  541 + }
  542 + return $defaultPriority;
  543 + }
528 544
529 /** 545 /**
530 * Read the plugins directory and register all plugins in the database. 546 * Read the plugins directory and register all plugins in the database.
@@ -539,17 +555,31 @@ class KTPluginUtil { @@ -539,17 +555,31 @@ class KTPluginUtil {
539 $oCache->deleteAllCaches(); 555 $oCache->deleteAllCaches();
540 556
541 // Remove all entries from the plugin_helper table and refresh it. 557 // Remove all entries from the plugin_helper table and refresh it.
542 - $query = "DELETE FROM plugin_helper"; 558 + $query = "TRUNCATE plugin_helper";
543 DBUtil::runQuery($query); 559 DBUtil::runQuery($query);
544 560
545 $files = array(); 561 $files = array();
  562 + $plugins = array();
  563 +
546 KTPluginUtil::_walk(KT_DIR . '/plugins', $files); 564 KTPluginUtil::_walk(KT_DIR . '/plugins', $files);
547 foreach ($files as $sFile) { 565 foreach ($files as $sFile) {
548 $plugin_ending = "Plugin.php"; 566 $plugin_ending = "Plugin.php";
549 if (substr($sFile, -strlen($plugin_ending)) === $plugin_ending) { 567 if (substr($sFile, -strlen($plugin_ending)) === $plugin_ending) {
550 - require_once($sFile); 568 + /* Set default priority */
  569 + $plugins[$sFile] = KTPluginUtil::getPluginPriority($sFile);
551 } 570 }
552 } 571 }
  572 +
  573 + /* Sort the plugins by priority */
  574 + asort($plugins);
  575 +
  576 + foreach($plugins as $sFile => $priority) {
  577 + require_once($sFile);
  578 + }
  579 +
  580 +
  581 +
  582 +
553 583
554 $oRegistry =& KTPluginRegistry::getSingleton(); 584 $oRegistry =& KTPluginRegistry::getSingleton();
555 $aRegistryList = $oRegistry->getPlugins(); 585 $aRegistryList = $oRegistry->getPlugins();