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

Classes

  • cUpgradeJob_0001
  • cUpgradeJob_0002
  • cUpgradeJob_0003
  • cUpgradeJob_0004
  • cUpgradeJob_0005
  • cUpgradeJob_0006
  • cUpgradeJob_0007
  • cUpgradeJob_0008
  • cUpgradeJob_0009
  • cUpgradeJob_0010
  • cUpgradeJob_0011
  • cUpgradeJob_0012
  • cUpgradeJob_0013
  • cUpgradeJob_0014
  • cUpgradeJob_0015
  • cUpgradeJob_0016
  • cUpgradeJob_0017
  • cUpgradeJobAbstract
  • cUpgradeJobMain
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: /**
  3:  * This file contains the main upgrade job class.
  4:  *
  5:  * @package Setup
  6:  * @subpackage UpgradeJob
  7:  * @author Murat Purc <murat@purc.de>
  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: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 14: 
 15: /**
 16:  * Main upgrade job class.
 17:  *
 18:  * @package Setup
 19:  * @subpackage UpgradeJob
 20:  */
 21: class cUpgradeJobMain extends cUpgradeJobAbstract {
 22: 
 23:     /**
 24:      * Main function to execute
 25:      */
 26:     public function _execute() {
 27:         global $cfg;
 28: 
 29:         $this->_version = getContenidoVersion($this->_oDb, $cfg['tab']['system_prop']);
 30:         $this->_executeInitialJobs();
 31: 
 32:         $upgradeJobs = $this->_getUpgradeJobFiles();
 33:         $this->_processUpgradeJobs($upgradeJobs);
 34:     }
 35: 
 36:     /**
 37:      * Initial update jobs.
 38:      *
 39:      * NOTE: Don't spam this function with additional upgrade tasks.
 40:      * Create a new upgrated job file and implement the execute() method!
 41:      */
 42:     protected function _executeInitialJobs() {
 43:         global $cfg;
 44: 
 45:         updateContenidoVersion($this->_oDb, $cfg['tab']['system_prop'], CON_SETUP_VERSION);
 46:         if ($this->_setupType == 'setup') {
 47:             updateSysadminPassword($this->_oDb, $cfg['sql']['sqlprefix'] . '_user', $_SESSION['adminpass'], $_SESSION['adminmail']);
 48:         }
 49: 
 50:         // Set code creation (on update) flag
 51:         $this->_oDb->query('UPDATE %s SET createcode = 1', $cfg['tab']['cat_art']);
 52: 
 53:         // Convert old category start articles to new format, we don't support
 54:         $this->_jobConvertOldStartArticlesToNewOne();
 55: 
 56:         // Update Keys
 57:         injectSQL($this->_oDb, $cfg['sql']['sqlprefix'], 'data/indexes.sql', array());
 58: 
 59:         // Update to autoincrement
 60:         addAutoIncrementToTables($this->_oDb, $cfg);
 61: 
 62:         // Insert or update default system properties
 63:         updateSystemProperties($this->_oDb, $cfg['tab']['system_prop']);
 64: 
 65:         // Renames table 'phplib_auth_user_md5' to 'user'
 66:         $this->_renameOldUserTableToNewOne();
 67:     }
 68: 
 69:     /**
 70:      * Function to convert old start article configuration to new style.
 71:      *
 72:      * In former CONTENIDO versions (4.6 or earlier) start articles were
 73:      * stored in table con_cat_art.is_start.
 74:      * Since 4.6 start articles are stored con_cat_lang.startidartlang.
 75:      *
 76:      * This function takes the start articles from con_cat_art.is_start and
 77:      * sets them in con_cat_lang.startidartlang for all available languages.
 78:      */
 79:     protected function _jobConvertOldStartArticlesToNewOne() {
 80:         global $cfg;
 81: 
 82:         // Convert old category start articles to new format, we don't support
 83:         // the configuration '$cfg["is_start_compatible"] = true;'
 84:         if ($this->_setupType == 'upgrade') {
 85:             $sql = "SELECT * FROM " . $cfg["tab"]["cat_art"] . " WHERE is_start = 1";
 86:             $this->_oDb->query($sql);
 87: 
 88:             $db2 = getSetupMySQLDBConnection();
 89: 
 90:             while ($this->_oDb->nextRecord()) {
 91:                 $startidart = (int) $this->_oDb->f("idart");
 92:                 $idcat = (int) $this->_oDb->f("idcat");
 93: 
 94:                 foreach (self::$_languages as $vlang => $oLang) {
 95:                     $vlang = (int) $vlang;
 96:                     $sql = "SELECT idartlang FROM " . $cfg["tab"]["art_lang"] . " WHERE idart = " . $startidart . " AND idlang = " . $vlang;
 97:                     $db2->query($sql);
 98:                     if ($db2->nextRecord()) {
 99:                         $idartlang = (int) $db2->f("idartlang");
100:                         $sql = "UPDATE " . $cfg["tab"]["cat_lang"] . " SET startidartlang = " . $idartlang . " WHERE idcat = " . $idcat . " AND idlang= " . $vlang;
101:                         $db2->query($sql);
102:                     }
103:                 }
104:             }
105: 
106:             $sql = "UPDATE " . $cfg["tab"]["cat_art"] . " SET is_start = 0";
107:             $this->_oDb->query($sql);
108:         }
109:     }
110: 
111:     /**
112:      * Renames table 'phplib_auth_user_md5' to 'user'
113:      */
114:     protected function _renameOldUserTableToNewOne() {
115:         global $cfg;
116: 
117:         $this->_oDb->query('SHOW TABLES LIKE "%s"', $cfg['sql']['sqlprefix'] . '_phplib_auth_user_md5');
118:         $oldTable = $this->_oDb->nextRecord();
119: 
120:         $this->_oDb->query('SHOW TABLES LIKE "%s"', $cfg['sql']['sqlprefix'] . '_user');
121:         $newTable = $this->_oDb->nextRecord();
122: 
123:         if ($oldTable === true) {
124:             if ($newTable === false) {
125:                 // Only the old table exists. Rename it.
126:                 $this->_oDb->query('RENAME TABLE ' . $cfg['sql']['sqlprefix'] . '_phplib_auth_user_md5 TO ' . $cfg['sql']['sqlprefix'] . '_user');
127:             } else {
128:                 // The new and the old table exists. We trust the old table more
129:                 // since the new one should've been deleted by the setup. Drop
130:                 // the new one and rename the old one
131:                 $this->_oDb->query('DROP TABLE ' . $cfg['sql']['sqlprefix'] . '_user');
132:                 $this->_oDb->query('RENAME TABLE ' . $cfg['sql']['sqlprefix'] . '_phplib_auth_user_md5 TO ' . $cfg['sql']['sqlprefix'] . '_user');
133:             }
134:         }
135: 
136:         // Convert passwords to salted ones
137:         addSalts($this->_oDb);
138:     }
139: 
140:     /**
141:      * Get all upgrade job files
142:      *
143:      * @return array
144:      */
145:     protected function _getUpgradeJobFiles() {
146:         $files = array();
147:         $dir = CON_SETUP_PATH . '/upgrade_jobs/';
148:         if (is_dir($dir)) {
149:             if (false !== ($handle = cDirHandler::read($dir))) {
150:                 foreach ($handle as $file) {
151:                     if (false === cFileHandler::fileNameIsDot($file) && is_file($dir . $file)) {
152:                         if (preg_match('/^class\.upgrade\.job\.(\d{4})\.php$/', $file, $match)) {
153:                             $files[$match[1]] = $file;
154:                         }
155:                     }
156:                 }
157:             }
158:             ksort($files, SORT_NUMERIC);
159:         }
160: 
161:         return $files;
162:     }
163: 
164:     /**
165:      * Execute passed upgrade job files
166:      *
167:      * @param array $upgradeJobs
168:      */
169:     protected function _processUpgradeJobs(array $upgradeJobs) {
170:         foreach ($upgradeJobs as $index => $file) {
171:             require_once (CON_SETUP_PATH . '/upgrade_jobs/' . $file);
172:             $className = 'cUpgradeJob_' . $index;
173:             if (!class_exists($className)) {
174:                 continue;
175:             }
176: 
177:             /* @var $obj cUpgradeJobAbstract */
178:             $obj = new $className($this->_oDb, $this->_aCfg, $this->_aCfgClient, $this->_version);
179:             $obj->execute();
180:         }
181:     }
182: 
183: }
184: 
CMS CONTENIDO 4.9.11 API documentation generated by ApiGen 2.8.0