Пример #1
0
 public function testSetGetFileContent()
 {
     $file = $this->fileSource->createFile('toto.txt', null);
     $file->setContent('toto is kite surfing !!! le ouf');
     $fileContent = $file->getFileContent();
     $this->assertEquals($fileContent, 'toto is kite surfing !!! le ouf');
     $this->assertTrue($file->delete(true));
     $file = $this->fileSource->createFile('', sys_get_temp_dir());
     $this->setExpectedException('common_Exception');
     $fileContent = $file->getFileContent();
     $this->assertTrue($file->delete());
 }
Пример #2
0
 /**
  * Short description of method createVersioned
  *
  * @access public
  * @author Lionel Lecaque, <*****@*****.**>
  * @param  string filename
  * @param  relativeFilePath
  * @param  Repository repository
  * @param  string uri
  * @param  array options
  * @return core_kernel_versioning_File
  * @deprecated
  */
 public static function createVersioned($filename, $relativeFilePath = null, core_kernel_versioning_Repository $repository = null, $uri = '', $options = array())
 {
     $returnValue = null;
     $returnValue = $repository->createFile($filename, $relativeFilePath);
     /*
             $repositoryPath = $repository->getPath();
             //add a slash at the end of the repository path if it does not exist
             $repositoryPath = substr($repositoryPath,strlen($repositoryPath)-1,1)==DIRECTORY_SEPARATOR ? $repositoryPath : $repositoryPath.DIRECTORY_SEPARATOR;
             //remove the first slash of the relative path if it exists
             $relativeFilePath = count($relativeFilePath) && $relativeFilePath[0]==DIRECTORY_SEPARATOR ? substr($relativeFilePath,1) : $relativeFilePath;
             //if the relative file path exists format the string
             $relativeFilePath = file_exists($relativeFilePath) ? realpath($relativeFilePath) : $relativeFilePath;
             //add a slash at the end of the relative file path unless the relative file path is empty
             //$relativeFilePath = empty($relativeFilePath) || substr($relativeFilePath,strlen($relativeFilePath)-1,1)==DIRECTORY_SEPARATOR ? $relativeFilePath : $relativeFilePath.DIRECTORY_SEPARATOR;
             
             //build the file path
             $filePath = $repositoryPath.$relativeFilePath;
             
             //Quick hack
             //@todo document and make the change clear
             $filePath = file_exists($filePath) ? realpath($filePath) : $filePath;
             //add directory separator at the end of the file path
             $filePath = substr($filePath,strlen($filePath)-1,1)==DIRECTORY_SEPARATOR ? $filePath : $filePath.DIRECTORY_SEPARATOR;
             
             //check if a resource with the same path exists yet in the repository
             $clazz = new core_kernel_classes_Class(CLASS_GENERIS_FILE);
             $options = array('like' => false, 'recursive' => true);
     		$propertyFilter = array(
     			PROPERTY_FILE_FILENAME => $filename,
     			PROPERTY_FILE_FILEPATH => $filePath,
     			PROPERTY_FILE_FILESYSTEM => $repository
     		);
             $sameNameFiles = $clazz->searchInstances($propertyFilter, $options);
             if(!empty($sameNameFiles)){
             	throw new core_kernel_versioning_exception_Exception(__('A file with the name "'.$filename.'" already exists at the location '.$repositoryPath.$filePath));
             }
             
             $instance = parent::create($filename, $filePath, $uri);
             $returnValue = new core_kernel_versioning_File($instance);
             
             // Add versioned file path, path of the file in the repository
     $versionedFilePathProp = new core_kernel_classes_Property(PROPERTY_FILE_FILEPATH);
     $instance->setPropertyValue($versionedFilePathProp, $relativeFilePath);
     
     // Add repository
     $versionedFileRepositoryProp = new core_kernel_classes_Property(PROPERTY_FILE_FILESYSTEM);
     $instance->setPropertyValue($versionedFileRepositoryProp, $repository);
     */
     return $returnValue;
 }
 /**
  * Create the defautl content directory of a QTI test.
  *
  * @param core_kernel_classes_Resource $test
  * @param boolean $createTestFile Whether or not create an empty QTI XML test file. Default is (boolean) true.
  * @return core_kernel_file_File the content file
  * @throws taoQtiTest_models_classes_QtiTestServiceException If a runtime error occurs while creating the test content.
  */
 public function createContent(core_kernel_classes_Resource $test, $createTestFile = true)
 {
     $props = self::getQtiTestDirectory()->getPropertiesValues(array(PROPERTY_FILE_FILESYSTEM, PROPERTY_FILE_FILEPATH));
     $repository = new core_kernel_versioning_Repository(current($props[PROPERTY_FILE_FILESYSTEM]));
     $path = (string) current($props[PROPERTY_FILE_FILEPATH]);
     // $directory is the directory where test related resources will be stored.
     $directory = $repository->createFile('', $path . DIRECTORY_SEPARATOR . md5($test->getUri()) . DIRECTORY_SEPARATOR);
     $dirPath = $directory->getAbsolutePath() . DIRECTORY_SEPARATOR;
     if (!file_exists($dirPath)) {
         mkdir($dirPath, 0770, true);
     }
     if ($createTestFile === true) {
         $emptyTestXml = $this->getQtiTestTemplateFileAsString();
         $doc = new DOMDocument();
         $doc->loadXML($emptyTestXml);
         // Set the test label as title.
         $doc->documentElement->setAttribute('title', $test->getLabel());
         //generate a valid qti identifier
         $identifier = tao_helpers_Display::textCleaner($test->getLabel(), '*', 32);
         $identifier = str_replace('_', '-', $identifier);
         if (preg_match('/^[0-9]/', $identifier)) {
             $identifier = '_' . $identifier;
         }
         $doc->documentElement->setAttribute('identifier', $identifier);
         $doc->documentElement->setAttribute('toolVersion', TAO_VERSION);
         $filePath = $dirPath . TAOQTITEST_FILENAME;
         if ($doc->save($filePath) === false) {
             $msg = "Unable to write raw QTI Test template at location '{$filePath}'.";
             throw new taoQtiTest_models_classes_QtiTestServiceException($msg, taoQtiTest_models_classes_QtiTestServiceException::TEST_WRITE_ERROR);
         }
         common_Logger::i("Created QTI Test content at location '" . $filePath . "'.");
     }
     $test->editPropertyValues(new core_kernel_classes_Property(TEST_TESTCONTENT_PROP), $directory);
     return $directory;
 }
