1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
14:
15: 16: 17: 18: 19: 20:
21: class cUpgradeJobMain extends cUpgradeJobAbstract {
22:
23: 24: 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: 38: 39: 40: 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:
51: $this->_oDb->query('UPDATE %s SET createcode = 1', $cfg['tab']['cat_art']);
52:
53:
54: $this->_jobConvertOldStartArticlesToNewOne();
55:
56:
57: injectSQL($this->_oDb, $cfg['sql']['sqlprefix'], 'data/indexes.sql', array());
58:
59:
60: addAutoIncrementToTables($this->_oDb, $cfg);
61:
62:
63: updateSystemProperties($this->_oDb, $cfg['tab']['system_prop']);
64:
65:
66: $this->_renameOldUserTableToNewOne();
67: }
68:
69: 70: 71: 72: 73: 74: 75: 76: 77: 78:
79: protected function _jobConvertOldStartArticlesToNewOne() {
80: global $cfg;
81:
82:
83:
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: 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:
126: $this->_oDb->query('RENAME TABLE ' . $cfg['sql']['sqlprefix'] . '_phplib_auth_user_md5 TO ' . $cfg['sql']['sqlprefix'] . '_user');
127: } else {
128:
129:
130:
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:
137: addSalts($this->_oDb);
138: }
139:
140: 141: 142: 143: 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: 166: 167: 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:
178: $obj = new $className($this->_oDb, $this->_aCfg, $this->_aCfgClient, $this->_version);
179: $obj->execute();
180: }
181: }
182:
183: }
184: