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