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(); }
/** * * @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); } } } }
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); } } } }