protected function setUp()
 {
     $config = new Configuration();
     //$config->setHydratorDir(sys_get_temp_dir());
     //$config->setHydratorNamespace('Hydrators');
     $config->setProxyDir(sys_get_temp_dir());
     $config->setProxyNamespace('Proxies');
     $locatorXml = new SymfonyFileLocator(array(__DIR__ . '/../../../../../lib/Vespolina/Product/Mapping' => 'Vespolina\\Entity\\Product', __DIR__ . '/../../../../../vendor/vespolina/pricing/lib/Vespolina/Pricing/Mapping' => 'Vespolina\\Entity\\Pricing', __DIR__ . '/../../../../../vendor/vespolina/taxonomy/lib/Vespolina/Taxonomy/Mapping' => 'Vespolina\\Entity\\Taxonomy'), '.orm.xml');
     $drivers = new MappingDriverChain();
     $xmlDriver = new XmlDriver($locatorXml);
     $config->setMetadataDriverImpl($xmlDriver);
     $config->setMetadataCacheImpl(new ArrayCache());
     $config->setAutoGenerateProxyClasses(true);
     $eventManager = new EventManager();
     $treeListener = new TreeListener();
     $eventManager->addEventSubscriber($treeListener);
     $em = EntityManager::create(array('driver' => 'pdo_sqlite', 'path' => 'database.sqlite'), $config, $eventManager);
     $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($em);
     $classes = array($em->getClassMetadata('Vespolina\\Entity\\Product\\Product'), $em->getClassMetadata('Vespolina\\Entity\\Taxonomy\\TaxonomyNode'));
     try {
         $schemaTool->dropSchema(array());
         $schemaTool->createSchema($classes);
     } catch (\Exception $e) {
     }
     $this->productGateway = new ProductDoctrineORMGateway($em, 'Vespolina\\Entity\\Product\\Product');
     $this->taxonomyGateway = new TaxonomyDoctrineORMGateway($em, 'Vespolina\\Entity\\Taxonomy\\TaxonomyNode');
     parent::setUp();
 }
 public function initDb()
 {
     $configArray = $this->sm->get('config');
     $db_name = $configArray['doctrine']['connection']['orm_default'];
     \Zend\Debug\Debug::dump($db_name);
     exit;
     $DEBUG = true;
     // Retrieve the Doctrine 2 entity manager
     $em = $this->sm->get('doctrine.entitymanager.orm_default');
     // Instantiate the schema tool
     $tool = new \Doctrine\ORM\Tools\SchemaTool($em);
     // Retrieve all of the mapping metadata
     $classes = $em->getMetadataFactory()->getAllMetadata();
     if ($DEBUG) {
         print "dropping schema\n";
     }
     // Delete the existing test database schema
     $tool->dropSchema($classes);
     if ($DEBUG) {
         print "creating schema\n";
     }
     // Create the test database schema
     $tool->createSchema($classes);
     if ($DEBUG) {
         print "schema created\n";
     }
 }
 /**
  * @see http://jamesmcfadden.co.uk/database-unit-testing-with-doctrine-2-and-phpunit/
  */
 public function getConnection()
 {
     // 別途 Application を生成しているような箇所があると動作しないので注意
     $app = EccubeTestCase::createApplication();
     // Get an instance of your entity manager
     $entityManager = $app['orm.em'];
     // Retrieve PDO instance
     $pdo = $entityManager->getConnection()->getWrappedConnection();
     // Clear Doctrine to be safe
     $entityManager->clear();
     // Schema Tool to process our entities
     $tool = new \Doctrine\ORM\Tools\SchemaTool($entityManager);
     $classes = $entityManager->getMetaDataFactory()->getAllMetaData();
     // Drop all classes and re-build them for each test case
     $tool->dropSchema($classes);
     $tool->createSchema($classes);
     $config = new Configuration($app['db']);
     $config->setMigrationsNamespace('DoctrineMigrations');
     $migrationDir = __DIR__ . '/../../../src/Eccube/Resource/doctrine/migration';
     $config->setMigrationsDirectory($migrationDir);
     $config->registerMigrationsFromDirectory($migrationDir);
     $migration = new Migration($config);
     $migration->migrate(null, false);
     self::$app = $app;
     // Pass to PHPUnit
     return $this->createDefaultDBConnection($pdo, 'db_name');
 }
 public static function UpdateSchema()
 {
     $metadata = self::$entityManager->getMetadataFactory()->getAllMetadata();
     $schemaTool = new Doctrine\ORM\Tools\SchemaTool(self::$entityManager);
     $schemaTool->updateSchema($metadata, true);
     return;
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $db = \Database::connection();
     $em = $db->getEntityManager();
     $cacheDriver = $em->getConfiguration()->getMetadataCacheImpl();
     $cacheDriver->flushAll();
     $tool = new \Doctrine\ORM\Tools\SchemaTool($em);
     $schemas = [];
     /**
      * @var $sm MySqlSchemaManager
      */
     $sm = $db->getSchemaManager();
     $dbSchema = $sm->createSchema();
     // core xml tables
     $schemas[] = Schema::getCoreXMLSchema();
     // core entities
     $sm = new DatabaseStructureManager($em);
     $entities = $sm->getMetadatas();
     $schemas[] = $tool->getSchemaFromMetadata($entities);
     // core, application and package block types
     $env = Environment::get();
     $list = new BlockTypeList();
     $list->includeInternalBlockTypes();
     foreach ($list->get() as $bt) {
         $r = $env->getRecord(DIRNAME_BLOCKS . '/' . $bt->getBlockTypeHandle() . '/' . FILENAME_BLOCK_DB, $bt->getPackageHandle());
         if ($r->exists()) {
             $parser = Schema::getSchemaParser(simplexml_load_file($r->file));
             $parser->setIgnoreExistingTables(false);
             $schemas[] = $parser->parse($db);
         }
     }
     // packages
     $packages = Package::getInstalledList();
     foreach ($packages as $pkg) {
         $xmlFile = $pkg->getPackagePath() . '/' . FILENAME_BLOCK_DB;
         if (file_exists($xmlFile)) {
             $parser = Schema::getSchemaParser(simplexml_load_file($xmlFile));
             $parser->setIgnoreExistingTables(false);
             $schemas[] = $parser->parse($db);
         }
     }
     // Finalize output.
     $comparator = new \Doctrine\DBAL\Schema\Comparator();
     $saveQueries = array();
     foreach ($schemas as $schema) {
         $schemaDiff = $comparator->compare($dbSchema, $schema);
         $saveQueries = array_merge($saveQueries, $schemaDiff->toSaveSql($db->getDatabasePlatform()));
     }
     $saveQueries = $this->filterQueries($saveQueries);
     if (count($saveQueries)) {
         $output->writeln(t2('%s query found', '%s queries found', count($saveQueries)));
         $i = 1;
         foreach ($saveQueries as $query) {
             $output->writeln(sprintf('%s: %s', $i, $query));
             $i++;
         }
     } else {
         $output->writeln(t('No differences found between schema and database.'));
     }
 }
 public function run()
 {
     $tool = new \Doctrine\ORM\Tools\SchemaTool($this->entityManager);
     $classes = PartKeepr::getClassMetaData();
     $tool->updateSchema($classes, true);
     $this->logMessage("Database Schema created/updated");
 }
