[BUGFIX] FAL storage repo uses hard-coded enableFields
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / Resource / StorageRepository.php
1 <?php
2 namespace TYPO3\CMS\Core\Resource;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2011 Andreas Wolf <andreas.wolf@ikt-werk.de>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the textfile GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29 /**
30 * Repository for accessing the file mounts
31 *
32 * @author Andreas Wolf <andreas.wolf@ikt-werk.de>
33 * @author Ingmar Schlecht <ingmar@typo3.org>
34 * @package TYPO3
35 * @subpackage t3lib
36 */
37 class StorageRepository extends \TYPO3\CMS\Core\Resource\AbstractRepository {
38
39 /**
40 * @var string
41 */
42 protected $objectType = 'TYPO3\\CMS\\Core\\Resource\\ResourceStorage';
43
44 /**
45 * @var string
46 */
47 protected $table = 'sys_file_storage';
48
49 /**
50 * @var string
51 */
52 protected $typeField = 'type';
53
54 /**
55 * Finds storages by type.
56 *
57 * @param string $storageType
58 * @return \TYPO3\CMS\Core\Resource\ResourceStorage[]
59 */
60 public function findByStorageType($storageType) {
61 $storageObjects = array();
62 $whereClause = $this->typeField . ' = ' . $GLOBALS['TYPO3_DB']->fullQuoteStr($storageType, $this->table);
63 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
64 '*',
65 $this->table,
66 $whereClause . $this->getWhereClauseForEnabledFields()
67 );
68 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
69 $storageObjects[] = $this->createDomainObject($row);
70 }
71 $GLOBALS['TYPO3_DB']->sql_free_result($res);
72 return $storageObjects;
73 }
74
75 /**
76 * Returns a list of mountpoints that are available in the VFS.
77 * In case no storage exists this automatically created a storage for fileadmin/
78 *
79 * @return \TYPO3\CMS\Core\Resource\ResourceStorage[]
80 */
81 public function findAll() {
82 $storageObjects = array();
83 $whereClause = NULL;
84 if ($this->type != '') {
85 $whereClause = $this->typeField . ' = ' . $GLOBALS['TYPO3_DB']->fullQuoteStr($this->type, $this->table);
86 }
87 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
88 '*',
89 $this->table,
90 ($whereClause ? $whereClause : '1=1') . $this->getWhereClauseForEnabledFields()
91 );
92 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
93 $storageObjects[] = $this->createDomainObject($row);
94 }
95 $GLOBALS['TYPO3_DB']->sql_free_result($res);
96 if (count($storageObjects) === 0) {
97 $this->createLocalStorage('fileadmin/ (auto-created)', $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'], 'relative', 'This is the local fileadmin/ directory. This storage mount has been created automatically by TYPO3.');
98 $storageObjects = self::findAll();
99 }
100 return $storageObjects;
101 }
102
103 /**
104 * Create the initial local storage base e.g. for the fileadmin/ directory.
105 *
106 * @param string $name
107 * @param string $basePath
108 * @param string $pathType
109 * @param string $description
110 * @return integer uid of the inserted record
111 */
112 public function createLocalStorage($name, $basePath, $pathType, $description = '') {
113 $field_values = array(
114 'pid' => 0,
115 'tstamp' => $GLOBALS['EXEC_TIME'],
116 'crdate' => $GLOBALS['EXEC_TIME'],
117 'name' => $name,
118 'description' => $description,
119 'driver' => 'Local',
120 'configuration' => '<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
121 <T3FlexForms>
122 <data>
123 <sheet index="sDEF">
124 <language index="lDEF">
125 <field index="basePath">
126 <value index="vDEF">' . rtrim($basePath, '/') . '/</value>
127 </field>
128 <field index="pathType">
129 <value index="vDEF">' . $pathType . '</value>
130 </field>
131 </language>
132 </sheet>
133 </data>
134 </T3FlexForms>',
135 'is_online' => 1,
136 'is_browsable' => 1,
137 'is_public' => 1,
138 'is_writable' => 1
139 );
140 $GLOBALS['TYPO3_DB']->exec_INSERTquery('sys_file_storage', $field_values);
141 return (int) $GLOBALS['TYPO3_DB']->sql_insert_id();
142 }
143
144 /**
145 * Creates an object managed by this repository.
146 *
147 * @param array $databaseRow
148 * @return \TYPO3\CMS\Core\Resource\ResourceStorage
149 */
150 protected function createDomainObject(array $databaseRow) {
151 return $this->factory->getStorageObject($databaseRow['uid'], $databaseRow);
152 }
153
154 /**
155 * get the WHERE clause for the enabled fields of this TCA table
156 * depending on the context
157 *
158 * @return string the additional where clause, something like " AND deleted=0 AND hidden=0"
159 */
160 protected function getWhereClauseForEnabledFields() {
161 if (is_object($GLOBALS['TSFE'])) {
162 // frontend context
163 $whereClause = $GLOBALS['TSFE']->sys_page->enableFields($this->table);
164 } else {
165 // backend context
166 $whereClause = \TYPO3\CMS\Backend\Utility\BackendUtility::BEenableFields($this->table);
167 }
168 return $whereClause;
169 }
170 }
171
172
173 ?>