public function getDataSet($fixtures = array()) { $db = Database::get(); if (count($this->tables)) { $partial = new SimpleXMLElement('<schema></schema>'); $partial->addAttribute('version', '0.3'); $xml = simplexml_load_file(DIR_BASE_CORE . '/config/db.xml'); foreach ($xml->table as $t) { $name = (string) $t['name']; if (in_array($name, $this->tables)) { $this->appendXML($partial, $t); } } $schema = \Concrete\Core\Database\Schema\Schema::loadFromXMLElement($partial, $db); $platform = $db->getDatabasePlatform(); $queries = $schema->toSql($platform); foreach ($queries as $query) { $db->query($query); } } if (empty($fixtures)) { $fixtures = $this->fixtures; } $reflectionClass = new ReflectionClass(get_called_class()); $fixturePath = dirname($reflectionClass->getFilename()) . DIRECTORY_SEPARATOR . 'fixtures'; $compositeDs = new PHPUnit_Extensions_Database_DataSet_CompositeDataSet(array()); foreach ((array) $fixtures as $fixture) { $path = $fixturePath . DIRECTORY_SEPARATOR . "{$fixture}.xml"; $ds = $this->createMySQLXMLDataSet($path); $compositeDs->addDataSet($ds); } return $compositeDs; }
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.')); } }
public function up(Schema $schema) { \Concrete\Core\Database\Schema\Schema::refreshCoreXMLSchema(array('Stacks')); if (\Core::make('multilingual/detector')->isEnabled()) { StackList::rescanMultilingualStacks(); } }
public function up(Schema $schema) { \Concrete\Core\Database\Schema\Schema::refreshCoreXMLSchema(array('PageFeeds')); // I can't seem to get the doctrine cache to clear any other way. $cms = \Core::make('app'); $cms->clearCaches(); $this->purgeOrphanedScrapbooksBlocks(); }
public static function refreshDatabase(Package $package) { if (version_compare(APP_VERSION, '5.7.4', '<')) { if (file_exists($package->getPackagePath() . '/' . FILENAME_PACKAGE_DB)) { $db = Database::get(); $db->beginTransaction(); $parser = Schema::getSchemaParser(simplexml_load_file($package->getPackagePath() . '/' . FILENAME_PACKAGE_DB)); $parser->setIgnoreExistingTables(false); $toSchema = $parser->parse($db); $fromSchema = $db->getSchemaManager()->createSchema(); $comparator = new \Doctrine\DBAL\Schema\Comparator(); $schemaDiff = $comparator->compare($fromSchema, $toSchema); $saveQueries = $schemaDiff->toSaveSql($db->getDatabasePlatform()); foreach ($saveQueries as $query) { $db->query($query); } $db->commit(); } } }
public function up(Schema $schema) { // image resizing options $sp = Page::getByPath('/dashboard/system/files/image_uploading'); if (!is_object($sp) || $sp->isError()) { $sp = \Concrete\Core\Page\Single::add('/dashboard/system/files/image_uploading'); $sp->update(array('cName' => 'Image Uploading')); } // background size/position \Concrete\Core\Database\Schema\Schema::refreshCoreXMLSchema(array('StyleCustomizerInlineStyleSets')); $bt = \BlockType::getByHandle('image_slider'); if (is_object($bt)) { $bt->refresh(); } $bt = \BlockType::getByHandle('youtube'); if (is_object($bt)) { $bt->refresh(); } $bt = \BlockType::getByHandle('autonav'); if (is_object($bt)) { $bt->refresh(); } }
public function up(Schema $schema) { \Concrete\Core\Database\Schema\Schema::refreshCoreXMLSchema(array('Users')); }
/** * refreshes the BlockType's database schema throws an Exception if error * * @return void */ public function refresh() { $db = DB::get(); $pkgHandle = false; if ($this->pkgID > 0) { $pkgHandle = $this->getPackageHandle(); } $class = static::getBlockTypeMappedClass($this->btHandle, $pkgHandle); $bta = new $class(); $this->loadFromController($bta); $em = $db->getEntityManager(); $em->persist($this); $em->flush(); $env = Environment::get(); $r = $env->getRecord(DIRNAME_BLOCKS . '/' . $this->btHandle . '/' . FILENAME_BLOCK_DB, $this->getPackageHandle()); if ($r->exists()) { $parser = Schema::getSchemaParser(simplexml_load_file($r->file)); $parser->setIgnoreExistingTables(false); $toSchema = $parser->parse($db); $fromSchema = $db->getSchemaManager()->createSchema(); $comparator = new \Doctrine\DBAL\Schema\Comparator(); $schemaDiff = $comparator->compare($fromSchema, $toSchema); $saveQueries = $schemaDiff->toSaveSql($db->getDatabasePlatform()); foreach ($saveQueries as $query) { $db->query($query); } } }
protected function updateDoctrineXmlTables() { $this->output(t('Updating tables found in doctrine xml...')); // Update tables that still exist in db.xml \Concrete\Core\Database\Schema\Schema::refreshCoreXMLSchema(array('TreeSearchQueryNodes')); }
public function up(Schema $schema) { \Concrete\Core\Database\Schema\Schema::refreshCoreXMLSchema(array('StyleCustomizerInlineStyleSets')); }
public static function installDB($xmlFile) { if (!file_exists($xmlFile)) { return false; } // currently this is just done from xml $db = Database::get(); $schema = Schema::loadFromXMLFile($xmlFile, $db); $platform = $db->getDatabasePlatform(); $queries = $schema->toSql($platform); foreach ($queries as $query) { $db->query($query); } unset($schema); unset($platform); /* $schema = Database::getADOSChema(); $sql = $schema->ParseSchema($xmlFile); $db->IgnoreErrors($handler); if (!$sql) { $result->message = $db->ErrorMsg(); return $result; } $r = $schema->ExecuteSchema(); if ($dbLayerErrorMessage != '') { $result->message = $dbLayerErrorMessage; return $result; } if (!$r) { $result->message = $db->ErrorMsg(); return $result; } $result->result = true; $db->CacheFlush(); */ $result = new \stdClass(); $result->result = false; return $result; }
public function up(Schema $schema) { \Concrete\Core\Database\Schema\Schema::refreshCoreXMLSchema(array('ConversationPermissionAddMessageAccessList', 'ConversationSubscriptions', 'Conversations')); // Subscribe admin to conversations by default, if we have no subscriptions $users = \Conversation::getDefaultSubscribedUsers(); if (count($users) == 0) { $admin = \UserInfo::getByID(USER_SUPER_ID); if (is_object($admin)) { $users = array($admin); \Conversation::setDefaultSubscribedUsers($users); } } $db = \Database::get(); $db->Execute('DROP TABLE IF EXISTS PageStatistics'); $pp = $schema->getTable('PagePaths'); if (!$pp->hasColumn('ppGeneratedFromURLSlugs')) { $db->Execute('alter table PagePaths add column ppGeneratedFromURLSlugs tinyint(1) unsigned not null default 0'); // we have to do this directly because the page path calls below will die otherwise. } $bt = BlockType::getByHandle('page_list'); if (is_object($bt)) { $bt->refresh(); } $bt = BlockType::getByHandle('page_title'); if (is_object($bt)) { $bt->refresh(); } $bt = BlockType::getByHandle('form'); if (is_object($bt)) { $bt->refresh(); } $c = \Page::getByPath('/dashboard/system/seo/urls'); if (is_object($c) && !$c->isError()) { $c->update(array('cName' => 'URLs and Redirection')); } $sp = \Page::getByPath('/dashboard/system/environment/entities'); if (!is_object($sp) || $sp->isError()) { $sp = \SinglePage::add('/dashboard/system/environment/entities'); $sp->update(array('cName' => 'Database Entities')); $sp->setAttribute('meta_keywords', 'database, entities, doctrine, orm'); } $pkx = Category::getByHandle('multilingual_section'); if (!is_object($pkx)) { $pkx = Category::add('multilingual_section'); } $pkx->associateAccessEntityType(Type::getByHandle('group')); $pkx->associateAccessEntityType(Type::getByHandle('user')); $pkx->associateAccessEntityType(Type::getByHandle('group_combination')); $db->Execute("alter table QueueMessages modify column body longtext not null"); $ms = $schema->getTable('MultilingualSections'); if (!$ms->hasColumn('msNumPlurals')) { $ms->addColumn('msNumPlurals', 'integer', array('notnull' => true, 'unsigned' => true, 'default' => 2)); $this->updateSectionPlurals = true; } if (!$ms->hasColumn('msPluralRule')) { $ms->addColumn('msPluralRule', 'string', array('notnull' => true, 'length' => 400, 'default' => '(n != 1)')); $this->updateSectionPlurals = true; } if (!$ms->hasColumn('msPluralCases')) { $ms->addColumn('msPluralCases', 'string', array('notnull' => true, 'length' => 1000, 'default' => "one@1\nother@0, 2~16, 100, 1000, 10000, 100000, 1000000, …")); $this->updateSectionPlurals = true; } $mt = $schema->getTable('MultilingualTranslations'); if (!$mt->hasColumn('msgidPlural')) { $mt->addColumn('msgidPlural', 'text', array('notnull' => false)); $this->updateMultilingualTranslations = true; } if (!$mt->hasColumn('msgstrPlurals')) { $mt->addColumn('msgstrPlurals', 'text', array('notnull' => false)); $this->updateMultilingualTranslations = true; } $cms = $schema->getTable('ConversationMessages'); if (!$cms->hasColumn('cnvMessageAuthorName')) { $cms->addColumn('cnvMessageAuthorName', 'string', array('notnull' => false, 'length' => 255)); } if (!$cms->hasColumn('cnvMessageAuthorEmail')) { $cms->addColumn('cnvMessageAuthorEmail', 'string', array('notnull' => false, 'length' => 255)); } if (!$cms->hasColumn('cnvMessageAuthorWebsite')) { $cms->addColumn('cnvMessageAuthorWebsite', 'string', array('notnull' => false, 'length' => 255)); } $this->updatePermissionDurationObjects(); $key = Key::getByHandle('add_conversation_message'); if (is_object($key) && !$key->permissionKeyHasCustomClass()) { $key->setPermissionKeyHasCustomClass(true); } $this->installMaintenanceModePermission(); }
public static function upgradeDatabase($pkg) { $dbm = $pkg->getDatabaseStructureManager(); $pkg->destroyProxyClasses(); if ($dbm->hasEntities()) { $dbm->generateProxyClasses(); //$dbm->dropObsoleteDatabaseTables(camelcase($this->getPackageHandle())); $dbm->installDatabase(); } if (file_exists($pkg->getPackagePath() . '/' . FILENAME_PACKAGE_DB)) { // Legacy db.xml // currently this is just done from xml $db = Database::get(); $db->beginTransaction(); $parser = Schema::getSchemaParser(simplexml_load_file($pkg->getPackagePath() . '/' . FILENAME_PACKAGE_DB)); $parser->setIgnoreExistingTables(false); $toSchema = $parser->parse($db); $fromSchema = $db->getSchemaManager()->createSchema(); $comparator = new \Doctrine\DBAL\Schema\Comparator(); $schemaDiff = $comparator->compare($fromSchema, $toSchema); $saveQueries = $schemaDiff->toSaveSql($db->getDatabasePlatform()); foreach ($saveQueries as $query) { $db->query($query); } $db->commit(); } }
public function createIndexedSearchTable() { if ($this->getIndexedSearchTable() != false) { $db = Database::get(); $platform = $db->getDatabasePlatform(); $array[$this->getIndexedSearchTable()] = $this->searchIndexFieldDefinition; $schema = Schema::loadFromArray($array, $db); $queries = $schema->toSql($platform); foreach ($queries as $query) { $db->query($query); } } }
protected function updateDoctrineXmlTables() { $this->output(t('Updating tables found in doctrine xml...')); // Update tables that still exist in db.xml \Concrete\Core\Database\Schema\Schema::refreshCoreXMLSchema(array('Pages', 'Stacks', 'PageTypes', 'NotificationPermissionSubscriptionList', 'NotificationPermissionSubscriptionListCustom', 'CollectionVersionBlocks', 'CollectionVersions', 'TreeNodes', 'Sessions', 'TreeFileNodes', 'UserWorkflowProgress', 'Users')); }
public function up(Schema $schema) { // background size/position \Concrete\Core\Database\Schema\Schema::refreshCoreXMLSchema(array('FileImageThumbnailPaths')); }
public function up(Schema $schema) { \Concrete\Core\Database\Schema\Schema::refreshCoreXMLSchema(array('AreaLayouts', 'AreaLayoutsUsingPresets')); }
/** * Installs a package's database from an XML file. * * @param string $xmlFile Path to the database XML file * * @return bool|\stdClass Returns false if the XML file could not be found * * @throws \Doctrine\DBAL\ConnectionException */ public static function installDB($xmlFile) { if (!file_exists($xmlFile)) { return false; } $db = \Database::connection(); $db->beginTransaction(); $parser = Schema::getSchemaParser(simplexml_load_file($xmlFile)); $parser->setIgnoreExistingTables(false); $toSchema = $parser->parse($db); $fromSchema = $db->getSchemaManager()->createSchema(); $comparator = new \Doctrine\DBAL\Schema\Comparator(); $schemaDiff = $comparator->compare($fromSchema, $toSchema); $saveQueries = $schemaDiff->toSaveSql($db->getDatabasePlatform()); foreach ($saveQueries as $query) { $db->query($query); } $db->commit(); $result = new \stdClass(); $result->result = false; return $result; }
public function up(Schema $schema) { \Concrete\Core\Database\Schema\Schema::refreshCoreXMLSchema(array('CollectionVersionBlocks')); }