关于DISCUZ升级程序
发布:smiling 来源: PHP粉丝网 添加日期:2014-11-19 10:24:49 浏览: 评论:0
DISCUZ版本过低腰升级的话,官方好像也没有升级程序,让DISCUZ提供技术支持,费用太贵,自己处理,以下是核心代码.
注意:cdb_templates 这个表不能导,否则一清空缓存就乱了,切记,花了一天时间才找到.
主程序:
- set_time_limit(9999999);
- include "inc/init.php
- cls::getDatabase()->start();
类程序:
- class common_database{
- //所有有数据的表
- private $_needtable = null;
- //表对应关系 - 优先这样导入
- private $_distablearr = array(
- 'cdb_members'=>array('yzlt_common_member','yzlt_ucenter_members'),
- 'cdb_settings'=>'yzlt_ucenter_settings',
- ''=>''
- );
- //明确禁止导入的表
- private $_disable_table = array('cdb_templates','cdb_buddys','cdb_caches','cdb_favorites','cdb_memberspaces','cdb_mythreads','cdb_myposts','cdb_projects','cdb_stats');
- //构造函数
- public function __construct()
- {
- }
- public function start(){
- //
- $rst = $this->getNeedTable();
- foreach($rst as $tb){
- $this->importTable($tb);//逐个导入表
- //break;
- }
- //收尾工作
- $this->endDoing();
- }
- private function endDoing(){
- //给会员再加密
- $rs = cls::getDB()->getRowsNew("select uid,password from yzlt_ucenter_members");$num = count($rs);
- for($i=0;$i<$num;$i++){
- cls::getDB()->Query("update yzlt_ucenter_members set password='".md5($rs[$i]["password"])."' where uid='".$rs[$i]["uid"]."'");
- }
- //其他操作
- }
- private function getShoulTable($tb){
- $DB1 = cls::getDB(1);
- $sqla = "describe ".$tb."";
- $rsa = $DB1->getRowsNew($sqla);//原来表字段
- $numa = count($rsa);
- $DB = cls::getDB();
- $sql = "show tables";
- $rs = $DB->getRowsNew($sql);$num = count($rs);
- $samenumtj = 0;$mytb='';
- for($i=0;$i<$num;$i++){
- $rscc = $DB->getRowsNew("describe ".$rs[$i][0]);$numcc = count($rscc);
- $samezd = 0;
- for($k1=0;$k1<$numa;$k1++){
- for($k=0;$k<$numcc;$k++){
- if($rsa[$k1][0]==$rscc[$k][0]){
- $samezd++;
- }
- }
- }
- //echo "
- 源表:".$tb.",目标表:".$rs[$i][0].",相同字段数:".$samezd."";
- if((int)$samezd>(int)$samenumtj){
- //echo "----------------".$samenumtj;
- $samenumtj = $samezd;$mytb = $rs[$i][0];
- }
- //$samefield = array_intersect($rsa,$rscc);$samenum = count($samefield);
- //if($samenum>=$samenumtj){
- // $samenumtj = $samenum;$mytb = $rs[$i][0];
- // echo "表名:".$mytb.",相同字段数:".$samenumtj."
- ";
- //}
- }
- //return $mytb."-".$samenumtj;
- return $mytb;
- }
- private function getNeedTable(){
- if(!isset($this->_needtable)){
- $DB1 = cls::getDB(1);
- $sql = "show tables";$table = array();
- $rs = $DB1->getRowsNew($sql);$num = count($rs);
- for($i=0;$i<$num;$i++){
- $sqla = "select count(*) from ".$rs[$i][0]."";$rsa = $DB1->getRowsNew($sqla);
- if($rsa[0][0]>0){
- $table[] = $rs[$i][0];
- }
- }
- $this->_needtable = $table;
- }
- return $this->_needtable;
- }
- private function getDistTable($tb){
- if(isset($this->_distablearr[$tb])){
- return $this->_distablearr[$tb];
- }else{
- //如果是明确禁止的,不要再找了
- if(in_array($tb,$this->_disable_table)){return "";}
- return $this->getShoulTable($tb);
- }
- }
- private function getFieldSource($tb){
- $DB1 = cls::getDB(1);
- $sql = "describe ".$tb;
- return $DB1->getRowsNew($sql);
- }
- private function getFieldDist($tb){
- $DB = cls::getDB(0);
- $sql = "describe ".$tb;
- return $DB->getRowsNew($sql);
- }
- private function getImportField($fieldsource,$fielddist){
- $backzd = array();
- for($i=0;$i
- $zd = $fieldsource[$i][0];
- for($k=0;$k
- if($zd == $fielddist[$k][0]){
- $backzd[] = $zd;
- }
- }
- }
- return $backzd;
- }
- private function getFieldValueStr($zd,$rssource,$i){
- $str="";
- foreach($zd as $field){
- $rssource[$i][$field] = str_replace("'","\'",$rssource[$i][$field]);$rssource[$i][$field] = str_replace("\\\'","\'",$rssource[$i][$field]);
- $rssource[$i][$field] = str_replace("(","\(",$rssource[$i][$field]);$rssource[$i][$field] = str_replace("\\\(","\(",$rssource[$i][$field]);
- $rssource[$i][$field] = str_replace(")","\)",$rssource[$i][$field]);$rssource[$i][$field] = str_replace("\\\)","\)",$rssource[$i][$field]);
- if($str==""){
- $str="'".$rssource[$i][$field]."'";
- }else{
- $str.=",'".$rssource[$i][$field]."'";
- }
- }
- return $str;
- }
- private function importTable($tb){
- $disTable = $this->getDistTable($tb); //获取目标表
- if(!is_array($disTable) && $disTable==''){echo "".$tb." not find distTable
- ";return false;}
- if(!is_array($disTable)){$disTable = array($disTable);}
- foreach($disTable as $mytable){
- echo "源表:".$tb.",导入到目的表:".$mytable."
- ";
- //删除目标表所有数据
- cls::getDB(0)->Query("delete from ".$mytable." where 1");
- //开始导入 - 先获取可导入的字段(目标和源头一样的字段)
- $fieldsource = $this->getFieldSource($tb); $fielddist = $this->getFieldDist($mytable);
- $rsf = $this->getImportField($fieldsource,$fielddist);
- //读取源表数据
- for($p=0;$p<1000;$p++){
- $limit_begin = $p*1000;
- $rssource = cls::getDB(1)->getRowsNew("select * from ".$tb." limit ".$limit_begin.",1000 ");$numsource = count($rssource);
- if($numsource == 0){break;}
- for($i=0;$i<$numsource;$i++){
- $sqla = "insert into ".$mytable."(".implode(',',$rsf).")values(".$this->getFieldValueStr($rsf,$rssource,$i).") ";
- //echo $sqla." //开源软件:phpfensi.com
- ";
- cls::getDB(0)->Query($sqla);
- }
- }
- }
- }
- }
Tags: DISCUZ升级程序 DISCUZ升级
相关文章
- ·Discuz升级到X3提示对不起,您安装的不是正版应用,安装程序(2014-12-05)
- ·discuz x2.5升级后,提示:抱歉,您的请求来路不正确或表单无法(2014-12-05)
推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
- PHP新手上路(一)(7)
- 惹恼程序员的十件事(5)
- PHP邮件发送例子,已测试成功(5)
- 致初学者:PHP比ASP优秀的七个理由(4)
- PHP会被淘汰吗?(4)
- PHP新手上路(四)(4)
- 如何去学习PHP?(2)
- 简单入门级php分页代码(2)
- php中邮箱email 电话等格式的验证(2)