Exemple #7
0
 public function runAction()
 {
     $em = $this->getEntityManager();
     $console = $this->getServiceLocator()->get('console');
     $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($em);
     $console->writeLine('建立資料表中, 請稍待!!', ColorInterface::GREEN);
     $classes = $em->getMetadataFactory()->getAllMetadata();
     if ($this->params()->fromRoute('re-create-database')) {
         $schemaTool->dropSchema($classes);
     }
     $schemaTool->createSchema($classes);
     // 安裝預設管理人員及選單
     $username = '******';
     $password = \Zend\Math\Rand::getString(8, null, true);
     $user = new \Base\Entity\User();
     $user->setUsername($username);
     $user->setPassword(\Zend\Ldap\Attribute::createPassword($password));
     $user->setDisplayName('管理者');
     $user->setRole('admin');
     $em->persist($user);
     $em->flush();
     $menu = new \Base\Entity\Menu();
     $menu->setName('首頁');
     $menu->setUser($user);
     $params = ['max_records' => 10, 'order_kind' => 'desc', 'term' => ''];
     $menu->setParams(serialize($params));
     $em->persist($menu);
     $em->flush();
     $console->writeLine('建立完成!!', ColorInterface::GREEN);
     $console->writeLine('預設帳號 ' . $username . ', 密碼 ' . $password, ColorInterface::GREEN);
 }
 public function setUp()
 {
     $config = new \Doctrine\ORM\Configuration();
     $config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache());
     $config->setQueryCacheImpl(new \Doctrine\Common\Cache\ArrayCache());
     $config->setProxyDir(__DIR__ . '/_files');
     $config->setProxyNamespace('DoctrineExtensions\\LargeCollections\\Proxies');
     $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver());
     $conn = array('driver' => 'pdo_sqlite', 'memory' => true);
     #$config->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger());
     $this->em = \Doctrine\ORM\EntityManager::create($conn, $config);
     $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($this->em);
     $schemaTool->createSchema(array($this->em->getClassMetadata('DoctrineExtensions\\LargeCollections\\Article'), $this->em->getClassMetadata('DoctrineExtensions\\LargeCollections\\Tag'), $this->em->getClassMetadata('DoctrineExtensions\\LargeCollections\\Comment')));
     $article = new Article();
     $tag1 = new Tag();
     $tag2 = new Tag();
     $comment1 = new Comment();
     $comment2 = new Comment();
     $article->addComment($comment1);
     $article->addComment($comment2);
     $article->addTag($tag1);
     $article->addTag($tag2);
     $this->em->persist($article);
     $this->em->persist($tag1);
     $this->em->persist($tag2);
     $this->em->persist($comment1);
     $this->em->persist($comment2);
     $this->em->flush();
     $this->articleId = $article->id();
     $this->em->clear();
 }
 /**
  * create schema from annotation mapping files
  * @return void
  */
 protected function _createSchemas()
 {
     $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($this->_em);
     $classes = array($this->_em->getClassMetadata("\\Ali\\DatatableBundle\\Tests\\TestBundle\\Entity\\Category"), $this->_em->getClassMetadata("\\Ali\\DatatableBundle\\Tests\\TestBundle\\Entity\\Product"), $this->_em->getClassMetadata("\\Ali\\DatatableBundle\\Tests\\TestBundle\\Entity\\Feature"));
     $schemaTool->dropSchema($classes);
     $schemaTool->createSchema($classes);
 }
 public function setUp()
 {
     if (version_compare(\Doctrine\Common\Version::VERSION, '2.1.0RC4-DEV', '>=')) {
         $this->markTestSkipped('Doctrine common is 2.1.0RC4-DEV version, skipping.');
     } else {
         if (version_compare(\Doctrine\Common\Version::VERSION, '2.1.0-BETA3-DEV', '>=')) {
             $reader = new AnnotationReader();
             $reader->setDefaultAnnotationNamespace('Doctrine\\ORM\\Mapping\\');
             $reader->setIgnoreNotImportedAnnotations(true);
             $reader->setAnnotationNamespaceAlias('Gedmo\\Mapping\\Annotation\\', 'gedmo');
             $reader->setEnableParsePhpImports(false);
             $reader->setAutoloadAnnotations(true);
             $reader = new CachedReader(new \Doctrine\Common\Annotations\IndexedReader($reader), new ArrayCache());
         } else {
             $reader = new AnnotationReader();
             $reader->setAutoloadAnnotations(true);
             $reader->setAnnotationNamespaceAlias('Gedmo\\Mapping\\Annotation\\', 'gedmo');
             $reader->setDefaultAnnotationNamespace('Doctrine\\ORM\\Mapping\\');
         }
     }
     $config = new \Doctrine\ORM\Configuration();
     $config->setProxyDir(TESTS_TEMP_DIR);
     $config->setProxyNamespace('Gedmo\\Mapping\\Proxy');
     $config->setMetadataDriverImpl(new AnnotationDriver($reader));
     $conn = array('driver' => 'pdo_sqlite', 'memory' => true);
     //$config->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger());
     $evm = new \Doctrine\Common\EventManager();
     $this->timestampable = new \Gedmo\Timestampable\TimestampableListener();
     $evm->addEventSubscriber($this->timestampable);
     $this->em = \Doctrine\ORM\EntityManager::create($conn, $config, $evm);
     $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($this->em);
     $schemaTool->dropSchema(array());
     $schemaTool->createSchema(array($this->em->getClassMetadata(self::ARTICLE)));
 }
 /**
  * Generates a new migration file and returns the path to it.
  *
  * If $diffAgainstCurrent is TRUE, it generates a migration file with the
  * diff between current DB structure and the found mapping metadata.
  *
  * Otherwise an empty migration skeleton is generated.
  *
  * @param boolean $diffAgainstCurrent
  * @return string Path to the new file
  */
 public function generateAndExecutePartialMigrationFor($tables = array(), $package = null, $diffAgainstCurrent = TRUE)
 {
     $configuration = $this->getMigrationConfiguration();
     $up = NULL;
     $down = NULL;
     if ($diffAgainstCurrent === TRUE) {
         $connection = $this->entityManager->getConnection();
         $platform = $connection->getDatabasePlatform();
         $metadata = $this->entityManager->getMetadataFactory()->getAllMetadata();
         if (empty($metadata)) {
             return 'No mapping information to process.';
         }
         $tool = new \Doctrine\ORM\Tools\SchemaTool($this->entityManager);
         $fromSchema = $connection->getSchemaManager()->createSchema();
         $toSchema = $tool->getSchemaFromMetadata($metadata);
         $fromSchema = $this->filterSchema($fromSchema, $tables);
         $toSchema = $this->filterSchema($toSchema, $tables);
         $up = $this->buildCodeFromSql($configuration, $fromSchema->getMigrateToSql($toSchema, $platform));
         $down = $this->buildCodeFromSql($configuration, $fromSchema->getMigrateFromSql($toSchema, $platform));
         if (!$up && !$down) {
             return 'No changes detected in your mapping information.';
         }
     }
     if (!is_null($package) && $this->packageManager->isPackageActive($package)) {
         $package = $this->packageManager->getPackage($package);
         $migrationsPath = $package->getPackagePath() . "Migrations/" . ucfirst($platform->getName()) . "/";
         $configuration->setMigrationsDirectory($migrationsPath);
     }
     $migrationFile = $this->writeMigrationClassToFile($configuration, $up, $down);
     preg_match("/Version([0-9]+)\\.php/", $migrationFile, $matches);
     $version = $matches[1];
     $this->executeMigration($version);
 }
