1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
16:
17: 18: 19: 20: 21: 22:
23: class cUpgradeJobMain extends cUpgradeJobAbstract {
24:
25: 26: 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: 40: 41: 42: 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:
53: $this->_oDb->query('UPDATE %s SET createcode = 1', $cfg['tab']['cat_art']);
54:
55:
56: $this->_jobConvertOldStartArticlesToNewOne();
57:
58:
59: $aNothing = array();
60: injectSQL($this->_oDb, $cfg['sql']['sqlprefix'], 'data/indexes.sql', array(), $aNothing);
61:
62:
63: addAutoIncrementToTables($this->_oDb, $cfg);
64:
65:
66: updateSystemProperties($this->_oDb, $cfg['tab']['system_prop']);
67:
68:
69: $this->_renameOldUserTableToNewOne();
70: }
71:
72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83:
84: protected function _jobConvertOldStartArticlesToNewOne() {
85: global $cfg;
86:
87:
88:
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: 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:
131: $this->_oDb->query('RENAME TABLE ' . $cfg['sql']['sqlprefix'] . '_phplib_auth_user_md5 TO ' . $cfg['sql']['sqlprefix'] . '_user');
132: } else {
133:
134:
135:
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:
142: addSalts($this->_oDb);
143: }
144:
145: 146: 147: 148: 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: 172: 173: 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: $obj = new $className($this->_oDb, $this->_aCfg, $this->_aCfgClient, $this->_version);
185: $obj->execute();
186: }
187: }
188:
189: }
190: