/** * Constructor * * @access public * @return void */ public function __construct(ipsRegistry $registry) { /* Make object */ $this->registry = $registry; $this->DB = $this->registry->DB(); $this->settings =& $this->registry->fetchSettings(); $this->request =& $this->registry->fetchRequest(); $this->cache = $this->registry->cache(); $this->caches =& $this->registry->cache()->fetchCaches(); /* Make sure tables exist that won't in pre 3.0 versions */ if (file_exists(IPS_ROOT_PATH . 'setup/sql/ipb3_' . strtolower(ipsRegistry::$settings['sql_driver']) . '.php')) { require IPS_ROOT_PATH . 'setup/sql/ipb3_' . strtolower(ipsRegistry::$settings['sql_driver']) . '.php'; $prefix = $this->registry->dbFunctions()->getPrefix(); if (!$this->DB->checkForField('upgrade_app', 'upgrade_history')) { if ($UPGRADE_TABLE_FIELD) { $this->DB->query(IPSSetUp::addPrefixToQuery($UPGRADE_TABLE_FIELD, $prefix)); } } if (!$this->DB->checkForTable('upgrade_sessions')) { if ($UPGRADE_SESSION_TABLE) { $this->DB->query(IPSSetUp::addPrefixToQuery($UPGRADE_SESSION_TABLE, $prefix)); } } } }
/** * Constructor * * @access public * @return @e void */ public function __construct(ipsRegistry $registry) { /* Make object */ $this->registry = $registry; $this->DB = $this->registry->DB(); $this->settings =& $this->registry->fetchSettings(); $this->request =& $this->registry->fetchRequest(); $this->cache = $this->registry->cache(); $this->caches =& $this->registry->cache()->fetchCaches(); //* Make sure tables exist that won't in pre 3.0 versions */ if (is_file(IPS_ROOT_PATH . 'setup/sql/ipb3_' . strtolower(ipsRegistry::$settings['sql_driver']) . '.php')) { /* Init vars */ $UPGRADE_HISTORY_TABLE = ''; $UPGRADE_TABLE_FIELD = ''; $UPGRADE_SESSION_TABLE = ''; $UPGRADE_CSS_PREVIOUS = ''; $UPGRADE_TEMPLATE_PREVIOUS = ''; require IPS_ROOT_PATH . 'setup/sql/ipb3_' . strtolower(ipsRegistry::$settings['sql_driver']) . '.php'; /*noLibHook*/ $prefix = $this->registry->dbFunctions()->getPrefix(); if (!$this->DB->checkForTable('upgrade_history')) { if ($UPGRADE_HISTORY_TABLE) { $this->DB->query(IPSSetUp::addPrefixToQuery($UPGRADE_HISTORY_TABLE, $prefix)); } } if (!$this->DB->checkForField('upgrade_app', 'upgrade_history')) { if ($UPGRADE_TABLE_FIELD) { $this->DB->query(IPSSetUp::addPrefixToQuery($UPGRADE_TABLE_FIELD, $prefix)); } } if (!$this->DB->checkForTable('upgrade_sessions')) { if ($UPGRADE_SESSION_TABLE) { $this->DB->query(IPSSetUp::addPrefixToQuery($UPGRADE_SESSION_TABLE, $prefix)); } } if (!$this->DB->checkForTable('skin_css_previous')) { if ($UPGRADE_CSS_PREVIOUS) { $this->DB->query(IPSSetUp::addPrefixToQuery($UPGRADE_CSS_PREVIOUS, $prefix)); } } if (!$this->DB->checkForTable('skin_templates_previous')) { if ($UPGRADE_TEMPLATE_PREVIOUS) { $this->DB->query(IPSSetUp::addPrefixToQuery($UPGRADE_TEMPLATE_PREVIOUS, $prefix)); } } } }
/** * Run SQL files * * @param int * @return @e void */ public function upgradeSql($id = 1) { $cnt = 0; $SQL = array(); $file = '_updates_' . $id . '.php'; $output = ""; $path = IPSLib::getAppDir('core') . '/setup/versions/upg_30001/' . strtolower($this->registry->dbFunctions()->getDriverType()) . $file; $prefix = $this->registry->dbFunctions()->getPrefix(); $sourceFile = ''; if (is_file($path)) { require $path; /*noLibHook*/ /* Set DB driver to return any errors */ $this->DB->return_die = 1; foreach ($SQL as $query) { $this->DB->allow_sub_select = 1; $this->DB->error = ''; $query = str_replace("<%time%>", time(), $query); if ($this->settings['mysql_tbl_type']) { if (preg_match("/^create table(.+?)/i", $query)) { $query = preg_replace("/^(.+?)\\);\$/is", "\\1) ENGINE={$this->settings['mysql_tbl_type']};", $query); } } /* Need to tack on a prefix? */ if ($prefix) { $query = IPSSetUp::addPrefixToQuery($query, $prefix); } if (IPSSetUp::getSavedData('man')) { $query = trim($query); /* Ensure the last character is a semi-colon */ if (substr($query, -1) != ';') { $query .= ';'; } $output .= $query . "\n\n"; } else { $this->DB->query($query); if ($this->DB->error) { $this->registry->output->addError("<br />" . $query . "<br />" . $this->DB->error); } else { $cnt++; } } } $this->registry->output->addMessage("{$cnt} запросов выполнено...."); } /* Next Page */ $this->request['st'] = 0; if ($id < 6) { $nextid = $id + 1; $this->request['workact'] = 'sql' . $nextid; } else { $this->request['workact'] = 'applications'; } if (IPSSetUp::getSavedData('man') and $output) { /* Create source file */ if ($this->registry->dbFunctions()->getDriverType() == 'mysql') { $sourceFile = IPSSetUp::createSqlSourceFile($output, '30001', $id); } $this->_output = $this->registry->output->template()->upgrade_manual_queries($output, $sourceFile); } }
/** * Upgrade log file tables * * @param int * @return @e void */ public function upgradeLogs($id = 1) { /* Verify posts alter table query has run */ if ($id == 1) { if (!$this->DB->checkForField('post_bwoptions', 'posts')) { $this->_output = ' '; $this->registry->output->addError("Вы должны выполнить запрос изменяющий таблицу posts. После того как вы выполните это, просто обновите данную страницу и обновление будет продолжено."); return; } } $cnt = 0; $file = '_updates_logs_' . $id . '.php'; $output = ""; $path = IPSLib::getAppDir('core') . '/setup/versions/upg_32000/' . strtolower($this->registry->dbFunctions()->getDriverType()) . $file; $prefix = $this->registry->dbFunctions()->getPrefix(); if (is_file($path)) { $SQL = array(); $TABLE = ''; require $path; /*noLibHook*/ /* Set DB driver to return any errors */ $this->DB->return_die = 1; foreach ($SQL as $query) { $this->DB->allow_sub_select = 1; $this->DB->error = ''; /* Need to tack on a prefix? */ if ($prefix) { $query = IPSSetUp::addPrefixToQuery($query, $prefix); } /* Chose to prune and run? */ if ($this->request['pruneAndRun']) { $this->DB->delete($TABLE); $man = false; } else { /* Show alter table / prune option? */ $man = IPSSetUp::getSavedData('man'); if ($TABLE) { $count = $this->DB->buildAndFetch(array('select' => 'count(*) as logs', 'from' => $TABLE)); if ($count['logs'] > 100000) { $man = true; } } } /* Show option to run manually or prune ? */ if ($man) { $query = trim($query); /* Ensure the last character is a semi-colon */ if (substr($query, -1) != ';') { $query .= ';'; } $output .= $query . "\n\n"; } else { $this->DB->query($query); if ($this->DB->error) { $this->registry->output->addError("<br />" . $query . "<br />" . $this->DB->error); } else { $cnt++; } } } $this->registry->output->addMessage("{$cnt} запросов выполнено...."); } /* Next Page */ if ($id < 10) { $nextid = $id + 1; $this->request['workact'] = 'logs' . $nextid; } else { $this->request['workact'] = 'forums'; } if ($output) { $this->_output = $this->registry->output->template()->upgrade_manual_queries_logs($output, $id, $TABLE); } }
function upgrade_sql($id = 1) { $man = 0; // Manual upgrade ? intval( $this->request['man'] ); $cnt = 0; $SQL = array(); $file = '_updates_' . $id . '.php'; $output = ""; $path = IPSLib::getAppDir('core') . '/setup/versions/upg_21003/' . strtolower($this->registry->dbFunctions()->getDriverType()) . $file; $prefix = $this->registry->dbFunctions()->getPrefix(); if (is_file($path)) { require $path; /*noLibHook*/ $this->error = array(); $this->sqlcount = 0; $output = ""; $this->DB->return_die = 1; foreach ($SQL as $query) { $this->DB->allow_sub_select = 1; $this->DB->error = ''; $query = str_replace("<%time%>", time(), $query); /* Need to tack on a prefix? */ if ($prefix) { $query = IPSSetUp::addPrefixToQuery($query, $prefix); } if (IPSSetUp::getSavedData('man')) { $output .= preg_replace("/\\s{1,}/", " ", $query) . "\n\n"; } else { if (!$query) { continue; } $this->DB->query($query); if ($this->DB->error) { $this->registry->output->addError($query . "<br /><br />" . $this->DB->error); } else { $this->sqlcount++; } } } $this->registry->output->addMessage("{$this->sqlcount} queries ran...."); } //-------------------------------- // Next page... //-------------------------------- $this->request['st'] = 0; if ($id != 4) { $nextid = $id + 1; $this->request['workact'] = 'sql' . $nextid; } else { $this->request['workact'] = 'polls'; } if (IPSSetUp::getSavedData('man') and $output) { /* Create source file */ if ($this->registry->dbFunctions()->getDriverType() == 'mysql') { $sourceFile = IPSSetUp::createSqlSourceFile($output, '21003', $id); } $this->_output = $this->registry->output->template()->upgrade_manual_queries($output, $sourceFile); } }
/** * Installs SQL schematic * * @return void */ public function install_sql() { /* Lets grab that SQL! */ $SQL = array(); $count = 0; $output = ''; $message = array(); $sourceFile = ''; $warnings = 0; /* Reset Errors */ $this->_resetErrors(); /* SQL */ $file = IPSLib::getAppDir($this->_currentApp) . '/setup/versions/upg_' . $this->_uipLong . '/' . $this->_dbDriver . '_updates.php'; /* Get file */ if (is_file($file)) { require $file; /*noLibHook*/ if (is_array($SQL) and count($SQL) > 0) { /* Loop */ foreach ($SQL as $q) { /* Set DB driver to return any errors */ $this->DB->return_die = 1; $this->DB->allow_sub_select = 1; $this->DB->error = ''; $q = str_replace("<%time%>", time(), $q); $q = IPSSetUp::addPrefixToQuery($q, $this->registry->dbFunctions()->getPrefix()); if ($this->settings['mysql_tbl_type']) { if (preg_match("/^create table(.+?)/i", $q)) { $q = preg_replace("/^(.+?)\\);\$/is", "\\1) ENGINE={$this->settings['mysql_tbl_type']};", $q); } } if (IPSSetUp::getSavedData('man')) { $q = trim($q); /* Ensure the last character is a semi-colon */ if (substr($q, -1) != ';') { $q .= ';'; } $output .= $q . "\n\n"; } else { $this->DB->query($q); if ($this->DB->error) { /* Log but do not fail on certain error logs */ $msg = $this->DB->error; if (preg_match("#table.*already exists#i", $msg) or preg_match("#Duplicate column name#i", $msg) or preg_match("#Duplicate entry.*for#i", $msg)) { $warnings++; IPSSetUp::addLogMessage("SQL Error: " . $q . "\n" . $msg, $this->_uipLong, $this->_currentApp); } else { $this->registry->output->addError(nl2br($q) . "<br /><br />" . $this->DB->error); } } else { $count++; } } } $message[] = $count . " запросов выполнено ({$warnings} не критичных ошибок)"; } } else { /* No SQL */ //$this->registry->output->addMessage("Нет SQL запросов для выполнения."); $this->install_appclass(); return; } /* Got queries to show? */ if (IPSSetUp::getSavedData('man') and $output) { /* Create source file */ if ($this->_dbDriver == 'mysql') { $sourceFile = IPSSetUp::createSqlSourceFile($output, $this->_uipLong); } $this->registry->output->setTitle("Обновление: База Данных"); $this->registry->output->setNextAction('upgrade&do=appclass'); $this->registry->output->addContent($this->registry->output->template()->upgrade_manual_queries($output, $sourceFile)); $this->registry->output->sendOutput(); } else { //----------------------------------------- // Next... //----------------------------------------- $output = (is_array($message) and count($message)) ? $message : array(0 => "Обновление Базы Данных завершено"); $this->_finishStep($output, "Обновление: База Данных", 'upgrade&do=appclass'); } }
function upgrade_sql($id = 1) { $man = 0; // Manual upgrade ? intval( $this->install->ipsclass->input['man'] ); $cnt = 0; $SQL = array(); $file = '_updates_' . $id . '.php'; $output = ""; $path = IPSLib::getAppDir('core') . '/setup/versions/upg_22005/' . strtolower($this->registry->dbFunctions()->getDriverType()) . $file; $prefix = $this->registry->dbFunctions()->getPrefix(); if (file_exists($path)) { require_once $path; $this->sqlcount = 0; $output = ""; $this->DB->return_die = 1; foreach ($SQL as $query) { $this->DB->allow_sub_select = 1; $this->DB->error = ''; $query = str_replace("<%time%>", time(), $query); if ($this->settings['mysql_tbl_type']) { if (preg_match("/^create table(.+?)/i", $query)) { $query = preg_replace("/^(.+?)\\);\$/is", "\\1) TYPE={$this->settings['mysql_tbl_type']};", $query); } } /* Need to tack on a prefix? */ if ($prefix) { $query = IPSSetUp::addPrefixToQuery($query, $prefix); } if (IPSSetUp::getSavedData('man')) { $output .= preg_replace("/\\s{1,}/", " ", $query) . "\n\n"; } else { $this->DB->query($query); if ($this->DB->error) { $this->registry->output->addError($query . "<br /><br />" . $this->DB->error); } else { $this->sqlcount++; } } } $this->registry->output->addMessage("{$this->sqlcount} queries run...."); } //-------------------------------- // Next page... //-------------------------------- $this->request['st'] = 0; if ($id != 4) { $nextid = $id + 1; $this->request['workact'] = 'sql' . $nextid; } else { $this->request['workact'] = 'forums'; } if (IPSSetUp::getSavedData('man') and $output) { $this->_output = $this->registry->output->template()->upgrade_manual_queries($output); } }
/** * Fix posts table * * @param int * @return @e void */ public function updatePostsTable() { $doManual = $options['core'][33000]['manualPostsTableQuery']; $prefix = $this->registry->dbFunctions()->getPrefix(); $output = ''; if ($doManual && !$this->DB->checkForField('post_field_int', 'posts')) { foreach (array('ALTER TABLE posts ADD post_field_int INT(10) DEFAULT 0', 'ALTER TABLE posts ADD post_field_t1 TEXT NULL DEFAULT NULL', 'ALTER TABLE posts ADD post_field_t2 TEXT NULL DEFAULT NULL') as $query) { $query = trim($query); /* Need to tack on a prefix? */ if ($prefix) { $query = IPSSetUp::addPrefixToQuery($query, $prefix); } /* Ensure the last character is a semi-colon */ if (substr($query, -1) != ';') { $query .= ';'; } $output .= $query . "\n\n"; } } else { if (!$this->DB->checkForField('post_field_int', 'posts')) { $this->DB->addField('posts', 'post_field_int', 'INT(10)', '0'); } if (!$this->DB->checkForField('post_field_t1', 'posts')) { $this->DB->addField('posts', 'post_field_t1', 'TEXT'); } if (!$this->DB->checkForField('post_field_t2', 'posts')) { $this->DB->addField('posts', 'post_field_t2', 'TEXT'); } } if ($output) { /* Create source file */ if ($this->registry->dbFunctions()->getDriverType() == 'mysql') { $sourceFile = IPSSetUp::createSqlSourceFile($output, '33000', 'posts'); } $this->_output = $this->registry->output->template()->upgrade_manual_queries($output, $sourceFile); } $this->registry->output->addMessage("Posts table updated"); $this->request['workact'] = 'ban'; }
/** * Installs SQL schematic * * @return void */ public function install_sql() { /* Lets grab that SQL! */ $SQL = array(); $cnt = 0; $output = ''; $message = array(); $sourceFile = ''; /* Reset Errors */ $this->_resetErrors(); /* SQL */ $file = IPSLib::getAppDir($this->_currentApp) . '/setup/versions/upg_' . $this->_uipLong . '/' . $this->_dbDriver . '_updates.php'; /* Get file */ if (file_exists($file)) { require $file; if (is_array($SQL) and count($SQL) > 0) { /* Loop */ foreach ($SQL as $q) { /* Set DB driver to return any errors */ $this->DB->return_die = 1; $this->DB->allow_sub_select = 1; $this->DB->error = ''; $q = str_replace("<%time%>", time(), $q); $q = IPSSetUp::addPrefixToQuery($q, $this->registry->dbFunctions()->getPrefix()); if ($this->settings['mysql_tbl_type']) { if (preg_match("/^create table(.+?)/i", $q)) { $q = preg_replace("/^(.+?)\\);\$/is", "\\1) TYPE={$this->settings['mysql_tbl_type']};", $q); } } if (IPSSetUp::getSavedData('man')) { $q = trim($q); /* Ensure the last character is a semi-colon */ if (substr($q, -1) != ';') { $q .= ';'; } $output .= $q . "\n\n"; } else { $this->DB->query($q); if ($this->DB->error) { $this->registry->output->addError(nl2br($q) . "<br /><br />" . $this->DB->error); } else { $count++; } } } $message[] = $count . " queries run..."; } } else { /* No SQL */ $this->registry->output->addMessage("No native SQL to run...."); $this->install_appclass(); return; } /* Got queries to show? */ if (IPSSetUp::getSavedData('man') and $output) { /* Create source file */ if ($this->_dbDriver == 'mysql') { $sourceFile = IPSSetUp::createSqlSourceFile($output, $this->_uipLong); } $this->registry->output->setTitle("Upgrade: SQL"); $this->registry->output->setNextAction('upgrade&do=appclass'); $this->registry->output->addContent($this->registry->output->template()->upgrade_manual_queries($output, $sourceFile)); $this->registry->output->sendOutput(); } else { //----------------------------------------- // Next... //----------------------------------------- $output = (is_array($message) and count($message)) ? $message : array(0 => "SQL complete"); $this->_finishStep($output, "Upgrade: SQL", 'upgrade&do=appclass'); } }