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_0005 extends cUpgradeJobAbstract {
 26: 
 27:     public $maxVersion = "4.9.0-beta1";
 28: 
 29:     public function _execute() {
 30:         global $cfg, $cfgClient;
 31: 
 32:         $db = $this->_oDb;
 33: 
 34:         if ($this->_setupType == 'upgrade') {
 35:             
 36:             $types = array();
 37:             $typeCollection = new cApiTypeCollection();
 38:             $typeCollection->addResultField('idtype');
 39:             $typeCollection->addResultField('type');
 40:             $typeCollection->query();
 41:             while (($typeItem = $typeCollection->next()) !== false) {
 42:                 $types[$typeItem->get('type')] = $typeItem->get('idtype');
 43:             }
 44: 
 45:              46:  47:  48:  49:  50:  51: 
 52:             $contentCollection = new cApiContentCollection();
 53:             $contentCollection->setWhere('idtype', $types['CMS_DATE']);
 54:             $contentCollection->query();
 55:             while (($item = $contentCollection->next()) !== false) {
 56:                 $idcontent = $item->get('idcontent');
 57:                 $oldValue = $item->get('value');
 58:                 
 59:                 $oldValueSplitted = explode('.', $oldValue);
 60:                 if (count($oldValueSplitted) !== 3 || !checkdate($oldValueSplitted[1], $oldValueSplitted[0], $oldValueSplitted[2])) {
 61:                     continue;
 62:                 }
 63:                 
 64:                 $timestamp = strtotime($oldValue);
 65:                 $xml = <<<EOT
 66: <?xml version="1.0" encoding="utf-8"?>
 67: <date><timestamp>$timestamp</timestamp><format>d.m.Y</format></date>
 68: EOT;
 69:                 $item->set('value', $xml);
 70:                 $item->store();
 71:             }
 72: 
 73:             
 74:             
 75:             $contentCollection->resetQuery();
 76:             $contentCollection->setWhere('idtype', $types['CMS_FILELIST']);
 77:             $contentCollection->query();
 78:             while (($item = $contentCollection->next()) !== false) {
 79:                 $oldFilelistVal = $item->get('value');
 80:                 
 81:                 if (0 === strlen(trim($oldFilelistVal))) {
 82:                     continue;
 83:                 }
 84:                 $oldFilelistArray = cXmlBase::xmlStringToArray($oldFilelistVal);
 85:                 
 86:                 if (true === empty($oldFilelistArray)) {
 87:                     continue;
 88:                 }
 89:                 
 90:                 if (isset($oldFilelistArray['directories']['dir'])) {
 91:                     $oldFilelistArray['directories'] = $oldFilelistArray['directories']['dir'];
 92:                 }
 93:                 if (isset($oldFilelistArray['incl_subdirectories'])) {
 94:                     if ($oldFilelistArray['incl_subdirectories'] == 'checked') {
 95:                         $oldFilelistArray['incl_subdirectories'] = 'true';
 96:                     } else {
 97:                         $oldFilelistArray['incl_subdirectories'] = 'false';
 98:                     }
 99:                 }
100:                 if (isset($oldFilelistArray['manual'])) {
101:                     if ($oldFilelistArray['manual'] == 'checked') {
102:                         $oldFilelistArray['manual'] = 'true';
103:                     } else {
104:                         $oldFilelistArray['manual'] = 'false';
105:                     }
106:                 }
107:                 if (isset($oldFilelistArray['incl_metadata'])) {
108:                     if ($oldFilelistArray['incl_metadata'] == 'checked') {
109:                         $oldFilelistArray['incl_metadata'] = 'true';
110:                     } else {
111:                         $oldFilelistArray['incl_metadata'] = 'false';
112:                     }
113:                 }
114:                 if (isset($oldFilelistArray['extensions']['ext'])) {
115:                     $oldFilelistArray['extensions'] = $oldFilelistArray['extensions']['ext'];
116:                 }
117:                 if (isset($oldFilelistArray['ignore_extensions'])) {
118:                     if ($oldFilelistArray['ignore_extensions'] == 'off') {
119:                         $oldFilelistArray['ignore_extensions'] = 'false';
120:                     } else {
121:                         $oldFilelistArray['ignore_extensions'] = 'true';
122:                     }
123:                 }
124:                 if (isset($oldFilelistArray['manual_files']['file'])) {
125:                     $oldFilelistArray['manual_files'] = $oldFilelistArray['manual_files']['file'];
126:                 }
127:                 $newFilelistVal = cXmlBase::arrayToXml($oldFilelistArray, null, 'filelist');
128:                 $item->set('value', $newFilelistVal->asXML());
129:                 $item->store();
130:             }
131: 
132:             133: 134: 135: 136: 137: 138: 139: 
140:             $sql = 'SELECT `idcontent`, `idartlang`, `idtype`, `typeid`, `value` FROM `' . $cfg['tab']['content'] . '` WHERE `idtype`=' . $types['CMS_IMG'] . ' OR `idtype`=' . $types['CMS_IMGDESCR'] . ' ORDER BY `typeid` ASC';
141:             $db->query($sql);
142:             $result = array();
143:             while ($db->nextRecord()) {
144:                 
145:                 $idartlang = $db->f('idartlang');
146:                 $typeid = $db->f('typeid');
147:                 $key = $idartlang . '_' . $typeid;
148:                 if (isset($result[$key])) {
149:                     $subResult = $result[$key];
150:                 } else {
151:                     $subResult = array();
152:                     $subResult['idartlang'] = $idartlang;
153:                 }
154: 
155:                 $subResult['typeid'] = $typeid;
156: 
157:                 if ($db->f('idtype') == $types['CMS_IMG']) {
158:                     $subResult['idupl'] = $db->f('value');
159:                     $subResult['imgidcontent'] = $db->f('idcontent');
160:                 } else if ($db->f('idtype') == $types['CMS_IMGDESCR']) {
161:                     $subResult['description'] = $db->f('value');
162:                     $subResult['imgdescridcontent'] = $db->f('idcontent');
163:                 }
164:                 $result[$key] = $subResult;
165:             }
166: 
167:             $metaItemCollection = new cApiUploadMetaCollection();
168: 
169:             
170:             foreach ($result as $imageInfo) {
171:                 
172:                 
173:                 $contentCollection->resetQuery();
174:                 $contentCollection->create($imageInfo['idartlang'], $types['CMS_IMGEDITOR'], $imageInfo['typeid'], $imageInfo['idupl'], '');
175:                 
176:                 $sql = 'SELECT `idlang` FROM `' . $cfg['tab']['art_lang'] . '` WHERE `idartlang`=' . $imageInfo['idartlang'];
177:                 $db->query($sql);
178:                 if ($db->nextRecord()) {
179:                     $idlang = $db->f('idlang');
180:                     $metaItem = new cApiUploadMeta();
181:                     $metaItemExists = $metaItem->loadByUploadIdAndLanguageId($imageInfo['idupl'], $idlang);
182:                     
183:                     if ($metaItemExists) {
184:                         
185:                         if ($metaItem->get('description') == '') {
186:                             $metaItem->set('description', $imageInfo['description']);
187:                             $metaItem->store();
188:                         }
189:                     } else {
190:                         
191:                         $metaItemCollection->create($imageInfo['idupl'], $idlang, '', $imageInfo['description']);
192:                     }
193:                 }
194:                 
195:                 $contentCollection->delete($imageInfo['imgidcontent']);
196:                 $contentCollection->delete($imageInfo['imgdescridcontent']);
197:             }
198: 
199:             200: 201: 202: 203: 204: 205: 206: 
207:             $sql = 'SELECT `idcontent`, `idartlang`, `idtype`, `typeid`, `value` FROM `' . $cfg['tab']['content'] . '` WHERE `idtype`=' . $types['CMS_LINK'] . ' OR `idtype`=' . $types['CMS_LINKTARGET'] . ' OR `idtype`=' . $types['CMS_LINKDESCR'] . ' ORDER BY `typeid` ASC';
208:             $db->query($sql);
209:             $result = array();
210:             while ($db->nextRecord()) {
211:                 
212:                 $idartlang = $db->f('idartlang');
213:                 $typeid = $db->f('typeid');
214:                 $key = $idartlang . '_' . $typeid;
215:                 if (isset($result[$key])) {
216:                     $subResult = $result[$key];
217:                 } else {
218:                     $subResult = array();
219:                     $subResult['idartlang'] = $idartlang;
220:                 }
221: 
222:                 $subResult['typeid'] = $typeid;
223: 
224:                 if ($db->f('idtype') == $types['CMS_LINK']) {
225:                     $subResult['link'] = $db->f('value');
226:                     $subResult['linkidcontent'] = $db->f('idcontent');
227:                 } else if ($db->f('idtype') == $types['CMS_LINKTARGET']) {
228:                     $subResult['linktarget'] = $db->f('value');
229:                     $subResult['linktargetidcontent'] = $db->f('idcontent');
230:                 } else if ($db->f('idtype') == $types['CMS_LINKDESCR']) {
231:                     $subResult['linkdescr'] = $db->f('value');
232:                     $subResult['linkdescridcontent'] = $db->f('idcontent');
233:                 }
234:                 $result[$key] = $subResult;
235:             }
236: 
237:             
238:             foreach ($result as $linkInfo) {
239:                 
240:                 $newWindow = ($linkInfo['linktarget'] == '_blank') ? 'true' : 'false';
241:                 
242: 
243:                 $link = $type = $articleId = $fileName = '';
244: 
245:                 if ((int) $linkInfo['link'] > 0) {
246:                     $type = 'internal';
247:                     $cApiCategoryArticle = new cApiCategoryArticle($linkInfo['link']);
248:                     $articleId = $cApiCategoryArticle->get('idart');
249:                 } elseif (strpos($linkInfo['link'], 'http://') == 0 || strpos($linkInfo['link'], 'www.') == 0) {
250:                     $link = $linkInfo['link'];
251:                     $type = 'external';
252:                 } else {
253:                     $fileName = $linkInfo['link'];
254:                     $type = 'file';
255:                 }
256: 
257:                 $xml = <<<EOT
258: <?xml version="1.0" encoding="utf-8"?>
259: <linkeditor><type>{$type}</type><externallink>{$link}</externallink><title>{$linkInfo['linkdescr']}</title><newwindow>{$newWindow}</newwindow><idart>{$articleId}</idart><filename>{$fileName}</filename></linkeditor>
260: EOT;
261:                 
262:                 
263:                 $contentCollection->resetQuery();
264:                 $contentCollection->create($linkInfo['idartlang'], $types['CMS_LINKEDITOR'], $linkInfo['typeid'], $xml, '');
265: 
266:                 
267:                 $contentCollection->delete($linkInfo['linkidcontent']);
268:                 $contentCollection->delete($linkInfo['linktargetidcontent']);
269:                 $contentCollection->delete($linkInfo['linkdescridcontent']);
270:             }
271: 
272:             273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 
283:             
284:             $contentCollection->resetQuery();
285:             $contentCollection->setWhere('idtype', $types['CMS_TEASER']);
286:             $contentCollection->query();
287:             while (($item = $contentCollection->next()) !== false) {
288:                 $oldTeaserVal = $item->get('value');
289:                 $oldTeaserArray = cXmlBase::xmlStringToArray($oldTeaserVal);
290:                 if (!isset($oldTeaserArray['manual_art']['art'])) {
291:                     continue;
292:                 }
293:                 $oldTeaserArray['manual_art'] = $oldTeaserArray['manual_art']['art'];
294:                 $newTeaserVal = cXmlBase::arrayToXml($oldTeaserArray, null, 'teaser');
295:                 $item->set('value', $newTeaserVal->asXML());
296:                 $item->store();
297:             }
298: 
299:         }
300:     }
301: 
302: }
303: