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
    • NavigationMain
    • 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

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