TYPO3 CMS  TYPO3_6-2
StorageRepository.php
Go to the documentation of this file.
1 <?php
3 
23 
27  protected static $storageRowCache = NULL;
28 
32  protected $objectType = 'TYPO3\\CMS\\Core\\Resource\\ResourceStorage';
33 
37  protected $table = 'sys_file_storage';
38 
42  protected $typeField = 'driver';
43 
47  protected $driverField = 'driver';
48 
52  protected $logger;
53 
57  protected $db;
58 
59  public function __construct() {
60  parent::__construct();
61 
63  $logManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Log\\LogManager');
64  $this->logger = $logManager->getLogger(__CLASS__);
65  $this->db = $GLOBALS['TYPO3_DB'];
66  }
67 
73  public function findByUid($uid) {
74  $this->initializeLocalCache();
75  if (isset(self::$storageRowCache[$uid])) {
76  return $this->factory->getStorageObject($uid, self::$storageRowCache[$uid]);
77  }
78  return NULL;
79  }
80 
81 
87  protected function initializeLocalCache() {
88  if (static::$storageRowCache === NULL) {
89 
90  static::$storageRowCache = $this->db->exec_SELECTgetRows(
91  '*',
92  $this->table,
93  '1=1' . $this->getWhereClauseForEnabledFields(),
94  '',
95  'name',
96  '',
97  'uid'
98  );
99  // if no storage is created before or the user has not access to a storage
100  // static::$storageRowCache would have the value array()
101  // so check if there is any record. If no record is found, create the fileadmin/ storage
102  // selecting just one row is enoung
103 
104  if (static::$storageRowCache === array()) {
105  $storageObjectsExists = $this->db->exec_SELECTgetSingleRow('uid', $this->table, '');
106  if ($storageObjectsExists !== NULL) {
107  if ($this->createLocalStorage(
108  'fileadmin/ (auto-created)',
109  $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'],
110  'relative',
111  'This is the local fileadmin/ directory. This storage mount has been created automatically by TYPO3.',
112  TRUE
113  ) > 0 ) {
114  // reset to null to force reloading of storages
115  static::$storageRowCache = NULL;
116  // call self for initialize Cache
117  $this->initializeLocalCache();
118  }
119  }
120  }
121  }
122  }
123 
130  public function findByStorageType($storageType) {
131  $this->initializeLocalCache();
132 
134  $driverRegistry = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\Driver\\DriverRegistry');
135 
136  $storageObjects = array();
137  foreach (static::$storageRowCache as $storageRow) {
138  if ($storageRow['driver'] !== $storageType) {
139  continue;
140  }
141  if ($driverRegistry->driverExists($storageRow['driver'])) {
142  $storageObjects[] = $this->factory->getStorageObject($storageRow['uid'], $storageRow);
143  } else {
144  $this->logger->warning(
145  sprintf('Could not instantiate storage "%s" because of missing driver.', array($storageRow['name'])),
146  $storageRow
147  );
148  }
149  }
150  return $storageObjects;
151  }
152 
159  public function findAll() {
160  $this->initializeLocalCache();
161 
163  $driverRegistry = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\Driver\\DriverRegistry');
164 
165  $storageObjects = array();
166  foreach (static::$storageRowCache as $storageRow) {
167  if ($driverRegistry->driverExists($storageRow['driver'])) {
168  $storageObjects[] = $this->factory->getStorageObject($storageRow['uid'], $storageRow);
169  } else {
170  $this->logger->warning(
171  sprintf('Could not instantiate storage "%s" because of missing driver.', array($storageRow['name'])),
172  $storageRow
173  );
174  }
175  }
176  return $storageObjects;
177  }
178 
189  public function createLocalStorage($name, $basePath, $pathType, $description = '', $default = FALSE) {
190  $caseSensitive = $this->testCaseSensitivity($pathType === 'relative' ? PATH_site . $basePath : $basePath);
191  // create the FlexForm for the driver configuration
192  $flexFormData = array(
193  'data' => array(
194  'sDEF' => array(
195  'lDEF' => array(
196  'basePath' => array('vDEF' => rtrim($basePath, '/') . '/'),
197  'pathType' => array('vDEF' => $pathType),
198  'caseSensitive' => array('vDEF' => $caseSensitive)
199  )
200  )
201  )
202  );
203 
205  $flexObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Configuration\\FlexForm\\FlexFormTools');
206  $flexFormXml = $flexObj->flexArray2Xml($flexFormData, TRUE);
207 
208  // create the record
209  $field_values = array(
210  'pid' => 0,
211  'tstamp' => $GLOBALS['EXEC_TIME'],
212  'crdate' => $GLOBALS['EXEC_TIME'],
213  'name' => $name,
214  'description' => $description,
215  'driver' => 'Local',
216  'configuration' => $flexFormXml,
217  'is_online' => 1,
218  'is_browsable' => 1,
219  'is_public' => 1,
220  'is_writable' => 1,
221  'is_default' => $default ? 1 : 0
222  );
223  $this->db->exec_INSERTquery('sys_file_storage', $field_values);
224  return (int)$this->db->sql_insert_id();
225  }
226 
233  protected function createDomainObject(array $databaseRow) {
234  return $this->factory->getStorageObject($databaseRow['uid'], $databaseRow);
235  }
236 
243  protected function testCaseSensitivity($absolutePath) {
244  $caseSensitive = TRUE;
245  $path = rtrim($absolutePath, '/') . '/aAbB';
246  $testFileExists = @file_exists($path);
247 
248  // create test file
249  if (!$testFileExists) {
250  touch($path);
251  }
252 
253  // do the actual sensitivity check
254  if (@file_exists(strtoupper($path)) && @file_exists(strtolower($path))) {
255  $caseSensitive = FALSE;
256  }
257 
258  // clean filesystem
259  if (!$testFileExists) {
260  unlink($path);
261  }
262 
263  return $caseSensitive;
264  }
265 
266 }
$uid
Definition: server.php:36
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]