Overview

Packages

  • CONTENIDO
  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • mpAutoloaderClassMap
  • None
  • PHP
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob

Classes

  • cUpgradeJob_0001
  • cUpgradeJob_0002
  • cUpgradeJob_0003
  • cUpgradeJob_0004
  • cUpgradeJob_0005
  • cUpgradeJob_0006
  • cUpgradeJob_0007
  • cUpgradeJob_0008
  • cUpgradeJob_0009
  • cUpgradeJob_0010
  • cUpgradeJob_0011
  • cUpgradeJob_0012
  • cUpgradeJob_0013
  • cUpgradeJob_0014
  • cUpgradeJob_0015
  • cUpgradeJob_0016
  • cUpgradeJob_0017
  • cUpgradeJob_0018
  • cUpgradeJobAbstract
  • cUpgradeJobMain
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: /**
  3:  * This file contains the upgrade job 5.
  4:  *
  5:  * @package    Setup
  6:  * @subpackage UpgradeJob
  7:  * @author     Murat Purc <murat@purc>
  8:  * @copyright  four for business AG <www.4fb.de>
  9:  * @license    http://www.contenido.org/license/LIZENZ.txt
 10:  * @link       http://www.4fb.de
 11:  * @link       http://www.contenido.org
 12:  */
 13: 
 14: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 15: 
 16: /**
 17:  * Upgrade job 5.
 18:  * Runs the upgrade job to convert old content types.
 19:  *
 20:  * @package Setup
 21:  * @subpackage UpgradeJob
 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:             // map all content types to their IDs
 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:             /* Convert the value of each CMS_DATE entry.
 44:              * Old:
 45:              * 16.07.2012
 46:              * New:
 47:              * <?xml version="1.0" encoding="utf-8"?>
 48:              * <date><timestamp>1342404000</timestamp><format>d.m.Y</format></date>
 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:                 // if the value has not the format dd.mm.yyyy, it is possibly the new format, so ignore it
 56:                 $oldValueSplitted = explode('.', $oldValue);
 57:                 if (count($oldValueSplitted) !== 3 || !checkdate($oldValueSplitted[1], $oldValueSplitted[0], $oldValueSplitted[2])) {
 58:                     continue;
 59:                 }
 60:                 // value has the format dd.mm.yyyy, so convert it to the new XML structure
 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:             // Convert the value of each CMS_FILELIST entry.
 71:             //$contentCollection = new cApiContentCollection();
 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:                 // skip CMS_FILELISTs w/ empty values
 78:                 if (0 === cString::getStringLength(trim($oldFilelistVal))) {
 79:                     continue;
 80:                 }
 81:                 $oldFilelistArray = cXmlBase::xmlStringToArray($oldFilelistVal);
 82:                 // skip empty filelist array
 83:                 if (true === empty($oldFilelistArray)) {
 84:                     continue;
 85:                 }
 86:                 // convert the whole entries
 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:             /* Convert all DB entries CMS_IMG and CMS_IMGDESCR to CMS_IMGEDITOR.
130:              * Old:
131:              * In the past, CMS_IMG saved the idupl and CMS_IMGDESCR the corresponding description.
132:              *
133:              * New:
134:              * Since CONTENIDO 4.9, CMS_IMGEDITOR saves the idupl and the description is saved
135:              * in the con_upl_meta table.
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:                 // create an array in which each entry contains the data needed for converting one entry
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:             // iterate over all entries and convert each of them
167:             foreach ($result as $imageInfo) {
168:                 // insert new CMS_IMGEDITOR content entry
169:                 //$contentCollection = new cApiContentCollection();
170:                 $contentCollection->resetQuery();
171:                 $contentCollection->create($imageInfo['idartlang'], $types['CMS_IMGEDITOR'], $imageInfo['typeid'], $imageInfo['idupl'], '');
172:                 // save description in con_upl_meta if it does not already exist
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:                     // $metaItemExists = $metaItem->loadByMany(array('idupl' => $imageInfo['idupl'], 'idlang' => $idlang));
180:                     if ($metaItemExists) {
181:                         // if meta item exists but there is no description, add the description
182:                         if ($metaItem->get('description') == '') {
183:                             $metaItem->set('description', $imageInfo['description']);
184:                             $metaItem->store();
185:                         }
186:                     } else {
187:                         // if no meta item exists, create a new one with the description
188:                         $metaItemCollection->create($imageInfo['idupl'], $idlang, '', $imageInfo['description']);
189:                     }
190:                 }
191:                 // delete old CMS_IMG and CMS_IMGDESCR content entries
192:                 $contentCollection->delete($imageInfo['imgidcontent']);
193:                 $contentCollection->delete($imageInfo['imgdescridcontent']);
194:             }
195: 
196:             /* Convert all DB entries CMS_LINK, CMS_LINKTARGET and CMS_LINKDESCR to CMS_LINKEDITOR.
197:              * Old:
198:              * In the past, CMS_LINK saved the actual link, CMS_LINKTARGET the corresponding target and
199:              * CMS_LINKDESCR the corresponding link text.
200:              *
201:              * New:
202:              * Since CONTENIDO 4.9, CMS_LINKEDITOR contains an XML structure with all information.
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:                 // create an array in which each entry contains the data needed for converting one entry
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:             // iterate over all entries and convert each of them
235:             foreach ($result as $linkInfo) {
236:                 // construct the XML structure
237:                 $newWindow = ($linkInfo['linktarget'] == '_blank') ? 'true' : 'false';
238:                 // if link is a relative path, prepend the upload path
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 (cString::findFirstPos($linkInfo['link'], 'http://') == 0 || cString::findFirstPos($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:                 // insert new CMS_LINKEDITOR content entry
259:                 //$contentCollection = new cApiContentCollection();
260:                 $contentCollection->resetQuery();
261:                 $contentCollection->create($linkInfo['idartlang'], $types['CMS_LINKEDITOR'], $linkInfo['typeid'], $xml, '');
262: 
263:                 // delete old CMS_LINK, CMS_LINKTARGET and CMS_LINKDESCR content entries
264:                 $contentCollection->delete($linkInfo['linkidcontent']);
265:                 $contentCollection->delete($linkInfo['linktargetidcontent']);
266:                 $contentCollection->delete($linkInfo['linkdescridcontent']);
267:             }
268: 
269:             /* Convert the value of each CMS_TEASER entry.
270:              * Only the format of the manual teaser settings has been changed as follows:
271:              * Old:
272:              * <manual_art>
273:              *   <art>6</art>
274:              *   <art>7</art>
275:              * </manual_art>
276:              *
277:              * New:
278:              * <manual_art><array_value>6</array_value><array_value>7</array_value></manual_art>
279:              */
280:             //$contentCollection = new cApiContentCollection();
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: 
CMS CONTENIDO 4.10.0 API documentation generated by ApiGen 2.8.0