コード例 #1
0
ファイル: create-schema.php プロジェクト: patrova/omeka-s
/**
 * Drop all existing tables, even those not defined in the schema.
 *
 * @param Doctrine\DBAL\Connection $connection
 */
function dropTables(Doctrine\DBAL\Connection $connection)
{
    $connection->query('SET FOREIGN_KEY_CHECKS=0');
    foreach ($connection->getSchemaManager()->listTableNames() as $table) {
        $connection->getSchemaManager()->dropTable($table);
    }
    $connection->query('SET FOREIGN_KEY_CHECKS=1');
}
コード例 #2
0
 /**
  * @return Doctrine\DBAL\Schema\AbstractSchemaManager
  */
 private function getSchemaManager()
 {
     return $this->connection->getSchemaManager();
 }
コード例 #3
0
 /**
  * Setup the metadata driver if necessary options are set. Otherwise Doctrine defaults are used (AnnotationReader).
  *
  * @param array $options
  * @param Doctrine\ORM\Configuration $config
  * @param Doctrine\Common\Cache\AbstractCache $cache
  * @param Doctrine\DBAL\Connection $conn
  */
 protected function _setupMetadataDriver($options, $config, $cache, $conn)
 {
     $driver = false;
     if (isset($options['metadata'])) {
         if (isset($options['metadata']['driver'])) {
             $driverName = $options['metadata']['driver'];
             switch (strtolower($driverName)) {
                 case 'annotation':
                     $driverName = 'Doctrine\\ORM\\Mapping\\Driver\\AnnotationDriver';
                     break;
                 case 'yaml':
                     $driverName = 'Doctrine\\ORM\\Mapping\\Driver\\YamlDriver';
                     break;
                 case 'xml':
                     $driverName = 'Doctrine\\ORM\\Mapping\\Driver\\XmlDriver';
                     break;
                 case 'php':
                     $driverName = 'Doctrine\\ORM\\Mapping\\Driver\\PhpDriver';
                     break;
                 case 'database':
                     $driverName = 'Doctrine\\ORM\\Mapping\\Driver\\DatabaseDriver';
                     break;
             }
             if (!class_exists($driverName)) {
                 throw new ZendX_Doctrine2_Exception("MetadataDriver class '" . $driverName . "' does not exist");
             }
             if (in_array('Doctrine\\ORM\\Mapping\\Driver\\AbstractFileDriver', class_parents($driverName))) {
                 if (!isset($options['metadata']['paths'])) {
                     throw new ZendX_Doctrine2_Exception("Metadata Driver is file based, but no config file paths were given.");
                 }
                 if (!isset($options['metadata']['mode'])) {
                     $options['metadata']['mode'] = \Doctrine\ORM\Mapping\Driver\AbstractFileDriver::FILE_PER_CLASS;
                 }
                 $driver = new $driverName($options['metadata']['paths'], $options['metadata']['mode']);
             } elseif ($driverName == 'Doctrine\\ORM\\Mapping\\Driver\\AnnotationDriver') {
                 $reader = new \Doctrine\Common\Annotations\AnnotationReader($cache);
                 $reader->setDefaultAnnotationNamespace('Doctrine\\ORM\\Mapping\\');
                 $driver = new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($reader);
                 if (isset($options['metadata']['classDirectory'])) {
                     $driver->addPaths(array($options['metadata']['classDirectory']));
                 } else {
                     throw new ZendX_Doctrine2_Exception("Doctrine Annotation Driver requires to set a class directory for the entities.");
                 }
                 //$driverImpl = $config->newDefaultAnnotationDriver("var/www/zfbench/application/models"));
                 //$config->setMetadataDriverImpl($driverImpl);
             } elseif ($driverName == 'Doctrine\\ORM\\Mapping\\Driver\\DatabaseDriver') {
                 $schemaManager = $conn->getSchemaManager();
                 $driver = new \Doctrine\ORM\Mapping\Driver\DatabaseDriver($schemaManager);
             }
             if (!$driver instanceof \Doctrine\ORM\Mapping\Driver\Driver) {
                 throw new ZendX_Doctrine2_Exception("No metadata driver could be loaded.");
             }
             $config->setMetadataDriverImpl($driver);
         }
     }
 }