コード例 #1
0
ファイル: createTables.php プロジェクト: talis/tripod-php
/**
 * @param string|null $id
 * @param string|null $tableId
 * @param string|null $storeName
 * @param \Tripod\ITripodStat|null $stat
 * @param string|null $queue
 */
function generateTables($id, $tableId, $storeName, $stat = null, $queue = null)
{
    $tableSpec = \Tripod\Mongo\Config::getInstance()->getTableSpecification($storeName, $tableId);
    if (array_key_exists("from", $tableSpec)) {
        \Tripod\Mongo\Config::getInstance()->setMongoCursorTimeout(-1);
        print "Generating {$tableId}";
        $tripod = new \Tripod\Mongo\Driver($tableSpec['from'], $storeName, array('stat' => $stat));
        $tTables = $tripod->getTripodTables();
        if ($id) {
            print " for {$id}....\n";
            $tTables->generateTableRows($tableId, $id);
        } else {
            print " for all tables....\n";
            $tTables->generateTableRows($tableId, null, null, $queue);
        }
    }
}
コード例 #2
0
/**
 * @param string|null $id
 * @param string|null $specId
 * @param string|null $storeName
 * @param \Tripod\iTripodStat|null $stat
 * @param string|null $queue
 */
function generateSearchDocuments($id, $specId, $storeName, $stat = null, $queue = null)
{
    $spec = \Tripod\Mongo\Config::getInstance()->getSearchDocumentSpecification($storeName, $specId);
    if (array_key_exists("from", $spec)) {
        \Tripod\Mongo\Config::getInstance()->setMongoCursorTimeout(-1);
        print "Generating {$specId}";
        $tripod = new \Tripod\Mongo\Driver($spec['from'], $storeName, array('stat' => $stat));
        $search = $tripod->getSearchIndexer();
        if ($id) {
            print " for {$id}....\n";
            $search->generateSearchDocuments($specId, $id, null, $queue);
        } else {
            print " for all tables....\n";
            $search->generateSearchDocuments($specId, null, null, $queue);
        }
    }
}
コード例 #3
0
ファイル: createViews.php プロジェクト: talis/tripod-php
/**
 * @param string|null $id
 * @param string|null $viewId
 * @param string $storeName
 * @param \Tripod\ITripodStat|null $stat
 * @param string $queue
 */
