/**
  * Get Online Media item id
  *
  * @param File $file
  * @return string
  */
 public function getOnlineMediaId(File $file)
 {
     if (!isset($this->onlineMediaIdCache[$file->getUid()])) {
         // By definition these files only contain the ID of the remote media source
         $this->onlineMediaIdCache[$file->getUid()] = trim($file->getContents());
     }
     return $this->onlineMediaIdCache[$file->getUid()];
 }
Example #2
0
 /**
  * Adds a files content from a sys file record to the export memory
  *
  * @param File $file
  * @return void
  */
 public function export_addSysFile(File $file)
 {
     if ($file->getProperty('size') >= $this->maxFileSize) {
         $this->error('File ' . $file->getPublicUrl() . ' was larger (' . GeneralUtility::formatSize($file->getProperty('size')) . ') than the maxFileSize (' . GeneralUtility::formatSize($this->maxFileSize) . ')! Skipping.');
         return;
     }
     $fileContent = '';
     try {
         if (!$this->saveFilesOutsideExportFile) {
             $fileContent = $file->getContents();
         } else {
             $file->checkActionPermission('read');
         }
     } catch (\Exception $e) {
         $this->error('Error when trying to add file ' . $file->getCombinedIdentifier() . ': ' . $e->getMessage());
         return;
     }
     $fileUid = $file->getUid();
     $fileInfo = $file->getStorage()->getFileInfo($file);
     // we sadly have to cast it to string here, because the size property is also returning a string
     $fileSize = (string) $fileInfo['size'];
     if ($fileSize !== $file->getProperty('size')) {
         $this->error('File size of ' . $file->getCombinedIdentifier() . ' is not up-to-date in index! File added with current size.');
         $this->dat['records']['sys_file:' . $fileUid]['data']['size'] = $fileSize;
     }
     $fileSha1 = $file->getStorage()->hashFile($file, 'sha1');
     if ($fileSha1 !== $file->getProperty('sha1')) {
         $this->error('File sha1 hash of ' . $file->getCombinedIdentifier() . ' is not up-to-date in index! File added on current sha1.');
         $this->dat['records']['sys_file:' . $fileUid]['data']['sha1'] = $fileSha1;
     }
     $fileRec = array();
     $fileRec['filesize'] = $fileSize;
     $fileRec['filename'] = $file->getProperty('name');
     $fileRec['filemtime'] = $file->getProperty('modification_date');
     // build unique id based on the storage and the file identifier
     $fileId = md5($file->getStorage()->getUid() . ':' . $file->getProperty('identifier_hash'));
     // Setting this data in the header
     $this->dat['header']['files_fal'][$fileId] = $fileRec;
     if (!$this->saveFilesOutsideExportFile) {
         // ... and finally add the heavy stuff:
         $fileRec['content'] = $fileContent;
     } else {
         GeneralUtility::upload_copy_move($file->getForLocalProcessing(false), $this->getTemporaryFilesPathForExport() . $file->getProperty('sha1'));
     }
     $fileRec['content_sha1'] = $fileSha1;
     $this->dat['files_fal'][$fileId] = $fileRec;
 }
Example #3
0
 /**
  * Get the contents of this file
  *
  * @return string File contents
  */
 public function getContents()
 {
     return $this->originalFile->getContents();
 }
Example #4
0
 /**
  * Adds a files content from a sys file record to the export memory
  *
  * @param \TYPO3\CMS\Core\Resource\File $file
  * @return void
  */
 public function export_addSysFile(\TYPO3\CMS\Core\Resource\File $file)
 {
     if ($file->getProperty('size') >= $this->maxFileSize) {
         $this->error('File ' . $file->getPublicUrl() . ' was larger (' . GeneralUtility::formatSize($file->getProperty('size')) . ') than the maxFileSize (' . GeneralUtility::formatSize($this->maxFileSize) . ')! Skipping.');
         return;
     }
     try {
         $fileContent = $file->getContents();
     } catch (\TYPO3\CMS\Core\Resource\Exception\InsufficientFileAccessPermissionsException $e) {
         $this->error('File ' . $file->getPublicUrl() . ': ' . $e->getMessage());
         return;
     } catch (\TYPO3\CMS\Core\Resource\Exception\IllegalFileExtensionException $e) {
         $this->error('File ' . $file->getPublicUrl() . ': ' . $e->getMessage());
         return;
     }
     $fileUid = $file->getUid();
     $fileInfo = $file->getStorage()->getFileInfo($file);
     // we sadly have to cast it to string here, because the size property is also returning a string
     $fileSize = (string) $fileInfo['size'];
     if ($fileSize !== $file->getProperty('size')) {
         $this->error('File size of ' . $file->getCombinedIdentifier() . ' is not up-to-date in index! File added with current size.');
         $this->dat['records']['sys_file:' . $fileUid]['data']['size'] = $fileSize;
     }
     $fileSha1 = $file->getStorage()->hashFile($file, 'sha1');
     if ($fileSha1 !== $file->getProperty('sha1')) {
         $this->error('File sha1 hash of ' . $file->getCombinedIdentifier() . ' is not up-to-date in index! File added on current sha1.');
         $this->dat['records']['sys_file:' . $fileUid]['data']['sha1'] = $fileSha1;
     }
     $fileRec = array();
     $fileRec['filesize'] = $fileSize;
     $fileRec['filename'] = $file->getProperty('name');
     $fileRec['filemtime'] = $file->getProperty('modification_date');
     // build unique id based on the storage and the file identifier
     $fileId = md5($file->getStorage()->getUid() . ':' . $file->getProperty('identifier_hash'));
     // Setting this data in the header
     $this->dat['header']['files_fal'][$fileId] = $fileRec;
     // ... and finally add the heavy stuff:
     $fileRec['content'] = $fileContent;
     $fileRec['content_sha1'] = $fileSha1;
     $this->dat['files_fal'][$fileId] = $fileRec;
 }
Example #5
0
 /**
  * Takes a file reference and extracts its meta data.
  *
  * @param \TYPO3\CMS\Core\Resource\File $file
  * @return array
  */
 public function extractMetaData(File $file)
 {
     $headers = array(TYPO3_user_agent, 'Accept: application/json', 'Content-Type: application/octet-stream', 'Connection: close');
     $context = stream_context_create(array('http' => array('protocol_version' => 1.1, 'method' => 'PUT', 'header' => implode(CRLF, $headers), 'content' => $file->getContents())));
     $rawResponse = file_get_contents($this->tikaUrl . '/meta', FALSE, $context);
     $response = (array) json_decode($rawResponse);
     return $response;
 }