Overview

Packages

  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Datatype
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationMain
    • NavigationTop
  • mpAutoloaderClassMap
  • None
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SearchSolr
    • 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
  • 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:  * @version    SVN Revision $Rev:$
  8:  *
  9:  * @author     Murat Purc <murat@purc>
 10:  * @copyright  four for business AG <www.4fb.de>
 11:  * @license    http://www.contenido.org/license/LIZENZ.txt
 12:  * @link       http://www.4fb.de
 13:  * @link       http://www.contenido.org
 14:  */
 15: 
 16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 17: 
 18: /**
 19:  * Upgrade job 5.
 20:  * Runs the upgrade job to convert old content types.
 21:  *
 22:  * @package Setup
 23:  * @subpackage UpgradeJob
 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:             // map all content types to their IDs
 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:             /* Convert the value of each CMS_DATE entry.
 46:              * Old:
 47:              * 16.07.2012
 48:              * New:
 49:              * <?xml version="1.0" encoding="utf-8"?>
 50:              * <date><timestamp>1342404000</timestamp><format>d.m.Y</format></date>
 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:                 // if the value has not the format dd.mm.yyyy, it is possibly the new format, so ignore it
 59:                 $oldValueSplitted = explode('.', $oldValue);
 60:                 if (count($oldValueSplitted) !== 3 || !checkdate($oldValueSplitted[1], $oldValueSplitted[0], $oldValueSplitted[2])) {
 61:                     continue;
 62:                 }
 63:                 // value has the format dd.mm.yyyy, so convert it to the new XML structure
 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:             // Convert the value of each CMS_FILELIST entry.
 74:             //$contentCollection = new cApiContentCollection();
 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:                 // skip CMS_FILELISTs w/ empty values
 81:                 if (0 === strlen(trim($oldFilelistVal))) {
 82:                     continue;
 83:                 }
 84:                 $oldFilelistArray = cXmlBase::xmlStringToArray($oldFilelistVal);
 85:                 // skip empty filelist array
 86:                 if (true === empty($oldFilelistArray)) {
 87:                     continue;
 88:                 }
 89:                 // convert the whole entries
 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:             /* Convert all DB entries CMS_IMG and CMS_IMGDESCR to CMS_IMGEDITOR.
133:              * Old:
134:              * In the past, CMS_IMG saved the idupl and CMS_IMGDESCR the corresponding description.
135:              *
136:              * New:
137:              * Since CONTENIDO 4.9, CMS_IMGEDITOR saves the idupl and the description is saved
138:              * in the con_upl_meta table.
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:                 // create an array in which each entry contains the data needed for converting one entry
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:             // iterate over all entries and convert each of them
170:             foreach ($result as $imageInfo) {
171:                 // insert new CMS_IMGEDITOR content entry
172:                 //$contentCollection = new cApiContentCollection();
173:                 $contentCollection->resetQuery();
174:                 $contentCollection->create($imageInfo['idartlang'], $types['CMS_IMGEDITOR'], $imageInfo['typeid'], $imageInfo['idupl'], '');
175:                 // save description in con_upl_meta if it does not already exist
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:                     // $metaItemExists = $metaItem->loadByMany(array('idupl' => $imageInfo['idupl'], 'idlang' => $idlang));
183:                     if ($metaItemExists) {
184:                         // if meta item exists but there is no description, add the description
185:                         if ($metaItem->get('description') == '') {
186:                             $metaItem->set('description', $imageInfo['description']);
187:                             $metaItem->store();
188:                         }
189:                     } else {
190:                         // if no meta item exists, create a new one with the description
191:                         $metaItemCollection->create($imageInfo['idupl'], $idlang, '', $imageInfo['description']);
192:                     }
193:                 }
194:                 // delete old CMS_IMG and CMS_IMGDESCR content entries
195:                 $contentCollection->delete($imageInfo['imgidcontent']);
196:                 $contentCollection->delete($imageInfo['imgdescridcontent']);
197:             }
198: 
199:             /* Convert all DB entries CMS_LINK, CMS_LINKTARGET and CMS_LINKDESCR to CMS_LINKEDITOR.
200:              * Old:
201:              * In the past, CMS_LINK saved the actual link, CMS_LINKTARGET the corresponding target and
202:              * CMS_LINKDESCR the corresponding link text.
203:              *
204:              * New:
205:              * Since CONTENIDO 4.9, CMS_LINKEDITOR contains an XML structure with all information.
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:                 // create an array in which each entry contains the data needed for converting one entry
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:             // iterate over all entries and convert each of them
238:             foreach ($result as $linkInfo) {
239:                 // construct the XML structure
240:                 $newWindow = ($linkInfo['linktarget'] == '_blank')? 'true' : 'false';
241:                 // if link is a relative path, prepend the upload path
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:                 // insert new CMS_LINKEDITOR content entry
262:                 //$contentCollection = new cApiContentCollection();
263:                 $contentCollection->resetQuery();
264:                 $contentCollection->create($linkInfo['idartlang'], $types['CMS_LINKEDITOR'], $linkInfo['typeid'], $xml, '');
265: 
266:                 // delete old CMS_LINK, CMS_LINKTARGET and CMS_LINKDESCR content entries
267:                 $contentCollection->delete($linkInfo['linkidcontent']);
268:                 $contentCollection->delete($linkInfo['linktargetidcontent']);
269:                 $contentCollection->delete($linkInfo['linkdescridcontent']);
270:             }
271: 
272:             /* Convert the value of each CMS_TEASER entry.
273:              * Only the format of the manual teaser settings has been changed as follows:
274:              * Old:
275:              * <manual_art>
276:              *   <art>6</art>
277:              *   <art>7</art>
278:              * </manual_art>
279:              *
280:              * New:
281:              * <manual_art><array_value>6</array_value><array_value>7</array_value></manual_art>
282:              */
283:             //$contentCollection = new cApiContentCollection();
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: 
CMS CONTENIDO 4.9.0 API documentation generated by ApiGen 2.8.0