[BUGFIX] Fix the unit tests to work with PHPUnit 3.6
[Packages/TYPO3.CMS.git] / t3lib / file / Service / BackwardsCompatibility / TslibContentAdapterService.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2011 Ingmar Schlecht <ingmar@typo3.org>
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24
25 /**
26 * Tslib content adapter to modify $row array ($cObj->data[]) for backwards compatibility
27 *
28 * @package TYPO3
29 * @author Ingmar Schlecht <ingmar@typo3.org>
30 * @license http://www.gnu.org/copyleft/gpl.html
31 */
32 class t3lib_file_Service_BackwardsCompatibility_TslibContentAdapterService {
33
34 /**
35 * The name of the table
36 *
37 * @var string
38 */
39 protected static $migrateFields = array(
40 'tt_content' => array(
41 'image' => array(
42 'paths' => 'image',
43 'titleTexts' => 'titleText',
44 'captions' => 'imagecaption',
45 'links' => 'image_link',
46 'alternativeTexts' => 'altText',
47 'sysFileUids' => 'sysFileUids', // additional fields for the UIDs
48 ),
49 'media' => array(
50 'paths' => 'media',
51 'captions' => 'imagecaption',
52 ),
53 ),
54 'pages' => array(
55 'media' => array(
56 'paths' => 'media'
57 ),
58 ),
59 );
60
61 /**
62 * Modifies the DB row in the CONTENT cObj of tslib_content for supplying
63 * backwards compatibility for some file fields which have switched to using
64 * the new File API instead of the old uploads/ folder for storing files.
65 *
66 * This method is called by the render() method of tslib_content_Content.
67 *
68 * @param $row
69 * @param $table
70 * @return void
71 */
72 public static function modifyDBRow(array &$row, $table) {
73 if (array_key_exists($table, static::$migrateFields)) {
74 foreach (static::$migrateFields[$table] as $migrateFieldName => $oldFieldNames) {
75 if (isset($row[$migrateFieldName])) {
76 /** @var $fileRepository t3lib_file_Repository_FileRepository */
77 $fileRepository = t3lib_div::makeInstance('t3lib_file_Repository_FileRepository');
78 $files = $fileRepository->findByRelation($table, $migrateFieldName, $row['uid']);
79 $fileFieldContents = array(
80 'paths' => array(),
81 'titleTexts' => array(),
82 'captions' => array(),
83 'links' => array(),
84 'alternativeTexts' => array(),
85 'sysFileUids' => array()
86 );
87 foreach ($files as $file) {
88 /** @var $file t3lib_file_FileReference */
89 $fileFieldContents['paths'][] = '../../' . $file->getPublicUrl();
90 $fileFieldContents['titleTexts'][] = $file->getProperty('title');
91 $fileFieldContents['captions'][] = $file->getProperty('description');
92 $fileFieldContents['links'][] = $file->getProperty('link');
93 $fileFieldContents['alternativeTexts'][] = $file->getProperty('alternative');
94 $fileFieldContents['sysFileUids'][] = $file->getUid();
95 }
96 foreach ($oldFieldNames as $oldFieldType => $oldFieldName) {
97 // For paths, make comma separated list
98 if ($oldFieldType === 'paths') {
99 $fieldContents = implode(',', $fileFieldContents[$oldFieldType]);
100 } else {
101 // For all other fields, separate by newline
102 $fieldContents = implode(chr(10), $fileFieldContents[$oldFieldType]);
103 }
104 if($fieldContents) {
105 $row[$oldFieldName] = $fieldContents;
106 }
107 }
108 if (count($files) > 0) {
109
110 } elseif ($row['image'] > 0) {
111 throw new RuntimeException('inconsistent count field in "' . $table . '".' . $migrateFieldName, 1333754565);
112 }
113 }
114 }
115 }
116 }
117
118 }
119
120 ?>