Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

70%: Introduce namespaces #56

Merged
merged 19 commits into from
May 29, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ Quickstart
```php
require_once("tripod.inc.php");

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update the requirements section of the README to say > php 5.3

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It already does in the branch this is merging into

MongoTripodConfig::setConfig($conf); // set the config, usually read in as JSON from a file
Config::setConfig($conf); // set the config, usually read in as JSON from a file

$tripod = new MongoTripod(
$tripod = new Driver(
"CBD_users", // pod (read: MongoDB collection) we're working with
"myapp" // store (read: MongoDB database) we're working with
);
Expand Down Expand Up @@ -65,7 +65,7 @@ $tripod->saveChanges(
);

// save, but background all the expensive view/table/search generation
$tripod = new MongoTripod("CBD_users", "usersdb", array(
$tripod = new Driver("CBD_users", "usersdb", array(
'async' = array(OP_VIEWS,OP_TABLES,OP_SEARCH) // async opt says what to do later via a queue rather than as part of the save
)
);
Expand All @@ -91,7 +91,7 @@ What does the config look like?

[Read the full docs](/docs/config.md)

Before you can do anything with tripod you need to initialise the config via the ```MongoTripodConfig::setConfig()``` method. This takes an associative array which can generally be decoded from a JSON string. Here's an example:
Before you can do anything with tripod you need to initialise the config via the ```Config::setConfig()``` method. This takes an associative array which can generally be decoded from a JSON string. Here's an example:

```javascript
{
Expand Down
4 changes: 2 additions & 2 deletions docs/config.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Tripod config documentation
===========================

Tripod config is typically defined as a JSON file or stream which is added to the MongoTripodConfig class somewhere early in your application, typically in your includes file or front controller:
Tripod config is typically defined as a JSON file or stream which is added to the Config class somewhere early in your application, typically in your includes file or front controller:

```php
$conf = json_decode(file_get_contents('tripod_config.json');
MongoTripodConfig::setConfig($conf); // set the config, usually read in as JSON from a file
Config::setConfig($conf); // set the config, usually read in as JSON from a file
```

Namespaces
Expand Down
2 changes: 1 addition & 1 deletion docs/primers/tables.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ Usage

```php

$tripod = MongoTripod("CBD_resources", "resources", array("async"=>array(OP_VIEWS=>false, OP_TABLES=>false, OP_SEARCH=>false)));
$tripod = new Driver("CBD_resources", "resources", array("async"=>array(OP_VIEWS=>false, OP_TABLES=>false, OP_SEARCH=>false)));

// Here is the id the tableSpec
$tableSpec = 't_resources';
Expand Down
Empty file added locks.log
Empty file.
6 changes: 3 additions & 3 deletions scripts/mongo/BSONToQuads.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@

array_shift($argv);
$config = json_decode(file_get_contents($argv[0]), true);
MongoTripodConfig::setConfig($config);
\Tripod\Mongo\Config::setConfig($config);

$tu = new TriplesUtil();
$tu = new \Tripod\Mongo\TriplesUtil();

while (($line = fgets(STDIN)) !== false) {
$line = rtrim($line);
$doc = json_decode($line, true);
$context = $doc['_id']['c'];

$graph = new MongoGraph();
$graph = new \Tripod\Mongo\MongoGraph();
$graph->add_tripod_array($doc);

echo $graph->to_nquads($context);
Expand Down
6 changes: 3 additions & 3 deletions scripts/mongo/BSONToTriples.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
}
array_shift($argv);
$config = json_decode(file_get_contents($argv[0]), true);
MongoTripodConfig::setConfig($config);
\Tripod\Mongo\Config::setConfig($config);

$tu = new TriplesUtil();
$tu = new \Tripod\Mongo\TriplesUtil();

while (($line = fgets(STDIN)) !== false) {
$line = rtrim($line);

$graph = new MongoGraph();
$graph = new \Tripod\Mongo\MongoGraph();
$doc = json_decode($line, true);

if(array_key_exists("_id", $doc)) {
Expand Down
24 changes: 12 additions & 12 deletions scripts/mongo/createTables.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function showUsage()

Options:
-h --help This help
-c --config path to MongoTripodConfig configuration (required)
-c --config path to Config configuration (required)
-s --storename Store to create tables for (required)
-t --spec Only create for specified table specs
-i --id Resource ID to regenerate table rows for
Expand Down Expand Up @@ -75,30 +75,30 @@ function showUsage()

require_once 'tripod.inc.php';
require_once 'classes/Timer.class.php';
require_once 'mongo/MongoTripodConfig.class.php';
require_once 'mongo/MongoTripod.class.php';
require_once 'mongo/Config.class.php';
require_once 'mongo/Driver.class.php';

/**
* @param string|null $id
* @param string|null $tableId
* @param string|null $storeName
* @param iTripodStat|null $stat
* @param \Tripod\ITripodStat|null $stat
* @param string|null $queue
*/
function generateTables($id, $tableId, $storeName, $stat = null, $queue = null)
{
$tableSpec = MongoTripodConfig::getInstance()->getTableSpecification($storeName, $tableId);
$tableSpec = \Tripod\Mongo\Config::getInstance()->getTableSpecification($storeName, $tableId);
if(empty($tableSpec)) // Older version of Tripod being used?
{
$tableSpec = MongoTripodConfig::getInstance()->getTableSpecification($tableId);
$tableSpec = \Tripod\Mongo\Config::getInstance()->getTableSpecification($tableId);
}
if (array_key_exists("from",$tableSpec))
{
MongoCursor::$timeout = -1;

print "Generating $tableId";
$tripod = new MongoTripod($tableSpec['from'], $storeName, array('stat'=>$stat));
$tTables = $tripod->getTripodTables();//new MongoTripodTables($tripod->storeName,$tripod->collection,$tripod->defaultContext);
$tripod = new \Tripod\Mongo\Driver($tableSpec['from'], $storeName, array('stat'=>$stat));
$tTables = $tripod->getTripodTables();//new Tables($tripod->storeName,$tripod->collection,$tripod->defaultContext);
if ($id)
{
print " for $id....\n";
Expand All @@ -112,10 +112,10 @@ function generateTables($id, $tableId, $storeName, $stat = null, $queue = null)
}
}

$t = new Timer();
$t = new \Tripod\Timer();
$t->start();

MongoTripodConfig::setConfig(json_decode(file_get_contents($configLocation),true));
\Tripod\Mongo\Config::setConfig(json_decode(file_get_contents($configLocation),true));

if(isset($options['s']) || isset($options['storename']))
{
Expand Down Expand Up @@ -153,7 +153,7 @@ function generateTables($id, $tableId, $storeName, $stat = null, $queue = null)
}
else
{
$queue = MongoTripodConfig::getInstance()->getApplyQueueName();
$queue = \Tripod\Mongo\Config::getInstance()->getApplyQueueName();
}
}

Expand All @@ -170,7 +170,7 @@ function generateTables($id, $tableId, $storeName, $stat = null, $queue = null)
}
else
{
foreach(MongoTripodConfig::getInstance()->getTableSpecifications($storeName) as $tableSpec)
foreach(\Tripod\Mongo\Config::getInstance()->getTableSpecifications($storeName) as $tableSpec)
{
generateTables($id, $tableSpec['_id'], $storeName, $stat, $queue);
}
Expand Down
22 changes: 11 additions & 11 deletions scripts/mongo/createViews.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function showUsage()

Options:
-h --help This help
-c --config path to MongoTripodConfig configuration (required)
-c --config path to Config configuration (required)
-s --storename Store to create views for (required)
-v --spec Only create for specified view specs
-i --id Resource ID to regenerate views for
Expand Down Expand Up @@ -75,30 +75,30 @@ function showUsage()

require_once 'tripod.inc.php';
require_once 'classes/Timer.class.php';
require_once 'mongo/MongoTripodConfig.class.php';
require_once 'mongo/MongoTripod.class.php';
require_once 'mongo/TripodConfigs.php';
require_once 'mongo/Tripods.php';

/**
* @param string|null $id
* @param string|null $viewId
* @param string $storeName
* @param iTripodStat|null $stat
* @param \Tripod\ITripodStat|null $stat
*/
function generateViews($id, $viewId, $storeName, $stat, $queue)
{
$viewSpec = MongoTripodConfig::getInstance()->getViewSpecification($storeName, $viewId);
$viewSpec = \Tripod\Mongo\Config::getInstance()->getViewSpecification($storeName, $viewId);
if(empty($viewSpec)) // Older version of Tripod being used?
{
$viewSpec = MongoTripodConfig::getInstance()->getViewSpecification($viewId);
$viewSpec = \Tripod\Mongo\Config::getInstance()->getViewSpecification($viewId);
}
echo $viewId;
if (array_key_exists("from",$viewSpec))
{
MongoCursor::$timeout = -1;

print "Generating $viewId";
$tripod = new MongoTripod($viewSpec['from'], $storeName, array('stat'=>$stat));
$views = $tripod->getTripodViews();//new MongoTripodViews($tripod->storeName,$tripod->collection,$tripod->defaultContext);
$tripod = new \Tripod\Mongo\Driver($viewSpec['from'], $storeName, array('stat'=>$stat));
$views = $tripod->getTripodViews();//new Views($tripod->storeName,$tripod->collection,$tripod->defaultContext);
if ($id)
{
print " for $id....\n";
Expand All @@ -112,10 +112,10 @@ function generateViews($id, $viewId, $storeName, $stat, $queue)
}
}

$t = new Timer();
$t = new \Tripod\Timer();
$t->start();

MongoTripodConfig::setConfig(json_decode(file_get_contents($configLocation),true));
\Tripod\Mongo\Config::setConfig(json_decode(file_get_contents($configLocation),true));

if(isset($options['s']) || isset($options['storename']))
{
Expand Down Expand Up @@ -170,7 +170,7 @@ function generateViews($id, $viewId, $storeName, $stat, $queue)
}
else
{
foreach(MongoTripodConfig::getInstance()->getViewSpecifications($storeName) as $viewSpec)
foreach(\Tripod\Mongo\Config::getInstance()->getViewSpecifications($storeName) as $viewSpec)
{
generateViews($id, $viewSpec['_id'], $storeName, $stat, $queue);
}
Expand Down
14 changes: 9 additions & 5 deletions scripts/mongo/detectNamespaces.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
. PATH_SEPARATOR . dirname(dirname(dirname(__FILE__))).'/src/classes');

require_once 'tripod.inc.php';
require_once 'mongo/MongoTripodConfig.class.php';
require_once 'mongo/Config.class.php';
require_once 'mongo/MongoGraph.class.php';
require_once 'mongo/util/TriplesUtil.class.php';

Expand Down Expand Up @@ -41,10 +41,10 @@
),
);

MongoTripodConfig::setConfig($config);
\Tripod\Mongo\Config::setConfig($config);


$util = new TriplesUtil();
$util = new \Tripod\Mongo\TriplesUtil();
$objectNs = array();
$i=0;
while (($line = fgets(STDIN)) !== false) {
Expand Down Expand Up @@ -92,7 +92,7 @@
$newNsConfig[$prefix] = $n;
echo "\nFound ns $n suggest prefix $prefix";
$config["namespaces"] = array_merge($config["namespaces"],$newNsConfig);
MongoTripodConfig::setConfig($config);
\Tripod\Mongo\Config::setConfig($config);
}
}
$ns = $util->extractMissingObjectNs($triples);
Expand All @@ -118,7 +118,7 @@
$newNsConfig[$prefix] = $n;
echo "\nFound object ns $n occurs > 500 times, suggest prefix $prefix";
$config["namespaces"] = array_merge($config["namespaces"],$newNsConfig);
MongoTripodConfig::setConfig($config);
\Tripod\Mongo\Config::setConfig($config);
}
}
}
Expand All @@ -131,6 +131,10 @@

print "Suggested namespace configuration:\n\n";

/**
* @param string $json
* @return string
*/
function indent($json) {

$result = '';
Expand Down
7 changes: 6 additions & 1 deletion scripts/mongo/discoverUnnamespacedUris.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@
}

array_shift($argv);
$client = new MongoClient($argv[0]);
$client = new \MongoClient($argv[0]);

/* @var $db MongoDB */
$db = $client->selectDb($argv[1]);

/**
* @param string $uri
* @param string|null $baseUri
* @return bool
*/
function isUnNamespaced($uri,$baseUri=null)
{
if ($baseUri==null)
Expand Down
10 changes: 5 additions & 5 deletions scripts/mongo/ensureIndexes.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
require_once 'tripod.inc.php';
require_once 'classes/Timer.class.php';
require_once 'mongo/util/IndexUtils.class.php';
require_once 'mongo/MongoTripodConfig.class.php';
require_once 'mongo/Config.class.php';

if ($argc!=2&&$argc!=3&&$argc!=4)
{
Expand All @@ -17,16 +17,16 @@
}
array_shift($argv);

MongoTripodConfig::setConfig(json_decode(file_get_contents($argv[0]),true));
\Tripod\Mongo\Config::setConfig(json_decode(file_get_contents($argv[0]),true));

$storeName = (isset($argv[1])) ? $argv[1] : null;
$forceReindex = (isset($argv[2])&&($argv[2]=="true")) ? true : false;

$ei = new IndexUtils();
$ei = new \Tripod\Mongo\IndexUtils();

$t = new Timer();
$t = new \Tripod\Timer();
$t->start();
print("About to start indexing on $dbName...\n");
print("About to start indexing on $storeName...\n");
$ei->ensureIndexes($forceReindex,$storeName);
$t->stop();
print "Indexing complete, took {$t->result()} seconds\n";
16 changes: 12 additions & 4 deletions scripts/mongo/loadTriples.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@
require_once 'mongo/util/TriplesUtil.class.php';
require_once 'classes/Timer.class.php';

function load(TriplesUtil $loader,$subject,Array $triples,Array &$errors,$podName,$storeName)
/**
* @param \Tripod\Mongo\TriplesUtil $loader
* @param string $subject
* @param array $triples
* @param array $errors
* @param string $podName
* @param string $storeName
*/
function load(\Tripod\Mongo\TriplesUtil $loader,$subject,Array $triples,Array &$errors,$podName,$storeName)
{
try
{
Expand All @@ -22,7 +30,7 @@ function load(TriplesUtil $loader,$subject,Array $triples,Array &$errors,$podNam
}
}

$timer = new Timer();
$timer = new \Tripod\Timer();
$timer->start();

if ($argc!=4)
Expand All @@ -34,13 +42,13 @@ function load(TriplesUtil $loader,$subject,Array $triples,Array &$errors,$podNam

$storeName = $argv[0];
$podName = $argv[1];
MongoTripodConfig::setConfig(json_decode(file_get_contents($argv[2]),true));
\Tripod\Mongo\Config::setConfig(json_decode(file_get_contents($argv[2]),true));

$i=0;
$currentSubject = "";
$triples = array();
$errors = array(); // array of subjects that failed to insert, even after retry...
$loader = new TriplesUtil();
$loader = new \Tripod\Mongo\TriplesUtil();

while (($line = fgets(STDIN)) !== false) {
$i++;
Expand Down
Loading