Overview

Packages

  • CONTENIDO
  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • mpAutoloaderClassMap
  • None
  • PHP
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SIWECOS
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob

Classes

  • PimPlugin
  • PimPluginArchiveExtractor
  • PimPluginCollection
  • PimPluginRelations
  • PimPluginRelationsCollection
  • PimPluginSetup
  • PimPluginSetupInstall
  • PimPluginSetupStatus
  • PimPluginSetupUninstall
  • PimPluginSetupUpdate
  • PimPluginViewDependencies
  • PimPluginViewNavSub
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: /**
  3:  * This file contains abstract class for change status of installed plugins
  4:  *
  5:  * @package Plugin
  6:  * @subpackage PluginManager
  7:  * @author Frederic Schneider
  8:  * @copyright four for business AG <www.4fb.de>
  9:  * @license http://www.contenido.org/license/LIZENZ.txt
 10:  * @link http://www.4fb.de
 11:  * @link http://www.contenido.org
 12:  */
 13: 
 14: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 15: 
 16: /**
 17:  * Class for change active status of installed plugins, extends PimPluginSetup
 18:  *
 19:  * @package Plugin
 20:  * @subpackage PluginManager
 21:  * @author frederic.schneider
 22:  */
 23: class PimPluginSetupStatus extends PimPluginSetup {
 24:     /**
 25:      * @var PimPluginCollection
 26:      */
 27:     protected $_PimPluginCollection;
 28: 
 29:     /**
 30:      * @var PimPluginRelationsCollection
 31:      */
 32:     protected $_PimPluginRelationsCollection;
 33: 
 34:     /**
 35:      * @var cApiNavSubCollection
 36:      */
 37:     protected $_ApiNavSubCollection;
 38: 
 39:     /**
 40:      * Initializing and set variable for PimPluginCollection class
 41:      *
 42:      * @return PimPluginCollection
 43:      */
 44:     private function _setPimPluginCollection() {
 45:         return $this->_PimPluginCollection = new PimPluginCollection();
 46:     }
 47: 
 48:     /**
 49:      * Initializing and set variable for PimPluginRelationsCollection class
 50:      *
 51:      * @return PimPluginRelationsCollection
 52:      */
 53:     private function _setPimPluginRelationsCollection() {
 54:         return $this->_PimPluginRelationsCollection = new PimPluginRelationsCollection();
 55:     }
 56: 
 57:     /**
 58:      * Initializing and set variable for cApiNavSubCollection
 59:      *
 60:      * @return cApiNavSubCollection
 61:      */
 62:     private function _setApiNavSubCollection() {
 63:         return $this->_ApiNavSubCollection = new cApiNavSubCollection();
 64:     }
 65: 
 66:     // Begin of installation routine
 67:     /**
 68:      * Construct function
 69:      */
 70:     public function __construct() {
 71: 
 72:         // Initializing and set classes
 73:         // PluginManager classes
 74:         $this->_setPimPluginCollection();
 75:         $this->_setPimPluginRelationsCollection();
 76: 
 77:         // cApiClasses
 78:         $this->_setApiNavSubCollection();
 79:     }
 80: 
 81:     /**
 82:      * Change plugin active status
 83:      *
 84:      * @param int $pluginId
 85:      *
 86:      * @throws cException
 87:      */
 88:     public function changeActiveStatus($pluginId) {
 89: 
 90:         // Set pluginId
 91:         self::setPluginId($pluginId);
 92: 
 93:         // Build WHERE-Query for *_plugin table with $pluginId as parameter
 94:         $this->_PimPluginCollection->setWhere('idplugin', cSecurity::toInteger($pluginId));
 95:         $this->_PimPluginCollection->query();
 96:         $plugin = $this->_PimPluginCollection->next();
 97: 
 98:         // Get name of selected plugin and his active status
 99:         $pluginName = $plugin->get('name');
100:         $pluginActiveStatus = $plugin->get('active');
101: 
102:         // Get relations
103:         $this->_PimPluginRelationsCollection->setWhere('idplugin', cSecurity::toInteger($pluginId));
104:         $this->_PimPluginRelationsCollection->setWhere('type', 'navs');
105:         $this->_PimPluginRelationsCollection->query();
106: 
107:         if ($pluginActiveStatus == 1) {
108:             // Plugin is online and now we change status to offline
109: 
110:             // Dependencies check
111:             $this->_updateCheckDependencies();
112: 
113:             $plugin->set('active', 0);
114:             $plugin->store();
115: 
116:             // If this plugin has some navSub entries, we must also change menu
117:             // status to offline
118:             while (($relation = $this->_PimPluginRelationsCollection->next()) !== false) {
119:                 $idnavs = $relation->get('iditem');
120:                 $this->_changeNavSubStatus($idnavs, 0);
121:             }
122: 
123:             parent::info(sprintf(i18n('The plugin <strong>%s</strong> has been sucessfully disabled. To apply the changes please login into backend again.', 'pim'), $pluginName));
124:         } else {
125:             // Plugin is offline and now we change status to online
126: 
127:             $plugin->set('active', 1);
128:             $plugin->store();
129: 
130:             // If this plugin has some navSub entries, we must also change menu
131:             // status to online
132:             while (($relation = $this->_PimPluginRelationsCollection->next()) !== false) {
133:                 $idnavs = $relation->get('iditem');
134:                 $this->_changeNavSubStatus($idnavs, 1);
135:             }
136: 
137:             parent::info(sprintf(i18n('The plugin <strong>%s</strong> has been sucessfully enabled. To apply the changes please login into backend again.', 'pim'), $pluginName));
138:         }
139:     }
140: 
141:     /**
142:      * Check dependencies to other plugins (dependencies-Tag at plugin.xml)
143:      *
144:      * @throws cException
145:      * @throws cInvalidArgumentException
146:      */
147:     private function _updateCheckDependencies() {
148: 
149:         // Call checkDepenendencies function at PimPlugin class
150:         // Function returns true or false
151:         $result = $this->checkDependencies();
152: 
153:         // Show an error message when dependencies could be found
154:         if ($result === false) {
155:             parent::error(sprintf(i18n('This plugin is required by the plugin <strong>%s</strong>, so you can not deactivate it.', 'pim'), parent::_getPluginName()));
156:         }
157:     }
158: 
159:     /**
160:      * Change *_nav_sub online status
161:      *
162:      * @param int  $idnavs (equivalent to column name)
163:      * @param bool $online (equivalent to column name)
164:      *
165:      * @throws cDbException
166:      * @throws cException
167:      */
168:     private function _changeNavSubStatus($idnavs, $online) {
169:         $this->_ApiNavSubCollection->setWhere('idnavs', cSecurity::toInteger($idnavs));
170:         $this->_ApiNavSubCollection->query();
171: 
172:         $navSub = $this->_ApiNavSubCollection->next();
173:         $navSub->set('online', cSecurity::toInteger($online));
174:         $navSub->store();
175:     }
176: }
177: 
CMS CONTENIDO 4.10.1 API documentation generated by ApiGen 2.8.0