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