[TASK] Add possibility to resolve a default storage 45/26945/6
authorSteffen Ritter <info@rs-websystems.de>
Mon, 20 Jan 2014 17:33:28 +0000 (18:33 +0100)
committerBenjamin Mack <benni@typo3.org>
Sun, 2 Feb 2014 14:40:35 +0000 (15:40 +0100)
Before FAL a default upload folder has been retrived by setting
$GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'] . 'user_upload'.
With FAL this even could be placed on a remote system. Furthermore
we do not won't users to fiddle around with path like that anymore.

Each Storage already provides "getDefaultFolder" meant for uploads.
But still, if there are several storages, there is no way to figure
out which storage should be the default one for uploads, if it is
legacy code or just not configurable.

This patch introduces the concept of a default storage as a flag
which can be set within the storage record. The automatic creation
of /fileadmin/ - storage will have this flag already set.

Resolves: #55177
Releases: 6.2
Change-Id: I6684670c5acb023bc26596e9a55ca84bb5c41b40
Reviewed-on: https://review.typo3.org/26945
Reviewed-by: Frans Saris
Tested-by: Frans Saris
Reviewed-by: Benjamin Mack
Tested-by: Benjamin Mack
typo3/sysext/core/Classes/Resource/ResourceFactory.php
typo3/sysext/core/Classes/Resource/ResourceStorage.php
typo3/sysext/core/Classes/Resource/StorageRepository.php
typo3/sysext/core/Configuration/DefaultConfiguration.php
typo3/sysext/core/Configuration/TCA/sys_file_storage.php
typo3/sysext/core/ext_tables.sql
typo3/sysext/lang/locallang_tca.xlf

index 56cbb38..c75478f 100644 (file)
@@ -108,6 +108,29 @@ class ResourceFactory implements \TYPO3\CMS\Core\SingletonInterface {
                return $driverObject;
        }
 
+
+       /**
+        * Returns the Default Storage
+        *
+        * The Default Storage is considered to be the replacement for the fileadmin/ construct.
+        * It is automatically created with the setting fileadminDir from install tool.
+        * getDefaultStorage->getDefaultFolder() will get you fileadmin/user_upload/ in a standard
+        * TYPO3 installation.
+        *
+        * @return null|ResourceStorage
+        */
+       public function getDefaultStorage() {
+               /** @var $storageRepository StorageRepository */
+               $storageRepository = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\StorageRepository');
+
+               $allStorages = $storageRepository->findAll();
+               foreach ($allStorages as $storage) {
+                       if ($storage->isDefault()) {
+                               return $storage;
+                       }
+               }
+               return NULL;
+       }
        /**
         * Creates an instance of the storage from given UID. The $recordData can
         * be supplied to increase performance.
@@ -135,7 +158,7 @@ class ResourceFactory implements \TYPO3\CMS\Core\SingletonInterface {
                                $recordData = array(
                                        'uid' => 0,
                                        'pid' => 0,
-                                       'name' => 'Default Storage',
+                                       'name' => 'Fallback Storage',
                                        'description' => 'Internal storage, mounting the main TYPO3_site directory.',
                                        'driver' => 'Local',
                                        'processingfolder' => 'typo3temp/_processed_/',
@@ -144,7 +167,8 @@ class ResourceFactory implements \TYPO3\CMS\Core\SingletonInterface {
                                        'is_online' => TRUE,
                                        'is_browsable' => TRUE,
                                        'is_public' => TRUE,
-                                       'is_writable' => TRUE
+                                       'is_writable' => TRUE,
+                                       'is_default' => FALSE,
                                );
                                $storageConfiguration = array(
                                        'basePath' => '/',
index c7c5dd0..9362084 100644 (file)
@@ -195,6 +195,11 @@ class ResourceStorage {
        protected $isOnline = NULL;
 
        /**
+        * @var boolean
+        */
+       protected $isDefault = FALSE;
+
+       /**
         * The filters used for the files and folder names.
         *
         * @var array
@@ -221,6 +226,7 @@ class ResourceStorage {
                }
                $this->driver->initialize();
                $this->capabilities = ($this->storageRecord['is_browsable'] && $this->driver->hasCapability(self::CAPABILITY_BROWSABLE) ? self::CAPABILITY_BROWSABLE : 0) + ($this->storageRecord['is_public'] && $this->driver->hasCapability(self::CAPABILITY_PUBLIC) ? self::CAPABILITY_PUBLIC : 0) + ($this->storageRecord['is_writable'] && $this->driver->hasCapability(self::CAPABILITY_WRITABLE) ? self::CAPABILITY_WRITABLE : 0);
+               $this->isDefault = (isset($storageRecord['is_default']) && $storageRecord['is_default'] == 1);
                // TODO do not set the "public" capability if no public URIs can be generated
                $this->processConfiguration();
                $this->resetFileAndFolderNameFiltersToDefault();
@@ -2494,4 +2500,19 @@ class ResourceStorage {
        protected function getIndexer() {
                return GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\Index\\Indexer', $this);
        }
+
+       /**
+        * @param boolean $isDefault
+        * @return void
+        */
+       public function setDefault($isDefault) {
+               $this->isDefault = (boolean)$isDefault;
+       }
+
+       /**
+        * @return boolean
+        */
+       public function isDefault() {
+               return $this->isDefault;
+       }
 }
