public function testDescribeResourcesWithNamespace() { $noNsG = $this->tripod->describeResources(array('http://basedata.com/b/1'), "http://basedata.com/b/DefaultGraph"); $nsResourceG = $this->tripod->describeResources(array('baseData:1'), "http://basedata.com/b/DefaultGraph"); $nsContextG = $this->tripod->describeResources(array('http://basedata.com/b/1'), "baseData:DefaultGraph"); $nsBothG = $this->tripod->describeResources(array('baseData:1'), "baseData:DefaultGraph"); $nsResourceCs = new \Tripod\ChangeSet(array('before' => $noNsG->get_index(), 'after' => $nsResourceG->get_index(), 'changeReason' => "testing!")); $this->assertFalse($nsResourceCs->has_changes(), "Non ns and nsResource not equal"); $nsContextCS = new \Tripod\ChangeSet(array('before' => $noNsG->get_index(), 'after' => $nsContextG->get_index(), 'changeReason' => "testing!")); $this->assertFalse($nsContextCS->has_changes(), "Non ns and nsContext not equal"); $nsBothCS = new \Tripod\ChangeSet(array('before' => $noNsG->get_index(), 'after' => $nsBothG->get_index(), 'changeReason' => "testing!")); $this->assertFalse($nsBothCS->has_changes(), "Non ns and nsBoth not equal"); }
/** * Create and apply a changeset which is the delta between $oldGraph and $newGraph * @param \Tripod\ExtendedGraph $oldGraph * @param \Tripod\ExtendedGraph $newGraph * @param string|null $context * @param string|null $description * @throws \Exception * @return bool */ public function saveChanges(\Tripod\ExtendedGraph $oldGraph, \Tripod\ExtendedGraph $newGraph, $context = null, $description = null) { $this->applyHooks($this::HOOK_FN_PRE, $this->saveChangesHooks, array("pod" => $this->getPodName(), "oldGraph" => $oldGraph, "newGraph" => $newGraph, "context" => $context)); $this->setReadPreferenceToPrimary(); try { $contextAlias = $this->getContextAlias($context); if (!Config::getInstance()->isPodWithinStore($this->getStoreName(), $this->getPodName())) { throw new \Tripod\Exceptions\Exception("database:collection " . $this->getStoreName() . ":" . $this->getPodName() . " is not referenced within config, so cannot be written to"); } $this->validateGraphCardinality($newGraph); $oldIndex = $oldGraph->get_index(); $newIndex = $newGraph->get_index(); $args = array('before' => $oldIndex, 'after' => $newIndex, 'changeReason' => $description); $cs = new \Tripod\ChangeSet($args); $subjectsAndPredicatesOfChange = array(); $transaction_id = null; if ($cs->has_changes()) { // store the actual CBDs $result = $this->storeChanges($cs, $contextAlias); if (!isset($result['subjectsAndPredicatesOfChange']) || !isset($result['transaction_id'])) { $this->errorLog("Result of storeChanges malformed, should have transaction_id and subjectsAndPredicatesOfChange array keys", array("result" => $result)); throw new Exception("Result of storeChanges malformed, should have transaction_id and subjectsAndPredicatesOfChange array keys"); } extract($result); // will unpack into $subjectsAndPredicatesOfChange // Process any syncronous operations $this->processSyncOperations($subjectsAndPredicatesOfChange, $contextAlias); // Schedule calculation of any async activity $this->queueAsyncOperations($subjectsAndPredicatesOfChange, $contextAlias); } $this->applyHooks($this::HOOK_FN_SUCCESS, $this->saveChangesHooks, array("pod" => $this->getPodName(), "oldGraph" => $oldGraph, "newGraph" => $newGraph, "context" => $context, "changeSet" => $cs, "subjectsAndPredicatesOfChange" => $subjectsAndPredicatesOfChange, "transaction_id" => $transaction_id)); } catch (\Exception $e) { // ensure we reset the original read preference in the event of an exception $this->resetOriginalReadPreference(); $this->applyHooks($this::HOOK_FN_FAILURE, $this->saveChangesHooks, array("pod" => $this->getPodName(), "oldGraph" => $oldGraph, "newGraph" => $newGraph, "context" => $context)); throw $e; } $this->resetOriginalReadPreference(); return true; }