/** * Set contents of a file object. * * @param \TYPO3\CMS\Core\Resource\AbstractFile $file * @param string $contents * @return integer The number of bytes written to the file * @throws \RuntimeException * @throws Exception\InsufficientFileWritePermissionsException * @throws Exception\InsufficientUserPermissionsException */ public function setFileContents(\TYPO3\CMS\Core\Resource\AbstractFile $file, $contents) { // Check if user is allowed to edit if (!$this->checkUserActionPermission('edit', 'File')) { throw new Exception\InsufficientUserPermissionsException('Updating file "' . $file->getIdentifier() . '" not allowed for user.', 1330121117); } // Check if $file is writable if (!$this->checkFileActionPermission('write', $file)) { throw new Exception\InsufficientFileWritePermissionsException('Writing to file "' . $file->getIdentifier() . '" is not allowed.', 1330121088); } // Call driver method to update the file and update file properties afterwards try { $result = $this->driver->setFileContents($file, $contents); $fileInfo = $this->driver->getFileInfo($file); $fileInfo['sha1'] = $this->driver->hash($file, 'sha1'); $file->updateProperties($fileInfo); } catch (\RuntimeException $e) { throw $e; } return $result; }