api.emotionhero.com/bin/generate_db.php

50 lines
1.2 KiB
PHP
Raw Normal View History

2016-09-01 10:15:17 +00:00
<?php
chdir(__DIR__);
require_once __DIR__ . "/../bootstrap.php";
// Show table creation statements
// And (re)generate Proxies
$em = $_em;
var_dump($em->getConnection()->getDatabasePlatform()->getName());
// $serializer = JMS\Serializer\SerializerBuilder::create()->build();
$metadatas = $em->getMetadataFactory()->getAllMetadata();
// $metadatas = MetadataFilter::filter($metadatas, $input->getOption('filter'));
$destPath = $em->getConfiguration()->getProxyDir();
$em->getProxyFactory()->generateProxyClasses($metadatas, $destPath);
$tool = new Doctrine\ORM\Tools\SchemaTool($em);
$classes = $metadatas;
// $classes = array(
// $em->getClassMetadata('EmotionHero\Models\Emotion'),
// );
// $tool->getCreateDatabaseSQL();
$queries = $tool->getCreateSchemaSQL($classes);
// $queries = $tool->getUpdateSchemaSql($classes);
foreach($queries as $sql){ echo "$sql;\n"; }
// updateSchema
$tool->updateSchema($classes);
$emotions = ['anger','contempt','disgust', 'fear', 'joy','sadness','surprise'];
foreach($emotions as $emo) {
$emotion = new EmotionHero\Models\Emotion();
$emotion->setName($emo);
$em->persist($emotion);
}
$user = new EmotionHero\Models\User();
$em->persist($user);
$em->flush();
var_dump($user->getId());