function safe_upgrade_index($table, $idxname, $type, $def, $debug = '') { // $type would typically be '' or 'unique' if (!safe_index_exists($table, $idxname)) { return safe_query('create ' . $type . ' index ' . PFX . $idxname . ' on ' . PFX . $table . ' (' . $def . ');'); } }
/* $HeadURL$ $LastChangedRevision$ */ safe_upgrade_table('textpattern', array('markup_body' => 'varchar(32)', 'markup_excerpt' => 'varchar(32)')); // user-specific preferences safe_upgrade_table('txp_prefs_user', array('id' => DB_AUTOINC . ' PRIMARY KEY', 'user' => "varchar(64) NOT NULL default ''", 'name' => "varchar(255) NOT NULL default ''", 'val' => "varchar(255) NOT NULL default ''")); // unique index on user+name safe_upgrade_index('txp_prefs_user', 'user_idx', 'unique', 'user, name'); if (!safe_column_exists('txp_section', 'id')) { safe_alter('txp_section', 'drop primary key'); } safe_upgrade_table('txp_section', array('id' => DB_AUTOINC . ' PRIMARY KEY', 'path' => "varchar(255) not null default ''", 'parent' => 'INT', 'lft' => 'INT not null default 0', 'rgt' => 'INT not null default 0', 'inherit' => 'SMALLINT not null default 0')); safe_update('txp_section', 'path=name', "path=''"); // shortname has to be unique within a parent if (!safe_index_exists('txp_section', 'parent_idx')) { safe_upgrade_index('txp_section', 'parent_idx', 'unique', 'parent,name'); } #if (!safe_index_exists('txp_section', 'path_idx')) # safe_upgrade_index('txp_section', 'path_idx', 'unique', 'path'); safe_update('txp_section', 'parent=0', "name='default'"); $root_id = safe_field('id', 'txp_section', "name='default'"); safe_update('txp_section', "parent='" . $root_id . "'", "parent IS NULL"); include_once txpath . '/lib/txplib_tree.php'; tree_rebuild('txp_section', $root_id, 1); // <txp:message /> is dropped safe_update('txp_form', "Form = REPLACE(Form, '<txp:message', '<txp:comment_message')", "1 = 1"); // Expiry datetime for articles safe_upgrade_table('textpattern', array('Expires' => "datetime NOT NULL default '0000-00-00 00:00:00' after `Posted`")); if (!safe_field('name', 'txp_prefs', "name = 'publish_expired_articles'")) { safe_insert('txp_prefs', "prefs_id = 1, name = 'publish_expired_articles', val = '0', type = '1', event='publish', html='yesnoradio', position='130'");
function upgrade_table() { parent::upgrade_table(); safe_update($this->_table_name, 'path=name', "path=''"); # shortname has to be unique within a parent if (!safe_index_exists($this->_table_name, 'parent_idx')) { safe_upgrade_index($this->_table_name, 'parent_idx', 'unique', 'parent,name'); } safe_update('txp_section', 'parent=0', "name='default'"); $this->update(array('parent' => 0), array('name' => 'default')); $root_id = safe_field('id', $this->_table_name, "name='default'"); safe_update($this->_table_name, "parent='" . $root_id . "'", "parent IS NULL"); include_once txpath . '/lib/txplib_tree.php'; tree_rebuild($this->_table_name, $root_id, 1); }