/** * Proceeds to a copy of resource provided as argument and stores it. * * @param BaseResource $resource * * @return BaseResource */ public function takeSnapshot($resource) { $res = $this->resource($resource->getUri()); $graph = $resource->getGraph(); foreach ($graph->toRdfPhp() as $resource2 => $properties) { if ($resource2 !== $res->getUri()) { continue; } if (!$this->unitOfWork->isManagementBlackListed($resource2)) { foreach ($properties as $property => $values) { foreach ($values as $value) { if ($value['type'] === 'bnode' || $value['type'] === 'uri') { $this->addResource($resource2, $property, $value['value']); } elseif ($value['type'] === 'literal') { $this->addLiteral($resource2, $property, Literal::create($value['value'], isset($value['lang']) ? $value['lang'] : null, isset($value['datatype']) ? $value['datatype'] : null)); } else { } } } } } return $res; }
/** * @param $resource * * @return BaseResource */ public function replaceResourceInstance(BaseResource $resource) { /** @var BaseResource $managedInstance */ $managedInstance = $this->retrieveResource($resource->getUri()); if (!$managedInstance) { return $resource; } //getting all triples of new resource $properties = $resource->properties(); foreach ($properties as $prop) { $values = $resource->getGraph()->all($resource->getUri(), $prop); foreach ($values as $value) { //var_dump($managedInstance) ; $status = $this->tripleStatus($managedInstance, $prop, $value); //we have no trace of this triple. We can add it to resource AND snapshot if ($status === self::STATUS_TRIPLE_UNKNOWN) { $managedInstance->add($prop, $value); $this->initialSnapshots->add($resource->getUri(), $prop, $value); } } } return $managedInstance; }