Example #1
0
 protected function setUp()
 {
     $this->singletonInstances = \TYPO3\CMS\Core\Utility\GeneralUtility::getSingletonInstances();
     $this->storageMock = $this->getMock(\TYPO3\CMS\Core\Resource\ResourceStorage::class, array(), array(), '', false);
     $this->storageMock->expects($this->any())->method('getUid')->will($this->returnValue(5));
     $mockedMetaDataRepository = $this->getMock(\TYPO3\CMS\Core\Resource\Index\MetaDataRepository::class);
     $mockedMetaDataRepository->expects($this->any())->method('findByFile')->will($this->returnValue(array('file' => 1)));
     \TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance(\TYPO3\CMS\Core\Resource\Index\MetaDataRepository::class, $mockedMetaDataRepository);
 }
Example #2
0
 public function setUp()
 {
     $this->singletonInstances = \TYPO3\CMS\Core\Utility\GeneralUtility::getSingletonInstances();
     $this->storageMock = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array(), array(), '', FALSE);
     $this->storageMock->expects($this->any())->method('getUid')->will($this->returnValue(5));
     $mockedMetaDataRepository = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Index\\MetaDataRepository');
     $mockedMetaDataRepository->expects($this->any())->method('findByFile')->will($this->returnValue(array('file' => 1)));
     \TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance('TYPO3\\CMS\\Core\\Resource\\Index\\MetaDataRepository', $mockedMetaDataRepository);
 }
Example #3
0
 /**
  * Test if the default filters filter out hidden folders (like .htaccess)
  *
  * @test
  */
 public function folderListingsDoNotContainHiddenFoldersByDefault()
 {
     $this->addToMount(array('someFolder' => array(), '.someHiddenFolder' => array()));
     $this->prepareFixture();
     $this->fixture->resetFileAndFolderNameFiltersToDefault();
     $folderList = $this->fixture->getFolderList('/');
     $this->assertContains('someFolder', array_keys($folderList));
     $this->assertNotContains('.someHiddenFolder', array_keys($folderList));
 }
 /**
  * @param ResourceStorage $storage
  * @param string $identifier
  *
  * @return null|ProcessedFile
  */
 public function findByStorageAndIdentifier(ResourceStorage $storage, $identifier)
 {
     $processedFileObject = null;
     if ($storage->hasFile($identifier)) {
         $databaseRow = $this->databaseConnection->exec_SELECTgetSingleRow('*', $this->table, 'storage = ' . (int) $storage->getUid() . ' AND identifier = ' . $this->databaseConnection->fullQuoteStr($identifier, $this->table));
         if ($databaseRow) {
             $processedFileObject = $this->createDomainObject($databaseRow);
         }
     }
     return $processedFileObject;
 }
Example #5
0
 /**
  * @param ResourceStorage $storage
  * @param string $identifier
  *
  * @return null|ProcessedFile
  */
 public function findByStorageAndIdentifier(ResourceStorage $storage, $identifier)
 {
     $processedFileObject = null;
     if ($storage->hasFile($identifier)) {
         $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($this->table);
         $databaseRow = $queryBuilder->select('*')->from($this->table)->where($queryBuilder->expr()->eq('storage', $queryBuilder->createNamedParameter($storage->getUid(), \PDO::PARAM_INT)), $queryBuilder->expr()->eq('identifier', $queryBuilder->createNamedParameter($identifier, \PDO::PARAM_STR)))->execute()->fetch();
         if ($databaseRow) {
             $processedFileObject = $this->createDomainObject($databaseRow);
         }
     }
     return $processedFileObject;
 }
Example #6
0
 /**
  * Adds file mounts from the user's file mount records
  *
  * @param ResourceStorage $storage
  * @return void
  */
 protected function addFileMountsToStorage(ResourceStorage $storage)
 {
     foreach ($this->backendUserAuthentication->getFileMountRecords() as $fileMountRow) {
         if ((int) $fileMountRow['base'] === (int) $storage->getUid()) {
             try {
                 $storage->addFileMount($fileMountRow['path'], $fileMountRow);
             } catch (FolderDoesNotExistException $e) {
                 // That file mount does not seem to be valid, fail silently
             }
         }
     }
 }
