Пример #1
0
 /**
  * Builds a system db for the test environment
  * 
  * @todo This replicates some code in Command/System/Build - needs to be much more DRY
  */
 protected function buildTestSystemDatabase()
 {
     // Load the Meshing_Test_Paths class
     $projectRoot = Meshing_Utils::getProjectRoot();
     require_once $projectRoot . '/tests/unit/Meshing_Test_Paths.php';
     Meshing_Utils::reinitialise(new Meshing_Test_Paths());
     $paths = Meshing_Utils::getPaths();
     // Build a system connection file
     $task = new Meshing_Propel_ConfBuilder();
     $task->addSchemas($projectRoot . $paths->getPathDbConfig(), $paths->getLeafStandardSchema());
     $task->setXmlFile($projectRoot . $paths->getFileRuntimeXml());
     $task->setPropelConnection(Meshing_Utils::CONN_SYSTEM_TEST);
     $task->setOutputDir($projectRoot . $paths->getPathConnsSystem());
     $task->setOutputFile($paths->getLeafRuntimePhp());
     $task->run();
     // Build the SQL for a test system database
     $task = new Meshing_Propel_SqlBuilder();
     $task->addSchemas($projectRoot . $paths->getPathDbConfig(), $paths->getLeafStandardSchema());
     $task->setOutputDir($projectRoot . $paths->getPathSqlSystem());
     $task->setPropelConnection(Meshing_Utils::CONN_SYSTEM_TEST);
     $task->run();
     // Run the sql
     $task = new Meshing_Propel_SqlRunner();
     $task->setSqlDir($projectRoot . $paths->getPathSqlSystem());
     $task->setMapFile($projectRoot . $paths->getFileDbMap());
     $task->setPropelConnection(Meshing_Utils::CONN_SYSTEM_TEST);
     $task->run();
 }
Пример #2
0
 protected function runCommand($command)
 {
     $projectRoot = Meshing_Utils::getProjectRoot();
     $command = $projectRoot . '/meshing ' . $command;
     $output = array();
     exec($command, $output);
     return implode("\n", $output);
 }
Пример #3
0
 public function __construct()
 {
     parent::__construct();
     // Sets up default Propel build properties
     $projectPath = Meshing_Utils::getProjectRoot();
     $propertiesFile = $projectPath . '/vendor/propel-1.6/generator/default.properties';
     $this->addPropertiesFile($propertiesFile);
 }
Пример #4
0
 /**
  * Specify which connection on which to carry out the schema task
  * 
  * @param strings $connName Optional connection name (defaults to system connection)
  */
 public function setPropelConnection($connName = Meshing_Utils::SYSTEM_CONNECTION)
 {
     // Grab the db details directly out of the Propel config file
     $xmlPath = Meshing_Utils::getProjectRoot() . Meshing_Utils::getPaths()->getFileRuntimeXml();
     $conf = simplexml_load_file($xmlPath);
     /* @var $conf SimpleXMLElement */
     $entry = $conf->xpath('/config/propel/datasources/datasource[@id="' . $connName . '"]');
     // If an element doesn't exist here, we've probably got the connection name wrong
     if (!array_key_exists(0, $entry)) {
         throw new Exception("Connection name '{$connName}' not found");
     }
     $entry = $entry[0];
     $this->setDatabaseCredentials((string) $entry->adapter, (string) $entry->connection->dsn, (string) $entry->connection->user, (string) $entry->connection->password);
 }
Пример #5
0
 protected function deleteDirectories()
 {
     $projectRoot = Meshing_Utils::getProjectRoot();
     $schemaDir = $projectRoot . Meshing_Utils::getPaths()->getPathSchemasNodes() . '/' . $this->opts->name;
     $modelDir = $projectRoot . Meshing_Utils::getPaths()->getPathModelsNodes() . '/' . $this->opts->name;
     echo "Done.\n";
     $ok = @rmdir($schemaDir);
     $ok = $ok && @rmdir($modelDir);
     if (!$ok) {
         echo "Not (yet) deleting empty dirs. Please run these, if safe:\n";
         echo "rm -rf " . $schemaDir . "\n";
         echo "rm -rf " . $modelDir . "\n";
     }
 }
Пример #6
0
 public function run()
 {
     // We access the node db twice, so let's init the autoloading for this schema
     Meshing_Utils::initialiseNodeDbs($this->opts->schema);
     $conn = Propel::getConnection($this->opts->connection);
     // Check "identity" table on this connection to see whether a build requires --force
     $this->checkNodeBuildCanProceed($conn);
     // Create SQL and run SQL on this connection
     $projectRoot = Meshing_Utils::getProjectRoot();
     $this->buildSql($projectRoot);
     $this->runSql($projectRoot);
     // Record node details in system and system details in node
     $ownNode = $this->writeOwnNodeRecord();
     $this->writeNodeIdentityRecord($ownNode, $conn);
 }
