function setEnabled($aIds) { $sTable = KTPluginEntity::_table(); $sIds = DBUtil::paramArray($aIds); $sQuery = sprintf('UPDATE %s SET disabled = 1 WHERE id NOT IN (%s)', $sTable, $sIds); DBUtil::runQuery(array($sQuery, $aIds)); $sQuery = sprintf('UPDATE %s SET disabled = 0 WHERE id IN (%s)', $sTable, $sIds); DBUtil::runQuery(array($sQuery, $aIds)); KTPluginEntity::clearAllCaches(); }
function register() { $oEntity = KTPluginEntity::getByNamespace($this->sNamespace); $friendly_name = ''; $iOrder = $this->iOrder; global $default; if (!empty($this->sFriendlyName)) { $friendly_name = $this->sFriendlyName; } if (!PEAR::isError($oEntity)) { // check for upgrade. $iEndVersion = 0; // dest. if ($this->iVersion != $oEntity->getVersion()) { // capture the filname version. // remember to -start- the upgrade from the "next" version $iEndVersion = $this->upgradePlugin($oEntity->getVersion() + 1, $this->iVersion); if ($iEndVersion != $this->iVersion) { $default->log->error("Plugin register: {$friendly_name}, namespace: {$this->sNamespace} failed to upgrade properly. Original version: {$oEntity->getVersion()}, upgrading to version {$this->iVersion}, current version {$iEndVersion}"); // we obviously failed. $oEntity->updateFromArray(array('path' => $this->stripKtDir($this->sFilename), 'version' => $iEndVersion, 'disabled' => true, 'unavailable' => false, 'friendlyname' => $friendly_name)); // FIXME we -really- need to raise an error here, somehow. } else { $default->log->debug("Plugin register: {$friendly_name}, namespace: {$this->sNamespace} upgraded. Original version: {$oEntity->getVersion()}, upgrading to version {$this->iVersion}, current version {$iEndVersion}"); $oEntity->updateFromArray(array('path' => $this->stripKtDir($this->sFilename), 'version' => $this->iVersion, 'unavailable' => false, 'friendlyname' => $friendly_name, 'orderby' => $iOrder)); } } /* ** Quick fix for optimisation. Reread must run plugin setup. ** */ $this->setup(); return $oEntity; } if (PEAR::isError($oEntity) && !is_a($oEntity, 'KTEntityNoObjects')) { $default->log->error("Plugin register: the plugin {$friendly_name}, namespace: {$this->sNamespace} returned an error: " . $oEntity->getMessage()); return $oEntity; } $disabled = 1; if ($this->bAlwaysInclude || $this->autoRegister) { $disabled = 0; } $default->log->debug("Plugin register: creating {$friendly_name}, namespace: {$this->sNamespace}"); $iEndVersion = $this->upgradePlugin(0, $this->iVersion); $oEntity = KTPluginEntity::createFromArray(array('namespace' => $this->sNamespace, 'path' => $this->stripKtDir($this->sFilename), 'version' => $iEndVersion, 'disabled' => $disabled, 'unavailable' => false, 'friendlyname' => $friendly_name, 'orderby' => $iOrder)); if (PEAR::isError($oEntity)) { $default->log->error("Plugin register: the plugin, {$friendly_name}, namespace: {$this->sNamespace} returned an error on creation: " . $oEntity->getMessage()); return $oEntity; } /* ** Quick fix for optimisation. Reread must run plugin setup. ** */ $this->setup(); return true; }
function do_update() { $sTable = KTUtil::getTableName('plugins'); $aIds = (array) KTUtil::arrayGet($_REQUEST, 'pluginids'); // Update disabled plugins $sIds = implode(',', $aIds); $sQuery = "UPDATE {$sTable} SET disabled = 1 WHERE id NOT IN ({$sIds})"; DBUtil::runQuery(array($sQuery)); // Select disabled plugins that have been enabled $sQuery = "SELECT * FROM {$sTable} WHERE disabled = 1 AND id IN ({$sIds})"; $res = DBUtil::getResultArray($sQuery); if (!PEAR::isError($res)) { // Enable the disabled plugins $sQuery = "UPDATE {$sTable} SET disabled = 0 WHERE id IN ({$sIds})"; DBUtil::runQuery(array($sQuery)); // run setup for each plugin $aEnabled = array(); if (!empty($res)) { foreach ($res as $item) { $aEnabled[] = $item['id']; } $sEnabled = implode(',', $aEnabled); $sQuery = "SELECT h.classname, h.pathname FROM {$sTable} p\n INNER JOIN plugin_helper h ON (p.namespace = h.plugin)\n WHERE classtype = 'plugin' AND p.id IN ({$sEnabled})"; $res = DBUtil::getResultArray($sQuery); if (!PEAR::isError($res)) { foreach ($res as $item) { $classname = $item['classname']; $path = $item['pathname']; if (!empty($path)) { require_once $path; } $oPlugin = new $classname($path); $oPlugin->setup(); } } } } KTPluginEntity::clearAllCaches(); // FIXME!!! Plugin manager needs to be updated to deal with this situation. This code should be in the plugin. //enabling or disabling Tag fieldset depending on whether tag cloud plugin is enabled or disabled. //Get tag cloud object $oTagClouPlugin = KTPluginEntity::getByNamespace('ktcore.tagcloud.plugin'); if (!PEAR::isError($oTagClouPlugin) && !is_a($oTagClouPlugin, 'KTEntityNoObjects') && !is_null($oTagClouPlugin)) { if ($oTagClouPlugin->getDisabled() == '1') { //disable tag fieldset $aFV = array('disabled' => true); $aWFV = array('namespace' => 'tagcloud'); $res = DBUtil::whereUpdate('fieldsets', $aFV, $aWFV); } else { //enable tag fieldset $aFV = array('disabled' => false); $aWFV = array('namespace' => 'tagcloud'); $res = DBUtil::whereUpdate('fieldsets', $aFV, $aWFV); } } // we reregister the plugins to ensure they are in the correct order KTPluginUtil::registerPlugins(); $this->successRedirectToMain(_kt('Plugins updated')); }
static function pluginIsActive($sNamespace) { $oReg =& KTPluginRegistry::getSingleton(); $plugin = $oReg->getPlugin($sNamespace); if (is_null($plugin) || PEAR::isError($plugin)) { return false; } else { // check if its active $ent = KTPluginEntity::getByNamespace($sNamespace); if (PEAR::isError($ent)) { return false; } // we now can ask return !$ent->getDisabled(); } }