/** * refreshes the BlockType's database schema throws an Exception if error. */ public function refresh() { $app = Facade::getFacadeApplication(); $db = $app->make('database')->connection(); $pkgHandle = false; if ($this->pkgID > 0) { $pkgHandle = $this->getPackageHandle(); } $class = \Concrete\Core\Block\BlockType\BlockType::getBlockTypeMappedClass($this->btHandle, $pkgHandle); $bta = $app->build($class); $this->loadFromController($bta); $em = \ORM::entityManager(); $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); } } }