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
    • 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 update 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:  * Update class for existing plugins, extends PimPluginSetup
 18:  *
 19:  * @package Plugin
 20:  * @subpackage PluginManager
 21:  * @author frederic.schneider
 22:  */
 23: class PimPluginSetupUpdate extends PimPluginSetup {
 24: 
 25:     // Classes
 26:     /**
 27:      * Variable for PIM class PimPluginCollection
 28:      *
 29:      * @var PimPluginCollection
 30:      */
 31:     protected $_PimPluginCollection;
 32: 
 33:     /**
 34:      * Initializing and set variable for PimPluginCollection class
 35:      *
 36:      * @return PimPluginCollection
 37:      */
 38:     private function _setPimPluginCollection() {
 39:         return $this->_PimPluginCollection = new PimPluginCollection();
 40:     }
 41: 
 42:     // Begin of update routine
 43:     /**
 44:      * Construct function
 45:      */
 46:     public function __construct() {
 47: 
 48:         // Initializing and set classes
 49:         // PluginManager classes
 50:         $this->_setPimPluginCollection();
 51: 
 52:         // Check same plugin (uuid)
 53:         $this->_checkSamePlugin();
 54: 
 55:         // Check for update specific sql files
 56:         $this->_updateSql();
 57: 
 58:         // Delete "old" plugin
 59:         $delete = new PimPluginSetupUninstall();
 60:         $delete->uninstall();
 61: 
 62:         // Install new plugin
 63:         $new = new PimPluginSetupInstall();
 64:         $new->install();
 65: 
 66:         // Success message
 67:         parent::info(i18n('The plugin has been successfully updated. To apply the changes please login into backend again.', 'pim'));
 68:     }
 69: 
 70:     /**
 71:      * Check uuId: You can update only the same plugin
 72:      */
 73:     private function _checkSamePlugin() {
 74:         $this->_PimPluginCollection->setWhere('idplugin', parent::_getPluginId());
 75:         $this->_PimPluginCollection->query();
 76:         while ($result = $this->_PimPluginCollection->next()) {
 77: 
 78:             if (parent::$XmlGeneral->uuid != $result->get('uuid')) {
 79:                 parent::error(i18n('You have to update the same plugin', 'pim'));
 80:             }
 81:         }
 82:     }
 83: 
 84:     /**
 85:      * Check for update specific sql files.
 86:      * If some valid sql file available, PIM does not run uninstall and install
 87:      * sql files.
 88:      */
 89:     private function _updateSql() {
 90: 
 91:         $cfg = cRegistry::getConfig();
 92:         $db = cRegistry::getDb();
 93: 
 94:         // Build sql filename with installed plugin version and new plugin
 95:         // version, i. e.: "plugin_update_100_to_101.sql" (without dots)
 96:         $tempSqlFilename = "plugin_update_" . str_replace('.', '', $this->_getInstalledPluginVersion()) . "_to_" . str_replace('.', '', parent::$XmlGeneral->version) . ".sql";
 97: 
 98:         // Filename to update sql file
 99:         $tempSqlFilename = parent::$_PimPluginArchiveExtractor->extractArchiveFileToVariable($tempSqlFilename, 0);
100: 
101:         if (cFileHandler::exists($tempSqlFilename)) {
102: 
103:             // Execute update sql file
104:             $tempSqlContent = cFileHandler::read($tempSqlFilename);
105:             $tempSqlContent = str_replace("\r\n", "\n", $tempSqlContent);
106:             $tempSqlContent = explode("\n", $tempSqlContent);
107:             $tempSqlLines = count($tempSqlContent);
108: 
109:             $pattern = '/^(CREATE TABLE IF NOT EXISTS|INSERT INTO|UPDATE|ALTER TABLE) `?' . parent::SQL_PREFIX . '`?\b/';
110: 
111:             for ($i = 0; $i < $tempSqlLines; $i++) {
112:                 if (preg_match($pattern, $tempSqlContent[$i])) {
113:                     $tempSqlContent[$i] = str_replace(parent::SQL_PREFIX, $cfg['sql']['sqlprefix'] . '_pi', $tempSqlContent[$i]);
114:                     $db->query($tempSqlContent[$i]);
115:                 }
116:             }
117: 
118:             // Do not run uninstall and install sql files
119:             PimPluginSetup::_setUpdateSqlFileExist(true);
120:         } else {
121:             return false;
122:         }
123:     }
124: 
125:     /**
126:      * Get installed plugin version
127:      */
128:     private function _getInstalledPluginVersion() {
129:         $this->_PimPluginCollection->setWhere('idplugin', parent::_getPluginId());
130:         $this->_PimPluginCollection->query();
131:         while ($result = $this->_PimPluginCollection->next()) {
132:             return $result->get('version');
133:         }
134:     }
135: 
136: }
CMS CONTENIDO 4.10.0 API documentation generated by ApiGen 2.8.0