public function refresh_database_schema() { if ($this->token->validate("refresh_database_schema")) { $msg = ''; if ($this->post('refresh_global_schema')) { // refresh concrete/config/db.xml and all installed blocks $cnt = Loader::controller("/upgrade"); try { $cnt->refresh_schema(); $msg .= t('Core database files and installed blocks refreshed.'); } catch (Exception $e) { $this->set('error', $e); } } if ($this->post('refresh_local_schema')) { // refresh concrete/config/db.xml and all installed blocks if (file_exists('config/' . FILENAME_LOCAL_DB)) { try { Package::installDB(DIR_BASE . '/config/' . FILENAME_LOCAL_DB); $msg .= ' ' . t('Local database file refreshed.'); } catch (Exception $e) { $this->set('error', $e); } } } $msg = trim($msg); $this->set('message', $msg); } else { $this->set('error', array($this->token->getErrorMessage())); } }
public function prepare() { // we install the updated schema just for tables that matter Package::installDB(dirname(__FILE__) . '/db/version_540.xml'); $db = Loader::db(); $db->Execute('alter table CollectionVersionBlockStyles drop primary key'); $db->Execute('alter table CollectionVersionBlockStyles add primary key (cID, bID, cvID, arHandle)'); }
public function upgrade() { Package::installDB($this->getPackagePath() . '/' . FILENAME_PACKAGE_DB); // now we refresh all blocks $items = $this->getPackageItems(); if (is_array($items['block_types'])) { foreach ($items['block_types'] as $item) { $item->refresh(); } } }
public static function add($atHandle, $atName, $pkg = false) { $pkgID = 0; if (is_object($pkg)) { $pkgID = $pkg->getPackageID(); } $db = Loader::db(); $db->Execute('insert into AttributeTypes (atHandle, atName, pkgID) values (?, ?, ?)', array($atHandle, $atName, $pkgID)); $id = $db->Insert_ID(); $est = AttributeType::getByID($id); $path = $est->getAttributeTypeFilePath(FILENAME_ATTRIBUTE_DB); if ($path) { Package::installDB($path); } return $est; }
public function install_database() { $db = Loader::db(); $installDirectory = DIR_BASE_CORE . '/config'; try { Database::ensureEncoding(); Package::installDB($installDirectory . '/db.xml'); } catch (Exception $e) { throw new Exception(t('Unable to install database: %s', $db->ErrorMsg())); } }
public function prepare() { $db = Loader::db(); Package::installDB(dirname(__FILE__) . '/db/version_5331.xml'); }
public function refresh_schema() { if ($this->upgrade_db) { $installDirectory = DIR_BASE_CORE . '/config'; $file = $installDirectory . '/db.xml'; if (!file_exists($file)) { throw new Exception(t('Unable to locate database import file.')); } $err = Package::installDB($file); // now we refresh the block schema $btl = new BlockTypeList(); $btArray = $btl->getInstalledList(); foreach ($btArray as $bt) { $bt->refresh(); } $this->upgrade_db = false; } }
/** * Installs the current block's DB xml file. If a block needs to do more than this, this should be overridden. * <code> * public function install($path) { * $this->doMySpecialInstallMethod(); * $this->doSecondSpecialInstallMethod(); * parent::install($path); * } * </code> * * There are several different possible return values: * Returns FALSE if $btTable is set but no db.xml file exists. * Otherwise returns object with two properties: ->result (a boolean), and ->message (a string). * If ->result is true, the installation was successful * (although the db.xml file might only have one field declared which will cause C5 to have problems later on, so you you will want to check for that separately). * If ->result is false, the installation failed and you can check ->message for the explanation * (usually -- sometimes ->message will be blank, in which case there's either a malformed db.xml file or an "unknown database error"). * See concrete/models/block_types.php::doInstallBlockType() for usage example. * * @param string $path * @return mixed boolean or object having ->result (boolean) and ->message (string) properties */ function install($path) { // passed path is the path to this block (try saying that ten times fast) // create the necessary table if (!$this->btTable) { $r = new stdClass(); $r->result = true; return $r; } $ret = Package::installDB($path . '/' . $this->dbFile); return $ret; }
public function prepare() { // we install the updated schema just for tables that matter Package::installDB(dirname(__FILE__) . '/db/version_542.xml'); }
/** * Installs the current block's DB xml file. If a block needs to do more than this, this should be overridden. * <code> * public function install($path) { * $this->doMySpecialInstallMethod(); * $this->doSecondSpecialInstallMethod(); * parent::install($path); * } * </code> * @param string $path * @return bool $didInstallCorrectly */ function install($path) { // passed path is the path to this block (try saying that ten times fast) // create the necessary table $ret = Package::installDB($path . '/' . $this->dbFile); return $ret; }
protected function refreshDatabaseTables($tables) { $dbxml = simplexml_load_file(DIR_BASE_CORE . '/config/db.xml'); $output = new SimpleXMLElement("<schema></schema>"); $output->addAttribute('version', '0.3'); foreach ($dbxml->table as $t) { $name = (string) $t['name']; if (in_array($name, $tables)) { $this->xmlAppend($output, $t); } } $xml = $output->asXML(); if ($xml) { $file = Loader::helper('file')->getTemporaryDirectory() . '/tmpupgrade_' . time() . '.xml'; @file_put_contents($file, $xml); if (file_exists($file)) { Package::installDB($file); @unlink($file); } else { throw new Exception(t('Unable to create temporary db xml file: %s', $file)); } } }