public function testDeepCloneTriplesItemContent() { // create a file / put it in item content property /** @var \core_kernel_versioning_Repository $repository */ $repository = \tao_models_classes_FileSourceService::singleton()->addLocalSource("repository test", \tao_helpers_File::createTempDir()); //see if clone item content works /** @var \core_kernel_versioning_File $file */ $file = $repository->createFile("test.xml", "test"); mkdir($repository->getPath() . 'test'); copy(__DIR__ . '/sample/test.xml', $repository->getPath() . 'test/test.xml'); copy(__DIR__ . '/sample/style.css', $repository->getPath() . 'test/style.css'); $rdfsTriple = new \core_kernel_classes_Triple(); $rdfsTriple->predicate = "http://www.tao.lu/Ontologies/TAOItem.rdf#ItemContent"; $rdfsTriple->object = $file->getUri(); $fileNameProp = new \core_kernel_classes_Property(PROPERTY_FILE_FILENAME); $return = CloneHelper::deepCloneTriples(array($rdfsTriple)); $this->assertNotEquals($rdfsTriple->object, $return[0]->object); $this->assertEquals($rdfsTriple->predicate, $return[0]->predicate); $this->assertCount(1, $return); $returnedFile = new \core_kernel_versioning_File($return[0]->object); $this->assertEquals($returnedFile->getPropertyValues($fileNameProp), $file->getPropertyValues($fileNameProp)); $this->assertNotEquals($file->getAbsolutePath(), $returnedFile->getAbsolutePath()); $files = scandir(dirname($returnedFile->getAbsolutePath())); $this->assertContains('test.xml', $files); $this->assertContains('style.css', $files); $file->delete(true); $returnedFile->delete(true); $repository->delete(true); }
protected static function cloneFile($fileUri) { \common_Logger::i('clone file ' . $fileUri); $file = new \core_kernel_versioning_File($fileUri); $newFile = $file->getRepository()->spawnFile($file->getAbsolutePath(), $file->getLabel(), function ($originalName) { return md5($originalName); }); return $newFile->getUri(); }
protected static function deleteDependencies(\core_kernel_classes_Triple $triple) { if ($triple->predicate == 'http://www.tao.lu/Ontologies/TAOItem.rdf#ItemContent') { $file = new \core_kernel_versioning_File($triple->object); if ($file->exists()) { $sourceDir = dirname($file->getAbsolutePath()); $file->delete(); \tao_helpers_File::delTree($sourceDir); } } elseif (CloneHelper::isFileReference($triple)) { $file = new \core_kernel_versioning_File($triple->object); if ($file->exists()) { $file->delete(); } } }
/** * * @author Lionel Lecaque, lionel@taotesting.com * @param core_kernel_classes_Resource $source * @param core_kernel_classes_Resource $destination * @param core_kernel_classes_Property $property */ protected function cloneInstanceProperty(core_kernel_classes_Resource $source, core_kernel_classes_Resource $destination, core_kernel_classes_Property $property) { $range = $property->getRange(); // Avoid doublons, the RDF TYPE property will be set by the implementation layer if ($property->getUri() != RDF_TYPE) { foreach ($source->getPropertyValuesCollection($property)->getIterator() as $propertyValue) { if (!is_null($range) && $range->getUri() == CLASS_GENERIS_FILE) { $file = new core_kernel_versioning_File($propertyValue->getUri()); $newFile = $file->getRepository()->spawnFile($file->getAbsolutePath(), $file->getLabel()); $destination->setPropertyValue($property, $newFile); } else { $destination->setPropertyValue($property, $propertyValue); } } } }
/** * Override the validate method of the form container to validate * linked elements * * @access public * @author Somsack Sipasseuth, <*****@*****.**> * @return boolean */ public function validate() { $returnValue = (bool) false; if ($this->form->isSubmited()) { if ($this->versionedFile->isVersioned()) { return true; } $fileNameElt = $this->form->getElement(tao_helpers_Uri::encode(PROPERTY_FILE_FILENAME)); $fileName = !is_null($fileNameElt) ? $fileNameElt->getValue() : ''; $filePathElt = $this->form->getElement(tao_helpers_Uri::encode(PROPERTY_FILE_FILEPATH)); $filePath = $filePathElt->getValue(); $fileRepositoryElt = $this->form->getElement(tao_helpers_Uri::encode(PROPERTY_FILE_FILESYSTEM)); $fileRepository = tao_helpers_Uri::decode($fileRepositoryElt->getValue()); //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 => $fileRepository); $sameNameFiles = $clazz->searchInstances($propertyFilter, $options); if (!empty($sameNameFiles)) { $sameFileResource = array_pop($sameNameFiles); $sameFile = new core_kernel_versioning_File($sameFileResource->getUri()); $this->form->valid = false; $this->form->error = __('A similar resource has already been versioned') . ' (' . $sameFile->getAbsolutePath() . ')'; } } return (bool) $returnValue; }
protected function cloneItemContent($source, $destination, $property) { $fileNameProp = new core_kernel_classes_Property(PROPERTY_FILE_FILENAME); foreach ($source->getPropertyValuesCollection($property)->getIterator() as $propertyValue) { $file = new core_kernel_versioning_File($propertyValue->getUri()); $repo = $file->getRepository(); $relPath = basename($file->getAbsolutePath()); if (!empty($relPath)) { $newPath = tao_helpers_File::concat(array($this->getItemFolder($destination), $relPath)); common_Logger::i('copy ' . dirname($file->getAbsolutePath()) . ' to ' . dirname($newPath)); tao_helpers_File::copy(dirname($file->getAbsolutePath()), dirname($newPath), true); if (file_exists($newPath)) { $subpath = substr($newPath, strlen($repo->getPath())); $newFile = $repo->createFile((string) $file->getOnePropertyValue($fileNameProp), dirname($subpath) . '/'); $destination->setPropertyValue($property, $newFile->getUri()); $newFile->add(true, true); $newFile->commit('Clone of ' . $source->getUri(), true); } } } }