Exemple #12
0
 public function updateSchema($em)
 {
     $tool = new \Doctrine\ORM\Tools\SchemaTool($em);
     $classes = array($em->getClassMetadata("Entities:User"), $em->getClassMetadata("Entities:Partener"), $em->getClassMetadata("Entities:Transaction"), $em->getClassMetadata("Entities:UserNotification"), $em->getClassMetadata("Entities:JobLog"), $em->getClassMetadata("Entities:Email"), $em->getClassMetadata("Entities:Task"), $em->getClassMetadata("Entities:TaskNotes"), $em->getClassMetadata("Entities:TaskList"), $em->getClassMetadata("Entities:TaskReminder"), $em->getClassMetadata("Entities:Rol"), $em->getClassMetadata("Entities:Permisiune"), $em->getClassMetadata("Entities:RolPermisiune"), $em->getClassMetadata("Entities:Pachet"), $em->getClassMetadata("Entities:Serviciu"), $em->getClassMetadata("Entities:CISession"), $em->getClassMetadata("Entities:Order"), $em->getClassMetadata("Entities:OrderItem"), $em->getClassMetadata("Entities:SimplePage"), $em->getClassMetadata("Entities:News"), $em->getClassMetadata("Entities:NewsletterSubscriber"));
     $tool->updateSchema($classes);
     exit("done");
 }
