/** * @param array $paths * @param bool|false $connection */ public function addPaths(array $paths = [], $connection = false) { $connections = $connection ? [$connection] : $this->registry->getManagerNames(); foreach ($connections as $connection) { $this->getMetaDataDriver($connection)->addPaths($paths); } }
/** * Execute the console command. * * @param ManagerRegistry $registry */ public function fire(ManagerRegistry $registry) { $names = $this->option('em') ? [$this->option('em')] : $registry->getManagerNames(); foreach ($names as $name) { $em = $registry->getManager($name); $cache = $em->getConfiguration()->getQueryCacheImpl(); if (!$cache) { throw new InvalidArgumentException('No Result cache driver is configured on given EntityManager.'); } if ($cache instanceof ApcCache) { throw new LogicException("Cannot clear APC Cache from Console, its shared in the Webserver memory and not accessible from the CLI."); } if ($cache instanceof XcacheCache) { throw new LogicException("Cannot clear XCache Cache from Console, its shared in the Webserver memory and not accessible from the CLI."); } $this->message('Clearing result cache entries for <info>' . $name . '</info> entity manager'); $result = $cache->deleteAll(); $message = $result ? 'Successfully deleted cache entries.' : 'No cache entries were deleted.'; if ($this->option('flush')) { $result = $cache->flushAll(); $message = $result ? 'Successfully flushed cache entries.' : $message; } $this->info($message); } }
/** * Execute the console command. * * @param ManagerRegistry $registry */ public function fire(ManagerRegistry $registry) { $names = $this->option('em') ? [$this->option('em')] : $registry->getManagerNames(); foreach ($names as $name) { $em = $registry->getManager($name); $validator = new SchemaValidator($em); $this->comment(''); $this->message('Validating for <info>' . $name . '</info> entity manager...'); if ($this->option('skip-mapping')) { $this->comment('Mapping] Skipped mapping check.'); } elseif ($errors = $validator->validateMapping()) { foreach ($errors as $className => $errorMessages) { $this->error("[Mapping] FAIL - The entity-class '" . $className . "' mapping is invalid:"); $this->comment(''); foreach ($errorMessages as $errorMessage) { $this->message('* ' . $errorMessage, 'red'); } } } else { $this->info('[Mapping] OK - The mapping files are correct.'); } if ($this->option('skip-sync')) { $this->comment('Database] SKIPPED - The database was not checked for synchronicity.'); } elseif (!$validator->schemaInSyncWithMetadata()) { $this->error('[Database] FAIL - The database schema is not in sync with the current mapping file.'); } else { $this->info('[Database] OK - The database schema is in sync with the mapping files.'); } } }
/** * Execute the console command. * * @param ManagerRegistry $registry */ public function fire(ManagerRegistry $registry) { $names = $this->option('em') ? [$this->option('em')] : $registry->getManagerNames(); foreach ($names as $name) { $em = $registry->getManager($name); try { $em->getConfiguration()->ensureProductionSettings(); if ($this->option('with-db')) { $em->getConnection()->connect(); } } catch (Exception $e) { $this->error('Error for ' . $name . ' entity manager'); $this->error($e->getMessage()); return; } $this->comment('Environment for <info>' . $name . '</info> entity manager is correctly configured for production.'); } }
/** * Execute the console command. * * @param ManagerRegistry $registry */ public function fire(ManagerRegistry $registry) { $this->error('ATTENTION: This operation should not be executed in a production environment.'); $names = $this->option('em') ? [$this->option('em')] : $registry->getManagerNames(); foreach ($names as $name) { $em = $registry->getManager($name); $tool = new SchemaTool($em); $this->info(''); $this->message('Checking scheme for <info>' . $name . '</info> entity manager...'); if ($this->option('sql')) { if ($this->option('full')) { $sql = $tool->getDropDatabaseSQL(); } else { $sql = $tool->getDropSchemaSQL($em->getMetadataFactory()->getAllMetadata()); } $this->comment(' ' . implode('; ' . PHP_EOL, $sql)); } else { if ($this->option('force')) { $this->message('Dropping database schema...'); if ($this->option('full')) { $tool->dropDatabase(); } else { $tool->dropSchema($em->getMetadataFactory()->getAllMetadata()); } $this->info('Database schema dropped successfully!'); } if ($this->option('full')) { $sql = $tool->getDropDatabaseSQL(); } else { $sql = $tool->getDropSchemaSQL($em->getMetadataFactory()->getAllMetadata()); } if (count($sql)) { $pluralization = 1 === count($sql) ? 'query was' : 'queries were'; $this->message(sprintf('The Schema-Tool would execute <info>"%s"</info> %s to update the database.', count($sql), $pluralization)); $this->message('Please run the operation by passing one - or both - of the following options:'); $this->comment(sprintf(' <info>php artisan %s --force</info> to execute the command', $this->getName())); $this->comment(sprintf(' <info>php artisan %s --sql</info> to dump the SQL statements to the screen', $this->getName())); } else { $this->error('Nothing to drop. The database is empty!'); } } } }
/** * Execute the console command. * * @param ManagerRegistry $registry */ public function fire(ManagerRegistry $registry) { $names = $this->option('em') ? [$this->option('em')] : $registry->getManagerNames(); if (!$this->option('sql')) { $this->error('ATTENTION: This operation should not be executed in a production environment.'); } foreach ($names as $name) { $em = $registry->getManager($name); $tool = new SchemaTool($em); $this->message('Creating database schema for <info>' . $name . '</info> entity manager...', 'blue'); if ($this->option('sql')) { $sql = $tool->getCreateSchemaSql($em->getMetadataFactory()->getAllMetadata()); $this->comment(' ' . implode('; ' . PHP_EOL, $sql)); } else { $tool->createSchema($em->getMetadataFactory()->getAllMetadata()); } } $this->info('Database schema created successfully!'); }
/** * Execute the console command. * * @param ManagerRegistry $registry * * @throws Exception */ public function fire(ManagerRegistry $registry) { $names = $this->option('em') ? [$this->option('em')] : $registry->getManagerNames(); foreach ($names as $name) { $em = $registry->getManager($name); $entityClassNames = $em->getConfiguration()->getMetadataDriverImpl()->getAllClassNames(); if (!$entityClassNames) { throw new Exception('You do not have any mapped Doctrine ORM entities according to the current configuration. ' . 'If you have entities or mapping files you should check your mapping configuration for errors.'); } $this->message(sprintf("Found <info>%d</info> mapped entities for <info>{$name}</info> entity manager:", count($entityClassNames))); foreach ($entityClassNames as $entityClassName) { try { $em->getClassMetadata($entityClassName); $this->comment(sprintf("<info>[OK]</info> %s", $entityClassName)); } catch (MappingException $e) { $this->comment("<error>[FAIL]</error> " . $entityClassName); $this->comment(sprintf("<comment>%s</comment>", $e->getMessage())); $this->comment(''); } } } }
/** * Execute the console command. * * @param ManagerRegistry $registry */ public function fire(ManagerRegistry $registry) { if (!$this->option('sql') && (!$this->laravel->environment('local') && !$this->option('force'))) { $this->error('ATTENTION: This operation should not be executed in a production environment.'); $this->error('Use the incremental update to detect changes during development and use'); $this->error('the SQL DDL provided to manually update your database in production.'); } $names = $this->option('em') ? [$this->option('em')] : $registry->getManagerNames(); foreach ($names as $name) { $em = $registry->getManager($name); $tool = new SchemaTool($em); $this->comment(''); $this->message('Checking if database connected to <info>' . $name . '</info> entity manager needs updating...', 'blue'); // Check if there are updates available $sql = $tool->getUpdateSchemaSql($em->getMetadataFactory()->getAllMetadata(), !$this->option('clean')); if (0 === count($sql)) { return $this->error('Nothing to update - your database is already in sync with the current entity metadata.'); } if ($this->option('sql')) { $this->comment(' ' . implode('; ' . PHP_EOL, $sql)); } else { if ($this->laravel->environment('local') || $this->option('force')) { $this->message('Updating database schema...', 'blue'); $tool->updateSchema($em->getMetadataFactory()->getAllMetadata(), !$this->option('clean')); $pluralization = 1 === count($sql) ? 'query was' : 'queries were'; $this->info(sprintf('Database schema updated successfully! "<info>%s</info>" %s executed', count($sql), $pluralization)); } else { $this->message(sprintf('The Schema-Tool would execute <info>"%s"</info> queries to update the database.', count($sql))); } } } if (!$this->option('sql') && (!$this->laravel->environment('local') && !$this->option('force'))) { $this->info(''); $this->message('Please run the operation by passing one - or both - of the following options:'); $this->comment(sprintf(' <info>php artisan %s --force</info> to execute the command', $this->getName())); $this->comment(sprintf(' <info>php artisan %s --sql</info> to dump the SQL statements to the screen', $this->getName())); } }
/** * Execute the console command. * * @param ManagerRegistry $registry */ public function fire(ManagerRegistry $registry) { $names = $this->option('em') ? [$this->option('em')] : $registry->getManagerNames(); foreach ($names as $name) { $em = $registry->getManager($name); $this->comment(''); $this->message('Generating proxies for <info>' . $name . '</info> entity manager...', 'blue'); $metadatas = $em->getMetadataFactory()->getAllMetadata(); $metadatas = MetadataFilter::filter($metadatas, $this->option('filter')); // Process destination directory if (($destPath = $this->argument('dest-path')) === null) { $destPath = $em->getConfiguration()->getProxyDir(); } if (!is_dir($destPath)) { mkdir($destPath, 0777, true); } $destPath = realpath($destPath); if (!file_exists($destPath)) { throw new InvalidArgumentException(sprintf("Proxies destination directory '<info>%s</info>' does not exist.", $em->getConfiguration()->getProxyDir())); } if (!is_writable($destPath)) { throw new InvalidArgumentException(sprintf("Proxies destination directory '<info>%s</info>' does not have write permissions.", $destPath)); } if (count($metadatas)) { foreach ($metadatas as $metadata) { $this->comment(sprintf('Processing entity "<info>%s</info>"', $metadata->name)); } // Generating Proxies $em->getProxyFactory()->generateProxyClasses($metadatas, $destPath); // Outputting information message $this->comment(sprintf('Proxy classes generated to "<info>%s</INFO>"', $destPath)); } else { $this->error('No Metadata Classes to process.'); } } }
public function __construct(ManagerRegistry $registry, DbalLogger $logger = null) { $this->connections = $registry->getConnectionNames(); $this->managers = $registry->getManagerNames(); $this->logger = $logger; }
public function __construct(ManagerRegistry $registry) { $this->registry = $registry; $this->connections = $registry->getConnectionNames(); $this->managers = $registry->getManagerNames(); }
/** * @param string|callable $callback */ public function extendAll($callback) { foreach ($this->registry->getManagerNames() as $connection) { $this->extend($connection, $callback); } }