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
  • Smarty
    • Cacher
    • Compiler
    • Config
    • Debug
    • PluginsBlock
    • PluginsFilter
    • PluginsFunction
    • PluginsInternal
    • PluginsModifier
    • PluginsModifierCompiler
    • PluginsShared
    • Security
    • Template
    • TemplateResources
  • Swift
    • ByteStream
    • CharacterStream
    • Encoder
    • Events
    • KeyCache
    • Mailer
    • Mime
    • Plugins
    • Transport

Classes

  • Swift_FailoverTransport
  • Swift_LoadBalancedTransport
  • Swift_MailTransport
  • Swift_Plugins_Loggers_ArrayLogger
  • Swift_Plugins_Loggers_EchoLogger
  • Swift_SendmailTransport
  • Swift_SmtpTransport
  • Swift_Transport_AbstractSmtpTransport
  • Swift_Transport_Esmtp_Auth_CramMd5Authenticator
  • Swift_Transport_Esmtp_Auth_LoginAuthenticator
  • Swift_Transport_Esmtp_Auth_PlainAuthenticator
  • Swift_Transport_Esmtp_AuthHandler
  • Swift_Transport_EsmtpTransport
  • Swift_Transport_FailoverTransport
  • Swift_Transport_LoadBalancedTransport
  • Swift_Transport_MailTransport
  • Swift_Transport_SendmailTransport
  • Swift_Transport_SimpleMailInvoker
  • Swift_Transport_StreamBuffer

