Exemplo n.º 1
0
 /**
  * Read the plugins directory and register all plugins in the database.
  */
 function doPluginRegistration()
 {
     global $default;
     KTPluginUtil::_deleteSmartyFiles();
     require_once KT_LIB_DIR . '/cache/cache.inc.php';
     $oCache =& KTCache::getSingleton();
     $oCache->deleteAllCaches();
     // Remove all entries from the plugin_helper table and refresh it.
     $query = "DELETE FROM plugin_helper";
     $res = DBUtil::runQuery($query);
     $files = array();
     $plugins = array();
     KTPluginUtil::_walk(KT_DIR . '/plugins', $files);
     foreach ($files as $sFile) {
         $plugin_ending = "Plugin.php";
         if (substr($sFile, -strlen($plugin_ending)) === $plugin_ending) {
             /* Set default priority */
             $plugins[$sFile] = KTPluginUtil::getPluginPriority($sFile);
         }
     }
     /* Sort the plugins by priority */
     asort($plugins);
     /*
     Add a check to indicate that plugin registration is occuring.
     This check has been put in place to prevent the plugin being registered on every page load.
     */
     $_SESSION['plugins_registerplugins'] = true;
     foreach ($plugins as $sFile => $priority) {
         require_once $sFile;
     }
     $_SESSION['plugins_registerplugins'] = false;
     $oRegistry =& KTPluginRegistry::getSingleton();
     $aRegistryList = $oRegistry->getPlugins();
     foreach ($aRegistryList as $oPlugin) {
         $res = $oPlugin->register();
         if (PEAR::isError($res)) {
             //var_dump($res);
             $default->log->debug('Register of plugin failed: ' . $res->getMessage());
         }
     }
     $aPluginList = KTPluginEntity::getList();
     foreach ($aPluginList as $oPluginEntity) {
         $sPath = $oPluginEntity->getPath();
         if (!KTUtil::isAbsolutePath($sPath)) {
             $sPath = sprintf("%s/%s", KT_DIR, $sPath);
         }
         if (!file_exists($sPath)) {
             $oPluginEntity->setUnavailable(true);
             $oPluginEntity->setDisabled(true);
             $res = $oPluginEntity->update();
         }
     }
     KTPluginEntity::clearAllCaches();
     KTPluginUtil::_deleteSmartyFiles();
     require_once KT_LIB_DIR . '/cache/cache.inc.php';
     $oCache =& KTCache::getSingleton();
     $oCache->deleteAllCaches();
     //KTPluginUtil::removePluginCache();
 }