index 98e61c1..6a0d78e 100644 (file)
@@ -121,7 +121,8 @@ class StorageRepository extends AbstractRepository {
                                                '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.'
+                                               'This is the local fileadmin/ directory. This storage mount has been created automatically by TYPO3.',
+                                               TRUE
                                        ) > 0 ) {
                                                // call self for initialize Cache
                                                $this->initializeLocalCache();
@@ -193,9 +194,10 @@ class StorageRepository extends AbstractRepository {
         * @param string $basePath
         * @param string $pathType
         * @param string $description
+        * @param bool $default set to default storage
         * @return integer uid of the inserted record
         */
-       public function createLocalStorage($name, $basePath, $pathType, $description = '') {
+       public function createLocalStorage($name, $basePath, $pathType, $description = '', $default = FALSE) {
                $caseSensitive = $this->testCaseSensitivity($pathType === 'relative' ? PATH_site . $basePath : $basePath);
                // create the FlexForm for the driver configuration
                $flexFormData = array(
@@ -226,7 +228,8 @@ class StorageRepository extends AbstractRepository {
                        'is_online' => 1,
                        'is_browsable' => 1,
                        'is_public' => 1,
-                       'is_writable' => 1
+                       'is_writable' => 1,
+                       'is_default' => $default ? 1 : 0
                );
                $this->db->exec_INSERTquery('sys_file_storage', $field_values);
                return (int)$this->db->sql_insert_id();
@@ -271,4 +274,4 @@ class StorageRepository extends AbstractRepository {
                return $caseSensitive;
        }
 
-}
\ No newline at end of file
+}
index c9d29f9..f3cf53f 100644 (file)
@@ -300,7 +300,7 @@ return array(
                ),
                'unzip_path' => '',                                                             // Path to "unzip". Only specify the path here, do not include the program name, it is expected to be called "unzip".
                'diff_path' => 'diff',                                                  // Path to "diff" including the program name. Example: /somepath/specialdiff<br />For Windows this program can be downloaded here: <a href="http://unxutils.sourceforge.net/" target="_blank">unxutils.sourceforge.net</a>
-               'fileadminDir' => 'fileadmin/',                                 // Path to the fileadmin dir. This is relative to PATH_site. (Automatically mounted for admin-users if set)
+               'fileadminDir' => 'fileadmin/',                                 // Path to the fileadmin dir. This is relative to PATH_site, DefaultStorage will be created with that configuration, do not access manually but ResourceFactory::getDefaultStorage()
                'RTEenabled' => TRUE,                                                   // Boolean: If set, the Rich Text editor will be an option in the backend. Notice that the editor must be enabled per-user and options are configurable. See admin guide.
                'RTE_imageStorageDir' => 'uploads/',                    // Default storage directory for Rich Text Editor files
                'RTE_reg' => array(),                                                   // Contains arrays of possible RTEs available (keys=extKey, values=cfg-array). Each array contains a key, "objRef", which contains a user function call with prefixed script path and instanciating a persistent global object. This can report back if browser requirements are OK, draw the RTE and do the transformations needed.
index f751cdb..1048d93 100644 (file)
@@ -55,6 +55,18 @@ return array(
                                'default' => 1
                        )
                ),
+               'is_default' => array(
+                       'exclude' => 0,
+                       'label' => 'LLL:EXT:lang/locallang_tca.xlf:sys_file_storage.is_default',
+                       'config' => array(
+                               'type' => 'check',
+                               'default' => 0,
+                               'eval' => 'maximumRecordsChecked',
+                               'validation' => array(
+                                       'maximumRecordsChecked' => 1
+                               )
+                       )
+               ),
                'is_public' => array(
                        'exclude' => 0,
                        'label' => 'LLL:EXT:lang/locallang_tca.xlf:sys_file_storage.is_public',
@@ -109,7 +121,7 @@ return array(
                )
        ),
        'types' => array(
-               '0' => array('showitem' => 'name, description, hidden, --div--;Configuration, driver, configuration, processingfolder, --div--;Access, --palette--;Capabilities;capabilities, is_online')
+               '0' => array('showitem' => 'name, description, hidden, --div--;Configuration, driver, configuration, is_default, processingfolder, --div--;Access, --palette--;Capabilities;capabilities, is_online')
        ),
        'palettes' => array(
                'capabilities' => array('showitem' => 'is_browsable, is_public, is_writable', 'canNotCollapse' => TRUE)
index 69cf63d..2a4a210 100644 (file)
@@ -267,6 +267,7 @@ CREATE TABLE sys_file_storage (
        description text,
        driver tinytext,
        configuration text,
+       is_default tinyint(4) DEFAULT '0' NOT NULL,
        is_browsable tinyint(4) DEFAULT '0' NOT NULL,
        is_public tinyint(4) DEFAULT '0' NOT NULL,
        is_writable tinyint(4) DEFAULT '0' NOT NULL,
@@ -702,4 +703,4 @@ CREATE TABLE sys_category_record_mm (
 
        KEY uid_local_foreign (uid_local,uid_foreign),
        KEY uid_foreign_tablenames (uid_foreign,tablenames)
-);
\ No newline at end of file
+);
index 3380b8c..5718ffe 100644 (file)
                        <trans-unit id="sys_file_storage.is_online" xml:space="preserve">
                                <source>Is online?</source>
                        </trans-unit>
+                       <trans-unit id="sys_file_storage.is_default" xml:space="preserve">
+                               <source>Is default storage?</source>
+                       </trans-unit>
                        <trans-unit id="sys_file_storage.is_browsable" xml:space="preserve">
                                <source>Is browsable?</source>
                        </trans-unit>