Example #7
0
 /**
  * Return duplicates file records
  *
  * @param \TYPO3\CMS\Core\Resource\ResourceStorage $storage
  * @return array
  */
 public function searchForDuplicateSha1(ResourceStorage $storage)
 {
     // Detect duplicate records.
     $query = "SELECT sha1 FROM sys_file WHERE storage = {$storage->getUid()} GROUP BY sha1, storage Having COUNT(*) > 1";
     $resource = $this->getDatabaseConnection()->sql_query($query);
     $duplicates = array();
     while ($row = $this->getDatabaseConnection()->sql_fetch_assoc($resource)) {
         $clause = sprintf('sha1 = "%s" AND storage = %s', $row['sha1'], $storage->getUid());
         $records = $this->getDatabaseConnection()->exec_SELECTgetRows('*', 'sys_file', $clause);
         $duplicates[$row['sha1']] = $records;
     }
     return $duplicates;
 }
 /**
  * Set up
  *
  * @return void
  */
 public function setUp()
 {
     $this->singletonInstances = \TYPO3\CMS\Core\Utility\GeneralUtility::getSingletonInstances();
     $this->fileCollectionMock = $this->getAccessibleMock('\\TYPO3\\CMS\\Core\\Resource\\Collection\\AbstractFileCollection', array('loadContents', 'getItems'), array(), '', FALSE);
     $this->fileCollectionMock->expects($this->atLeastOnce())->method('loadContents');
     $this->fileCollectionRepositoryMock = $this->getMock('\\TYPO3\\CMS\\Core\\Resource\\FileCollectionRepository', array('findByUid'), array(), '', FALSE);
     $this->fileCollectionRepositoryMock->expects($this->any())->method('findByUid')->will($this->returnValue($this->fileCollectionMock));
     $this->frontendConfigurationManagerMock = $this->getMock('\\TYPO3\\CMS\\Extbase\\Configuration\\FrontendConfigurationManager', array('getConfiguration'), array(), '', FALSE);
     $this->storageMock = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array(), array(), '', FALSE);
     $this->storageMock->expects($this->any())->method('getUid')->will($this->returnValue(5));
     $this->subject = GeneralUtility::makeInstance('SKYFILLERS\\SfFilecollectionGallery\\Service\\FileCollectionService');
     $this->subject->injectFileCollectionRepository($this->fileCollectionRepositoryMock);
     $this->subject->injectFrontendConfigurationManager($this->frontendConfigurationManagerMock);
 }