Exemple #13
0
 /**
  * @test
  */
 public function shouldHandleApcQueryCache()
 {
     if (!extension_loaded('apc') || !ini_get('apc.enable_cli')) {
         $this->markTestSkipped('APC extension is not loaded.');
     }
     $config = new \Doctrine\ORM\Configuration();
     $config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ApcCache());
     $config->setQueryCacheImpl(new \Doctrine\Common\Cache\ApcCache());
     $config->setProxyDir(__DIR__);
     $config->setProxyNamespace('Gedmo\\Mapping\\Proxy');
     $config->getAutoGenerateProxyClasses(false);
     $config->setMetadataDriverImpl($this->getMetadataDriverImplementation());
     $conn = array('driver' => 'pdo_sqlite', 'memory' => true);
     $em = \Doctrine\ORM\EntityManager::create($conn, $config);
     $schema = array_map(function ($class) use($em) {
         return $em->getClassMetadata($class);
     }, (array) $this->getUsedEntityFixtures());
     $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($em);
     $schemaTool->dropSchema(array());
     $schemaTool->createSchema($schema);
     $this->populate($em);
     $_GET['filterField'] = 'a.title';
     $_GET['filterValue'] = 'summer';
     $query = $em->createQuery('SELECT a FROM Test\\Fixture\\Entity\\Article a');
     $p = new Paginator();
     $view = $p->paginate($query, 1, 10);
     $query = $em->createQuery('SELECT a FROM Test\\Fixture\\Entity\\Article a');
     $view = $p->paginate($query, 1, 10);
 }
 public static function cleanDatabase($em)
 {
     $tool = new \Doctrine\ORM\Tools\SchemaTool($em);
     $classes = array($em->getClassMetadata('Poc\\PocPlugins\\Tagging\\Driver\\Doctrine2\\Entities\\Cache'), $em->getClassMetadata('Poc\\PocPlugins\\Tagging\\Driver\\Doctrine2\\Entities\\CacheTag'), $em->getClassMetadata('Poc\\PocPlugins\\Tagging\\Driver\\Doctrine2\\Entities\\Tag'));
     $tool->dropDatabase();
     $tool->createSchema($classes);
 }
 public static function init()
 {
     // Load the user-defined test configuration file, if it exists; otherwise, load
     if (is_readable(__DIR__ . '/TestConfig.php')) {
         $testConfig = (include __DIR__ . '/TestConfig.php');
     } else {
         $testConfig = (include __DIR__ . '/TestConfig.php.dist');
     }
     $zf2ModulePaths = array();
     if (isset($testConfig['module_listener_options']['module_paths'])) {
         $modulePaths = $testConfig['module_listener_options']['module_paths'];
         foreach ($modulePaths as $modulePath) {
             if ($path = static::findParentPath($modulePath)) {
                 $zf2ModulePaths[] = $path;
             }
         }
     }
     $zf2ModulePaths = implode(PATH_SEPARATOR, $zf2ModulePaths) . PATH_SEPARATOR;
     $zf2ModulePaths .= getenv('ZF2_MODULES_TEST_PATHS') ?: (defined('ZF2_MODULES_TEST_PATHS') ? ZF2_MODULES_TEST_PATHS : '');
     static::initAutoloader();
     // use ModuleManager to load this module and it's dependencies
     $baseConfig = array('module_listener_options' => array('module_paths' => explode(PATH_SEPARATOR, $zf2ModulePaths)));
     $config = ArrayUtils::merge($baseConfig, $testConfig);
     $application = \Zend\Mvc\Application::init($config);
     // build test database
     $entityManager = $application->getServiceManager()->get('doctrine.entitymanager.orm_default');
     $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($entityManager);
     $schemaTool->createSchema($entityManager->getMetadataFactory()->getAllMetadata());
     static::$application = $application;
 }
