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
    • ContentRssCreator
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • 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
  • PimPluginViewDependencies
  • PimPluginViewNavSub
  • 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:  * @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:  * Uninstall class for existing plugins, extends PimPluginSetup
 18:  *
 19:  * @package Plugin
 20:  * @subpackage PluginManager
 21:  * @author frederic.schneider
 22:  */
 23: class PimPluginSetupUninstall extends PimPluginSetup {
 24: 
 25:     // Initializing variables
 26:     // Plugin specific data
 27:     // Foldername of installed plugin
 28:     private $_PluginFoldername;
 29: 
 30:     // Classes
 31:     // Class variable for PimPluginCollection
 32:     protected $_PimPluginCollection;
 33: 
 34:     // Class variable for PimPluginRelationsCollection
 35:     protected $_PimPluginRelationsCollection;
 36: 
 37:     // Class variable for cApiAreaCollection;
 38:     protected $_ApiAreaCollection;
 39: 
 40:     // Class variable for cApiActionCollection
 41:     protected $_ApiActionCollection;
 42: 
 43:     // Class variable for cApiFileCollection
 44:     protected $_ApiFileCollection;
 45: 
 46:     // Class variable for cApiFrameFileCollection
 47:     protected $_ApiFrameFileCollection;
 48: 
 49:     // Class variable for cApiNavMainCollection
 50:     protected $_ApiNavMainCollection;
 51: 
 52:     // Class variable for cApiNavSubCollection
 53:     protected $_ApiNavSubCollection;
 54: 
 55:     // Class variable for cApiTypeCollection
 56:     protected $_ApiTypeCollection;
 57: 
 58:     // GET and SET methods for installation routine
 59:     /**
 60:      * Set variable for plugin foldername
 61:      *
 62:      * @param string $foldername
 63:      * @return string
 64:      */
 65:     public function setPluginFoldername($foldername) {
 66:         return $this->_PluginFoldername = cSecurity::escapeString($foldername);
 67:     }
 68: 
 69:     /**
 70:      * Initializing and set variable for PimPluginCollection class
 71:      *
 72:      * @return PimPluginCollection
 73:      */
 74:     private function _setPimPluginCollection() {
 75:         return $this->_PimPluginCollection = new PimPluginCollection();
 76:     }
 77: 
 78:     /**
 79:      * Initializing and set variable for PimPluginRelationsCollection class
 80:      *
 81:      * @return PimPluginRelationsCollection
 82:      */
 83:     private function _setPimPluginRelationsCollection() {
 84:         return $this->_PimPluginRelationsCollection = new PimPluginRelationsCollection();
 85:     }
 86: 
 87:     /**
 88:      * Initializing and set variable for cApiAreaCollection
 89:      *
 90:      * @return cApiAreaCollection
 91:      */
 92:     private function _setApiAreaCollection() {
 93:         return $this->_ApiAreaCollection = new cApiAreaCollection();
 94:     }
 95: 
 96:     /**
 97:      * Initializing and set variable for cApiActionCollection
 98:      *
 99:      * @return cApiActionCollection
100:      */
101:     private function _setApiActionCollection() {
102:         return $this->_ApiActionCollection = new cApiActionCollection();
103:     }
104: 
105:     /**
106:      * Initializing and set variable for cApiAFileCollection
107:      *
108:      * @return cApiFileCollection
109:      */
110:     private function _setApiFileCollection() {
111:         return $this->_ApiFileCollection = new cApiFileCollection();
112:     }
113: 
114:     /**
115:      * Initializing and set variable for cApiFrameFileCollection
116:      *
117:      * @return cApiFrameFileCollection
118:      */
119:     private function _setApiFrameFileCollection() {
120:         return $this->_ApiFrameFileCollection = new cApiFrameFileCollection();
121:     }
122: 
123:     /**
124:      * Initializing and set variable for cApiNavMainFileCollection
125:      *
126:      * @return cApiNavMainCollection
127:      */
128:     private function _setApiNavMainCollection() {
129:         return $this->_ApiNavMainCollection = new cApiNavMainCollection();
130:     }
131: 
132:     /**
133:      * Initializing and set variable for cApiNavSubCollection
134:      *
135:      * @return cApiNavSubCollection
136:      */
137:     private function _setApiNavSubCollection() {
138:         return $this->_ApiNavSubCollection = new cApiNavSubCollection();
139:     }
140: 
141:     /**
142:      * Initializing and set variable for cApiTypeCollection
143:      *
144:      * @return cApiNavSubCollection
145:      */
146:     private function _setApiTypeCollection() {
147:         return $this->_ApiTypeCollection = new cApiTypeCollection();
148:     }
149: 
150:     /**
151:      * Get method for foldername of installed plugin
152:      *
153:      * @return string
154:      */
155:     protected function _getPluginFoldername() {
156:         return $this->_PluginFoldername;
157:     }
158: 
159:     // Begin of uninstallation routine
160:     /**
161:      * Construct function
162:      */
163:     public function __construct() {
164: 
165:         // Initializing and set classes
166:         // PluginManager classes
167:         $this->_setPimPluginCollection();
168:         $this->_setPimPluginRelationsCollection();
169: 
170:         // cApiClasses
171:         $this->_setApiAreaCollection();
172:         $this->_setApiActionCollection();
173:         $this->_setApiFileCollection();
174:         $this->_setApiFrameFileCollection();
175:         $this->_setApiNavMainCollection();
176:         $this->_setApiNavSubCollection();
177:         $this->_setApiTypeCollection();
178:     }
179: 
180:     /**
181:      * Uninstall function
182:      *
183:      * @param bool $sql Optional parameter to set sql true (standard) or
184:      *        false
185:      */
186:     public function uninstall($sql = true) {
187:         $cfg = cRegistry::getConfig();
188: 
189:         // Dependencies checks
190:         $this->_uninstallCheckDependencies();
191: 
192:         // get relations
193:         $this->_PimPluginRelationsCollection->setWhere('idplugin', parent::_getPluginId());
194:         $this->_PimPluginRelationsCollection->query();
195: 
196:         $relations = array();
197: 
198:         while (($relation = $this->_PimPluginRelationsCollection->next()) !== false) {
199:             // Relation to tables *_action_, *_area, *_nav_main, *_nav_sub and
200:             // *_type
201:             $index = $relation->get('type');
202: 
203:             // Is equivalent to idaction, idarea, idnavm, idnavs or idtype
204:             // column
205:             $value = $relation->get('iditem');
206:             $relations[$index][] = $value;
207:         }
208: 
209:         // Delete entries with relations to *_actions
210:         if (!empty($relations['action'])) {
211:             $this->_ApiActionCollection->deleteByWhereClause("idaction IN('" . join("', '", $relations['action']) . "')");
212:         }
213: 
214:         // Delete entries with relations to *_frame_files
215:         if (!empty($relations['framefl'])) {
216:             $this->_ApiFrameFileCollection->deleteByWhereClause("idframefile IN('" . join("', '", $relations['framefl']) . "')");
217:         }
218: 
219:         // Delete entries with relations to *_area
220:         if (!empty($relations['area'])) {
221:             $this->_ApiFileCollection->deleteByWhereClause("idarea IN('" . join("', '", $relations['area']) . "')");
222:             $this->_ApiFrameFileCollection->deleteByWhereClause("idarea IN('" . join("', '", $relations['area']) . "')");
223:             $this->_ApiAreaCollection->deleteByWhereClause("idarea IN('" . join("', '", $relations['area']) . "')");
224:         }
225: 
226:         // Delete entries with relations to *_nav_main
227:         if (!empty($relations['navm'])) {
228:             $this->_ApiNavMainCollection->deleteByWhereClause("idnavm IN('" . join("', '", $relations['navm']) . "')");
229:         }
230: 
231:         // Delete entries with relations to *_nav_sub
232:         if (!empty($relations['navs'])) {
233:             $this->_ApiNavSubCollection->deleteByWhereClause("idnavs IN('" . join("', '", $relations['navs']) . "')");
234:         }
235: 
236:         // Delete content types
237:         if (!empty($relations['ctype'])) {
238:             $this->_ApiTypeCollection->deleteByWhereClause("idtype IN('" . join("', '", $relations['ctype']) . "')");
239:         }
240: 
241:         // Get plugininformations
242:         $this->_PimPluginCollection->resetQuery();
243:         $this->_PimPluginCollection->setWhere('idplugin', parent::_getPluginId());
244:         $this->_PimPluginCollection->query();
245:         $pimPluginSql = $this->_PimPluginCollection->next();
246: 
247:         // Set foldername
248:         $this->setPluginFoldername($pimPluginSql->get('folder'));
249: 
250:         // Delete specific sql entries or tables, run only if we have no update
251:         // sql file
252:         if ($sql == true && PimPluginSetup::_getUpdateSqlFileExist() == false) {
253:             $this->_uninstallDeleteSpecificSql();
254:         }
255: 
256:         // Pluginname
257:         $pluginname = $pimPluginSql->get('name');
258: 
259:         // Delete entries at *_plugins_rel and *_plugins
260:         $this->_PimPluginRelationsCollection->deleteByWhereClause('idplugin = ' . parent::_getPluginId());
261:         $this->_PimPluginCollection->deleteByWhereClause('idplugin = ' . parent::_getPluginId());
262: 
263:         // Write new execution order
264:         $this->_writeNewExecutionOrder();
265: 
266:         // Success message for uninstall mode
267:         if (parent::$_GuiPage instanceof cGuiPage && parent::getMode() == 3) {
268:             parent::info(sprintf(i18n('The plugin <strong>%s</strong> has been successfully removed. To apply the changes please login into backend again.', 'pim'), $pluginname));
269:         }
270:     }
271: 
272:     /**
273:      * Check dependencies to other plugins (dependencies-Tag at plugin.xml)
274:      */
275:     private function _uninstallCheckDependencies() {
276: 
277:         // Call checkDepenendencies function at PimPlugin class
278:         // Function returns true or false
279:         $result = $this->checkDependencies();
280: 
281:         // Show an error message when dependencies could be found
282:         if ($result === false) {
283:             parent::error(sprintf(i18n('This plugin is required by the plugin <strong>%s</strong>, so you can not remove it.', 'pim'), parent::_getPluginName()));
284:         }
285:     }
286: 
287:     /**
288:      * Delete specific sql entries or tables, full uninstall mode
289:      */
290:     protected function _uninstallDeleteSpecificSql() {
291:         $cfg = cRegistry::getConfig();
292:         $db = cRegistry::getDb();
293: 
294:         $tempSqlFilename = $cfg['path']['contenido'] . $cfg['path']['plugins'] . $this->_getPluginFoldername() . DIRECTORY_SEPARATOR . 'plugin_uninstall.sql';
295: 
296:         if (!cFileHandler::exists($tempSqlFilename)) {
297:             return;
298:         }
299: 
300:         $tempSqlContent = cFileHandler::read($tempSqlFilename);
301:         $tempSqlContent = str_replace("\r\n", "\n", $tempSqlContent);
302:         $tempSqlContent = explode("\n", $tempSqlContent);
303:         $tempSqlLines = count($tempSqlContent);
304: 
305:         $pattern = '/^(DELETE FROM|DROP TABLE) `?' . parent::SQL_PREFIX . '`?\b/';
306: 
307:         for ($i = 0; $i < $tempSqlLines; $i++) {
308:             if (preg_match($pattern, $tempSqlContent[$i])) {
309:                 $tempSqlContent[$i] = str_replace(parent::SQL_PREFIX, $cfg['sql']['sqlprefix'] . '_pi', $tempSqlContent[$i]);
310:                 $db->query($tempSqlContent[$i]);
311:             }
312:         }
313:     }
314: 
315:     /**
316:      * Delete a installed plugin directory
317:      */
318:     public function uninstallDir() {
319:         $cfg = cRegistry::getConfig();
320: 
321:         // delete folders
322:         $folderpath = $cfg['path']['contenido'] . $cfg['path']['plugins'] . $this->_getPluginFoldername();
323:         cDirHandler::recursiveRmdir($folderpath);
324: 
325:         if (parent::$_GuiPage instanceof cGuiPage) {
326: 
327:             // success message
328:             if (!cFileHandler::exists($folderpath)) {
329:                 parent::info(sprintf(i18n('The pluginfolder <strong>%s</strong> has been successfully uninstalled.', 'pim'), $this->_getPluginFoldername()));
330:             } else if (cFileHandler::exists($folderpath)) {
331:                 parent::error(sprintf(i18n('The pluginfolder <strong>%s</strong> could not be uninstalled.', 'pim'), $this->_getPluginFoldername()));
332:             }
333:         }
334:     }
335: 
336:     /**
337:      * Generate (write) new execution order
338:      *
339:      * @return boolean
340:      */
341:     protected function _writeNewExecutionOrder() {
342: 
343:         // Lowest executionorder is one
344:         $i = 1;
345: 
346:         $pimPluginColl = new PimPluginCollection();
347:         $pimPluginColl->setOrder('executionorder ASC');
348:         $pimPluginColl->query();
349:         while ($pimPluginSql = $pimPluginColl->next()) {
350:             $pimPluginSql->set('executionorder', $i);
351:             $pimPluginSql->store();
352: 
353:             $i++;
354:         }
355: 
356:         return true;
357:     }
358: 
359: }
360: ?>
CMS CONTENIDO 4.9.11 API documentation generated by ApiGen 2.8.0