/** * Download a resource file content * @param {String} uri Uri of the resource file */ public function downloadFile() { if ($this->hasRequestParameter('uri')) { $uri = tao_helpers_Uri::decode($this->getRequestParameter('uri')); $resource = new core_kernel_classes_Resource($uri); if (core_kernel_versioning_File::isVersionedFile($resource) || core_kernel_file_File::isFile($resource)) { $file = new core_kernel_file_File($uri); $fileName = $file->getOnePropertyValue(new core_kernel_classes_Property(PROPERTY_FILE_FILENAME)); $content = $file->getFileContent(); $size = strlen($content); $mimeType = tao_helpers_File::getMimeType($file->getAbsolutePath(), true); $this->setContentHeader($mimeType); header("Content-Length: {$size}"); header("Content-Disposition: attachment; filename=\"{$fileName}\""); header("Expires: 0"); header("Cache-Control: no-cache, must-revalidate"); header("Pragma: no-cache"); print $content; return; } else { throw new Exception('The resource (' . $uri . ') is not a valid file resource'); } } }
/** * Revert a file * * @access public * @author Cédric Alfonsi, <*****@*****.**> * @param File resource * @param int revision * @param string msg * @return boolean * @see core_kernel_versioning_File::revert() */ public function revert(core_kernel_file_File $resource, $revision = null, $msg = "") { $returnValue = (bool) false; if ($resource->getRepository()->authenticate()) { //no revision, revert local change if (is_null($revision)) { $returnValue = svn_revert($resource->getAbsolutePath()); } else { $path = realpath($resource->getAbsolutePath()); common_Logger::i('svn_revert ' . $path); //get the svn revision number $log = svn_log($path); $oldRevision = count($log) - $revision; if (isset($log[$oldRevision])) { $svnRevision = $log[$oldRevision]; $svnRevisionNumber = $svnRevision['rev']; //destroy the existing version helpers_VersionedFile::rmWorkingCopy($path); //replace with the target revision if ($resource->update($svnRevisionNumber)) { if (is_file($path)) { //get old content $content = $resource->getFileContent(); //update to the current version $resource->update(); //set the new content $resource->setContent($content); //commit the change } if (is_dir($path)) { $i = 10; do { $tmpDir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . uniqid('versionedFolder'); common_Logger::i(__LINE__ . ' ' . $tmpDir); $exists = file_exists($tmpDir); $i--; } while ($exists || !$i); helpers_VersionedFile::cpWorkingCopy($path, $tmpDir); $resource->update(); //@TODO: empty the current folder $path, to delete no longer versioned files helpers_VersionedFile::cpWorkingCopy($tmpDir, $path); } if ($resource->commit($msg)) { $returnValue = true; } else { @helpers_VersionedFile::rmWorkingCopy($path); $resource->update(); } } else { @helpers_VersionedFile::rmWorkingCopy($path); $resource->update(); } } } } return (bool) $returnValue; }