Пример #7
0
 protected static function readCommands($incHidden = false)
 {
     static $commands = array();
     static $hidden = array();
     if (!$commands) {
         $projectRoot = Meshing_Utils::getProjectRoot();
         $consoleRoot = $projectRoot . Meshing_Utils::getPaths()->getPathMeshingCommands();
         $directory = new RecursiveDirectoryIterator($consoleRoot);
         $iterator = new RecursiveIteratorIterator($directory);
         $regex = new RegexIterator($iterator, '/^.+\\.php$/i', RecursiveRegexIterator::GET_MATCH);
         $regex->next();
         $i++;
         while ($regex->valid()) {
             // For safety!
             if ($i > 50) {
                 break;
             }
             // Get the full pathname of the class
             $item = $regex->current();
             $item = $item[0];
             // Strip out the full path bit, and generally tidy
             $item = str_replace($consoleRoot . DIRECTORY_SEPARATOR, '', $item);
             $item = str_replace('.php', '', $item);
             $className = 'Meshing_Console_Command_' . str_replace(DIRECTORY_SEPARATOR, '_', $item);
             $item = strtolower(str_replace(DIRECTORY_SEPARATOR, ':', $item));
             // Classes without this method are not commands at all
             $realCommand = method_exists($className, 'getDescription');
             // We consult a special method to determine whether to show the command
             if ($realCommand) {
                 $cmdClass = new $className();
                 $commands[$className] = $item;
                 if ($cmdClass->isHiddenCommand()) {
                     $hidden[] = $className;
                 }
             }
             $regex->next();
         }
         // Preserve the keys when sorting
         asort($commands);
     }
     // Strip out hidden commands
     if (!$incHidden) {
         foreach ($hidden as $removeClass) {
             unset($commands[$removeClass]);
         }
     }
     return $commands;
 }
Пример #8
0
 public function run()
 {
     $this->projectRoot = Meshing_Utils::getProjectRoot();
     $verbose = $this->opts->verbose;
     if ($verbose) {
         echo "Generating... ";
     }
     // @todo Move this to a hidden developer command
     if ($this->opts->classes) {
         $this->buildModel($verbose);
     }
     if ($this->opts->database) {
         $this->buildDatabase($verbose);
         $this->runFixtures($verbose);
     }
     // @todo Need to build model-only for schema-node.xml
     // @todo Move this to a hidden developer command
 }
Пример #9
0
 public function testMaxContention()
 {
     // If Windows, we can't test
     if (substr(PHP_OS, 0, 3) == 'WIN') {
         user_error("Can't currently test locking on the Windows platform", E_USER_WARNING);
         return;
     }
     // Append errors to this log file
     $logDir = Meshing_Utils::getProjectRoot() . Meshing_Utils::getPaths()->getTestLogPath();
     $childCount = 10;
     for ($id = 0; $id < $childCount; $id++) {
         $command = 'php "' . __FILE__ . '" ' . CHILD_TOKEN . ' ' . $id;
         $background = '>> ' . $logDir . '/' . LOCKING_TEST_LOG . ' 2>&1 &';
         $return = null;
         $output = system($command . ' ' . $background, $return);
         // @todo Need to find a way to detect if the process launch failed
         // (no $output is returned even if errors are output to stdout)
         if ($output === false) {
             user_error('There was a problem executing a background task', E_USER_WARNING);
             break;
         }
     }
     // Wait for all children to finish
     $iter = 0;
     $okCount = null;
     do {
         sleep(1);
         $iter++;
         $completed = $this->allChildrenFinished($childCount, $okCount);
         // Time limit
         if ($iter > 20 && !$completed) {
             user_error("Time limit expired, but only {$okCount} of {$childCount} children finished", E_USER_WARNING);
             break;
         }
     } while (!$completed);
     $this->assertEqual($okCount, $childCount, 'Check that all inserts have completed without race condition problems');
 }
Пример #10
0
 public function __construct($argv = array())
 {
     parent::__construct($argv);
     $this->projectRoot = Meshing_Utils::getProjectRoot();
 }
Пример #11
0
 public function testCreateChangeTables()
 {
     $paths = Meshing_Utils::getPaths();
     $snippetsPath = Meshing_Utils::getProjectRoot() . $paths->getPathSystemSnippets();
     $tables = $this->xml->getTables();
     $changeTables = $this->xml->createChangeTables($snippetsPath . '/change_table.xml', $tables);
     $this->assertEqual(count($tables), count($changeTables), 'Ensure there is a change table for each real table');
     // @todo Check that the prefix is the same for each change table
     // @todo Check that the FKs in each change table are mapped to current table PK equivs
 }
Пример #12
0
 public function __construct($inFilename, $outFilename)
 {
     $this->xml = simplexml_load_file($inFilename, 'Meshing_Schema_Element');
     $this->filename = $outFilename;
     $this->snippetDir = Meshing_Utils::getProjectRoot() . Meshing_Utils::getPaths()->getPathSystemSnippets();
 }