private function exportToDB($graph, OutputInterface $output, Client $client)
 {
     $converter = new CypherStatementsConverter();
     $converter->convert($graph);
     try {
         $constraints = 0;
         foreach ($converter->getConstraintStatements() as $statement) {
             $client->sendCypherQuery($statement['statement']);
             $constraints++;
         }
         $output->writeln('<info>Created ' . $constraints . ' constraint(s)</info>');
         $nodes = 0;
         foreach ($converter->getNodeStatements() as $ns) {
             $client->sendCypherQuery($ns['statement'], $ns['parameters']);
             $nodes += count($ns['parameters']['props']);
         }
         $output->writeln('<info>Created ' . $nodes . ' node(s)</info>');
         $edges = 0;
         foreach ($converter->getEdgeStatements() as $es) {
             $params = isset($es['parameters']) ? $es['parameters'] : ['pairs' => []];
             $client->sendCypherQuery($es['statement'], $params);
             $edges += count($params['pairs']);
         }
         $output->writeln('<info>Created ' . $edges . ' relationship(s)</info>');
     } catch (HttpException $e) {
         $output->writeln('<error>Unable to connect to the database' . PHP_EOL . $e->getMessage() . PHP_EOL . '</error>');
     }
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function inspect(InspectionRequest $request) : Inspection
 {
     $query = 'MATCH (parent:Message {identifier: {messageIdentifier}})-[:PARENT_MESSAGE*0..]-(message:Message) ' . 'OPTIONAL MATCH (message)<-[received:RECEIVED_MESSAGE]-(p:Peer) ' . 'OPTIONAL MATCH (message)-[sent:SENT_MESSAGE]-(sender:Peer) ' . 'OPTIONAL MATCH (message)-[:PARENT_MESSAGE*1]->(directParent:Message) ' . 'WITH message, count(p) AS c, collect(p) AS peers, sender, collect(received) as receivedCollection, sent, directParent ' . 'RETURN message, sender, head(receivedCollection) AS received, sent, directParent AS parent, ' . 'CASE c WHEN 1 THEN peers[0] ELSE head(filter(x in peers where x.virtual IS NULL)) END AS receiver ' . 'ORDER BY received.start ASC';
     $response = $this->getResponse($this->client->sendCypherQuery($query, ['messageIdentifier' => (string) $request->getMessageIdentifier()]));
     $profiles = array_map(function (array $row) {
         return $this->createProfile($row);
     }, $response);
     return new Inspection($profiles);
 }
 public function getExpectedGraphResult($cypher, Client $client)
 {
     $transaction = $client->createTransaction();
     $transaction->pushQuery('MATCH (n) OPTIONAL MATCH (n)-[r]-() DELETE r,n');
     $transaction->pushQuery($cypher);
     $expectedResult = $transaction->pushQuery('MATCH (n) OPTIONAL MATCH (n)-[r]-() RETURN n,r');
     $transaction->rollback();
     return $expectedResult;
 }
Example #4
0
 public function getPostsExtended($limit = 10, $skip = 0)
 {
     $cql = "\n        MATCH (post:Post)-[:TAGGED_WITH]->(t:Tag),\n        (post)-[:CATEGORIZED_AS]->(c:Category),\n        (post)-[:AUTHORED_BY]->(author:Author)\n        RETURN post, COLLECT(DISTINCT t) as tags, COLLECT(DISTINCT c) as categories, author\n        ORDER BY post.date\n        SKIP {$skip}\n        LIMIT {$limit};\n        ";
     $response = $this->client->sendCypherQuery($cql);
     $result = $response->getResult();
     if ($result->getNodesCount() > 0) {
         return $this->postExtendedTableFormatToModels($result->getTableFormat());
     }
     return null;
 }
 public function testPushMultipleInTransaction()
 {
     $q = 'MATCH (n:MultiplePersonNode) DELETE n';
     $this->client->sendCypherQuery($q);
     $statements = [];
     $statement = 'CREATE (n:MultiplePersonNode {id:{myId} })';
     for ($i = 0; $i <= 2000; $i++) {
         $statements[] = ['statement' => $statement, 'parameters' => ['myId' => uniqid()]];
     }
     $this->client->sendMultiple($statements);
     $q = 'MATCH (n:MultiplePersonNode) RETURN count(n)';
     $r = $this->client->sendCypherQuery($q);
     $count = $r->getRows()['count(n)'][0];
     $this->assertEquals(2001, $count);
 }
 private function sendGA()
 {
     $td = sys_get_temp_dir();
     if (!is_writable($td)) {
         return;
     }
     $f = $td . DIRECTORY_SEPARATOR . 'neoping.txt';
     $c = $td . DIRECTORY_SEPARATOR . 'neoi.txt';
     $t = time();
     if (file_exists($f) && file_exists($c)) {
         $last = (int) file_get_contents($f);
         $new = false;
         $ci = file_get_contents($c);
     } else {
         $last = 0;
         $ci = sha1($t);
         $new = true;
     }
     if ($t - $last < 120) {
         return;
     }
     $r = $this->hc->createRequest('GET', 'http://stats.neoxygen.io/collect', array('timeout' => 1));
     $r->setQuery(['v' => Client::getNeoClientVersion(), 'cid' => $ci]);
     try {
         $this->hc->send($r);
         $this->lc = $t;
         file_put_contents($f, $t);
         if ($new) {
             file_put_contents($c, $ci);
         }
     } catch (RequestException $e) {
     }
 }
 public function onSuccessfulRequest(PostRequestSendEvent $event)
 {
     $request = $event->getRequest();
     $this->fails[$request->getConnection()] = null;
     $this->slavesUsed = [];
     $this->masterUsed = null;
     if ($request->hasQueryMode()) {
         if ($request->getQueryMode() === 'WRITE') {
             $master = $this->connectionManager->getMasterConnection()->getAlias();
             if ($request->getConnection() === $master) {
                 $slaves = $this->connectionManager->getSlaves();
                 $slave = current($slaves);
                 $this->writeReplicationUsed[] = $slave;
                 Client::log('debug', sprintf('Performing write replication on connection "%s"', $slave));
                 $request->setInfoFromConnection($this->connectionManager->getConnection($slave));
                 $event->stopPropagation();
             } elseif ($this->connectionManager->hasNextSlave($this->writeReplicationUsed)) {
                 $next = $this->connectionManager->getNextSlave($this->writeReplicationUsed);
                 $nc = $this->connectionManager->getConnection($next);
                 Client::log('debug', sprintf('Performing write replication on connection "%s"', $next));
                 $request->setInfoFromConnection($nc);
                 $event->stopPropagation();
             } elseif (null !== $this->masterUsed && !$this->connectionManager->hasNextSlave($this->masterUsed) && $request->getConnection() !== $master) {
                 $this->masterUsed = [];
                 Client::log('debug', 'Replication terminated');
             }
         }
     }
 }
 /**
  * @param \Neoxygen\NeoClient\Event\HttpExceptionEvent $event
  */
 public function onHttpException(HttpExceptionEvent $event)
 {
     $request = $event->getRequest();
     $exception = $event->getException();
     $message = $exception->getMessage();
     Client::log('emergency', sprintf('Error on connection "%s" - %s', $request->getConnection(), $message));
     throw new HttpException(sprintf('Error on Connection "%s" with message "%s"', $request->getConnection(), $message));
 }
 private function assertIndexIsLive(Index $index)
 {
     $indexes = $this->client->getSchemaIndexes();
     $this->assertThat($index, new SchemaContainsIndexConstraint($indexes));
 }
 /**
  *
  */
 private function detectReelectedMaster()
 {
     $slaves = $this->connectionManager->getSlaves();
     foreach ($slaves as $slave) {
         if ($this->isMaster($slave)) {
             Client::log('debug', sprintf('Master Reelection detected, new Master is "%s".', $slave));
             return $slave;
         }
     }
     return;
 }
<?php

require_once 'vendor/autoload.php';
use Neoxygen\NeoClient\Client;
$logger = new \Monolog\Logger("neoclient");
$logger->pushHandler(new \Monolog\Handler\ErrorLogHandler());
$client = new Client();
/**
* Specific for Heroku
*/
$db1_password = getenv('DEFAULTDB__PASSWORD');
$db2_password = getenv('TESTDB2__PASSWORD');
$client->getServiceContainer()->setParameter('defaultdb_password', $db1_password);
$client->getServiceContainer()->setParameter('testdb2_password', $db2_password);
/** End of heroku specific config
*/
$client->loadConfigurationFile(__DIR__ . '/neoclient.yml')->createDefaultChromePHPLogger('browserlog')->setLogger('neolog', $logger)->build();
$query = 'MATCH (actor:Actor) RETURN actor.name ORDER BY actor.name';
$actors = json_decode($client->sendCypherQuery($query), true);
?>
<html>
<body>
<h1>Neo4j connection fallback example using <a href="https://github.com/neoxygen/neo4j-neoclient" title="NeoClient">NeoClient</a>.</h1>

<h2>Simple heroku app using 2 db instances from <a href="http://www.graphenedb.com/" title="Graphene DB">Graphene DB</a></h2>
<p>The two instances are loaded with the MovieDB example from <a href="http://neo4j.org" title="Neo4j">Neo4j</a>, one of the databases 
has been shutdowned and the app automatically fallback on the second configured connection. If you have ChromePHP, you can see logs in the 
browser. The query used is "<b>MATCH (actor:Actor) RETURN actor.name ORDER BY actor.name</b>"</p>

<?php 
echo '<pre>';
 private function getUserAgent()
 {
     return 'NeoClient-PHP/v-' . BaseClient::getNeoClientVersion();
 }
 /**
  * Commit the prepared transaction.
  *
  * @return mixed
  *
  * @throws \Neoxygen\NeoClient\Exception\CommandException if the transaction was already committed
  */
 public function commit()
 {
     if ($this->committed) {
         throw new CommandException('The prepared transaction has already been commited');
     }
     $response = Client::commitPreparedTransaction($this);
     $this->committed = true;
     return $response;
 }