/** * Retrieve current MYSQL process list * */ protected function fetch_query_status() { $xml = new vB_AJAX_XML_Builder($this->registry, 'text/xml', vB_Template_Runtime::fetchStyleVar('charset')); $xml->add_group('processes'); $xml->add_tag('query_status', $this->phrase['core']['query_status_title']); $processes = $this->db->query_read("\n\t\t\tSHOW FULL PROCESSLIST\n\t\t"); $found = false; while ($process = $this->db->fetch_array($processes)) { if ($process['db'] == $this->registry->config['Database']['dbname'] and $process['User'] == $this->registry->config['MasterServer']['username'] and $process['Info'] != 'SHOW FULL PROCESSLIST' and $process['Command'] == 'Query' and preg_match('/^(\\s+)?### vBulletin Database Alter ###/s', $process['Info'])) { $process['Info'] = preg_replace("/^(\\s+)?### vBulletin Database Alter ###/s", "", $process['Info']); $found = true; $totalseconds = intval($process['Time']); $hours = floor($seconds / 3600); $totalseconds -= $hours * 3600; $minutes = floor($totalseconds / 60); $totalseconds -= $minutes * 60; $seconds = $totalseconds; $xml->add_tag('process', construct_phrase($this->phrase['core']['process_x_y_z'], str_pad($hours, 2, "0", STR_PAD_LEFT), str_pad($minutes, 2, "0", STR_PAD_LEFT), str_pad($seconds, 2, "0", STR_PAD_LEFT), htmlspecialchars_uni($process['State']), htmlspecialchars_uni($process['Info']))); } } if (!$found) { $xml->add_tag('noprocess', $this->phrase['core']['no_processes_found']); } $xml->close_group('processes'); $xml->print_xml(); }
/** * Output a command prompt * * @var string String to echo * @var array Accepted responses * * @return string Response value */ private function prompt($value, $responses = null) { do { $this->echo_phrase("\r\n----------------------------------\r\n"); $this->echo_phrase($this->convert_phrase($value)); $this->echo_phrase('>'); $response = trim(@fgets(STDIN)); } while (!empty($responses) and is_array($responses) and !in_array($response, $responses)); $this->db->ping(); return $response; }
function &execute_query($buffered = true, &$link) { if ($link == $this->connection_slave and preg_match('#(^|\\s)SELECT\\s#s', $this->sql)) { $this->explain_query(); } else { $this->output("<pre>" . trim(preg_match('#(\\n\\s+)(UPDATE|INSERT|REPLACE)\\s#s', $this->sql, $match) ? str_replace($match[1], "\n", $this->sql) : $this->sql) . "</pre>"); } $this->timer_start('SQL Query'); $return = parent::execute_query($buffered, $link); $this->timer_stop(); return $return; }
public function GetGroupsSettings(array &$vbphrase, array $setting) { $setting['value'] = unserialize($setting['value']); $resource = $this->vbulletin->db->query_read("SELECT usergroupid, title FROM " . TABLE_PREFIX . "usergroup"); $text = "<table><tr><td align='right'><b>vB Groups</b></td><td><b>DLE GroupID</b></td></tr>"; while ($row = $this->vbulletin->db->fetch_array($resource)) { $text .= "<tr><td align='right'>{$row['title']}</td><td style='padding:1px;'><input style='text-align:center;' class='bginput' type='text' name='setting[{$setting['varname']}][{$row['usergroupid']}]' value='{$setting['value'][$row['usergroupid']]}' size='10' /></td></tr>\n"; } $text .= "</table>"; $descr = ''; $this->_db_connect(); $resource = $this->db->query_read("SELECT group_name, id FROM " . USERPREFIX . "_usergroups"); while ($row = $this->vbulletin->db->fetch_array($resource)) { if (DLE_CHARSET && DLE_CHARSET != $this->vbulletin->userinfo['lang_charset']) { $row['group_name'] = iconv(DLE_CHARSET, $this->vbulletin->userinfo['lang_charset'], $row['group_name']); } $descr .= $row['id'] . " - " . $row['group_name'] . "<br />"; } $this->_db_disconnect(); return array('text' => $text, 'description' => $descr); }
/** * Disable a product, not delete * */ public function disable($productid = null) { $productid = $productid ? $productid : $this->productinfo['productid']; $this->db->query_write("\n\t\t\tUPDATE " . TABLE_PREFIX . "product\n\t\t\tSET active = 0\n\t\t\tWHERE productid = '" . $this->db->escape_string($productid) . "'\n\t\t"); build_product_datastore(); // build bitfields to remove/add this products bitfields require_once DIR . '/includes/class_bitfield_builder.php'; vB_Bitfield_Builder::save($this->db); // Products can enable a cron entries, so we need to rebuild that as well require_once DIR . '/includes/functions_cron.php'; build_cron_next_run(); // Purge cache -- doesn't apply to pre-vB4 versions if (class_exists('vB_Cache')) { vB_Cache::instance()->purge('vb_types.types'); } // Reload blocks and block types -- doesn't apply to pre-vB4 versions if (class_exists('vB_BlockManager')) { $blockmanager = vB_BlockManager::create($this->registry); $blockmanager->reloadBlockTypes(); $blockmanager->getBlocks(true, true); } }
/** * This function iterate over a large result set, only processing records in * batches to keep the memory usage reasonable. After a batch has been collected, * a reference to this object is passed to a callback function. That function * will update any columns necessary. This function will the save the changes * and start on a new batch. * * Callback function first argument must be a reference to a vB_DataManager_Multiple object. * Additional arguments should be passed to this function in an array. * * @param string|resource A query result resource or a string containing the query to execute * @param callback The function to call to make changes to the records * @param integer Number of records to process in a batch * @param array Any additional arguments to pass to the callback function */ function batch_iterate($records, $callback, $batch_size = 500, $args = array()) { if (is_string($records)) { $records = $this->dbobject->query_read($records); } $intargs = array(&$this); foreach (array_keys($args) as $argkey) { $intargs[] =& $args["{$argkey}"]; } $counter = 0; while ($record = $this->dbobject->fetch_array($records)) { // this if is seperate because otherwise, if we had // count($records) % $batch_size == 0, $this->children would be empty // so we couldn't call post_save_once(). if ($counter % $batch_size == 0) { $this->reset(); } $this->add_existing($record); $counter++; if ($counter % $batch_size == 0) { call_user_func_array($callback, $intargs); $this->save(true, false); } } if ($this->children and $counter % $batch_size != 0) { call_user_func_array($callback, $intargs); $this->save(true, false); } $master =& $this->children[reset($this->primary_ids)]; if ($master) { $master->post_save_once(); } }
/** * Verifies the an image property. Must come from this user's album and the album must be public/profile. * * @param string Value to verfiy. May be modified. * * @return boolean True if value. */ function verify_image(&$value) { if (!($this->registry->options['socnet'] & $this->registry->bf_misc_socnet['enable_albums'])) { $value = ''; return true; } $foundalbum = preg_match('#albumid=([0-9]+)#', $value, $albumid); $foundpicture = preg_match('#pictureid=([0-9]+)#', $value, $pictureid); if ($foundalbum and $foundpicture and $picture = $this->dbobject->query_first("\n\t\t\tSELECT album.userid\n\t\t\tFROM " . TABLE_PREFIX . "albumpicture AS albumpicture\n\t\t\tINNER JOIN " . TABLE_PREFIX . "picture AS picture ON (albumpicture.pictureid = picture.pictureid)\n\t\t\tINNER JOIN " . TABLE_PREFIX . "album AS album ON (albumpicture.albumid = album.albumid)\n\t\t\tWHERE albumpicture.albumid = " . intval($albumid[1]) . "\n\t \t\t\tAND albumpicture.pictureid = " . intval($pictureid[1]) . "\n\t \t\t\tAND album.state IN ('profile', 'public')\n\t \t\t\tAND album.userid = " . $this->userid . "\n\t \t")) { $value = $albumid[1] . "," . $pictureid[1]; return true; } else { return false; } }
/** * Executes the specified modifications. * * @param boolean Whether to close the list tags at the end of exeuction */ function execute($close_list = true) { if (!$this->inside_list) { echo "<ul>\n"; $this->inside_list = true; } foreach ($this->modifications as $modification) { if (!empty($modification['message'])) { echo "\t<li>{$modification['message']}</li>\n"; } $data =& $modification['data']; if (!empty($modification['alter'])) { $db_alter =& $this->setup_db_alter_class($data['table']); } else { unset($db_alter); } $alter_result = null; switch ($modification['modification_type']) { case 'add_field': $alter_result = $db_alter->add_field($data); break; case 'drop_field': $alter_result = $db_alter->drop_field($data['name']); break; case 'add_index': $alter_result = $db_alter->add_index($data['name'], $data['fields'], $data['type']); break; case 'drop_index': $alter_result = $db_alter->drop_index($data['name']); break; case 'run_query': $error_state = $this->db->reporterror; if ($error_state) { $this->db->hide_errors(); } $query_result = $this->db->query_write($data['query']); if ($errno = $this->db->errno()) { if (!in_array($errno, $data['ignorable_errors'])) { echo "</ul>"; $this->db->show_errors(); $this->db->sql = $data['query']; $this->db->halt(); } else { // error occurred, but was ignorable $this->db->errno = 0; } } if ($error_state) { $this->db->show_errors(); } break; case 'show_message': // do nothing -- just show the message break; case 'debug_break': echo "</ul><div>Debug break point. Stopping execution.</div>"; exit; default: trigger_error("<strong>vB_UpgradeQueries</strong>: Invalid modification type '{$modification['modification_type']}' specified.", E_USER_ERROR); } if ($alter_result === false) { if ($db_alter->error_no == ERRDB_MYSQL) { echo "</ul>"; $this->db->show_errors(); $this->db->sql = $db_alter->sql; $this->db->connection_recent = null; $this->db->error = $db_alter->error_desc; $this->db->errno = -1; $this->db->halt(); } else { if (ob_start()) { print_r($modification); $results = ob_get_contents(); ob_end_clean(); } else { $results = serialize($modification); } echo "\t\t<!-- {$results}\n\t\t" . "Error information: " . $db_alter->error_no . " / " . htmlspecialchars($db_alter->error_desc) . " -->\n\n"; } } } if ($close_list) { echo "</ul>\n"; $this->inside_list = false; } $this->modifications = array(); }
/** * Closes the connection to both the read database server * * @return integer */ function close() { $parent = parent::close(); return $parent and @$this->functions['close']($this->connection_slave); }
/** * Prepares an array of items into a list. * The result is a comma delimited, db escaped, quoted list for use in SQL. * * @param array string $items - An array of item titles * @param bool $prepare_items - Wether to check the items first * * @return string - A sql safe comma delimited list */ function prepare_itemlist($items, $prepare_items = false) { if (is_string($items) or $prepare_items) { $items = $this->prepare_itemarray($items); } if (!sizeof($items)) { return false; } foreach ($items as &$item) { $item = "'" . $this->dbobject->escape_string($item) . "'"; } return implode(',', $items); }
/** * Verifies the an image property. Must come from this user's album and the album must be public/profile. * * @param string Value to verfiy. May be modified. * * @return boolean True if value. */ function verify_image(&$value) { if (!($this->registry->options['socnet'] & $this->registry->bf_misc_socnet['enable_albums'])) { $value = ''; return true; } $foundalbum = preg_match('#albumid=([0-9]+)#', $value, $albumid); $foundpicture = preg_match('#attachmentid=([0-9]+)#', $value, $attachmentid); require_once(DIR . '/includes/class_bootstrap_framework.php'); require_once(DIR . '/vb/types.php'); vB_Bootstrap_Framework::init(); $types = vB_Types::instance(); $contenttypeid = intval($types->getContentTypeID('vBForum_Album')); if ($foundalbum AND $foundpicture AND $picture = $this->dbobject->query_first(" SELECT album.userid FROM " . TABLE_PREFIX . "attachment AS a INNER JOIN " . TABLE_PREFIX . "album AS album ON (a.contentid = album.albumid) WHERE a.attachmentid = " . intval($attachmentid[1]) . " AND a.contenttypeid = $contenttypeid AND album.state IN ('profile', 'public') AND album.userid = " . $this->userid . " AND album.albumid = " . intval($albumid[1]) . " ")) { $value = $albumid[1] . "," . $attachmentid[1]; return true; } else { return false; } }
/** * Log the current location of the upgrade * * @param string Upgrade Step * @param int Startat value for multi step steps * @param bool Process only the current version upgrade */ public function log_upgrade_step($step, $startat = 0, $only = false) { $complete = $step == $this->stepcount; $perpage = 0; $insertstep = true; if ($complete) { $step = 0; if ($this->SHORT_VERSION == 'final' or $only) { $this->db->query_write("\n\t\t\t\t\tDELETE FROM " . TABLE_PREFIX . "upgradelog\n\t\t\t\t\tWHERE script IN ('final', 'vbblog', 'vbcms', 'skimlinks', 'forumrunner', 'postrelease')\n\t\t\t\t"); $insertstep = false; } else { if (is_newer_version($this->LONG_VERSION, $this->registry->options['templateversion'])) { $this->db->query_write("UPDATE " . TABLE_PREFIX . "setting SET value = '" . $this->LONG_VERSION . "' WHERE varname = 'templateversion'"); } if (!defined('SKIPDB')) { build_options(); } $this->registry->options['templateversion'] = $this->LONG_VERSION; } } if ($insertstep and !defined('SKIPDB')) { // use time() not TIMENOW to actually time the script's execution /*insert query*/ $this->db->query_write("\n\t\t\t\tINSERT INTO " . TABLE_PREFIX . "upgradelog(script, steptitle, step, startat, perpage, dateline, only)\n\t\t\t\tVALUES (\n\t\t\t\t\t'" . $this->db->escape_string($this->SHORT_VERSION) . "',\n\t\t\t\t\t'',\n\t\t\t\t\t{$step},\n\t\t\t\t\t{$startat},\n\t\t\t\t\t{$perpage},\n\t\t\t\t\t" . time() . ",\n\t\t\t\t\t" . intval($only) . "\n\t\t\t)"); } }
/** * Builds the priority array for an arbitrary content type * */ protected function set_priorities($contenttype) { $forum_priorities = $this->dbobject->query_read_slave("SELECT sourceid, prioritylevel FROM " . TABLE_PREFIX . "contentpriority WHERE contenttypeid = '{$contenttype}'"); if (!isset($this->custom_priority[$contenttype])) { $this->custom_priority[$contenttype] = array(); } while ($f_pri = $this->dbobject->fetch_array($forum_priorities)) { if (!isset($this->custom_priority[$contenttype][$f_pri['sourceid']])) { $this->custom_priority[$contenttype][$f_pri['sourceid']] = array(); } $this->custom_priority[$contenttype][$f_pri['sourceid']]['priority'] = $f_pri['prioritylevel']; } }
function replacePerms($params, vB_Database $db, $check_only = false) { if ($check_only) { return !empty($params['fields']); } $sql = "REPLACE INTO " . TABLE_PREFIX . "attachmentpermission\n\t\t\t\t\t\t(extension, usergroupid, size, width, height, attachmentpermissions)\n\t\t\t\t\tVALUES\n\t\t\t\t\t\t" . implode(',', $params['fields']); $config = vB::getConfig(); if (isset($config['Misc']['debug_sql']) and $config['Misc']['debug_sql']) { echo "sql: {$sql}<br />\n"; } $db->query_write($sql); }
/** * Closes the connection to both the read database server * * @return integer */ function close() { $parent = parent::close(); return ($parent AND @$this->functions['close']($this->connection_slave)); }
/** * Verifies the an image property. Must come from this user's album and the album must be public/profile. * * @param string Value to verfiy. May be modified. * * @return boolean True if value. */ function verify_image(&$value) { if (!($this->registry->options['socnet'] & $this->registry->bf_misc_socnet['enable_albums'])) { $value = ''; return true; } $foundalbum = preg_match('#albumid=([0-9]+)#', $value, $albumid); $foundpicture = preg_match('#attachmentid=([0-9]+)#', $value, $attachmentid); $types = vB_Types::instance(); $contenttypeid = intval($types->getContentTypeID('vBForum_Album')); if ($foundalbum and $foundpicture and $picture = $this->dbobject->query_first("\n\t\t\tSELECT album.userid\n\t\t\tFROM " . TABLE_PREFIX . "attachment AS a\n\t\t\tINNER JOIN " . TABLE_PREFIX . "album AS album ON (a.contentid = album.albumid)\n\t\t\tWHERE\n\t\t\t\ta.attachmentid = " . intval($attachmentid[1]) . "\n\t \t\t\t\tAND\n\t \t\t\ta.contenttypeid = {$contenttypeid}\n\t \t\t\t\tAND\n\t \t\t\talbum.state IN ('profile', 'public')\n\t \t\t\t\tAND\n\t \t\t\talbum.userid = " . $this->userid . "\n\t \t\t\t\tAND\n\t \t\t\talbum.albumid = " . intval($albumid[1]) . "\n\t \t")) { $value = $albumid[1] . "," . $attachmentid[1]; return true; } else { return false; } }