Exemple #16
0
function buildSchema()
{
    $em = \Codeception\Module\Doctrine2::$em;
    $tool = new \Doctrine\ORM\Tools\SchemaTool($em);
    $classes = array($em->getClassMetadata('Facilis\\Users\\UserAggregate'), $em->getClassMetadata('Facilis\\Users\\UserData'), $em->getClassMetadata('Facilis\\Users\\OAuth2\\OAuthAccount'));
    $tool->createSchema($classes);
}
 /**
  * データベースを初期化する.
  *
  * データベースを初期化し、マイグレーションを行なう.
  * 全てのデータが初期化されるため注意すること.
  *
  * @link http://jamesmcfadden.co.uk/database-unit-testing-with-doctrine-2-and-phpunit/
  */
 public function initializeDatabase()
 {
     // Get an instance of your entity manager
     $entityManager = $this->app['orm.em'];
     // Retrieve PDO instance
     $pdo = $entityManager->getConnection()->getWrappedConnection();
     // Clear Doctrine to be safe
     $entityManager->clear();
     // Schema Tool to process our entities
     $tool = new \Doctrine\ORM\Tools\SchemaTool($entityManager);
     $classes = $entityManager->getMetaDataFactory()->getAllMetaData();
     // Drop all classes and re-build them for each test case
     $tool->dropSchema($classes);
     $tool->createSchema($classes);
     $config = new Configuration($this->app['db']);
     $config->setMigrationsNamespace('DoctrineMigrations');
     $migrationDir = __DIR__ . '/../../../src/Eccube/Resource/doctrine/migration';
     $config->setMigrationsDirectory($migrationDir);
     $config->registerMigrationsFromDirectory($migrationDir);
     $migration = new Migration($config);
     $migration->migrate(null, false);
     // 通常は eccube_install.sh で追加されるデータを追加する
     $sql = "INSERT INTO dtb_member (member_id, login_id, password, salt, work, del_flg, authority, creator_id, rank, update_date, create_date,name,department) VALUES (2, 'admin', 'test', 'test', 1, 0, 0, 1, 1, current_timestamp, current_timestamp,'管理者','EC-CUBE SHOP')";
     $stmt = $pdo->prepare($sql);
     $stmt->execute();
     $sql = "INSERT INTO dtb_base_info (id, shop_name, email01, email02, email03, email04, update_date, option_product_tax_rule) VALUES (1, 'SHOP_NAME', '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', current_timestamp, 0)";
     $stmt = $pdo->prepare($sql);
     $stmt->execute();
 }
 private function prepare()
 {
     $cmf = $this->em->getMetadataFactory();
     $metadata = new ClassMetadata('Mapping\\Fixture\\Unmapped\\Timestampable');
     $id = array();
     $id['fieldName'] = 'id';
     $id['type'] = 'integer';
     $id['nullable'] = false;
     $id['columnName'] = 'id';
     $id['id'] = true;
     $metadata->mapField($id);
     $created = array();
     $created['fieldName'] = 'created';
     $created['type'] = 'datetime';
     $created['nullable'] = false;
     $created['columnName'] = 'created';
     $metadata->mapField($created);
     $metadata->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_IDENTITY);
     $metadata->setIdGenerator(new \Doctrine\ORM\Id\IdentityGenerator(null));
     $metadata->setPrimaryTable(array('name' => 'temp_test'));
     $cmf->setMetadataFor('Mapping\\Fixture\\Unmapped\\Timestampable', $metadata);
     // trigger loadClassMetadata event
     $evm = $this->em->getEventManager();
     $eventArgs = new \Doctrine\ORM\Event\LoadClassMetadataEventArgs($metadata, $this->em);
     $evm->dispatchEvent(\Doctrine\ORM\Events::loadClassMetadata, $eventArgs);
     if (Version::compare('2.3.0-dev') <= 0) {
         $metadata->wakeupReflection($cmf->getReflectionService());
     }
     $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($this->em);
     $schemaTool->dropSchema(array());
     $schemaTool->createSchema(array($this->em->getClassMetadata('Mapping\\Fixture\\Unmapped\\Timestampable')));
 }