Interfaces

  • Swift_Plugins_Logger
  • Swift_Plugins_Pop_Pop3Exception
  • Swift_Transport
  • Swift_Transport_Esmtp_Authenticator
  • Swift_Transport_EsmtpHandler
  • Swift_Transport_IoBuffer
  • Swift_Transport_MailInvoker
  • Swift_Transport_SmtpAgent
  • Swift_TransportException
  • Overview
  • Package
  • Function
  • Todo
  • Download
  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:      * @param string $foldername
 65:      * @return string
 66:      */
 67:     public function setPluginFoldername($foldername) {
 68:         return $this->_PluginFoldername = cSecurity::escapeString($foldername);
 69:     }
 70: 
 71:     /**
 72:      * Initializing and set variable for PimPluginCollection class
 73:      *
 74:      * @return PimPluginCollection
 75:      */
 76:     private function _setPimPluginCollection() {
 77:         return $this->_PimPluginCollection = new PimPluginCollection();
 78:     }
 79: 
 80:     /**
 81:      * Initializing and set variable for PimPluginRelationsCollection class
 82:      *
 83:      * @return PimPluginRelationsCollection
 84:      */
 85:     private function _setPimPluginRelationsCollection() {
 86:         return $this->_PimPluginRelationsCollection = new PimPluginRelationsCollection();
 87:     }
 88: 
 89:     /**
 90:      * Initializing and set variable for cApiAreaCollection
 91:      *
 92:      * @return cApiAreaCollection
 93:      */
 94:     private function _setApiAreaCollection() {
 95:         return $this->_ApiAreaCollection = new cApiAreaCollection();
 96:     }
 97: 
 98:     /**
 99:      * Initializing and set variable for cApiActionCollection
100:      *
101:      * @return cApiActionCollection
102:      */
103:     private function _setApiActionCollection() {
104:         return $this->_ApiActionCollection = new cApiActionCollection();
105:     }
106: 
107:     /**
108:      * Initializing and set variable for cApiAFileCollection
109:      *
110:      * @return cApiFileCollection
111:      */
112:     private function _setApiFileCollection() {
113:         return $this->_ApiFileCollection = new cApiFileCollection();
114:     }
115: 
116:     /**
117:      * Initializing and set variable for cApiFrameFileCollection
118:      *
119:      * @return cApiFrameFileCollection
120:      */
121:     private function _setApiFrameFileCollection() {
122:         return $this->_ApiFrameFileCollection = new cApiFrameFileCollection();
123:     }
124: 
125:     /**
126:      * Initializing and set variable for cApiNavMainFileCollection
127:      *
128:      * @return cApiNavMainCollection
129:      */
130:     private function _setApiNavMainCollection() {
131:         return $this->_ApiNavMainCollection = new cApiNavMainCollection();
132:     }
133: 
134:     /**
135:      * Initializing and set variable for cApiNavSubCollection
136:      *
137:      * @return cApiNavSubCollection
138:      */
139:     private function _setApiNavSubCollection() {
140:         return $this->_ApiNavSubCollection = new cApiNavSubCollection();
141:     }
142: 
143:     /**
144:      * Initializing and set variable for cApiTypeCollection
145:      *
146:      * @return cApiNavSubCollection
147:      */
148:     private function _setApiTypeCollection() {
149:         return $this->_ApiTypeCollection = new cApiTypeCollection();
150:     }
151: 
152:     /**
153:      * Get method for foldername of installed plugin
154:      *
155:      * @return string
156:      */
157:     protected function _getPluginFoldername() {
158:         return $this->_PluginFoldername;
159:     }
160: 
161:     // Begin of uninstallation routine
162:     /**
163:      * Construct function
164:      */
165:     public function __construct() {
166: 
167:         // Initializing and set classes
168:         // PluginManager classes
169:         $this->_setPimPluginCollection();
170:         $this->_setPimPluginRelationsCollection();
171: 
172:         // cApiClasses
173:         $this->_setApiAreaCollection();
174:         $this->_setApiActionCollection();
175:         $this->_setApiFileCollection();
176:         $this->_setApiFrameFileCollection();
177:         $this->_setApiNavMainCollection();
178:         $this->_setApiNavSubCollection();
179:         $this->_setApiTypeCollection();
180:     }
181: 
182:     /**
183:      * Uninstall function
184:      *
185:      * @param bool $sql Optional parameter to set sql true (standard) or
186:      *        false
187:      */
188:     public function uninstall($sql = true) {
189:         $cfg = cRegistry::getConfig();
190: 
191:         // Dependencies checks
192:         $this->_uninstallCheckDependencies();
193: 
194:         // get relations
195:         $this->_PimPluginRelationsCollection->setWhere('idplugin', parent::_getPluginId());
196:         $this->_PimPluginRelationsCollection->query();
197: 
198:         $relations = array();
199: 
200:         while (($relation = $this->_PimPluginRelationsCollection->next()) !== false) {
201:             // Relation to tables *_action_, *_area, *_nav_main, *_nav_sub and
202:             // *_type
203:             $index = $relation->get('type');
204: 
205:             // Is equivalent to idaction, idarea, idnavm, idnavs or idtype
206:             // column
207:             $value = $relation->get('iditem');
208:             $relations[$index][] = $value;
209:         }
210: 
211:         // Delete entries with relations to *_actions
212:         if (!empty($relations['action'])) {
213:             $this->_ApiActionCollection->deleteByWhereClause("idaction IN('" . join("', '", $relations['action']) . "')");
214:         }
215: 
216:         // Delete entries with relations to *_area
217:         if (!empty($relations['area'])) {
218:             $this->_ApiFileCollection->deleteByWhereClause("idarea IN('" . join("', '", $relations['area']) . "')");
219:             $this->_ApiFrameFileCollection->deleteByWhereClause("idarea IN('" . join("', '", $relations['area']) . "')");
220:             $this->_ApiAreaCollection->deleteByWhereClause("idarea IN('" . join("', '", $relations['area']) . "')");
221:         }
222: 
223:         // Delete entries with relations to *_nav_main
224:         if (!empty($relations['navm'])) {
225:             $this->_ApiNavMainCollection->deleteByWhereClause("idnavm IN('" . join("', '", $relations['navm']) . "')");
226:         }
227: 
228:         // Delete entries with relations to *_nav_sub
229:         if (!empty($relations['navs'])) {
230:             $this->_ApiNavSubCollection->deleteByWhereClause("idnavs IN('" . join("', '", $relations['navs']) . "')");
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->resetQuery();
240:         $this->_PimPluginCollection->setWhere('idplugin', parent::_getPluginId());
241:         $this->_PimPluginCollection->query();
242:         $pimPluginSql = $this->_PimPluginCollection->next();
243: 
244:         // Set foldername
245:         $this->setPluginFoldername($pimPluginSql->get('folder'));
246: 
247:         // Delete specific sql entries or tables, run only if we have no update
248:         // sql file
249:         if ($sql == true && PimPluginSetup::_getUpdateSqlFileExist() == false) {
250:             $this->_uninstallDeleteSpecificSql();
251:         }
252: 
253:         // Pluginname
254:         $pluginname = $pimPluginSql->get('name');
255: 
256:         // Delete entries at *_plugins_rel and *_plugins
257:         $this->_PimPluginRelationsCollection->deleteByWhereClause('idplugin = ' . parent::_getPluginId());
258:         $this->_PimPluginCollection->deleteByWhereClause('idplugin = ' . parent::_getPluginId());
259: 
260:         // Write new execution order
261:         $this->_writeNewExecutionOrder();
262: 
263:         // Success message for uninstall mode
264:         if (parent::$_GuiPage instanceof cGuiPage && parent::getMode() == 3) {
265:             parent::info(sprintf(i18n('The plugin <strong>%s</strong> has been successfully removed. To apply the changes please login into backend again.', 'pim'), $pluginname));
266:         }
267:     }
268: 
269:     /**
270:      * Check dependencies to other plugins (dependencies-Tag at plugin.xml)
271:      */
272:     private function _uninstallCheckDependencies() {
273: 
274:         // Call checkDepenendencies function at PimPlugin class
275:         // Function returns true or false
276:         $result = $this->checkDependencies();
277: 
278:         // Show an error message when dependencies could be found
279:         if ($result === false) {
280:             parent::error(sprintf(i18n('This plugin is required by the plugin <strong>%s</strong>, so you can not remove it.', 'pim'), parent::_getPluginName()));
281:         }
282:     }
283: 
284:     /**
285:      * Delete specific sql entries or tables, full uninstall mode
286:      */
287:     protected function _uninstallDeleteSpecificSql() {
288:         $cfg = cRegistry::getConfig();
289:         $db = cRegistry::getDb();
290: 
291:         $tempSqlFilename = $cfg['path']['contenido'] . $cfg['path']['plugins'] . $this->_getPluginFoldername() . DIRECTORY_SEPARATOR . 'plugin_uninstall.sql';
292: 
293:         if (!cFileHandler::exists($tempSqlFilename)) {
294:             return;
295:         }
296: 
297:         $tempSqlContent = cFileHandler::read($tempSqlFilename);
298:         $tempSqlContent = str_replace("\r\n", "\n", $tempSqlContent);
299:         $tempSqlContent = explode("\n", $tempSqlContent);
300:         $tempSqlLines = count($tempSqlContent);
301: 
302:         $pattern = '/^(DELETE FROM|DROP TABLE) `?' . parent::SQL_PREFIX . '`?\b/';
303: 
304:         for ($i = 0; $i < $tempSqlLines; $i++) {
305:             if (preg_match($pattern, $tempSqlContent[$i])) {
306:                 $tempSqlContent[$i] = str_replace(parent::SQL_PREFIX, $cfg['sql']['sqlprefix'] . '_pi', $tempSqlContent[$i]);
307:                 $db->query($tempSqlContent[$i]);
308:             }
309:         }
310:     }
311: 
312:     /**
313:      * Delete a installed plugin directory
314:      *
315:      * @param $foldername name of extracted plugin
316:      * @param $page page class for success or error message
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.7 API documentation generated by ApiGen