/** * Creates an OrmController * @return OrmController an OrmController instance */ public static function create() { //check, if an instance of OrmController already exists if (OrmController::$ormController == null) { OrmController::$ormController = new OrmController(); } //return instance return OrmController::$ormController; }
/** * private constructor */ private function __construct() { $ormController = OrmController::create(); $this->entityManager = $ormController->getEntityManager(); }
<?php use Doctrine\ORM\Tools\Console\ConsoleRunner; use yourCMDB\orm\OrmController; $scriptBaseDir = dirname(__FILE__); $coreBaseDir = realpath("{$scriptBaseDir}/../../../../../"); require_once "{$coreBaseDir}/bootstrap.php"; $ormController = OrmController::create(); $entityManager = $ormController->getEntityManager(); return ConsoleRunner::createHelperSet($entityManager);
/** * tries to repair the schema in the configured datastore */ public function repairSchema() { //get instances $ormController = OrmController::create(); $entityManager = $ormController->getEntityManager(); $schemaTool = new SchemaTool($entityManager); $classes = $entityManager->getMetadataFactory()->getAllMetadata(); //create schema $schemaTool->updateSchema($classes); //set version for doctrine migrations $migrationConfig = $this->getMigrationsConfiguration(); $migrationVersions = $migrationConfig->getAvailableVersions(); foreach ($migrationVersions as $migrationVersionString) { $migrationVersion = $migrationConfig->getVersion($migrationVersionString); $migrationVersion->markMigrated(); } }