Example #9
0
 public function setUp()
 {
     $this->singletonInstances = GeneralUtility::getSingletonInstances();
     // Disable xml2array cache used by ResourceFactory
     GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->setCacheConfigurations(array('cache_hash' => array('frontend' => 'TYPO3\\CMS\\Core\\Cache\\Frontend\\VariableFrontend', 'backend' => 'TYPO3\\CMS\\Core\\Cache\\Backend\\TransientMemoryBackend')));
     $this->testDocumentsPath = ExtensionManagementUtility::extPath('tika') . 'Tests/TestDocuments/';
     $driver = $this->createDriverFixture(array('basePath' => $this->testDocumentsPath, 'caseSensitive' => TRUE));
     $storageRecord = array('uid' => $this->storageUid, 'is_public' => TRUE, 'is_writable' => FALSE, 'is_browsable' => TRUE, 'is_online' => TRUE, 'configuration' => $this->convertConfigurationArrayToFlexformXml(array('basePath' => $this->testDocumentsPath, 'pathType' => 'absolute', 'caseSensitive' => '1')));
     $this->storageMock = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', NULL, array($driver, $storageRecord));
     $this->storageMock->expects($this->any())->method('getUid')->will($this->returnValue($this->storageUid));
     $mockedMetaDataRepository = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Index\\MetaDataRepository');
     $mockedMetaDataRepository->expects($this->any())->method('findByFile')->will($this->returnValue(array('file' => 1)));
     \TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance('TYPO3\\CMS\\Core\\Resource\\Index\\MetaDataRepository', $mockedMetaDataRepository);
 }
    /**
     * Processes the actual transformation from CSV to sys_file_references
     *
     * @param array $record
     * @return void
     */
    protected function migrateRecord(array $record)
    {
        $collections = array();
        if (trim($record['select_key'])) {
            $GLOBALS['TYPO3_DB']->exec_INSERTquery('sys_file_collection', array('pid' => $record['pid'], 'title' => $record['select_key'], 'storage' => $this->storage->getUid(), 'folder' => ltrim('fileadmin/', $record['select_key'])));
            $collections[] = $GLOBALS['TYPO3_DB']->sql_insert_id();
        }
        $files = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $record['media'], TRUE);
        $descriptions = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode('
', $record['imagecaption']);
        $titleText = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode('
', $record['titleText']);
        $i = 0;
        foreach ($files as $file) {
            if (file_exists(PATH_site . 'uploads/media/' . $file)) {
                \TYPO3\CMS\Core\Utility\GeneralUtility::upload_copy_move(PATH_site . 'uploads/media/' . $file, $this->targetDirectory . $file);
                $fileObject = $this->storage->getFile(self::FOLDER_ContentUploads . '/' . $file);
                $this->fileRepository->addToIndex($fileObject);
                $dataArray = array('uid_local' => $fileObject->getUid(), 'tablenames' => 'tt_content', 'uid_foreign' => $record['uid'], 'fieldname' => 'media', 'sorting_foreign' => $i);
                if (isset($descriptions[$i])) {
                    $dataArray['description'] = $descriptions[$i];
                }
                if (isset($titleText[$i])) {
                    $dataArray['alternative'] = $titleText[$i];
                }
                $GLOBALS['TYPO3_DB']->exec_INSERTquery('sys_file_reference', $dataArray);
                unlink(PATH_site . 'uploads/media/' . $file);
            }
            $i++;
        }
        $this->cleanRecord($record, $i, $collections);
    }
Example #11
0
 /**
  * Checks if this file exists. This should normally always return TRUE;
  * it might only return FALSE when this object has been created from an
  * index record without checking for.
  *
  * @return boolean TRUE if this file physically exists
  */
 public function exists()
 {
     if ($this->deleted) {
         return FALSE;
     }
     return $this->storage->hasFile($this->getIdentifier());
 }
 /**
  * @return void
  */
 protected function setFileExtensionFilter()
 {
     // Don't inject the filter, because it's a prototype
     $this->fileExtensionFilter = $this->objectManager->get('TYPO3\\CMS\\Core\\Resource\\Filter\\FileExtensionFilter');
     $this->fileExtensionFilter->setAllowedFileExtensions($this->imageFileExtensions);
     $this->selectedStorage->addFileAndFolderNameFilter(array($this->fileExtensionFilter, 'filterFileList'));
 }
 /**
  * @test
  */
 public function getFileListHandsOverRecursiveTRUEifSet()
 {
     $this->prepareFixture(array());
     $driver = $this->createDriverMock(array('basePath' => $this->getMountRootUrl()), $this->fixture, array('getFileList'));
     $driver->expects($this->once())->method('getFileList')->with($this->anything(), $this->anything(), $this->anything(), $this->anything(), $this->anything(), TRUE)->will($this->returnValue(array()));
     $this->fixture->getFileList('/', 0, 0, TRUE, TRUE, TRUE);
 }
 /**
  * Migrate dam references to fal references
  *
  * @param \mysqli_result $result
  * @param string $table
  * @param string $type
  * @param array $fieldnameMapping Re-map fieldnames e.g.
  *    tx_damnews_dam_images => tx_falttnews_fal_images
  *
  * @return void
  */
 protected function migrateDamReferencesToFalReferences($result, $table, $type, $fieldnameMapping = array())
 {
     $counter = 0;
     $total = $this->database->sql_num_rows($result);
     $this->controller->infoMessage('Found ' . $total . ' ' . $table . ' records with a dam ' . $type);
     while ($record = $this->database->sql_fetch_assoc($result)) {
         $identifier = $this->getFullFileName($record);
         try {
             $fileObject = $this->storageObject->getFile($identifier);
         } catch (\Exception $e) {
             // If file is not found
             // getFile will throw an invalidArgumentException if the file
             // does not exist. Create an empty file to avoid this. This is
             // usefull in a development environment that has the production
             // database but not all the physical files.
             try {
                 GeneralUtility::mkdir_deep(PATH_site . $this->storageBasePath . dirname($identifier));
             } catch (\Exception $e) {
                 $this->controller->errorMessage('Unable to create directory: ' . PATH_site . $this->storageBasePath . $identifier);
                 continue;
             }
             $config = $this->controller->getConfiguration();
             if (isset($config['createMissingFiles']) && (int) $config['createMissingFiles']) {
                 $this->controller->infoMessage('Creating empty missing file: ' . PATH_site . $this->storageBasePath . $identifier);
                 try {
                     GeneralUtility::writeFile(PATH_site . $this->storageBasePath . $identifier, '');
                 } catch (\Exception $e) {
                     $this->controller->errorMessage('Unable to create file: ' . PATH_site . $this->storageBasePath . $identifier);
                     continue;
                 }
             } else {
                 $this->controller->errorMessage('File not found: ' . PATH_site . $this->storageBasePath . $identifier);
                 continue;
             }
             $fileObject = $this->storageObject->getFile($identifier);
         }
         if ($fileObject instanceof \TYPO3\CMS\Core\Resource\File) {
             if ($fileObject->isMissing()) {
                 $this->controller->warningMessage('FAL did not find any file resource for DAM record. DAM uid: ' . $record['uid'] . ': "' . $identifier . '"');
                 continue;
             }
             $record['uid_local'] = $fileObject->getUid();
             foreach ($fieldnameMapping as $old => $new) {
                 if ($record['ident'] === $old) {
                     $record['ident'] = $new;
                 }
             }
             $progress = number_format(100 * ($counter++ / $total), 1) . '% of ' . $total;
             if (!$this->doesFileReferenceExist($record)) {
                 $insertData = array('tstamp' => time(), 'crdate' => time(), 'cruser_id' => $GLOBALS['BE_USER']->user['uid'], 'uid_local' => $record['uid_local'], 'uid_foreign' => (int) $record['uid_foreign'], 'sorting' => (int) $record['sorting'], 'sorting_foreign' => (int) $record['sorting_foreign'], 'tablenames' => (string) $record['tablenames'], 'fieldname' => (string) $record['ident'], 'table_local' => 'sys_file', 'pid' => $record['item_pid'], 'l10n_diffsource' => (string) $record['l18n_diffsource']);
                 $this->database->exec_INSERTquery('sys_file_reference', $insertData);
                 $this->amountOfMigratedRecords++;
                 $this->controller->message($progress . ' Migrating relation for ' . (string) $record['tablenames'] . ' uid: ' . $record['item_uid'] . ' dam uid: ' . $record['dam_uid'] . ' to fal uid: ' . $record['uid_local']);
             } else {
                 $this->controller->message($progress . ' Reference already exists for uid: ' . (int) $record['item_uid']);
             }
         }
     }
     $this->database->sql_free_result($result);
 }
Example #15
0
 /**
  * @test
  */
 public function replaceFileFailsIfLocalFileDoesNotExist()
 {
     $this->setExpectedException('InvalidArgumentException', '', 1325842622);
     $this->prepareFixture(array(), TRUE);
     $mockedFile = $this->getSimpleFileMock('/someFile');
     $this->fixture->replaceFile($mockedFile, PATH_site . uniqid());
 }
Example #16
0
 /**
  * Processes the actual transformation from CSV to sys_file_references
  *
  * @param array $record
  * @param string $field
  * @return void
  */
 protected function migrateRecord(array $record, $field)
 {
     if ($field === 'fal_related_files') {
         $file = $record['file'];
     } else {
         $file = $record['image'];
     }
     if (!empty($file) && file_exists(PATH_site . 'uploads/tx_news/' . $file)) {
         GeneralUtility::upload_copy_move(PATH_site . 'uploads/tx_news/' . $file, $this->targetDirectory . $file);
         $fileObject = $this->storage->getFile(self::FOLDER_ContentUploads . '/' . $file);
         $this->fileRepository->add($fileObject);
         $dataArray = ['uid_local' => $fileObject->getUid(), 'tablenames' => 'tx_news_domain_model_news', 'fieldname' => $field, 'uid_foreign' => $record['newsUid'], 'table_local' => 'sys_file', 'cruser_id' => 999, 'pid' => $record['newsPid'], 'sorting_foreign' => $record['sorting'], 'title' => $record['title'], 'hidden' => $record['hidden']];
         if ($field === 'fal_media') {
             $description = [];
             if (!empty($record['caption'])) {
                 $description[] = $record['caption'];
             }
             if (!empty($record['description'])) {
                 $description[] = $record['description'];
             }
             $additionalData = ['description' => implode(LF . LF, $description), 'alternative' => $record['alt'], 'showinpreview' => $record['showinpreview']];
         } else {
             $additionalData = ['description' => $record['description']];
         }
         $dataArray += $additionalData;
         $GLOBALS['TYPO3_DB']->exec_INSERTquery('sys_file_reference', $dataArray);
     }
 }
 /**
  * Performs the database update.
  *
  * @param array $dbQueries queries done in this update
  * @param mixed $customMessages custom messages
  * @return boolean TRUE on success, FALSE on error
  */
 public function performUpdate(array &$dbQueries, &$customMessages)
 {
     $this->init();
     if (!PATH_site) {
         throw new \Exception('PATH_site was undefined.');
     }
     $fileadminDirectory = rtrim($GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'], '/');
     $targetDirectory = '/_migrated/RTE/';
     $fullTargetDirectory = PATH_site . $fileadminDirectory . $targetDirectory;
     // Create the directory, if necessary
     if (!is_dir($fullTargetDirectory)) {
         \TYPO3\CMS\Core\Utility\GeneralUtility::mkdir_deep($fullTargetDirectory);
     }
     $oldRecords = $this->findMagicImagesInOldLocation();
     foreach ($oldRecords as $refRecord) {
         // Is usually uploads/RTE_magicC_123423324.png.png
         $sourceFileName = $refRecord['ref_string'];
         // Absolute path/filename
         $fullSourceFileName = PATH_site . $refRecord['ref_string'];
         $targetFileName = $targetDirectory . \TYPO3\CMS\Core\Utility\PathUtility::basename($refRecord['ref_string']);
         // Full directory
         $fullTargetFileName = $fullTargetDirectory . \TYPO3\CMS\Core\Utility\PathUtility::basename($refRecord['ref_string']);
         // maybe the file has been moved previously
         if (!file_exists($fullTargetFileName)) {
             // If the source file does not exist, we should just continue, but leave a message in the docs;
             // ideally, the user would be informed after the update as well.
             if (!file_exists(PATH_site . $sourceFileName)) {
                 $this->logger->notice('File ' . $sourceFileName . ' does not exist. Reference was not migrated.', array());
                 $format = 'File \'%s\' does not exist. Referencing field: %s.%d.%s. The reference was not migrated.';
                 $message = sprintf($format, $sourceFileName, $refRecord['tablename'], $refRecord['recuid'], $refRecord['field']);
                 $customMessages .= PHP_EOL . $message;
                 continue;
             }
             rename($fullSourceFileName, $fullTargetFileName);
         }
         // Get the File object
         $file = $this->storage->getFile($targetFileName);
         if ($file instanceof \TYPO3\CMS\Core\Resource\File) {
             // And now update the referencing field
             $targetFieldName = $refRecord['field'];
             $targetRecord = $this->db->exec_SELECTgetSingleRow('uid, ' . $targetFieldName, $refRecord['tablename'], 'uid=' . (int) $refRecord['recuid']);
             if ($targetRecord) {
                 // Replace the old filename with the new one, and add data-* attributes used by the RTE
                 $searchString = 'src="' . $sourceFileName . '"';
                 $replacementString = 'src="' . $fileadminDirectory . $targetFileName . '"';
                 $replacementString .= ' data-htmlarea-file-uid="' . $file->getUid() . '"';
                 $replacementString .= ' data-htmlarea-file-table="sys_file"';
                 $targetRecord[$targetFieldName] = str_replace($searchString, $replacementString, $targetRecord[$targetFieldName]);
                 // Update the record
                 $this->db->exec_UPDATEquery($refRecord['tablename'], 'uid=' . (int) $refRecord['recuid'], array($targetFieldName => $targetRecord[$targetFieldName]));
                 $queries[] = str_replace(LF, ' ', $this->db->debug_lastBuiltQuery);
                 // Finally, update the sys_refindex table as well
                 $this->db->exec_UPDATEquery('sys_refindex', 'hash=' . $this->db->fullQuoteStr($refRecord['hash'], 'sys_refindex'), array('ref_table' => 'sys_file', 'softref_key' => 'rtehtmlarea_images', 'ref_uid' => $file->getUid(), 'ref_string' => $fileadminDirectory . $targetFileName));
                 $queries[] = str_replace(LF, ' ', $this->db->debug_lastBuiltQuery);
             }
         }
     }
     return TRUE;
 }
Example #18
0
 protected function setUpLanguagesStorageMock()
 {
     $this->testLanguagesPath = ExtensionManagementUtility::extPath('tika') . 'Tests/TestLanguages/';
     $languagesDriver = $this->createDriverFixture(array('basePath' => $this->testLanguagesPath, 'caseSensitive' => TRUE));
     $languagesStorageRecord = array('uid' => $this->languagesStorageUid, 'is_public' => TRUE, 'is_writable' => FALSE, 'is_browsable' => TRUE, 'is_online' => TRUE, 'configuration' => $this->convertConfigurationArrayToFlexformXml(array('basePath' => $this->testLanguagesPath, 'pathType' => 'absolute', 'caseSensitive' => '1')));
     $this->languagesStorageMock = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', NULL, array($languagesDriver, $languagesStorageRecord));
     $this->languagesStorageMock->expects($this->any())->method('getUid')->will($this->returnValue($this->languagesStorageUid));
 }
Example #19
0
 /**
  * @test
  */
 public function deletingProcessedFileThatUsesOriginalFileDoesNotRemoveFile()
 {
     $this->storageMock->expects($this->never())->method('deleteFile');
     $processedDatabaseRow = $this->databaseRow;
     $processedDatabaseRow['identifier'] = NULL;
     $processedFile = $this->getProcessedFileFixture($processedDatabaseRow);
     $processedFile->delete(TRUE);
 }
 /**
  * Generate public url for file
  *
  * @param Resource\ResourceStorage $storage
  * @param Resource\Driver\DriverInterface $driver
  * @param Resource\FileInterface $file
  * @param $relativeToCurrentScript
  * @param array $urlData
  * @return void
  */
 public function generatePublicUrl(Resource\ResourceStorage $storage, Resource\Driver\DriverInterface $driver, Resource\FileInterface $file, $relativeToCurrentScript, array $urlData)
 {
     // We only render special links for non-public files
     if ($this->enabled && !$storage->isPublic()) {
         $queryParameterArray = array('eID' => 'dumpFile', 't' => '');
         if ($file instanceof Resource\File) {
             $queryParameterArray['f'] = $file->getUid();
             $queryParameterArray['t'] = 'f';
         } elseif ($file instanceof Resource\ProcessedFile) {
             $queryParameterArray['p'] = $file->getUid();
             $queryParameterArray['t'] = 'p';
         }
         $queryParameterArray['token'] = GeneralUtility::hmac(implode('|', $queryParameterArray), 'BeResourceStorageDumpFile');
         // $urlData['publicUrl'] is passed by reference, so we can change that here and the value will be taken into account
         $urlData['publicUrl'] = BackendUtility::getAjaxUrl('FalSecuredownload::publicUrl', $queryParameterArray);
     }
 }
 /**
  * Relative filemounts are transformed to relate to our fileadmin/ storage
  * and their path is modified to be a valid resource location
  */
 protected function migrateRelativeFilemounts()
 {
     $relativeFilemounts = $this->db->exec_SELECTgetRows('*', 'sys_filemounts', 'base = 1' . \TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause('sys_filemounts'));
     foreach ($relativeFilemounts as $filemount) {
         $this->db->exec_UPDATEquery('sys_filemounts', 'uid=' . intval($filemount['uid']), array('base' => $this->storage->getUid(), 'path' => '/' . ltrim($filemount['path'], '/')));
         $this->sqlQueries[] = $GLOBALS['TYPO3_DB']->debug_lastBuiltQuery;
     }
 }
Example #22
0
 /**
  * @param \TYPO3\CMS\Core\Resource\ResourceStorage $resourceStorage
  * @param \TYPO3\CMS\Core\Resource\Driver\DriverInterface $driver
  * @param \TYPO3\CMS\Core\Resource\ResourceInterface $resourceObject
  * @param boolean $relativeToCurrentScript
  * @param string $urlData
  */
 public function getCdnPublicUrl($resourceStorage, $driver, $resourceObject, $relativeToCurrentScript, $urlData)
 {
     if (!$driver instanceof LocalDriver || $this->environmentService->isEnvironmentInBackendMode()) {
         return;
     }
     if (($resourceObject instanceof File || $resourceObject instanceof ProcessedFile) && ($resourceStorage->getCapabilities() & ResourceStorageInterface::CAPABILITY_PUBLIC) == ResourceStorageInterface::CAPABILITY_PUBLIC) {
         $publicUrl = $driver->getPublicUrl($resourceObject->getIdentifier());
         $urlData['publicUrl'] = $GLOBALS['TSFE']->config['config']['cdnBaseUrl'] . $publicUrl;
         if ($resourceObject instanceof File) {
             $urlData['publicUrl'] .= '?' . $resourceObject->getModificationTime();
         } else {
             if ($resourceObject instanceof ProcessedFile) {
                 $urlData['publicUrl'] .= '?' . $resourceObject->getProperty('tstamp');
             }
         }
     }
 }
 /**
  * @test
  * @TODO: Rewrite or move to functional suite
  */
 public function getRoleReturnsDefaultForRegularFolders()
 {
     $this->markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
     $folderIdentifier = uniqid();
     $this->addToMount(array($folderIdentifier => array()));
     $this->prepareFixture(array());
     $role = $this->fixture->getRole($this->getSimpleFolderMock('/' . $folderIdentifier . '/'));
     $this->assertSame(\TYPO3\CMS\Core\Resource\FolderInterface::ROLE_DEFAULT, $role);
 }
Example #24
0
 /**
  * @return int
  */
 public function getTotalNumberOfFiles()
 {
     $clause = 'storage > 0';
     if ($this->storage) {
         $clause = 'storage = ' . $this->storage->getUid();
     }
     $record = $this->getDatabaseConnection()->exec_SELECTgetSingleRow('count(*) AS totalNumberOfFiles', 'sys_file', $clause);
     return (int) $record['totalNumberOfFiles'];
 }
 /**
  * @test
  * @TODO: Rewrite or move to functional suite
  */
 public function getRoleReturnsDefaultForRegularFolders()
 {
     $this->markTestSkipped('This test does way to much and is mocked incomplete. Skipped for now.');
     $folderIdentifier = $this->getUniqueId();
     $this->addToMount(array($folderIdentifier => array()));
     $this->prepareSubject(array());
     $role = $this->subject->getRole($this->getSimpleFolderMock('/' . $folderIdentifier . '/'));
     $this->assertSame(FolderInterface::ROLE_DEFAULT, $role);
 }
Example #26
0
 /**
  * Collects the information to be cached in sys_file
  *
  * @param string $identifier
  * @return array
  */
 protected function gatherFileInformationArray($identifier)
 {
     $fileInfo = $this->storage->getFileInfoByIdentifier($identifier);
     $fileInfo = $this->transformFromDriverFileInfoArrayToFileObjectFormat($fileInfo);
     $fileInfo['type'] = $this->getFileType($fileInfo['mime_type']);
     $fileInfo['sha1'] = $this->storage->hashFileByIdentifier($identifier, 'sha1');
     $fileInfo['extension'] = \TYPO3\CMS\Core\Utility\PathUtility::pathinfo($fileInfo['name'], PATHINFO_EXTENSION);
     $fileInfo['missing'] = 0;
     return $fileInfo;
 }
Example #27
0
 /**
  * @param \TYPO3\CMS\Core\Resource\File $file
  * @return $this
  */
 public function extractMetadata(File $file)
 {
     $extractionServices = $this->getExtractorRegistry()->getExtractorsWithDriverSupport($this->storage->getDriverType());
     $newMetaData = array(0 => $file->_getMetaData());
     foreach ($extractionServices as $service) {
         if ($service->canProcess($file)) {
             $newMetaData[$service->getPriority()] = $service->extractMetaData($file, $newMetaData);
         }
     }
     ksort($newMetaData);
     $metaData = array();
     foreach ($newMetaData as $data) {
         $metaData = array_merge($metaData, $data);
     }
     $file->_updateMetaDataProperties($metaData);
     $this->getMetaDataRepository()->update($file->getUid(), $metaData);
     $this->getFileIndexRepository()->updateIndexingTime($file->getUid());
     return $this;
 }
 /**
  * Relative filemounts are transformed to relate to our fileadmin/ storage
  * and their path is modified to be a valid resource location
  *
  * @return void
  */
 protected function migrateRelativeFilemounts()
 {
     $relativeFilemounts = $this->db->exec_SELECTgetRows('*', 'sys_filemounts', 'base = 1' . BackendUtility::deleteClause('sys_filemounts'));
     foreach ($relativeFilemounts as $filemount) {
         $storagePath = trim($filemount['path'], '/') . '/';
         if ($storagePath !== '/') {
             $storagePath = '/' . $storagePath;
         }
         $this->db->exec_UPDATEquery('sys_filemounts', 'uid=' . (int) $filemount['uid'], array('base' => $this->storage->getUid(), 'path' => $storagePath));
         $this->sqlQueries[] = $GLOBALS['TYPO3_DB']->debug_lastBuiltQuery;
     }
 }
Example #29
0
 /**
  * Optimize the given uploaded image.
  *
  * @param \Fab\Media\FileUpload\UploadedFileInterface $uploadedFile
  * @return \Fab\Media\FileUpload\UploadedFileInterface
  */
 public function optimize($uploadedFile)
 {
     $imageInfo = getimagesize($uploadedFile->getFileWithAbsolutePath());
     $currentWidth = $imageInfo[0];
     $currentHeight = $imageInfo[1];
     // resize an image if this one is bigger than telling by the settings.
     if (is_object($this->storage)) {
         $storageRecord = $this->storage->getStorageRecord();
     } else {
         // Will only work in the BE for now.
         $storage = $this->getMediaModule()->getCurrentStorage();
         $storageRecord = $storage->getStorageRecord();
     }
     if (strlen($storageRecord['maximum_dimension_original_image']) > 0) {
         /** @var \Fab\Media\Dimension $imageDimension */
         $imageDimension = GeneralUtility::makeInstance('Fab\\Media\\Dimension', $storageRecord['maximum_dimension_original_image']);
         if ($currentWidth > $imageDimension->getWidth() || $currentHeight > $imageDimension->getHeight()) {
             // resize taking the width as reference
             $this->resize($uploadedFile->getFileWithAbsolutePath(), $imageDimension->getWidth(), $imageDimension->getHeight());
         }
     }
     return $uploadedFile;
 }
 /**
  * Migrate files to sys_file_references
  *
  * @param array $record
  * @param string $field
  * @return void
  */
 protected function migrateFiles(array $record, $field)
 {
     $filesList = $record['tx_jhopengraphprotocol_ogimage'];
     $files = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $filesList, TRUE);
     if ($files) {
         foreach ($files as $file) {
             if (file_exists(PATH_site . 'uploads/tx_jhopengraphprotocol/' . $file)) {
                 \TYPO3\CMS\Core\Utility\GeneralUtility::upload_copy_move(PATH_site . 'uploads/tx_jhopengraphprotocol/' . $file, $this->targetDirectory . $file);
                 $fileObject = $this->storage->getFile(self::FOLDER_ContentUploads . '/' . $file);
                 $this->fileRepository->add($fileObject);
                 $dataArray = array('uid_local' => $fileObject->getUid(), 'tablenames' => 'pages', 'fieldname' => $field, 'uid_foreign' => $record['uid'], 'table_local' => 'sys_file', 'cruser_id' => self::CruserId, 'pid' => $record['pid'], 'sorting_foreign' => $record['sorting'], 'title' => $record['title']);
                 $GLOBALS['TYPO3_DB']->exec_INSERTquery('sys_file_reference', $dataArray);
             }
         }
     }
 }