function generateViews($id, $viewId, $storeName, $stat, $queue)
{
    $viewSpec = \Tripod\Mongo\Config::getInstance()->getViewSpecification($storeName, $viewId);
    if (array_key_exists("from", $viewSpec)) {
        \Tripod\Mongo\Config::getInstance()->setMongoCursorTimeout(-1);
        print "Generating {$viewId}";
        $tripod = new \Tripod\Mongo\Driver($viewSpec['from'], $storeName, array('stat' => $stat));
        $views = $tripod->getTripodViews();
        if ($id) {
            print " for {$id}....\n";
            $views->generateView($viewId, $id, null, $queue);
        } else {
            print " for all views....\n";
            $views->generateView($viewId, null, null, $queue);
        }
    }
}
コード例 #4
0
ファイル: index.php プロジェクト: talis/tripod-php
     });
     $app->post('/', function ($storeName, $podName) use($app, $tripodOptions) {
         $tripodOptions['statsConfig'] = getStat($app, $tripodOptions);
         $tripod = new \Tripod\Mongo\Driver($podName, $storeName, $tripodOptions);
         $rawGraphData = $app->request()->getBody();
         $graph = new \Tripod\Mongo\MongoGraph();
         $graph->add_rdf($rawGraphData);
         $tripod->saveChanges(new \Tripod\ExtendedGraph(), $graph);
     });
 });
 $app->group('/change', function () use($app, $tripodOptions) {
     $app->post('/', function ($storeName, $podName) use($app, $tripodOptions) {
         \Tripod\Mongo\Config::setConfig(json_decode(file_get_contents('./config/tripod-config-' . $storeName . '.json'), true));
         $app->response()->setStatus(500);
         $tripodOptions['statsConfig'] = getStat($app, $tripodOptions);
         $tripod = new \Tripod\Mongo\Driver($podName, $storeName, $tripodOptions);
         $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])) {
コード例 #5
0
 public function testSavingToAPreviouslyEmptyJoinUpdatesView()
 {
     // create a tripod with views sync
     $tripod = new \Tripod\Mongo\Driver("CBD_testing", "tripod_php_testing", array("defaultContext" => "http://talisaspire.com/", "async" => array(OP_VIEWS => false)));
     // should be no triples with "http://basedata.com/b/sequence123" as subject in existing view
     $view = $tripod->getViewForResource("http://basedata.com/b/docWithEmptySeq123", "v_doc_with_seqeunce");
     $this->assertTrue($view->has_triples_about("http://basedata.com/b/docWithEmptySeq123"));
     $this->assertFalse($view->has_triples_about("http://schemas.talis.com/2005/user/schema#xyz"));
     $newGraph = new \Tripod\ExtendedGraph();
     $newGraph->add_literal_triple("http://schemas.talis.com/2005/user/schema#xyz", "http://rdfs.org/sioc/spec/name", "Some name");
     $tripod->saveChanges(new \Tripod\ExtendedGraph(), $newGraph);
     // should be triples with "http://basedata.com/b/sequence123" as subject in new view
     $view = $tripod->getViewForResource("http://basedata.com/b/docWithEmptySeq123", "v_doc_with_seqeunce");
     $this->assertTrue($view->has_triples_about("http://basedata.com/b/docWithEmptySeq123"));
     $this->assertTrue($view->has_triples_about("http://schemas.talis.com/2005/user/schema#xyz"));
 }
コード例 #6
0
 public function testDeleteResourceCreatesImpactedSubjects()
 {
     $uri = 'http://example.com/users/' . uniqid();
     $labeller = new \Tripod\Mongo\Labeller();
     $uriAlias = $labeller->uri_to_alias($uri);
     $graph = new \Tripod\ExtendedGraph();
     $graph->add_resource_triple($uri, RDF_TYPE, $labeller->qname_to_uri('spec:User'));
     $graph->add_literal_triple($uri, $labeller->qname_to_uri('foaf:firstName'), 'Anne');
     $graph->add_literal_triple($uri, $labeller->qname_to_uri('foaf:surname'), 'Onymous');
     $uri2 = 'http://example.com/users/' . uniqid();
     $uriAlias2 = $labeller->uri_to_alias($uri2);
     $graph2 = new \Tripod\ExtendedGraph();
     $graph2->add_resource_triple($uri2, RDF_TYPE, $labeller->qname_to_uri('spec:User'));
     $graph2->add_literal_triple($uri2, $labeller->qname_to_uri('foaf:firstName'), 'Ann');
     $graph2->add_literal_triple($uri2, $labeller->qname_to_uri('foaf:surname'), 'O\'ther');
     // Save the graphs and ensure that table rows are generated
     $tripod = new \Tripod\Mongo\Driver($this->defaultPodName, $this->defaultStoreName, array('defaultContext' => $this->defaultContext, OP_ASYNC => array(OP_VIEWS => false, OP_TABLES => false, OP_SEARCH => false)));
     $tripod->saveChanges(new \Tripod\ExtendedGraph(), $graph);
     $tableRows = $tripod->getTableRows('t_users', array(_ID_KEY . '.' . _ID_RESOURCE => $uriAlias, _ID_KEY . '.' . _ID_CONTEXT => $this->defaultContext));
     $this->assertEquals(1, $tableRows['head']['count']);
     $tripod->saveChanges(new \Tripod\ExtendedGraph(), $graph2);
     $tableRows = $tripod->getTableRows('t_users', array(_ID_KEY . '.' . _ID_RESOURCE => $uriAlias2, _ID_KEY . '.' . _ID_CONTEXT => $this->defaultContext));
     $this->assertEquals(1, $tableRows['head']['count']);
     /** @var \Tripod\Mongo\Driver|PHPUnit_Framework_MockObject_MockObject $mockTripod */
     $mockTripod = $this->getMockBuilder('\\Tripod\\Mongo\\Driver')->setMethods(array('getDataUpdater'))->setConstructorArgs(array($this->defaultPodName, $this->defaultStoreName, array('defaultContext' => $this->defaultContext, OP_ASYNC => array(OP_VIEWS => false, OP_TABLES => false, OP_SEARCH => false))))->getMock();
     /** @var \Tripod\Mongo\Updates|PHPUnit_Framework_MockObject_MockObject $mockUpdates */
     $mockTripodUpdates = $this->getMockBuilder('\\Tripod\\Mongo\\Updates')->setConstructorArgs(array($mockTripod, array('defaultContext' => $this->defaultContext, OP_ASYNC => array(OP_VIEWS => false, OP_TABLES => false, OP_SEARCH => false))))->setMethods(array('processSyncOperations'))->getMock();
     $mockTripod->expects($this->once())->method('getDataUpdater')->will($this->returnValue($mockTripodUpdates));
     $expectedSubjectsAndPredicatesOfChange = array($uriAlias => array('rdf:type', 'foaf:firstName', 'foaf:surname'), $uriAlias2 => array('rdf:type', 'foaf:firstName', 'foaf:surname'));
     $mockTripodUpdates->expects($this->once())->method('processSyncOperations')->with($expectedSubjectsAndPredicatesOfChange, $this->defaultContext);
     $graph->add_graph($graph2);
     // Delete both user resources
     $mockTripod->saveChanges($graph, new \Tripod\ExtendedGraph());
     $deletedGraph = $mockTripod->describeResources(array($uri, $uri2));
     $this->assertTrue($deletedGraph->is_empty());
     // Manually walk through the tables operation
     /** @var \Tripod\Mongo\Composites\Tables $tables */
     $tables = $mockTripod->getComposite(OP_TABLES);
     $expectedImpactedSubjects = array(new \Tripod\Mongo\ImpactedSubject(array(_ID_RESOURCE => $uriAlias, _ID_CONTEXT => $this->defaultContext), OP_TABLES, $this->defaultStoreName, $this->defaultPodName, array('t_users')), new \Tripod\Mongo\ImpactedSubject(array(_ID_RESOURCE => $uriAlias2, _ID_CONTEXT => $this->defaultContext), OP_TABLES, $this->defaultStoreName, $this->defaultPodName, array('t_users')));
     $this->assertEquals($expectedImpactedSubjects, $tables->getImpactedSubjects($expectedSubjectsAndPredicatesOfChange, $this->defaultContext));
     foreach ($expectedImpactedSubjects as $subject) {
         $tables->update($subject);
     }
     $tableRows = $tripod->getTableRows('t_users', array(_ID_KEY . '.' . _ID_RESOURCE => $uriAlias, _ID_KEY . '.' . _ID_CONTEXT => $this->defaultContext));
     $this->assertEquals(0, $tableRows['head']['count']);
     $tableRows = $tripod->getTableRows('t_users', array(_ID_KEY . '.' . _ID_RESOURCE => $uriAlias2, _ID_KEY . '.' . _ID_CONTEXT => $this->defaultContext));
     $this->assertEquals(0, $tableRows['head']['count']);
 }
コード例 #7
0
 /** START: getETag tests */
 public function testEtagIsMicrotimeFormat()
 {
     $config = \Tripod\Mongo\Config::getInstance();
     $updatedAt = \Tripod\Mongo\DateUtil::getMongoDate();
     $_id = array('r' => 'http://talisaspire.com/resources/testEtag', 'c' => 'http://talisaspire.com/');
     $doc = array('_id' => $_id, 'dct:title' => array('l' => 'etag'), '_version' => 0, '_cts' => $updatedAt, '_uts' => $updatedAt);
     $config->getCollectionForCBD('tripod_php_testing', 'CBD_testing')->insertOne($doc, array("w" => 1));
     $tripod = new \Tripod\Mongo\Driver('CBD_testing', 'tripod_php_testing', array('defaultContext' => 'http://talisaspire.com/'));
     $this->assertRegExp('/^0.[0-9]{8} [0-9]{10}/', $tripod->getETag($_id['r']));
 }
コード例 #8
0
 public function testDeleteResourceCreatesImpactedSubjects()
 {
     $uri = 'http://example.com/resources/' . uniqid();
     $labeller = new Tripod\Mongo\Labeller();
     $uriAlias = $labeller->uri_to_alias($uri);
     $creatorUri = 'http://example.com/identities/oscar-wilde';
     $creatorUriAlias = $labeller->uri_to_alias($creatorUri);
     $graph = new \Tripod\ExtendedGraph();
     $graph->add_resource_triple($uri, RDF_TYPE, $labeller->qname_to_uri('acorn:Resource'));
     $graph->add_resource_triple($uri, RDF_TYPE, $labeller->qname_to_uri('bibo:Book'));
     $graph->add_literal_triple($uri, $labeller->qname_to_uri('dct:title'), 'The Importance of Being Earnest');
     $graph->add_literal_triple($uri, $labeller->qname_to_uri('dct:subject'), 'Plays -- Satire');
     $graph->add_resource_triple($uri, $labeller->qname_to_uri('dct:creator'), $creatorUri);
     $uri2 = 'http://example.com/resources/' . uniqid();
     $uriAlias2 = $labeller->uri_to_alias($uri2);
     $graph2 = new \Tripod\ExtendedGraph();
     $graph2->add_resource_triple($uri2, RDF_TYPE, $labeller->qname_to_uri('acorn:Resource'));
     $graph2->add_resource_triple($uri2, RDF_TYPE, $labeller->qname_to_uri('bibo:Book'));
     $graph2->add_literal_triple($uri2, $labeller->qname_to_uri('dct:title'), 'The Picture of Dorian Gray');
     $graph2->add_literal_triple($uri2, $labeller->qname_to_uri('dct:subject'), 'Portraits -- Fiction');
     $graph2->add_resource_triple($uri2, $labeller->qname_to_uri('dct:creator'), $creatorUri);
     $graph3 = new \Tripod\ExtendedGraph();
     $graph3->add_resource_triple($creatorUri, RDF_TYPE, $labeller->qname_to_uri('foaf:Person'));
     $graph3->add_literal_triple($creatorUri, $labeller->qname_to_uri('foaf:name'), 'Oscar Wilde');
     // Save the graphs and ensure that table rows are generated
     $tripod = new \Tripod\Mongo\Driver($this->defaultPodName, $this->defaultStoreName, array('defaultContext' => $this->defaultContext, OP_ASYNC => array(OP_VIEWS => false, OP_TABLES => false, OP_SEARCH => false)));
     // Save the author graph first so the joins work
     $tripod->saveChanges(new \Tripod\ExtendedGraph(), $graph3);
     $tripod->saveChanges(new \Tripod\ExtendedGraph(), $graph);
     $collection = \Tripod\Mongo\Config::getInstance()->getCollectionForSearchDocument($this->defaultStoreName, 'i_search_resource');
     $query = array(_ID_KEY => array(_ID_RESOURCE => $uriAlias, _ID_CONTEXT => $this->defaultContext, _ID_TYPE => 'i_search_resource'));
     $this->assertEquals(1, $collection->count($query));
     $tripod->saveChanges(new \Tripod\ExtendedGraph(), $graph2);
     $query[_ID_KEY][_ID_RESOURCE] = $uriAlias2;
     $this->assertEquals(1, $collection->count($query));
     $impactQuery = array(_ID_KEY . '.' . _ID_TYPE => 'i_search_resource', '_impactIndex' => array(_ID_RESOURCE => $creatorUriAlias, _ID_CONTEXT => $this->defaultContext), 'result.author' => 'Oscar Wilde');
     $this->assertEquals(2, $collection->count($impactQuery));
     /** @var \Tripod\Mongo\Driver|PHPUnit_Framework_MockObject_MockObject $mockTripod */
     $mockTripod = $this->getMockBuilder('\\Tripod\\Mongo\\Driver')->setMethods(array('getDataUpdater'))->setConstructorArgs(array($this->defaultPodName, $this->defaultStoreName, array('defaultContext' => $this->defaultContext, OP_ASYNC => array(OP_VIEWS => false, OP_TABLES => false, OP_SEARCH => false))))->getMock();
     $mockTripodUpdates = $this->getMockBuilder('\\Tripod\\Mongo\\Updates')->setConstructorArgs(array($mockTripod, array('defaultContext' => $this->defaultContext, OP_ASYNC => array(OP_VIEWS => false, OP_TABLES => false, OP_SEARCH => false))))->setMethods(array('processSyncOperations'))->getMock();
     $mockTripod->expects($this->once())->method('getDataUpdater')->will($this->returnValue($mockTripodUpdates));
     $expectedSubjectsAndPredicatesOfChange = array($creatorUriAlias => array('rdf:type', 'foaf:name'));
     $mockTripodUpdates->expects($this->once())->method('processSyncOperations')->with($expectedSubjectsAndPredicatesOfChange, $this->defaultContext);
     // Delete creator resource
     $mockTripod->saveChanges($graph3, new \Tripod\ExtendedGraph());
     $deletedGraph = $mockTripod->describeResource($creatorUri);
     $this->assertTrue($deletedGraph->is_empty());
     // Manually walk through the tables operation
     /** @var \Tripod\Mongo\Composites\SearchIndexer $search */
     $search = $mockTripod->getComposite(OP_SEARCH);
     $expectedImpactedSubjects = array(new \Tripod\Mongo\ImpactedSubject(array(_ID_RESOURCE => $uriAlias, _ID_CONTEXT => $this->defaultContext), OP_SEARCH, $this->defaultStoreName, $this->defaultPodName, array('i_search_resource')), new \Tripod\Mongo\ImpactedSubject(array(_ID_RESOURCE => $uriAlias2, _ID_CONTEXT => $this->defaultContext), OP_SEARCH, $this->defaultStoreName, $this->defaultPodName, array('i_search_resource')));
     $this->assertEquals($expectedImpactedSubjects, $search->getImpactedSubjects($expectedSubjectsAndPredicatesOfChange, $this->defaultContext));
     foreach ($expectedImpactedSubjects as $subject) {
         $search->update($subject);
     }
     $query = array(_ID_KEY => array(_ID_RESOURCE => $uriAlias, _ID_CONTEXT => $this->defaultContext, _ID_TYPE => 'i_search_resource'));
     $this->assertEquals(1, $collection->count($query));
     $query[_ID_KEY][_ID_RESOURCE] = $uriAlias2;
     $this->assertEquals(1, $collection->count($query));
     // Deleted resource will still be impact indexes because join still exists
     $impactQuery = array(_ID_KEY . '.' . _ID_TYPE => 'i_search_resource', '_impactIndex' => array(_ID_RESOURCE => $creatorUriAlias, _ID_CONTEXT => $this->defaultContext));
     $this->assertEquals(2, $collection->count($impactQuery));
     // But the document should have been regenerated without the value
     $impactQuery['result.author'] = 'Oscar Wilde';
     $this->assertEquals(0, $collection->count($impactQuery));
 }