1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15:
16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
17:
18: 19: 20: 21: 22: 23: 24:
25: class cUpgradeJob_0004 extends cUpgradeJobAbstract {
26:
27: public $maxVersion = "4.9.0-beta1";
28:
29: public function _execute() {
30: global $cfg;
31:
32: if ($this->_setupType != 'setup') {
33: $done = false;
34: $sSql = "SHOW COLUMNS FROM " . $cfg['tab']['upl'];
35: $this->_oDb->query($sSql);
36: while ($this->_oDb->nextRecord()) {
37: if ($this->_oDb->f("Field") == 'description') {
38: $done = true;
39: }
40: }
41: if ($done) {
42: $this->_updateUpl2Meta();
43: }
44: }
45: }
46:
47:
48: protected function _updateUpl2Meta() {
49: global $cfg;
50:
51: $db = $this->_oDb;
52: $aUploads = array();
53: $sSql = "SELECT * FROM " . $cfg['tab']['upl'] . " WHERE `description` != '' ORDER BY idupl ASC";
54: $db->query($sSql);
55:
56: while ($db->nextRecord()) {
57: $uploadId = $db->f('idupl');
58: $aUploads[$uploadId]['description'] = $db->f('description');
59: $aUploads[$uploadId]['author'] = $db->f('author');
60: $aUploads[$uploadId]['created'] = $db->f('created');
61: $aUploads[$uploadId]['lastmodified'] = $db->f('lastmodified');
62: $aUploads[$uploadId]['modifiedby'] = $db->f('modifiedby');
63: $aUploads[$uploadId]['idclient'] = $db->f('idclient');
64: }
65:
66: $aClientLanguages = array();
67: $sSql = "SELECT idclient, idlang FROM " . $cfg['tab']['clients_lang'] . " ORDER BY idclient ASC";
68: $db->query($sSql);
69: while ($db->nextRecord()) {
70: $clientId = $db->f('idclient');
71: $aClientLanguages[$clientId][] = $db->f('idlang');
72: }
73:
74: $bError = false;
75: $j = 0;
76:
77: foreach ($aUploads as $idupl => $elem) {
78: if ($elem['description'] == '') {
79: continue;
80: }
81:
82: $clientId = $elem['idclient'];
83: if (isset($aClientLanguages[$clientId]) === false) {
84: continue;
85: }
86:
87: foreach ($aClientLanguages[$clientId] as $idlang) {
88: $aUplMeta = array();
89: $sSql = "SELECT * FROM " . $cfg['tab']['upl_meta'] . " WHERE idlang = " . $idlang . " AND idupl = " . $idupl . " ORDER BY id_uplmeta ASC";
90: $db->query($sSql);
91: $i = 0;
92: while ($db->nextRecord()) {
93: $aUplMeta[$i]['description'] = $db->f('description');
94: $aUplMeta[$i]['id_uplmeta'] = $db->f('id_uplmeta');
95: $i++;
96: }
97:
98: if (count($aUplMeta) < 1) {
99:
100: $sSql = "INSERT INTO " . $cfg['tab']['upl_meta'] . " SET
101: idupl = $idupl,
102: idlang = $idlang,
103: medianame = '',
104: description = '" . $elem['description'] . "',
105: keywords = '',
106: internal_notice = '',
107: author = '" . $elem['author'] . "',
108: created = '" . $elem['created'] . "',
109: modified = '" . $elem['lastmodified'] . "',
110: modifiedby = '" . $elem['modifiedby'] . "',
111: copyright = ''";
112: } elseif (count($aUplMeta) == 1 && $aUplMeta[0]['description'] == '') {
113:
114: $sSql = "UPDATE " . $cfg['tab']['upl_meta'] . " SET
115: description = '" . $elem['description'] . "'
116: WHERE id_uplmeta = " . $aUplMeta[0]['id_uplmeta'];
117: } else {
118:
119:
120: }
121:
122: $db->query($sSql);
123: if ($db->getErrorNumber() != 0) {
124: $bError = true;
125: $this->_logError($sSql . "\nMysql Error:" . $db->getErrorMessage() . "(" . $db->getErrorNumber() . ")");
126: }
127: }
128:
129: $j++;
130: }
131:
132:
133: if ($bError === false && $j == count($aUploads)) {
134: $sSql = "ALTER TABLE `" . $cfg['tab']['upl'] . "` DROP `description`";
135: $db->query($sSql);
136: if ($db->getErrorNumber() != 0) {
137: $this->_logError($sSql . "\nMysql Error:" . $db->getErrorMessage() . "(" . $db->getErrorNumber() . ")");
138: }
139: } else {
140: $this->_logError("error on _updateUpl2Meta();" . $j . '==' . count($aUploads));
141: }
142: }
143:
144: }
145: