Ejemplo n.º 1
0
 public function check()
 {
     $return = array();
     $status = helper_dbtool::gettablestatus(DB::table('forum_thread'), false);
     if ($status && $status['Data_length'] > 400 * 1048576) {
         $return = array('status' => '1', 'type' => 'header', 'lang' => lang('optimizer', 'optimizer_thread_need_optimizer'));
     } else {
         $return = array('status' => '0', 'type' => 'header', 'lang' => lang('optimizer', 'optimizer_thread_no_need'));
     }
     return $return;
 }
Ejemplo n.º 2
0
 public function check()
 {
     global $_G;
     loadcache('posttable_info');
     $count = 0;
     $posttableids = array_keys($_G['cache']['posttable_info']);
     foreach ($posttableids as $id) {
         $table = empty($id) ? 'forum_post' : (is_numeric($id) ? 'forum_post_' . $id : $id);
         $status = helper_dbtool::gettablestatus(DB::table($table), false);
         if ($status && $status['Data_length'] > 400 * 1048576) {
             $count++;
         }
     }
     if ($count) {
         $return = array('status' => '1', 'type' => 'header', 'lang' => lang('optimizer', 'optimizer_post_need_split', array('count' => $count)));
     } else {
         $return = array('status' => '0', 'type' => 'header', 'lang' => lang('optimizer', 'optimizer_post_not_need'));
     }
     return $return;
 }
Ejemplo n.º 3
0
 function updatetable($sql)
 {
     global $_G;
     $config = array('dbcharset' => $_G['config']['db']['1']['dbcharset'], 'charset' => $_G['config']['output']['charset'], 'tablepre' => $_G['config']['db']['1']['tablepre']);
     preg_match_all("/CREATE\\s+TABLE.+?pre\\_(.+?)\\s*\\((.+?)\\)\\s*(ENGINE|TYPE)\\s*=\\s*(\\w+)/is", $sql, $matches);
     $newtables = empty($matches[1]) ? array() : $matches[1];
     $newsqls = empty($matches[0]) ? array() : $matches[0];
     if (empty($newtables) || empty($newsqls)) {
         return array(1);
     }
     foreach ($newtables as $i => $newtable) {
         $newcols = updatetable_getcolumn($newsqls[$i]);
         //获取当前SQL
         if (!($query = DB::query("SHOW CREATE TABLE " . DB::table($newtable), 'SILENT'))) {
             //添加表
             preg_match("/(CREATE TABLE .+?)\\s*(ENGINE|TYPE)\\s*=\\s*(\\w+)/is", $newsqls[$i], $maths);
             $maths[3] = strtoupper($maths[3]);
             if ($maths[3] == 'MEMORY' || $maths[3] == 'HEAP') {
                 $type = helper_dbtool::dbversion() > '4.1' ? " ENGINE=MEMORY" . (empty($config['dbcharset']) ? '' : " DEFAULT CHARSET={$config['dbcharset']}") : " TYPE=HEAP";
             } else {
                 $type = helper_dbtool::dbversion() > '4.1' ? " ENGINE=MYISAM" . (empty($config['dbcharset']) ? '' : " DEFAULT CHARSET={$config['dbcharset']}") : " TYPE=MYISAM";
             }
             $usql = $maths[1] . $type;
             $usql = str_replace("CREATE TABLE IF NOT EXISTS pre_", 'CREATE TABLE IF NOT EXISTS ' . $config['tablepre'], $usql);
             $usql = str_replace("CREATE TABLE pre_", 'CREATE TABLE ' . $config['tablepre'], $usql);
             if (!DB::query($usql, 'SILENT')) {
                 return array(-1, $newtable);
             }
         } else {
             $value = DB::fetch($query);
             $oldcols = updatetable_getcolumn($value['Create Table']);
             //获取升级SQL文
             $updates = array();
             $allfileds = array_keys($newcols);
             foreach ($newcols as $key => $value) {
                 if ($key == 'PRIMARY') {
                     if ($value != $oldcols[$key]) {
                         if (!empty($oldcols[$key])) {
                             $usql = "RENAME TABLE " . DB::table($newtable) . " TO " . DB::table($newtable . '_bak');
                             if (!DB::query($usql, 'SILENT')) {
                                 return array(-1, $newtable);
                             }
                         }
                         $updates[] = "ADD PRIMARY KEY {$value}";
                     }
                 } elseif ($key == 'KEY') {
                     foreach ($value as $subkey => $subvalue) {
                         if (!empty($oldcols['KEY'][$subkey])) {
                             if ($subvalue != $oldcols['KEY'][$subkey]) {
                                 $updates[] = "DROP INDEX `{$subkey}`";
                                 $updates[] = "ADD INDEX `{$subkey}` {$subvalue}";
                             }
                         } else {
                             $updates[] = "ADD INDEX `{$subkey}` {$subvalue}";
                         }
                     }
                 } elseif ($key == 'UNIQUE') {
                     foreach ($value as $subkey => $subvalue) {
                         if (!empty($oldcols['UNIQUE'][$subkey])) {
                             if ($subvalue != $oldcols['UNIQUE'][$subkey]) {
                                 $updates[] = "DROP INDEX `{$subkey}`";
                                 $updates[] = "ADD UNIQUE INDEX `{$subkey}` {$subvalue}";
                             }
                         } else {
                             $usql = "ALTER TABLE  " . DB::table($newtable) . " DROP INDEX `{$subkey}`";
                             DB::query($usql, 'SILENT');
                             $updates[] = "ADD UNIQUE INDEX `{$subkey}` {$subvalue}";
                         }
                     }
                 } else {
                     if (!empty($oldcols[$key])) {
                         if (strtolower($value) != strtolower($oldcols[$key])) {
                             $updates[] = "CHANGE `{$key}` `{$key}` {$value}";
                         }
                     } else {
                         $i = array_search($key, $allfileds);
                         $fieldposition = $i > 0 ? 'AFTER `' . $allfileds[$i - 1] . '`' : 'FIRST';
                         $updates[] = "ADD `{$key}` {$value} {$fieldposition}";
                     }
                 }
             }
             //升级处理
             if (!empty($updates)) {
                 $usql = "ALTER TABLE " . DB::table($newtable) . " " . implode(', ', $updates);
                 if (!DB::query($usql, 'SILENT')) {
                     return array(-1, $newtable);
                 }
             }
         }
     }
     return array(1);
 }
Ejemplo n.º 4
0
function get_cachedata_threadprofile() {
	global $_G;
	if(!helper_dbtool::isexisttable('forum_threadprofile')) {
		return;
	}
	$threadprofiles = C::t('forum_threadprofile')->fetch_all();
	$threadprofile_group = C::t('forum_threadprofile_group')->fetch_all();
	$data = array();
	foreach($threadprofiles as $id => $threadprofile) {
		if($threadprofile['global']) {
			$data['template'][0] = dunserialize($threadprofile['template']);
		}
	}
	foreach($threadprofile_group as $group) {
		if($threadprofiles[$group['tpid']]) {
			$id = $threadprofiles[$group['tpid']]['global'] ? 0 : $group['tpid'];
			if(!isset($data['template'][$id])) {
				$data['template'][$id] = dunserialize($threadprofiles[$group['tpid']]['template']);
			}
			if($id) {
				$data['groupid'][$group['gid']] = $id;
			}
		}
	}
	foreach($data['template'] as $id => $template) {
		foreach($template as $type => $row) {
			$data['template'][$id][$type] = preg_replace('/\{([\w:]+)(=([^}]+?))?\}(([^}]+?)\{\*\}([^}]+?)\{\/\\1\})?/es', "get_cachedata_threadprofile_nodeparse(\$id, \$type, '\\1', '\\5', '\\6', '\\3')", $template[$type]);
		}
	}
	$data['code'] = $_G['cachedata_threadprofile_code'];
	return $data;
}
 public function merge_table()
 {
     $limit = 2000;
     $tmptable = $this->_table . '_tmp___';
     $archivetable = $this->_table . '_archive';
     $key = $this->_pk ? $this->_pk : 'split_id';
     if (!helper_dbtool::isexisttable($archivetable)) {
         return 2;
     }
     $this->create_relatedtable($tmptable);
     $targettable = helper_dbtool::showtablecloumn($this->_table);
     $fieldstr = '`' . implode('`, `', array_keys($targettable)) . '`';
     DB::query("INSERT INTO %t ({$fieldstr}) SELECT {$fieldstr} FROM %t " . DB::limit($limit), array($tmptable, $archivetable));
     if (DB::result_first('SELECT COUNT(*) FROM %t', array($tmptable))) {
         $keylist = DB::fetch_all('SELECT ' . $key . ' FROM %t', array($tmptable), $key);
         $keylist = dimplode(array_keys($keylist));
         if (DB::query("INSERT INTO %t ({$fieldstr}) SELECT {$fieldstr} FROM %t WHERE {$key} in ({$keylist})", array($this->_table, $archivetable), false, true)) {
             DB::query("DELETE FROM %t WHERE {$key} in ({$keylist})", array($archivetable), false, true);
         }
         DB::query('DROP TABLE %t', array($tmptable));
         return 1;
     } else {
         DB::query('DROP TABLE %t', array($tmptable));
         DB::query('DROP TABLE %t', array($archivetable));
         $this->optimize();
         return 2;
     }
 }
        showtableheader();
        showtitle('usergroups_copy');
        showsetting(cplang('usergroups_copy_source') . ':', '', '', $sourceusergroup['grouptitle']);
        showsetting('usergroups_merge_target', '', '', $usergroupselect);
        showsetting('usergroups_merge_delete_source', 'delete_source', 0, 'radio');
        showsubmit('copysubmit');
        showtablefooter();
        showformfooter();
    } else {
        $target = intval($_GET['target']);
        $targetusergroup = $_G['cache']['usergroups'][$target];
        if (empty($targetusergroup) || $targetusergroup['type'] == 'system' || $targetusergroup['type'] == 'special' && $targetusergroup['radminid']) {
            cpmsg('usergroups_copy_target_invalid', '', 'error');
        }
        C::t('common_member')->update_groupid_by_groupid($source, $target);
        if (helper_dbtool::isexisttable('common_member_archive')) {
            C::t('common_member_archive')->update_groupid_by_groupid($source, $target);
        }
        if ($_GET['delete_source']) {
            C::t('common_usergroup')->delete($source, $sourceusergroup['type']);
            C::t('common_usergroup_field')->delete($source);
            C::t('forum_onlinelist')->delete_by_groupid($source);
        }
        updatecache('usergroups');
        cpmsg('usergroups_merge_succeed', 'action=usergroups', 'succeed');
    }
}
function array_flip_keys($arr)
{
    $arr2 = array();
    $arrkeys = @array_keys($arr);
Ejemplo n.º 7
0
        $_GET['newexpiration'] = TIMESTAMP + (intval($_GET['newexpiration']) > 0 ? intval($_GET['newexpiration']) : 30) * 86400;
        $_GET['newmessage'] = nl2br(dhtmlspecialchars($_GET['newmessage']));
        $data = array('admin' => $_G['username'], 'access' => 0, 'adminid' => $_G['adminid'], 'dateline' => $_G['timestamp'], 'expiration' => $_GET['newexpiration'], 'message' => $_GET['newmessage']);
        C::t('common_adminnote')->insert($data);
    }
}
$serverinfo = PHP_OS . ' / PHP v' . PHP_VERSION;
$serverinfo .= @ini_get('safe_mode') ? ' Safe Mode' : NULL;
$serversoft = $_SERVER['SERVER_SOFTWARE'];
$dbversion = helper_dbtool::dbversion();
if (@ini_get('file_uploads')) {
    $fileupload = ini_get('upload_max_filesize');
} else {
    $fileupload = '<font color="red">' . $lang['no'] . '</font>';
}
$dbsize = helper_dbtool::dbsize();
$dbsize = $dbsize ? sizecount($dbsize) : $lang['unknown'];
if (isset($_GET['attachsize'])) {
    $attachsize = C::t('forum_attachment_n')->get_total_filesize();
    $attachsize = is_numeric($attachsize) ? sizecount($attachsize) : $lang['unknown'];
} else {
    $attachsize = '<a href="' . ADMINSCRIPT . '?action=index&attachsize">[ ' . $lang['detail'] . ' ]</a>';
}
$membersmod = C::t('common_member_validate')->count_by_status(0);
$threadsdel = C::t('forum_thread')->count_by_displayorder(-1);
$groupmod = C::t('forum_forum')->validate_level_num();
$modcount = array();
foreach (C::t('common_moderate')->count_group_idtype_by_status(0) as $value) {
    $modcount[$value['idtype']] = $value['count'];
}
$medalsmod = C::t('forum_medallog')->count_by_type(2);
Ejemplo n.º 8
0
function create_table($sql, $dbcharset) {
	$type = strtoupper(preg_replace("/^\s*CREATE TABLE\s+.+\s+\(.+?\).*(ENGINE|TYPE)\s*=\s*([a-z]+?).*$/isU", "\\2", $sql));
	$type = in_array($type, array('MYISAM', 'HEAP', 'MEMORY')) ? $type : 'MYISAM';
	return preg_replace("/^\s*(CREATE TABLE\s+.+\s+\(.+?\)).*$/isU", "\\1", $sql).
	(helper_dbtool::dbversion() > '4.1' ? " ENGINE=$type DEFAULT CHARSET=".$dbcharset : " TYPE=$type");
}
Ejemplo n.º 9
0
    if (!intval($_GET['checking'])) {
        cpmsg('upgrade_checking', 'action=upgrade&operation=check&checking=1', 'loading', '', false);
    }
    $discuz_upgrade->check_upgrade();
    dheader('Location: ' . ADMINSCRIPT . '?action=upgrade&operation=showupgrade');
} elseif ($operation == 'showupgrade') {
    shownav('tools', 'nav_founder_upgrade');
    showsubmenu('nav_founder_upgrade');
    showtableheader();
    if (!$_G['setting']['upgrade']) {
        cpmsg('upgrade_latest_version', '', 'succeed');
    } else {
        C::t('common_cache')->insert(array('cachekey' => 'upgrade_step', 'cachevalue' => serialize(array('curversion' => $discuz_upgrade->versionpath(), 'currelease' => DISCUZ_RELEASE)), 'dateline' => $_G['timestamp']), false, true);
        $upgraderow = $patchrow = array();
        $charset = str_replace('-', '', strtoupper($_G['config']['output']['charset']));
        $dbversion = helper_dbtool::dbversion();
        $locale = '';
        if ($charset == 'BIG5') {
            $locale = 'TC';
        } elseif ($charset == 'GBK') {
            $locale = 'SC';
        } elseif ($charset == 'UTF8') {
            if ($_G['config']['output']['language'] == 'zh_cn') {
                $locale = 'SC';
            } elseif ($_G['config']['output']['language'] == 'zh_tw') {
                $locale = 'TC';
            }
        }
        foreach ($_G['setting']['upgrade'] as $type => $upgrade) {
            $unupgrade = 0;
            if (version_compare($upgrade['phpversion'], PHP_VERSION) > 0 || version_compare($upgrade['mysqlversion'], $dbversion) > 0) {
Ejemplo n.º 10
0
function movedate($tids)
{
    global $sourcesize, $tableid, $movesize, $targettableid, $hash, $tableindex, $threadtableids, $fieldstr, $fromtableid, $posttable_info;
    $fromtable = getposttable($fromtableid, true);
    C::t('forum_post')->move_table($targettableid, $fieldstr, $fromtable, $tids);
    if (DB::errno()) {
        C::t('forum_post')->delete_by_tid($targettableid, $tids);
    } else {
        foreach ($threadtableids as $threadtableid) {
            $affected_rows = C::t('forum_thread')->update($tids, array('posttableid' => $targettableid), false, false, $threadtableid);
            if ($affected_rows == count($tids)) {
                break;
            }
        }
        C::t('forum_post')->delete_by_tid($fromtableid, $tids);
    }
    $status = helper_dbtool::gettablestatus(getposttable($targettableid, true), false);
    $targetsize = $sourcesize + $movesize * 1048576;
    $nowdatasize = $targetsize - $status['Data_length'];
    if ($status['Data_length'] >= $targetsize) {
        cpmsg('postsplit_done', 'action=postsplit&operation=optimize&tableid=' . $fromtableid, 'form');
    }
    cpmsg('postsplit_doing', 'action=postsplit&operation=movepost&fromtable=' . $tableid . '&movesize=' . $movesize . '&targettable=' . $targettableid . '&hash=' . $hash . '&tindex=' . $tableindex, 'loadingform', array('datalength' => sizecount($status['Data_length']), 'nowdatalength' => sizecount($nowdatasize)));
}
Ejemplo n.º 11
0
function get_cachedata_threadprofile()
{
    global $_G;
    if (!helper_dbtool::isexisttable('forum_threadprofile')) {
        return;
    }
    $threadprofiles = C::t('forum_threadprofile')->fetch_all();
    $threadprofile_group = C::t('forum_threadprofile_group')->fetch_all();
    $data = array();
    foreach ($threadprofiles as $id => $threadprofile) {
        if ($threadprofile['global']) {
            $data['template'][0] = dunserialize($threadprofile['template']);
        }
    }
    foreach ($threadprofile_group as $group) {
        if ($threadprofiles[$group['tpid']]) {
            $id = $threadprofiles[$group['tpid']]['global'] ? 0 : $group['tpid'];
            if (!isset($data['template'][$id])) {
                $data['template'][$id] = dunserialize($threadprofiles[$group['tpid']]['template']);
            }
            if ($id) {
                $data['groupid'][$group['gid']] = $id;
            }
        }
    }
    foreach ($data['template'] as $id => $template) {
        foreach ($template as $type => $row) {
            //Coxxs
            $data['template'][$id][$type] = preg_replace_callback('/\\{([\\w:]+)(=([^}]+?))?\\}(([^}]+?)\\{\\*\\}([^}]+?)\\{\\/\\1\\})?/s', function ($matches) use($type, $id) {
                return get_cachedata_threadprofile_nodeparse($id, $type, isset($matches[1]) ? $matches[1] : '', isset($matches[5]) ? $matches[5] : '', isset($matches[6]) ? $matches[6] : '', isset($matches[3]) ? $matches[3] : '');
            }, $template[$type]);
            //Coxxs
        }
    }
    $data['code'] = $_G['cachedata_threadprofile_code'];
    return $data;
}