/** * 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())); } }