Overview

Packages

  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Datatype
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
  • mpAutoloaderClassMap
  • None
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SearchSolr
    • 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
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: /**
  3:  * This file contains abstract class for installation new plugins
  4:  *
  5:  * @package Plugin
  6:  * @subpackage PluginManager
  7:  * @version SVN Revision $Rev:$
  8:  *
  9:  * @author Frederic Schneider
 10:  * @copyright four for business AG <www.4fb.de>
 11:  * @license http://www.contenido.org/license/LIZENZ.txt
 12:  * @link http://www.4fb.de
 13:  * @link http://www.contenido.org
 14:  */
 15: 
 16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 17: 
 18: /**
 19:  * Uninstall class for existing plugins, extends PimPluginSetup
 20:  *
 21:  * @package Plugin
 22:  * @subpackage PluginManager
 23:  * @author frederic.schneider
 24:  */
 25: class PimPluginSetupUninstall extends PimPluginSetup {
 26: 
 27:     // Initializing variables
 28:     // Plugin specific data
 29:     // Foldername of installed plugin
 30:     private $_PluginFoldername;
 31: 
 32:     // Classes
 33:     // Class variable for PimPluginCollection
 34:     protected $_PimPluginCollection;
 35: 
 36:     // Class variable for PimPluginRelationsCollection
 37:     protected $_PimPluginRelationsCollection;
 38: 
 39:     // Class variable for cApiAreaCollection;
 40:     protected $_ApiAreaCollection;
 41: 
 42:     // Class variable for cApiActionCollection
 43:     protected $_ApiActionCollection;
 44: 
 45:     // Class variable for cApiFileCollection
 46:     protected $_ApiFileCollection;
 47: 
 48:     // Class variable for cApiFrameFileCollection
 49:     protected $_ApiFrameFileCollection;
 50: 
 51:     // Class variable for cApiNavMainCollection
 52:     protected $_ApiNavMainCollection;
 53: 
 54:     // Class variable for cApiNavSubCollection
 55:     protected $_ApiNavSubCollection;
 56: 
 57:     // Class variable for cApiTypeCollection
 58:     protected $_ApiTypeCollection;
 59: 
 60:     // GET and SET methods for installation routine
 61:     /**
 62:      * Set variable for plugin foldername
 63:      *
 64:      * @access public
 65:      * @param string $foldername
 66:      * @return string
 67:      */
 68:     public function setPluginFoldername($foldername) {
 69:         return $this->_PluginFoldername = cSecurity::escapeString($foldername);
 70:     }
 71: 
 72:     /**
 73:      * Initializing and set variable for PimPluginCollection class
 74:      *
 75:      * @access private
 76:      * @return PimPluginCollection
 77:      */
 78:     private function _setPimPluginCollection() {
 79:         return $this->_PimPluginCollection = new PimPluginCollection();
 80:     }
 81: 
 82:     /**
 83:      * Initializing and set variable for PimPluginRelationsCollection class
 84:      *
 85:      * @access private
 86:      * @return PimPluginRelationsCollection
 87:      */
 88:     private function _setPimPluginRelationsCollection() {
 89:         return $this->_PimPluginRelationsCollection = new PimPluginRelationsCollection();
 90:     }
 91: 
 92:     /**
 93:      * Initializing and set variable for cApiAreaCollection
 94:      *
 95:      * @access private
 96:      * @return cApiAreaCollection
 97:      */
 98:     private function _setApiAreaCollection() {
 99:         return $this->_ApiAreaCollection = new cApiAreaCollection();
100:     }
101: 
102:     /**
103:      * Initializing and set variable for cApiActionCollection
104:      *
105:      * @access private
106:      * @return cApiActionCollection
107:      */
108:     private function _setApiActionCollection() {
109:         return $this->_ApiActionCollection = new cApiActionCollection();
110:     }
111: 
112:     /**
113:      * Initializing and set variable for cApiAFileCollection
114:      *
115:      * @access private
116:      * @return cApiFileCollection
117:      */
118:     private function _setApiFileCollection() {
119:         return $this->_ApiFileCollection = new cApiFileCollection();
120:     }
121: 
122:     /**
123:      * Initializing and set variable for cApiFrameFileCollection
124:      *
125:      * @access private
126:      * @return cApiFrameFileCollection
127:      */
128:     private function _setApiFrameFileCollection() {
129:         return $this->_ApiFrameFileCollection = new cApiFrameFileCollection();
130:     }
131: 
132:     /**
133:      * Initializing and set variable for cApiNavMainFileCollection
134:      *
135:      * @access private
136:      * @return cApiNavMainCollection
137:      */
138:     private function _setApiNavMainCollection() {
139:         return $this->_ApiNavMainCollection = new cApiNavMainCollection();
140:     }
141: 
142:     /**
143:      * Initializing and set variable for cApiNavSubCollection
144:      *
145:      * @access private
146:      * @return cApiNavSubCollection
147:      */
148:     private function _setApiNavSubCollection() {
149:         return $this->_ApiNavSubCollection = new cApiNavSubCollection();
150:     }
151: 
152:     /**
153:      * Initializing and set variable for cApiTypeCollection
154:      *
155:      * @access private
156:      * @return cApiNavSubCollection
157:      */
158:     private function _setApiTypeCollection() {
159:         return $this->_ApiTypeCollection = new cApiTypeCollection();
160:     }
161: 
162:     /**
163:      * Get method for foldername of installed plugin
164:      *
165:      * @return string
166:      */
167:     protected function _getPluginFoldername() {
168:         return $this->_PluginFoldername;
169:     }
170: 
171:     // Begin of uninstallation routine
172:     /**
173:      * Construct function
174:      *
175:      * @access public
176:      */
177:     public function __construct() {
178: 
179:         // Initializing and set classes
180:         // PluginManager classes
181:         $this->_setPimPluginCollection();
182:         $this->_setPimPluginRelationsCollection();
183: 
184:         // cApiClasses
185:         $this->_setApiAreaCollection();
186:         $this->_setApiActionCollection();
187:         $this->_setApiFileCollection();
188:         $this->_setApiFrameFileCollection();
189:         $this->_setApiNavMainCollection();
190:         $this->_setApiNavSubCollection();
191:         $this->_setApiTypeCollection();
192:     }
193: 
194:     /**
195:      * Uninstall function
196:      *
197:      * @access public
198:      * @param boolean $sql Optional parameter to set sql true (standard) or
199:      *        false
200:      */
201:     public function uninstall($sql = true) {
202:         $cfg = cRegistry::getConfig();
203: 
204:         // get relations
205:         $this->_PimPluginRelationsCollection->setWhere('idplugin', parent::_getPluginId());
206:         $this->_PimPluginRelationsCollection->query();
207: 
208:         $relations = array();
209: 
210:         while (($relation = $this->_PimPluginRelationsCollection->next()) !== false) {
211:             // Relation to tables *_area, *_nav_main and *_type
212:             $index = $relation->get('type');
213: 
214:             // Is equivalent to idarea, idnavm or idtype column
215:             $value = $relation->get('iditem');
216:             $relations[$index][] = $value;
217:         }
218: 
219:         // Delete entries with relations to *_area
220:         if (!empty($relations['area'])) {
221:             $this->_ApiActionCollection->deleteByWhereClause("idarea IN('" . join("', '", $relations['area']) . "')");
222:             $this->_ApiFileCollection->deleteByWhereClause("idarea IN('" . join("', '", $relations['area']) . "')");
223:             $this->_ApiFrameFileCollection->deleteByWhereClause("idarea IN('" . join("', '", $relations['area']) . "')");
224:             $this->_ApiNavSubCollection->deleteByWhereClause("idarea IN('" . join("', '", $relations['area']) . "')");
225:             $this->_ApiAreaCollection->deleteByWhereClause("idarea IN('" . join("', '", $relations['area']) . "')");
226:         }
227: 
228:         // Delete entries from *_nav_main
229:         if (!empty($relations['navm'])) {
230:             $this->_ApiNavMainCollection->deleteByWhereClause("idnavm IN('" . join("', '", $relations['navm']) . "')");
231:         }
232: 
233:         // Delete content types
234:         if (!empty($relations['ctype'])) {
235:             $this->_ApiTypeCollection->deleteByWhereClause("idtype IN('" . join("', '", $relations['ctype']) . "')");
236:         }
237: 
238:         // Get plugininformations
239:         $this->_PimPluginCollection->setWhere('idplugin', parent::_getPluginId());
240:         $this->_PimPluginCollection->query();
241:         $pimPluginSql = $this->_PimPluginCollection->next();
242: 
243:         // Set foldername
244:         $this->setPluginFoldername($pimPluginSql->get('folder'));
245: 
246:         // Delete specific sql entries or tables, run only if we have no update
247:         // sql file
248:         if ($sql == true && PimPluginSetup::_getUpdateSqlFileExist() == false) {
249:             $this->_uninstallDeleteSpecificSql();
250:         }
251: 
252:         // Pluginname
253:         $pluginname = $pimPluginSql->get('name');
254: 
255:         // Delete entries at *_plugins_rel and *_plugins
256:         $this->_PimPluginRelationsCollection->deleteByWhereClause('idplugin = ' . parent::_getPluginId());
257:         $this->_PimPluginCollection->deleteByWhereClause('idplugin = ' . parent::_getPluginId());
258: 
259:         // Success message for uninstall mode
260:         if (parent::$_GuiPage instanceof cGuiPage && parent::getMode() == 3) {
261:             parent::info(i18n('The plugin', 'pim') . ' <strong>' . $pluginname . '</strong> ' . i18n('has been successfully uninstalled. To apply the changes please login into backend again.', 'pim'));
262:         }
263:     }
264: 
265:     /**
266:      * Delete specific sql entries or tables, full uninstall mode
267:      *
268:      * @access protected
269:      */
270:     protected function _uninstallDeleteSpecificSql() {
271:         $cfg = cRegistry::getConfig();
272:         $db = cRegistry::getDb();
273: 
274:         $tempSqlFilename = $cfg['path']['contenido'] . $cfg['path']['plugins'] . $this->_getPluginFoldername() . DIRECTORY_SEPARATOR . 'plugin_uninstall.sql';
275: 
276:         if (!cFileHandler::exists($tempSqlFilename)) {
277:             return;
278:         }
279: 
280:         $tempSqlContent = cFileHandler::read($tempSqlFilename);
281:         $tempSqlContent = str_replace("\r\n", "\n", $tempSqlContent);
282:         $tempSqlContent = explode("\n", $tempSqlContent);
283:         $tempSqlLines = count($tempSqlContent);
284: 
285:         $pattern = '/^(DELETE FROM|DROP TABLE) `?' . parent::SQL_PREFIX . '`?\b/';
286: 
287:         for ($i = 0; $i < $tempSqlLines; $i++) {
288:             if (preg_match($pattern, $tempSqlContent[$i])) {
289:                 $tempSqlContent[$i] = str_replace(parent::SQL_PREFIX, $cfg['sql']['sqlprefix'] . '_pi', $tempSqlContent[$i]);
290:                 $db->query($tempSqlContent[$i]);
291:             }
292:         }
293:     }
294: 
295:     /**
296:      * Delete a installed plugin directory
297:      *
298:      * @access public
299:      * @param $foldername name of extracted plugin
300:      * @param $page page class for success or error message
301:      */
302:     public function uninstallDir() {
303:         $cfg = cRegistry::getConfig();
304: 
305:         // delete folders
306:         $folderpath = $cfg['path']['contenido'] . $cfg['path']['plugins'] . $this->_getPluginFoldername();
307:         cFileHandler::recursiveRmdir($folderpath);
308: 
309:         if (parent::$_GuiPage instanceof cGuiPage) {
310: 
311:             // success message
312:             if (!cFileHandler::exists($folderpath)) {
313:                 parent::info(i18n('The pluginfolder', 'pim') . ' <strong>' . $this->_getPluginFoldername() . '</strong> ' . i18n('has been successfully uninstalled.', 'pim'));
314:             } else if (cFileHandler::exists($folderpath)) {
315:                 parent::info(i18n('The pluginfolder', 'pim') . ' <strong>' . $this->_getPluginFoldername() . '</strong> ' . i18n('could not be uninstalled.', 'pim'));
316:             }
317:         }
318:     }
319: 
320: }
321: ?>
CMS CONTENIDO 4.9.1 API documentation generated by ApiGen 2.8.0