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