TYPO3 CMS  TYPO3_6-2
FilemountUpdateWizard.php
Go to the documentation of this file.
1 <?php
3 
18 
29 
33  protected $title = 'Migrate existing filemounts to be file abstraction layer compatible.';
34 
38  protected $db;
39 
43  protected $sqlQueries = array();
44 
48  protected $storage;
49 
53  protected $storageRepository;
54 
58  public function __construct() {
59  $this->db = $GLOBALS['TYPO3_DB'];
60  }
61 
65  public function init() {
66  $this->storageRepository = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\StorageRepository');
67  $storages = $this->storageRepository->findAll();
68  $this->storage = $storages[0];
69  }
70 
77  public function checkForUpdate(&$description) {
78  $description = 'Migrate all filemounts to be based on file abstraction layer storages.';
79  $filemountCount = $this->db->exec_SELECTcountRows(
80  '*',
81  'sys_filemounts',
82  'base IN (0,1) ' . BackendUtility::deleteClause('sys_filemounts')
83  );
84  return $filemountCount > 0 && !$this->isWizardDone();
85  }
86 
94  public function performUpdate(array &$dbQueries, &$customMessages) {
95  $this->init();
98  if (is_array($this->sqlQueries) && is_array($dbQueries)) {
99  $dbQueries = array_merge($dbQueries, $this->sqlQueries);
100  }
101 
102  // Initialize processing folders for all storages
103  foreach ($this->storageRepository->findAll() as $storage) {
104  $storage->getProcessingFolders();
105  }
106 
107  $this->markWizardAsDone();
108  return TRUE;
109  }
110 
117  protected function migrateAbsoluteFilemounts() {
118  $description = 'This is the local %s directory. This storage mount has been created by the TYPO3 upgrade wizards.';
119  $fileadminDir = PATH_site . $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'];
120  $absoluteFilemounts = $this->db->exec_SELECTgetRows(
121  '*',
122  'sys_filemounts',
123  'base = 0' . BackendUtility::deleteClause('sys_filemounts')
124  );
125  foreach ($absoluteFilemounts as $filemount) {
126  if (stristr($filemount['path'], $fileadminDir)) {
127  $storageId = $this->storage->getUid();
128  $storagePath = rtrim(str_replace($fileadminDir, '', $filemount['path']), '/') . '/';
129  } else {
130  $storageId = $this->storageRepository->createLocalStorage(
131  $filemount['title'] . ' (auto-created)',
132  $filemount['path'],
133  'absolute',
134  sprintf($description, $filemount['path'])
135  );
136  $storagePath = '/';
137  $this->sqlQueries[] = $GLOBALS['TYPO3_DB']->debug_lastBuiltQuery;
138  }
139  $this->db->exec_UPDATEquery(
140  'sys_filemounts',
141  'uid=' . (int)$filemount['uid'],
142  array('base' => $storageId, 'path' => $storagePath)
143  );
144  $this->sqlQueries[] = $GLOBALS['TYPO3_DB']->debug_lastBuiltQuery;
145  }
146  }
147 
154  protected function migrateRelativeFilemounts() {
155  $relativeFilemounts = $this->db->exec_SELECTgetRows(
156  '*',
157  'sys_filemounts',
158  'base = 1' . BackendUtility::deleteClause('sys_filemounts')
159  );
160  foreach ($relativeFilemounts as $filemount) {
161  $storagePath = trim($filemount['path'], '/') . '/';
162  if ($storagePath !== '/') {
163  $storagePath = '/' . $storagePath;
164  }
165  $this->db->exec_UPDATEquery(
166  'sys_filemounts',
167  'uid=' . (int)$filemount['uid'],
168  array('base' => $this->storage->getUid(), 'path' => $storagePath)
169  );
170  $this->sqlQueries[] = $GLOBALS['TYPO3_DB']->debug_lastBuiltQuery;
171  }
172  }
173 
174 }
performUpdate(array &$dbQueries, &$customMessages)
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]
static deleteClause($table, $tableAlias='')