Пример #4
0
 /**
  * Import specific source from the repository to the given target at the given revision
  *
  * @access public
  * @author Cédric Alfonsi, <*****@*****.**>
  * @param  Repository vcs
  * @param  string src
  * @param  string target
  * @param  string message
  * @param  array options
  * @return core_kernel_file_File
  */
 public function import(core_kernel_versioning_Repository $vcs, $src, $target, $message = "", $options = array())
 {
     $returnValue = null;
     //Does not work in the current version of php (try later) https://bugs.php.net/bug.php?id=60293
     //$returnValue = svn_import($src, $target, true);
     $startTime = helpers_Time::getMicroTime();
     $saveResource = isset($options['saveResource']) && $options['saveResource'] ? true : false;
     if (!$vcs->authenticate()) {
         throw new core_kernel_versioning_exception_Exception('Authentication failed on fileSource ' . $vcs->getUri());
     }
     $repositoryUrl = $vcs->getUrl();
     $relativePath = substr($target, strlen($repositoryUrl));
     $absolutePath = $vcs->getPath() . $relativePath;
     /*
     // The resource could already exist, this is not a problem
     //check if the resource already exist
     if(helpers_File::resourceExists($absolutePath)){
     	throw new core_kernel_versioning_exception_ResourceAlreadyExistsException('The folder ('.$absolutePath.') already exists in the repository ('.$vcs->getPath().')');
     }
     // Same thing here
     //check if the file already exist
     else if(file_exists($absolutePath)){
     	throw new common_exception_FileAlreadyExists($absolutePath);
     }
     */
     //Copy the src folder to the target destination
     helpers_File::copy($src, $absolutePath);
     // Create the importFolder
     $importFolder = $vcs->createFile('', $relativePath);
     //			//Get status of the imported folder
     //			$importFolderStatus = $importFolder->getStatus(array('SHOW_UPDATES'=>false));
     //			$importFolderYetCommited = true;
     //			if($importFolderStatus == VERSIONING_FILE_STATUS_ADDED || $importFolderStatus == VERSIONING_FILE_STATUS_UNVERSIONED){
     //				$importFolderYetCommited = false;
     //			}
     //
     //			//If the import folder has been yet commited, commit its content
     //			if($importFolderYetCommited){
     //				$filesToCommit = tao_helpers_File::scandir($importFolder->getAbsolutePath());
     //				$pathsFilesToCommit = array();
     //				foreach($filesToCommit as $fileToCommit){
     //					$pathFileToCommit = $fileToCommit->getAbsolutePath();
     //					$pathsFilesToCommit[] = $pathFileToCommit;
     //					//Add content of the folder if it is not versioned or partially not versioned
     //					if(!core_kernel_versioning_FileProxy::add($importFolder, $pathFileToCommit, true, true)){
     //						throw new core_kernel_versioning_exception_Exception('unable to import the folder ('.$src.') to the destination ('.$target.'). The add step encountered a problem');
     //					}
     //				}
     //				//Commit all the files in one commit operation
     //				if(!core_kernel_versioning_FileProxy::commit($VersionedUnitFolderInstance, $pathsFilesToCommit)){
     //					throw new core_kernel_versioning_exception_Exception('unable to import the folder ('.$src.') to the destination ('.$target.'). The commit step encountered a problem');
     //				}
     //			}
     //			//Else commit itself
     //			else{
     //				//Add the folder
     //				if(!$importFolder->add(true, true)){
     //					throw new core_kernel_versioning_exception_Exception('unable to import the folder ('.$src.') to the destination ('.$target.'). The add step encountered a problem');
     //				}
     //				//And commit it
     //				if(!$importFolder->commit($message, true)){
     //					throw new core_kernel_versioning_exception_Exception('unable to import the folder ('.$src.') to the destination ('.$target.'). The commit step encountered a problem');
     //				}
     //			}
     //Add the folder
     if (!$importFolder->add(true, true)) {
         throw new core_kernel_versioning_exception_Exception('unable to import the folder (' . $src . ') to the destination (' . $target . '). The add step encountered a problem');
     }
     //And commit it
     if (!$importFolder->commit($message, true)) {
         throw new core_kernel_versioning_exception_Exception('unable to import the folder (' . $src . ') to the destination (' . $target . '). The commit step encountered a problem');
     }
     //Delete the resource if the developer does not want to keep a reference in the onthology
     if ($saveResource) {
         $returnValue = $importFolder;
     } else {
         $resourceToDelete = new core_kernel_classes_Resource($importFolder->getUri());
         $resourceToDelete->delete();
     }
     $endTime = helpers_Time::getMicroTime();
     common_Logger::i("svn_import (" . $src . ' -> ' . $target . ') -> ' . ($endTime - $startTime) . 's');
     return $returnValue;
 }