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