/**
  * Get the Platform object for this class
  *
  * @return Platform
  */
 protected function getPlatform()
 {
     static $platform;
     if (!$platform) {
         $platform = new MysqlPlatform();
         $config = new GeneratorConfig();
         $config->setBuildProperties(array('propel.mysql.tableType' => 'InnoDB'));
         $platform->setGeneratorConfig($config);
     }
     return $platform;
 }
 /**
  * @return MigrationManager
  */
 private function createMigrationManager(array $migrationTimestamps)
 {
     $generatorConfig = new GeneratorConfig(__DIR__ . '/../../../../Fixtures/migration/');
     $connections = $generatorConfig->getBuildConnections();
     $migrationManager = $this->getMock('Propel\\Generator\\Manager\\MigrationManager', ['getMigrationTimestamps']);
     $migrationManager->setGeneratorConfig($generatorConfig);
     $migrationManager->setConnections($connections);
     $migrationManager->setMigrationTable('migration');
     $migrationManager->expects($this->any())->method('getMigrationTimestamps')->will($this->returnValue($migrationTimestamps));
     // make sure there is no other table named migration
     $migrationManager->getAdapterConnection('migration')->query('DROP TABLE IF EXISTS migration');
     return $migrationManager;
 }
Beispiel #3
0
    public function testAppendXmlNamespaceWithAutoPackage()
    {
        $schema = <<<EOF
<?xml version="1.0"?>
<table name="test" namespace="\\testNs"/>
EOF;
        $doc = new DOMDocument('1.0');
        $doc->formatOutput = true;
        $config = new GeneratorConfig();
        $config->setBuildProperties(array('propel.namespace.autoPackage' => 'true'));
        $appData = new AppData();
        $appData->setGeneratorConfig($config);
        $db = new Database('testDb');
        $db->setAppData($appData);
        $table = new Table('test');
        $table->setDatabase($db);
        $table->setNamespace('\\testNs');
        $table->appendXml($doc);
        $xmlstr = trim($doc->saveXML());
        $this->assertSame($schema, $xmlstr);
        $schema = <<<EOF
<?xml version="1.0"?>
<table name="test" namespace="\\testNs" package="testPkg"/>
EOF;
        $doc = new DOMDocument('1.0');
        $doc->formatOutput = true;
        $table->setPackage('testPkg');
        $table->appendXml($doc);
        $xmlstr = trim($doc->saveXML());
        $this->assertSame($schema, $xmlstr);
    }
 /**
  * Gets the GeneratorConfig object for this task or creates it on-demand.
  * @return     GeneratorConfig
  */
 protected function getGeneratorConfig()
 {
     if ($this->generatorConfig === null) {
         $this->generatorConfig = new GeneratorConfig();
         $this->generatorConfig->setBuildProperties($this->getProject()->getProperties());
     }
     return $this->generatorConfig;
 }
 /**
  * @expectedException \Propel\Generator\Exception\BuildException
  */
 public function testGetClassNameOnInexistantProperty()
 {
     $generator = new GeneratorConfig();
     $generator->getClassName('propel.foo.bar');
 }
Beispiel #6
0
 /**
  * Load the sql file and then execute it
  *
  * @throws     BuildException
  */
 public function main()
 {
     $conf = new GeneratorConfig();
     $conf->setBuildProperties($this->getProject()->getProperties());
     $this->setBuildConnections($conf->getBuildConnections());
     if ($this->sqldbmap === null || $this->getSqlDbMap()->exists() === false) {
         throw new BuildException("You haven't provided an sqldbmap, or " . "the one you specified doesn't exist: " . $this->sqldbmap->getPath());
     }
     if ($this->url === null) {
         throw new BuildException("DSN url attribute must be set!");
     }
     // get an ordered list of SQL files to execute
     $databases = $this->getFilesToExecute();
     $this->log(sprintf('Reading SQL files...'));
     foreach ($databases as $database => $files) {
         $statements[$database] = array();
         foreach ($files as $fileName) {
             $fullFileName = $this->srcDir ? $this->srcDir . DIRECTORY_SEPARATOR . $fileName : $fileName;
             if (file_exists($fullFileName)) {
                 $this->log(sprintf('  Loading statements from "%s"', $fullFileName));
                 $fileStatements = PropelSQLParser::parseFile($fullFileName);
                 $this->log(sprintf('    %d statements to execute', count($fileStatements)), Project::MSG_VERBOSE);
                 $statements[$database] = array_merge($statements[$database], $fileStatements);
             } else {
                 $this->log(sprintf('File "%s" in sqldbmap does not exist, skipping it.', $fullFileName));
             }
         }
     }
     $successfullStatements = 0;
     $this->log(sprintf('Executing SQL statements...'));
     foreach ($statements as $database => $statementList) {
         $successfullStatements += $this->insertDatabaseSqlFiles($database, $statementList);
     }
     $this->log(sprintf('SQL execution complete. %d statements successfully executed.', $successfullStatements));
 }