/** * @param string $filename */ private function loadDataViaTripod($filename) { $docs = json_decode(file_get_contents(dirname(__FILE__) . $filename), true); foreach ($docs as $d) { $g = new \Tripod\Mongo\MongoGraph(); $g->add_tripod_array($d); $this->tripod->saveChanges(new \Tripod\ExtendedGraph(), $g, $d['_id'][_ID_CONTEXT]); } }
public function testWriteLockedDocDoesNotExposeVersionOrLockPropertyInGraph() { $doc = array("_id" => array("r" => "http://example.com/things/1", "c" => "http://example.com/"), _VERSION => 0, _LOCKED_FOR_TRANS => "transaction_234"); $g = new \Tripod\Mongo\MongoGraph(); $g->add_tripod_array($doc); $this->assertTrue(count($g->get_index()) == 0, "Graph should contain no data"); }
$rawChangeData = $app->request()->post('data'); if ($rawChangeData) { $changeData = json_decode($rawChangeData, true); $from = new \Tripod\Mongo\MongoGraph(); $to = new \Tripod\Mongo\MongoGraph(); if (isset($changeData['originalCBDs'])) { foreach ($changeData['originalCBDs'] as $change) { if (is_array($change) && isset($change[_ID_KEY])) { $from->add_tripod_array($change); } } } if (isset($changeData['newCBDs'])) { foreach ($changeData['newCBDs'] as $change) { if (is_array($change) && isset($change[_ID_KEY])) { $to->add_tripod_array($change); } } } try { $tripod->saveChanges($from, $to); $app->response()->setStatus(202); } catch (Exception $e) { error_log("POST failed: " . $e->getMessage()); $app->response()->setStatus(400); } } }); }); }); });
<?php require_once dirname(__FILE__) . '/common.inc.php'; require_once dirname(dirname(dirname(__FILE__))) . '/src/tripod.inc.php'; if ($argc != 2) { echo "usage: ./BSONToQuads.php tripodConfig.json < bsondata\n"; echo " When exporting bson data from Mongo use: \n"; echo " mongoexport -d <dbname> -c <collectionName> > bsondata.txt \n"; die; } array_shift($argv); $config = json_decode(file_get_contents($argv[0]), true); \Tripod\Mongo\Config::setConfig($config); $tu = new \Tripod\Mongo\TriplesUtil(); while (($line = fgets(STDIN)) !== false) { $line = rtrim($line); $doc = json_decode($line, true); $context = $doc['_id']['c']; $graph = new \Tripod\Mongo\MongoGraph(); $graph->add_tripod_array($doc); echo $graph->to_nquads($context); }