Exemple #19
0
 /**
  * @todo
  */
 public function dbUpdate()
 {
     $success = true;
     try {
         $dummy = DB::em()->getConfiguration()->getMetadataDriverImpl();
         $dummy->addPaths(array(APPLICATION_PATH . '/models'));
         $metadatas = DB::em()->getMetadataFactory()->getAllMetadata();
         if (!empty($metadatas)) {
             $schemaTool = new \Doctrine\ORM\Tools\SchemaTool(DB::em());
             $sqls = $schemaTool->getUpdateSchemaSql($metadatas, true);
             if (!empty($sqls)) {
                 if (App::$inst->request->post('update')) {
                     $schemaTool->updateSchema($metadatas, true);
                     $message = 'Database schema updated successfully!';
                 } else {
                     $message = 'List of updates:<br/>';
                     $message .= implode(';' . PHP_EOL, $sqls) . ';';
                 }
             } else {
                 $message = 'SQLs are empty. Database schema is up to date';
             }
         } else {
             $message = 'Database schema is up to date';
         }
     } catch (Exception $e) {
         $success = false;
         $message = $e->getMessage() . $e->getTraceAsString();
     }
     $this->jsonResponse($success, $message);
 }
Exemple #20
0
 public function resetDatabase()
 {
     $metadatas = $this->em->getMetadataFactory()->getAllMetadata();
     $tool = new \Doctrine\ORM\Tools\SchemaTool($this->em);
     $tool->dropDatabase();
     $tool->createSchema($metadatas);
 }
