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.'));
     }
 }
Beispiel #2
0
 public function installEntitiesDatabase()
 {
     $em = $this->getPackageEntityManager();
     if (is_object($em)) {
         $structure = new DatabaseStructureManager($em);
         $structure->installDatabase();
         // Create or update entity proxies
         $metadata = $em->getMetadataFactory()->getAllMetadata();
         $em->getProxyFactory()->generateProxyClasses($metadata, $em->getConfiguration()->getProxyDir());
     }
 }
Beispiel #3
0
 /**
  * Upgrade the current core version to the latest locally available by running the applicable migrations.
  */
 public static function updateToCurrentVersion(Configuration $configuration = null)
 {
     $cms = Core::make('app');
     $cms->clearCaches();
     $em = ORM::entityManager();
     $dbm = new DatabaseStructureManager($em);
     $dbm->destroyProxyClasses('ConcreteCore');
     $dbm->generateProxyClasses();
     if (!$configuration) {
         $configuration = new \Concrete\Core\Updater\Migrations\Configuration();
     }
     $configuration->registerPreviousMigratedVersions();
     $migrations = $configuration->getMigrationsToExecute('up', $configuration->getLatestVersion());
     foreach ($migrations as $migration) {
         $migration->execute('up');
     }
     try {
         $cms->make('helper/file')->makeExecutable(DIR_BASE_CORE . '/bin/concrete5', 'all');
     } catch (\Exception $x) {
     }
     Config::save('concrete.version_installed', Config::get('concrete.version'));
     Config::save('concrete.version_db_installed', Config::get('concrete.version_db'));
 }
 public function install_database()
 {
     $db = Database::get();
     $num = $db->GetCol("show tables");
     if (count($num) > 0) {
         throw new \Exception(t('There are already %s tables in this database. concrete5 must be installed in an empty database.', count($num)));
     }
     $installDirectory = DIR_BASE_CORE . '/config';
     try {
         // Retrieving metadata from the entityManager created with \ORM::entityManager()
         // will result in a empty metadata array. Because all drivers are wrapped in a driverChain
         // the method getAllMetadata() of Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory
         // is going to return a empty array. To overcome this issue a new EntityManager is create with the
         // only purpose to be used during the installation.
         $config = Setup::createConfiguration(true, \Config::get('database.proxy_classes'));
         \Doctrine\Common\Annotations\AnnotationReader::addGlobalIgnoredName('subpackages');
         \Doctrine\Common\Annotations\AnnotationReader::addGlobalIgnoredName('package');
         // Use default AnnotationReader
         $driverImpl = $config->newDefaultAnnotationDriver(DIR_BASE_CORE . DIRECTORY_SEPARATOR . DIRNAME_CLASSES . DIRECTORY_SEPARATOR . DIRNAME_ENTITIES, false);
         $config->setMetadataDriverImpl($driverImpl);
         $em = EntityManager::create(\Database::connection(), $config);
         $dbm = new DatabaseStructureManager($em);
         $dbm->destroyProxyClasses();
         $dbm->generateProxyClasses();
         Package::installDB($installDirectory . '/db.xml');
         $dbm->installDatabase();
         $this->indexAdditionalDatabaseFields();
         $configuration = new Configuration();
         $version = $configuration->getVersion(Config::get('concrete.version_db'));
         $version->markMigrated();
         $configuration->registerPreviousMigratedVersions();
     } catch (\Exception $e) {
         throw new \Exception(t('Unable to install database: %s', $db->ErrorMsg() ? $db->ErrorMsg() : $e->getMessage()));
     }
 }