/** * Short description of method authenticate * * @access public * @author Joel Bout, <*****@*****.**> * @param Repository vcs * @param string login * @param string password * @return boolean */ public function authenticate(core_kernel_versioning_Repository $vcs, $login, $password) { $returnValue = (bool) false; common_Logger::i(__FUNCTION__ . ' called on local directory', 'LOCALVCS'); $returnValue = is_dir($vcs->getPath()); return (bool) $returnValue; }
protected function tearDown() { helpers_File::remove($this->directory); if ($this->repository != null) { $directory = $this->repository->getPath(); $this->repository->delete(); parent::tearDown(); } else { throw new common_Exception('Repository should never be null'); } }
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()); }
/** * 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; }
/** * Short description of method checkout * * @access public * @author Cédric Alfonsi, <*****@*****.**> * @param Repository vcs * @param string url * @param string path * @param int revision * @return boolean */ public function checkout(core_kernel_versioning_Repository $vcs, $url, $path, $revision = null) { $returnValue = (bool) false; try { $url = $vcs->getOnePropertyValue(new core_kernel_classes_Property(PROPERTY_GENERIS_VERSIONEDREPOSITORY_URL)); $path = $vcs->getOnePropertyValue(new core_kernel_classes_Property(PROPERTY_GENERIS_VERSIONEDREPOSITORY_PATH)); if (empty($url)) { throw new common_Exception(__CLASS__ . ' -> ' . __FUNCTION__ . '() : the url must be specified'); } if (empty($path)) { throw new common_Exception(__CLASS__ . ' -> ' . __FUNCTION__ . '() : the path must be specified'); } $returnValue = core_kernel_versioning_subversionWindows_Utils::exec($vcs, 'checkout "' . $url . '" "' . $path . '" 2>&1'); } catch (Exception $e) { die('Error code `svn_error_checkout` in ' . $e->getMessage()); } return (bool) $returnValue; }
private static function getFSInfo(core_kernel_versioning_Repository $fileSystem) { if (is_null(self::$cache)) { try { self::$cache = common_cache_FileCache::singleton()->get(self::SERIAL); } catch (common_cache_NotFoundException $e) { self::$cache = array(); } } if (!isset(self::$cache[$fileSystem->getUri()])) { $props = $fileSystem->getPropertiesValues(array(PROPERTY_GENERIS_VERSIONEDREPOSITORY_PATH, PROPERTY_GENERIS_VERSIONEDREPOSITORY_TYPE)); if (count($props[PROPERTY_GENERIS_VERSIONEDREPOSITORY_PATH]) == 1 && count($props[PROPERTY_GENERIS_VERSIONEDREPOSITORY_TYPE]) == 1) { self::$cache[$fileSystem->getUri()] = array(PROPERTY_GENERIS_VERSIONEDREPOSITORY_PATH => current($props[PROPERTY_GENERIS_VERSIONEDREPOSITORY_PATH]), PROPERTY_GENERIS_VERSIONEDREPOSITORY_TYPE => current($props[PROPERTY_GENERIS_VERSIONEDREPOSITORY_TYPE])); common_cache_FileCache::singleton()->put(self::$cache, self::SERIAL); } else { throw new common_exception_InconsistentData('Filesystem ' . $fileSystem->getUri() . ' has ' . count($props[PROPERTY_GENERIS_VERSIONEDREPOSITORY_PATH]) . ' path entries and ' . count($props[PROPERTY_GENERIS_VERSIONEDREPOSITORY_PATH]) . ' type entries'); } } return self::$cache[$fileSystem->getUri()]; }
/** * 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; }
/** * Set the default file source for TAO File Upload. * * @access public * @author Jerome Bogaerts, <*****@*****.**> * @param Repository source The repository to be used as the default TAO File Upload Source. * @return void */ public function setUploadFileSource(core_kernel_versioning_Repository $source) { $ext = common_ext_ExtensionsManager::singleton()->getExtensionById('tao'); $ext->setConfig(self::CONFIG_UPLOAD_FILESOURCE, $source->getUri()); }
/** * sets the filesource to use for new items * * @access public * @author Joel Bout, <*****@*****.**> * @param Repository filesource * @return mixed */ public function setDefaultFilesource(core_kernel_versioning_Repository $filesource) { $ext = common_ext_ExtensionsManager::singleton()->getExtensionById('taoItems'); $ext->setConfig(self::CONFIG_DEFAULT_FILESOURCE, $filesource->getUri()); }
private function getOneRepository() { $repository = null; if (!is_null($this->defaultRepository) && $this->defaultRepository instanceof core_kernel_versioning_Repository) { $repository = $this->defaultRepository; } else { $versioningRepositoryClass = new core_kernel_classes_Class(CLASS_GENERIS_VERSIONEDREPOSITORY); $repositories = $versioningRepositoryClass->getInstances(); $repository = null; if (!count($repositories)) { throw new Exception('no default repository exists in TAO'); } else { $repository = array_pop($repositories); $repository = new core_kernel_versioning_Repository($repository->getUri()); $this->defaultRepository = $repository; } } return $repository; }
/** * List repository content at a given revision * * @access public * @author Cédric Alfonsi, <*****@*****.**> * @param Repository vcs * @param string path * @param int revision * @return array */ public function listContent(core_kernel_versioning_Repository $vcs, $path, $revision = null) { $returnValue = array(); $startTime = helpers_Time::getMicroTime(); if ($vcs->authenticate()) { $svnList = svn_ls($path, $revision); foreach ($svnList as $svnEntry) { $returnValue[] = array('name' => $svnEntry['name'], 'type' => $svnEntry['type'], 'revision' => $svnEntry['created_rev'], 'author' => $svnEntry['last_author'], 'time' => $svnEntry['time_t']); } } $endTime = helpers_Time::getMicroTime(); common_Logger::i("svn_listContent (" . $path . ') -> ' . ($endTime - $startTime) . 's'); return (array) $returnValue; }