本文整理汇总了PHP中Doctrine\ORM\Tools\SchemaTool::dropSchema方法的典型用法代码示例。如果您正苦于以下问题:PHP SchemaTool::dropSchema方法的具体用法?PHP SchemaTool::dropSchema怎么用?PHP SchemaTool::dropSchema使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\Tools\SchemaTool
的用法示例。
在下文中一共展示了SchemaTool::dropSchema方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createSchema
public function createSchema($table)
{
foreach (self::$classes as $meta) {
if ($table === $meta->getTableName() || ".{$table}" === substr($meta->getTableName(), -strlen(".{$table}"))) {
self::$tool->dropSchema([$meta]);
self::$tool->createSchema([$meta]);
}
}
}
示例2: setUpBeforeClass
public static function setUpBeforeClass()
{
$em = self::getEntityManager();
$metaData = $em->getMetadataFactory()->getAllMetadata();
self::$schemaTool = new SchemaTool($em);
self::$schemaTool->dropSchema($metaData);
self::$schemaTool->createSchema($metaData);
static::prepareTestData($em);
}
示例3: doSetUpBeforeClass
/**
* {@inheritdoc}
*/
public static function doSetUpBeforeClass()
{
static::$schemaTool = new SchemaTool(static::$em);
static::$schemaTool->dropSchema(static::getTablesMetadata());
static::$schemaTool->createSchema(static::getTablesMetadata());
static::$encoder = static::$container->get('security.encoder_factory');
static::$user = new User();
static::$user->setEmail('test@test.com');
static::$user->setPassword(static::$encoder->getEncoder(static::$user)->encodePassword('1234', static::$user->getSalt()));
static::$user->setUsername('testUser');
$entityPermissionCategory = new PermissionCategory();
$entityPermissionCategory->setName('backend_user');
$entityPermissionCategory->setTechnicalName('backend_user');
static::$em->persist($entityPermissionCategory);
$entityPermission = new Permission();
$entityPermission->setRoleName('IS_AUTHENTICATED_FULLY');
$entityPermission->setDescription('IS_AUTHENTICATED_FULLY');
$entityPermission->setName('IS_AUTHENTICATED_FULLY');
$entityPermission->setCategory($entityPermissionCategory);
$entityPermission2 = new Permission();
$entityPermission2->setRoleName('ROLE_MANAGE_PERMISSIONS');
$entityPermission2->setDescription('ROLE_MANAGE_PERMISSIONS');
$entityPermission2->setName('ROLE_MANAGE_PERMISSIONS');
$entityPermission2->setCategory($entityPermissionCategory);
$entityPermission3 = new Permission();
$entityPermission3->setRoleName('ROLE_ACCESS_BACKEND_TOOLS_SECURITY_SECTION');
$entityPermission3->setDescription('ROLE_ACCESS_BACKEND_TOOLS_SECURITY_SECTION');
$entityPermission3->setName('ROLE_ACCESS_BACKEND_TOOLS_SECURITY_SECTION');
$entityPermission3->setCategory($entityPermissionCategory);
$entityPermission4 = new Permission();
$entityPermission4->setRoleName('ROLE_MANAGE_USER_PROFILES');
$entityPermission4->setDescription('ROLE_MANAGE_USER_PROFILES');
$entityPermission4->setName('ROLE_MANAGE_USER_PROFILES');
$entityPermission4->setCategory($entityPermissionCategory);
static::$em->persist($entityPermission);
static::$em->persist($entityPermission2);
static::$em->persist($entityPermission3);
static::$em->persist($entityPermission4);
static::$em->flush();
$group = new Group();
$group->setRefName('BACKEND-USER');
$group->setName('backend-user');
$group->addPermission($entityPermission);
$group->addPermission($entityPermission2);
$group->addPermission($entityPermission3);
$group->addPermission($entityPermission4);
static::$user->addToGroup($group);
static::$em->persist($group);
static::$em->persist(static::$user);
static::$em->flush();
}
示例4: setUp
/**
* @inheritdoc
*/
protected function setUp()
{
parent::setUp();
$this->client = $this->createClient(['debug' => false]);
$container = static::$kernel->getContainer();
/** @var EntityManagerInterface[] $managers */
$managers = $container->get('doctrine')->getManagers();
foreach ($managers as $manager) {
$metadata = $manager->getMetadataFactory()->getAllMetadata();
if (!empty($metadata)) {
$tool = new SchemaTool($manager);
$tool->dropSchema($metadata);
$tool->createSchema($metadata);
}
}
$class = $container->getParameter('tree_house.keystone.model.user.class');
$salt = uniqid();
/** @var UserInterface $user */
$user = new $class();
$user->setEnabled(true);
$user->setUsername('test');
$user->addRole('ROLE_USER');
$user->setSalt($salt);
/** @var EncoderFactoryInterface $encoder */
$encoder = $container->get('security.encoder_factory');
$password = $encoder->getEncoder($class)->encodePassword(static::$password, $user->getSalt());
$user->setPassword($password);
/** @var ManagerRegistry $doctrine */
$doctrine = static::$kernel->getContainer()->get('doctrine');
$manager = $doctrine->getManagerForClass($class);
$manager->persist($user);
$manager->flush($user);
$manager->refresh($user);
$this->user = $user;
}
示例5: clean
public static function clean(EntityManager $entityManager)
{
$metadatas = $entityManager->getMetadataFactory()->getAllMetadata();
$database = new SchemaTool($entityManager);
$database->dropSchema($metadatas);
$database->createSchema($metadatas);
}
示例6: adminRefreshDatabaseAction
public function adminRefreshDatabaseAction(Request $request, Application $app)
{
$conn = $app['db'];
$em = $app['doctrine.orm.entity_manager'];
$params = $conn->getParams();
$name = isset($params['path']) ? $params['path'] : (isset($params['dbname']) ? $params['dbname'] : false);
try {
$conn->getSchemaManager()->dropDatabase($name);
$conn->getSchemaManager()->createDatabase($name);
$conn->close();
} catch (\Exception $e) {
return 1;
}
$classes = [];
foreach ($app['authbucket_oauth2.model'] as $class) {
$classes[] = $em->getClassMetadata($class);
}
PersistentObject::setObjectManager($em);
$tool = new SchemaTool($em);
$tool->dropSchema($classes);
$tool->createSchema($classes);
$purger = new ORMPurger();
$executor = new ORMExecutor($em, $purger);
$loader = new Loader();
$loader->loadFromDirectory(__DIR__ . '/../DataFixtures/ORM');
$executor->execute($loader->getFixtures());
return $app->redirect($app['url_generator']->generate('index'));
}
示例7: createDatabaseSchema
private function createDatabaseSchema(EntityManager $em)
{
$tool = new SchemaTool($em);
$allMetadata = $em->getMetadataFactory()->getAllMetadata();
$tool->dropSchema($allMetadata);
$tool->createSchema($allMetadata);
}
示例8: fire
/**
* Execute the console command.
*
* @return void
*/
public function fire()
{
$sql = $this->tool->getDropSchemaSQL($this->metadata->getAllMetadata());
if (empty($sql)) {
$this->info('Current models do not exist in schema.');
return;
}
if ($this->option('sql')) {
$this->info('Outputting drop query:');
$this->info(implode(';' . PHP_EOL, $sql));
} else {
$this->info('Dropping database schema....');
$this->tool->dropSchema($this->metadata->getAllMetadata());
$this->info('Schema has been dropped!');
}
}
示例9: setUp
/**
* Test setup
*/
protected function setUp()
{
// setup entity aliases
$this->em = DoctrineTestHelper::createTestEntityManager();
$entityManagerNamespaces = $this->em->getConfiguration()->getEntityNamespaces();
$entityManagerNamespaces['WebtownPhpBannerBundle'] = 'WebtownPhp\\BannerBundle\\Entity';
$this->em->getConfiguration()->setEntityNamespaces($entityManagerNamespaces);
// setup schema
$schemaTool = new SchemaTool($this->em);
$classes = [];
foreach ($this->getEntities() as $entityClass) {
$classes[] = $this->em->getClassMetadata($entityClass);
}
try {
$schemaTool->dropSchema($classes);
} catch (\Exception $e) {
}
try {
$schemaTool->createSchema($classes);
} catch (\Exception $e) {
}
$registry = \Mockery::mock('Doctrine\\Bundle\\DoctrineBundle\\Registry');
$registry->shouldReceive('getManager')->andReturn($this->em);
$this->bm = new ORMManager($registry, new EventDispatcher());
}
示例10: setUp
/**
* Initializes the database (once).
*
* @throws \Doctrine\DBAL\DBALException
* @throws \Doctrine\ORM\ORMException
* @throws \Doctrine\ORM\Tools\ToolsException
*/
protected function setUp()
{
if (null === static::$_conn) {
$dbPath = __DIR__ . '/../../../db.sqlite';
if (file_exists($dbPath)) {
unlink($dbPath);
}
$params = ['driver' => 'pdo_sqlite', 'path' => $dbPath];
static::$_conn = DriverManager::getConnection($params);
static::$_conn->getConfiguration()->setSQLLogger(null);
}
if (null === static::$_em) {
$paths = [__DIR__ . '/../../../../../src/Ekyna/Commerce/Bridge/Doctrine/ORM/Resources/mapping'];
$isDevMode = true;
$config = Setup::createXMLMetadataConfiguration($paths, $isDevMode);
$em = EntityManager::create(static::$_conn, $config);
$classes = [];
foreach (static::$_classes as $class) {
array_push($classes, $em->getClassMetadata($class));
}
$schemaTool = new SchemaTool($em);
$schemaTool->dropSchema($classes);
$schemaTool->createSchema($classes);
// Load fixtures
$loader = new Loader();
$loader->loadFromDirectory(__DIR__ . '/../../../../../src/Ekyna/Commerce/Bridge/Doctrine/Fixtures');
$purger = new ORMPurger();
$executor = new ORMExecutor($em, $purger);
$executor->execute($loader->getFixtures());
static::$_em = $em;
}
}
示例11: testCreateSchema
function testCreateSchema()
{
/* @var $em \Doctrine\ORM\EntityManager */
$em = $this->app["orm.em"];
$tool = new SchemaTool($em);
//@note @doctrine générer les fichiers de classe à partir de métadonnées
/* generate entity classes */
$dmf = new DisconnectedClassMetadataFactory();
$dmf->setEntityManager($em);
$metadatas = $dmf->getAllMetadata();
//print_r($metadatas);
$generator = new EntityGenerator();
$generator->setGenerateAnnotations(TRUE);
$generator->setGenerateStubMethods(TRUE);
$generator->setRegenerateEntityIfExists(TRUE);
$generator->setUpdateEntityIfExists(TRUE);
$generator->generate($metadatas, ROOT_TEST_DIR);
$generator->setNumSpaces(4);
$this->assertFileExists(ROOT_TEST_DIR . "/Entity/Post.php");
/* @note @doctrine générer la base de donnée à partir des métadonnées */
/* @see Doctrine\ORM\Tools\Console\Command\SchemaTool\CreateCommand */
/* generate database */
$tool->dropSchema($metadatas);
$tool->createSchema($metadatas);
$post = new \Entity\Post();
$post->setTitle("the title");
$em->persist($post);
$em->flush();
$this->assertInternalType("int", $post->getId());
}
示例12: initOrm
protected function initOrm(EntityManagerInterface $entityManager)
{
$schemaTool = new SchemaTool($entityManager);
$metadatas = $entityManager->getMetadataFactory()->getAllMetadata();
$schemaTool->dropSchema($metadatas);
$schemaTool->createSchema($metadatas);
}
示例13: executeSchemaCommand
protected function executeSchemaCommand(InputInterface $input, OutputInterface $output, SchemaTool $schemaTool, array $metadatas)
{
$isFullDatabaseDrop = $input->getOption('full-database');
if ($input->getOption('dump-sql') === true) {
if ($isFullDatabaseDrop) {
$sqls = $schemaTool->getDropDatabaseSQL();
} else {
$sqls = $schemaTool->getDropSchemaSQL($metadatas);
}
$output->write(implode(';' . PHP_EOL, $sqls) . PHP_EOL);
} else {
if ($input->getOption('force') === true) {
$output->write('Dropping database schema...' . PHP_EOL);
if ($isFullDatabaseDrop) {
$schemaTool->dropDatabase();
} else {
$schemaTool->dropSchema($metadatas);
}
$output->write('Database schema dropped successfully!' . PHP_EOL);
} else {
$output->write('ATTENTION: This operation should not be executed in a production environment.' . PHP_EOL . PHP_EOL);
if ($isFullDatabaseDrop) {
$sqls = $schemaTool->getDropDatabaseSQL();
} else {
$sqls = $schemaTool->getDropSchemaSQL($metadatas);
}
if (count($sqls)) {
$output->write('Schema-Tool would execute ' . count($sqls) . ' queries to drop the database.' . PHP_EOL);
$output->write('Please run the operation with --force to execute these queries or use --dump-sql to see them.' . PHP_EOL);
} else {
$output->write('Nothing to drop. The database is empty!' . PHP_EOL);
}
}
}
}
示例14: setUp
protected function setUp()
{
if (!class_exists('Symfony\\Component\\Form\\Form')) {
$this->markTestSkipped('The "Form" component is not available');
}
if (!class_exists('Doctrine\\DBAL\\Platforms\\MySqlPlatform')) {
$this->markTestSkipped('Doctrine DBAL is not available.');
}
if (!class_exists('Doctrine\\Common\\Version')) {
$this->markTestSkipped('Doctrine Common is not available.');
}
if (!class_exists('Doctrine\\ORM\\EntityManager')) {
$this->markTestSkipped('Doctrine ORM is not available.');
}
$this->em = DoctrineOrmTestCase::createTestEntityManager();
$this->emRegistry = $this->createRegistryMock('default', $this->em);
parent::setUp();
$schemaTool = new SchemaTool($this->em);
$classes = array($this->em->getClassMetadata(self::ITEM_GROUP_CLASS), $this->em->getClassMetadata(self::SINGLE_IDENT_CLASS), $this->em->getClassMetadata(self::SINGLE_STRING_IDENT_CLASS), $this->em->getClassMetadata(self::COMPOSITE_IDENT_CLASS), $this->em->getClassMetadata(self::COMPOSITE_STRING_IDENT_CLASS));
try {
$schemaTool->dropSchema($classes);
} catch (\Exception $e) {
}
try {
$schemaTool->createSchema($classes);
} catch (\Exception $e) {
}
}
示例15: setUp
protected function setUp()
{
parent::setUp();
if (!class_exists('Symfony\\Component\\Form\\Form')) {
$this->markTestSkipped('The "Form" component is not available');
}
if (!class_exists('Doctrine\\DBAL\\Platforms\\MySqlPlatform')) {
$this->markTestSkipped('Doctrine DBAL is not available.');
}
if (!class_exists('Doctrine\\Common\\Version')) {
$this->markTestSkipped('Doctrine Common is not available.');
}
if (!class_exists('Doctrine\\ORM\\EntityManager')) {
$this->markTestSkipped('Doctrine ORM is not available.');
}
$this->em = DoctrineTestHelper::createTestEntityManager();
$this->emRegistry = $this->createRegistryMock('default', $this->em);
$this->items = array();
$schemaTool = new SchemaTool($this->em);
$classes = array($this->em->getClassMetadata(self::SINGLE_INT_ID_CLASS));
try {
$schemaTool->dropSchema($classes);
} catch (\Exception $e) {
}
try {
$schemaTool->createSchema($classes);
} catch (\Exception $e) {
}
$this->createEntities();
$this->factory = Forms::createFormFactoryBuilder()->addExtensions($this->getExtensions())->addTypeExtension(new ChoiceSelect2TypeExtension($this->dispatcher, $this->requestStack, $this->router, $this->getExtensionTypeName(), 10))->addType(new EntityType($this->emRegistry))->addTypeExtension(new EntitySelect2TypeExtension())->getFormFactory();
$this->builder = new FormBuilder(null, null, $this->dispatcher, $this->factory);
}