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