Exemple #21
0
 public function initDb()
 {
     $this->create_database("whathood_test");
     $DEBUG = false;
     // Retrieve the Doctrine 2 entity manager
     $em = $this->getServiceManager()->get('mydoctrineentitymanager');
     // Instantiate the schema tool
     $tool = new \Doctrine\ORM\Tools\SchemaTool($em);
     // Retrieve all of the mapping metadata
     $classes = $em->getMetadataFactory()->getAllMetadata();
     if ($DEBUG) {
         print "dropping schema\n";
     }
     // Delete the existing test database schema
     $tool->dropSchema($classes);
     if ($DEBUG) {
         print "creating schema\n";
     }
     // Create the test database schema
     $tool->createSchema($classes);
     if ($DEBUG) {
         print "schema created\n";
     }
     // don't really know why we have to clear this but it works to stop
     // it when the entity manager doesn't seem to persist shit
     $em->clear();
 }
 public function remove(GenericEvent $event)
 {
     if ($event->getArgument('plugin_name') != 'newscoop/meteoblue-plugin-bundle') {
         return;
     }
     $tool = new \Doctrine\ORM\Tools\SchemaTool($this->em);
     $tool->dropSchema($this->getClasses(), true);
 }
Exemple #23
0
 public function tearDown()
 {
     $this->doctrineContainer->getConnection()->close();
     $em = $this->doctrineContainer->getEntityManager();
     $tool = new \Doctrine\ORM\Tools\SchemaTool($em);
     $tool->dropDatabase();
     parent::tearDown();
 }
 private function importSchemaForEm(EntityManager $em)
 {
     $metadata = $em->getMetadataFactory()->getAllMetadata();
     if (!empty($metadata)) {
         $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($em);
         $schemaTool->createSchema($metadata);
     }
 }
Exemple #25
0
 protected function dropAndCreateSchema()
 {
     $em = $this->getEntityManager();
     $metadatas = $em->getMetadataFactory()->getAllMetadata();
     $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($this->getEntityManager());
     $schemaTool->dropSchema($metadatas);
     $schemaTool->createSchema($metadatas);
 }
 public function update(GenericEvent $event)
 {
     $tool = new \Doctrine\ORM\Tools\SchemaTool($this->em);
     $tool->updateSchema($this->getClasses(), true);
     $this->em->getProxyFactory()->generateProxyClasses($this->getClasses(), __DIR__ . '/../../../../library/Proxy');
     $this->setPermissions();
     $this->addJobs();
 }
 /**
  */
 protected function generateSchema()
 {
     $metadatas = $this->getMetadatas();
     if (!empty($metadatas)) {
         $tool = new \Doctrine\ORM\Tools\SchemaTool($this->em);
         $tool->dropSchema($metadatas);
         $tool->createSchema($metadatas);
     }
 }
Exemple #28
0
 protected final function importDatabaseSchema()
 {
     $em = self::$kernel->getContainer()->get('em');
     $metadata = $em->getMetadataFactory()->getAllMetadata();
     if (!empty($metadata)) {
         $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($em);
         $schemaTool->createSchema($metadata);
     }
 }
 public function remove(GenericEvent $event)
 {
     $tool = new \Doctrine\ORM\Tools\SchemaTool($this->em);
     $tool->dropSchema($this->getClasses(), true);
     $removeEmail = $this->em->getRepository('Newscoop\\NewscoopBundle\\Entity\\SystemPreferences')->findOneBy(array('option' => 'SendRecommendationEmail'));
     $this->em->remove($removeEmail);
     $this->em->remove($removeNonUserPref);
     $this->em->flush();
 }
 protected function setUp()
 {
     parent::setUp();
     $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($this->_em);
     try {
         $schemaTool->createSchema(array($this->_em->getClassMetadata('Doctrine\\Tests\\ORM\\Functional\\Train'), $this->_em->getClassMetadata('Doctrine\\Tests\\ORM\\Functional\\TrainDriver'), $this->_em->getClassMetadata('Doctrine\\Tests\\ORM\\Functional\\TrainOwner'), $this->_em->getClassMetadata('Doctrine\\Tests\\ORM\\Functional\\Waggon'), $this->_em->getClassMetadata('Doctrine\\Tests\\ORM\\Functional\\TrainOrder')));
     } catch (\Exception $e) {
     }
 }