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