public function preRunCheck() { if (!$this->opts->name) { throw new Zend_Console_Getopt_Exception('The node must have a name (use --name)'); } if (!$this->opts->connection) { throw new Zend_Console_Getopt_Exception('The node must have a connection (use --connection)'); } if (!$this->opts->schema) { throw new Zend_Console_Getopt_Exception('The node must have a schema (use --schema)'); } // Check that the name supplied is unique Meshing_Utils::initialiseDb(); $node = P2POwnNodeQuery::create()->findOneByName($this->opts->name); if ($node) { throw new Zend_Console_Getopt_Exception('A node of that name already exists'); } // Check that the connection exists $this->connection = P2PConnectionQuery::create()->findOneByName($this->opts->connection); if (!$this->connection) { throw new Zend_Console_Getopt_Exception('The specified connection is not registered'); } // Check that the schema exists $this->schema = MeshingSchemaQuery::create()->findOneByName($this->opts->schema); if (!$this->schema) { throw new Zend_Console_Getopt_Exception('The specified schema is not registered'); } }
public function preRunCheck() { if (!$this->opts->name) { throw new Zend_Console_Getopt_Exception('All schemas need an identifying name (use --name)'); } if (!$this->opts->file) { throw new Zend_Console_Getopt_Exception('A schema XML file must be specified (use --file)'); } // Let's check that the file exists if (!file_exists($this->opts->file)) { throw new Zend_Console_Getopt_Exception('The specified XML schema does not exist'); } // @todo Test whether the input XML file already has a schema, unless --force is present // ... // @todo Do an XML validation check here // ... // Check that the schema name is not already taken Meshing_Utils::initialiseDb(); $schema = MeshingSchemaQuery::create()->findOneByName($this->opts->name); if ($schema) { throw new Zend_Console_Getopt_Exception('That schema name is already in use'); } // Try to create the folders required $this->schemaDir = $this->projectRoot . Meshing_Utils::getPaths()->getPathSchemasNodes() . '/' . $this->opts->name; if (!is_dir($this->schemaDir)) { if (!@mkdir($this->schemaDir)) { throw new Zend_Console_Getopt_Exception("Error when creating the schema folder '{$this->opts->name}', check permissions?"); } } }
public function preRunCheck() { if (!$this->opts->name) { throw new Zend_Console_Getopt_Exception('Which node would you like have send updates? (use --name)'); } Meshing_Utils::initialiseDb(); $this->node = P2POwnNodeQuery::create()->findOneByName($this->opts->name); if (!$this->node) { throw new Zend_Console_Getopt_Exception('A node of that name is not registered'); } }
public function run() { Meshing_Utils::initialiseDb(); $outFormat = '%-15s'; $this->ruleOff($lineLength = 15); echo sprintf($outFormat, 'Name', 'Schema', 'Connection') . "\n"; $this->ruleOff($lineLength); /* @var $schema MeshingSchema */ foreach (MeshingSchemaPeer::doSelect(new Criteria()) as $schema) { echo sprintf($outFormat, $schema->getName()) . "\n"; } }
public function run() { Meshing_Utils::initialiseDb(); $outFormat = '%-15s%-15s%-15s'; $this->ruleOff($lineLength = 15 + 15 + 15); echo sprintf($outFormat, 'Name', 'Schema', 'Connection') . "\n"; $this->ruleOff($lineLength); /* @var $ownNode P2POwnNode */ foreach (P2POwnNodePeer::doSelect(new Criteria()) as $ownNode) { echo sprintf($outFormat, $ownNode->getName(), $ownNode->getMeshingSchema()->getName(), $ownNode->getP2PConnection()->getName()) . "\n"; } }
public function preRunCheck() { $name = $this->opts->name; if (!$name) { throw new Zend_Console_Getopt_Exception('The connection name must be specified.'); } // @todo Check that this connection isn't in use Meshing_Utils::initialiseDb(); $this->connection = P2PConnectionQuery::create()->findOneByName($name); if (!$this->connection) { throw new Zend_Console_Getopt_Exception('No such connection.'); } }
public function preRunCheck() { if (!$this->opts->name) { throw new Zend_Console_Getopt_Exception('You need to specify which schema (use --name)'); } // Check that the schema exists Meshing_Utils::initialiseDb(); $this->schema = MeshingSchemaQuery::create()->findOneByName($this->opts->name); if (!$this->schema) { throw new Zend_Console_Getopt_Exception('That schema is not registered'); } // @todo Check that the schema is not in use on a node // ... }
public function run() { Meshing_Utils::initialiseDb(); $outFormat = '%-15s%-12s%-15s%-40s'; $this->ruleOff($lineLength = 15 + 12 + 15 + 40); echo sprintf($outFormat, 'Name', 'Adaptor', 'User', 'Host') . "\n"; $this->ruleOff($lineLength); $connections = P2PConnectionPeer::doSelect(new Criteria()); /* @var $connection P2PConnection */ foreach ($connections as $connection) { echo sprintf($outFormat, $connection->getName(), $connection->getAdaptor(), $connection->getUsername() ? $connection->getUsername() : 'n/a', $connection->getHost()); echo "\n"; } }
public function preRunCheck() { // Used to track bad combos e.g. local-to AND remote-to $hasToLocal = $hasToRemote = false; $localFromName = $this->opts->{'local-from'}; if (!$localFromName) { throw new Zend_Console_Getopt_Exception('A local node must be specified (use --local-from)'); } if ($localToName = $this->opts->{'local-to'}) { $hasToLocal = true; } // @todo Not implemented yet if ($remoteToName = $this->opts->{'remote-to'}) { throw new Zend_Console_Getopt_Exception('Remote nodes are not currently supported'); //$hasToRemote = true; } // Check for bad combinations if ($localToName && $remoteToName) { throw new Zend_Console_Getopt_Exception('You cannot have a local-to AND a remote-to node'); } if (!$localToName && !$remoteToName) { throw new Zend_Console_Getopt_Exception('You must have one \'to\' node (use --local-to or --remote-to)'); } // Check that the local from actually exists Meshing_Utils::initialiseDb(); $this->localFromNode = P2POwnNodeQuery::create()->findOneByName($localFromName); if (!$this->localFromNode) { throw new Zend_Console_Getopt_Exception('A local node of that (from) name is not registered'); } if ($localToName) { $this->localToNode = P2POwnNodeQuery::create()->findOneByName($localToName); if (!$this->localToNode) { throw new Zend_Console_Getopt_Exception('A local node of that (to) name is not registered'); } } // We cannot trust ourselves, so to speak ;-) if ($localFromName == $localToName) { throw new Zend_Console_Getopt_Exception('There is no point in setting a node to trust itself'); } }
public function preRunCheck() { if (!$this->opts->name) { throw new Zend_Console_Getopt_Exception('Which node would you like to start? (use --name)'); } Meshing_Utils::initialiseDb(); $node = P2POwnNodeQuery::create()->findOneByName($this->opts->name); if (!$node) { throw new Zend_Console_Getopt_Exception('A node of that name is not registered'); } // Connect with this node's connection, and ensure there are rows in known_nodes $conn = Propel::getConnection($node->getP2PConnection()->getName()); $schemaName = $node->getMeshingSchema()->getName(); Meshing_Utils::initialiseNodeDbs($schemaName); // Obtain the number of trusted nodes $class = Meshing_Node_Utils::getNodeClassName($schemaName, 'KnownNodePeer'); $knownNodeCount = call_user_func(array($class, 'doCount'), new Criteria(), $distinct = false, $conn); // If there are no trust rows, we cannot start if (!$knownNodeCount) { throw new Zend_Console_Getopt_Exception('A node needs to trust other nodes before it can be started'); } }
<?php // Set up project $projectRoot = realpath(dirname(__FILE__) . '/../../..'); require_once $projectRoot . '/lib/Meshing/Paths.php'; require_once $projectRoot . '/tests/unit/Meshing_Test_Paths.php'; require_once $projectRoot . '/lib/Meshing/Utils.php'; Meshing_Utils::reinitialise(new Meshing_Test_Paths()); define('CHILD_TOKEN', 'meshing_test'); define('LOCKING_TEST_LOG', 'log.log'); // If we're running the child here, we'll pass an token global $argv; $token = array_key_exists(1, $argv) ? $argv[1] : null; if ($token == CHILD_TOKEN) { // Initialise database (normally done by DatabaseTestCase) Meshing_Utils::initialiseDb($testMode = true); Meshing_Utils::initialiseNodeDbs('test_model', $testMode); // Run child test new LockingTestCaseChild($argv[2]); exit; } else { // Init simpletest require_once 'simpletest/autorun.php'; } class LockingTestCase extends Meshing_Test_ModelTestCase { public function __construct($label = false) { // Same package name as test 2 parent::__construct('test_model', $label); $this->node = $this->createKnownNode(new TestModelKnownNode(), $this->conNode);
/** * Get XML version of default runtime file, returns temp version to convert to PHP */ protected function createRuntimeXml($runTime, $newRunTime) { // Ensure the file exists if (!is_readable($runTime)) { throw new Exception("Can't load runtime configuration"); } // Ensure the new file won't overwrite the old one! if ($runTime == $newRunTime) { throw new Exception('The new XML location must be different to the existing one'); } // Load up the XML doc $xml = simplexml_load_file($runTime); // @todo Validate XML file // Grab the connections known to the system (@todo would we want more than 50!?) Meshing_Utils::initialiseDb(); $c = new Criteria(); $c->setLimit(50); $connections = P2PConnectionPeer::doSelect($c); // Add each connection in as a datasource /* @var $connection P2PConnection */ foreach ($connections as $connection) { // Modify XML document $element = $xml->propel->datasources->addChild('datasource'); $element['id'] = $connection->getName(); $inner1 = $element->addChild('adapter', $connection->getAdaptor()); $inner2 = $element->addChild('connection'); $inner2->addChild('dsn', $connection->getCalculatedDsn()); $inner2->addChild('user', $connection->getUsername()); $inner2->addChild('password', $connection->getPassword()); } // Write out modified XML doc to new file $xml->asXml($newRunTime); }
public function __construct($fixturesFile) { $this->fixturesFile = $fixturesFile; Meshing_Utils::initialiseDb(); }
/** * Connect to the new connection, and throw exception if it fails * * @return boolean */ protected function testNewConnection() { if ($this->opts->test) { Meshing_Utils::initialiseDb(); try { $conn = Propel::getConnection($this->opts->name); } catch (PropelException $e) { throw new Meshing_Console_RunException($e->getMessage()); } } return true; }
/** * Initialise the test system and test node databases * * Can't init the test node db in the constructor, since the conf file may not be created */ protected function initConnections() { Meshing_Utils::initialiseDb($testMode = true); Meshing_Utils::initialiseNodeDbs($this->package, $testMode); $this->conSystem = Propel::getConnection(Meshing_Utils::CONN_SYSTEM_TEST); $this->conNode = Propel::getConnection(Meshing_Utils::CONN_NODE_TEST_1); }