首页 > CMS建站 > Discuz > 正文

关于DISCUZ升级程序

2020-10-12 20:06:44
字体:
来源:转载
供稿:网友

DISCUZ版本过低腰升级的话,官方好像也没有升级程序,让DISCUZ提供技术支持,费用太贵,自己处理,以下是核心代码.

注意:cdb_templates 这个表不能导,否则一清空缓存就乱了,切记,花了一天时间才找到.

主程序:

  1. set_time_limit(9999999); 
  2.  
  3. include "inc/init.php 
  4.  
  5. cls::getDatabase()->start(); 

类程序:

  1. class common_database{ 
  2.   //所有有数据的表 
  3.   private $_needtable = null; 
  4.   //表对应关系 - 优先这样导入 
  5.   private $_distablearr = array
  6.    'cdb_members'=>array('yzlt_common_member','yzlt_ucenter_members'), 
  7.    'cdb_settings'=>'yzlt_ucenter_settings'
  8.     
  9.    ''=>'' 
  10.   ); 
  11.   //明确禁止导入的表 
  12.   private $_disable_table = array('cdb_templates','cdb_buddys','cdb_caches','cdb_favorites','cdb_memberspaces','cdb_mythreads','cdb_myposts','cdb_projects','cdb_stats'); 
  13.  
  14.   //构造函数 
  15.   public function __construct() 
  16.   { 
  17.   } 
  18.    
  19.    
  20.   public function start(){ 
  21.    // 
  22.    $rst = $this->getNeedTable(); 
  23.    foreach($rst as $tb){ 
  24.     $this->importTable($tb);//逐个导入表 
  25.     //break; 
  26.    } 
  27.    //收尾工作 
  28.    $this->endDoing(); 
  29.   } 
  30.    
  31.   private function endDoing(){ 
  32.    //给会员再加密 
  33.    $rs = cls::getDB()->getRowsNew("select uid,password from yzlt_ucenter_members");$num = count($rs); 
  34.    for($i=0;$i<$num;$i++){ 
  35.     cls::getDB()->Query("update yzlt_ucenter_members set password='".md5($rs[$i]["password"])."' where uid='".$rs[$i]["uid"]."'"); 
  36.    } 
  37.    //其他操作 
  38.   } 
  39.    
  40.   private function getShoulTable($tb){ 
  41.    $DB1 = cls::getDB(1); 
  42.    $sqla = "describe ".$tb.""
  43.    $rsa = $DB1->getRowsNew($sqla);//原来表字段 
  44.    $numa = count($rsa); 
  45.    $DB = cls::getDB(); 
  46.    $sql = "show tables"
  47.    $rs = $DB->getRowsNew($sql);$num = count($rs); 
  48.    $samenumtj = 0;$mytb=''
  49.    for($i=0;$i<$num;$i++){ 
  50.     $rscc = $DB->getRowsNew("describe ".$rs[$i][0]);$numcc = count($rscc); 
  51.     $samezd = 0; 
  52.     for($k1=0;$k1<$numa;$k1++){ 
  53.      for($k=0;$k<$numcc;$k++){ 
  54.       if($rsa[$k1][0]==$rscc[$k][0]){ 
  55.        $samezd++; 
  56.       } 
  57.      } 
  58.     } 
  59.     //echo " 
  60. 源表:".$tb.",目标表:".$rs[$i][0].",相同字段数:".$samezd.""; 
  61.     if((int)$samezd>(int)$samenumtj){ 
  62.      //echo "----------------".$samenumtj; 
  63.      $samenumtj = $samezd;$mytb = $rs[$i][0]; 
  64.     } 
  65.     //$samefield = array_intersect($rsa,$rscc);$samenum = count($samefield); 
  66.     //if($samenum>=$samenumtj){ 
  67.     // $samenumtj = $samenum;$mytb = $rs[$i][0]; 
  68.     // echo "表名:".$mytb.",相同字段数:".$samenumtj." 
  69. "; 
  70.     //} 
  71.    } 
  72.    //return $mytb."-".$samenumtj; 
  73.    return $mytb
  74.   } 
  75.    
  76.    
  77.   private function getNeedTable(){ 
  78.    if(!isset($this->_needtable)){ 
  79.     $DB1 = cls::getDB(1); 
  80.     $sql = "show tables";$table = array(); 
  81.     $rs = $DB1->getRowsNew($sql);$num = count($rs); 
  82.     for($i=0;$i<$num;$i++){ 
  83.      $sqla = "select count(*) from ".$rs[$i][0]."";$rsa = $DB1->getRowsNew($sqla); 
  84.      if($rsa[0][0]>0){ 
  85.       $table[] = $rs[$i][0]; 
  86.      } 
  87.     } 
  88.     $this->_needtable = $table
  89.    } 
  90.    return $this->_needtable; 
  91.   } 
  92.    
  93.   private function getDistTable($tb){ 
  94.    if(isset($this->_distablearr[$tb])){ 
  95.     return $this->_distablearr[$tb]; 
  96.    }else
  97.     //如果是明确禁止的,不要再找了 
  98.     if(in_array($tb,$this->_disable_table)){return "";} 
  99.     return $this->getShoulTable($tb); 
  100.    } 
  101.   } 
  102.    
  103.   private function getFieldSource($tb){ 
  104.    $DB1 = cls::getDB(1); 
  105.    $sql = "describe ".$tb
  106.    return $DB1->getRowsNew($sql); 
  107.   } 
  108.    
  109.   private function getFieldDist($tb){ 
  110.    $DB = cls::getDB(0); 
  111.     
  112.    $sql = "describe ".$tb
  113.    return $DB->getRowsNew($sql); 
  114.   } 
  115.    
  116.   private function getImportField($fieldsource,$fielddist){ 
  117.    $backzd = array(); 
  118.    for($i=0;$i 
  119.     $zd = $fieldsource[$i][0]; 
  120.     for($k=0;$k 
  121.      if($zd == $fielddist[$k][0]){ 
  122.       $backzd[] = $zd
  123.      } 
  124.     } 
  125.    } 
  126.    return $backzd
  127.   } 
  128.    
  129.   private function getFieldValueStr($zd,$rssource,$i){ 
  130.    $str=""
  131.    foreach($zd as $field){ 
  132.      
  133.     $rssource[$i][$field] = str_replace("'","/'",$rssource[$i][$field]);$rssource[$i][$field] = str_replace("///'","/'",$rssource[$i][$field]); 
  134.     $rssource[$i][$field] = str_replace("(","/(",$rssource[$i][$field]);$rssource[$i][$field] = str_replace("///(","/(",$rssource[$i][$field]); 
  135.     $rssource[$i][$field] = str_replace(")","/)",$rssource[$i][$field]);$rssource[$i][$field] = str_replace("///)","/)",$rssource[$i][$field]); 
  136.     if($str==""){ 
  137.      $str="'".$rssource[$i][$field]."'"
  138.     }else
  139.      $str.=",'".$rssource[$i][$field]."'"
  140.     } 
  141.    } 
  142.    return $str
  143.   } 
  144.    
  145.   private function importTable($tb){ 
  146.    $disTable = $this->getDistTable($tb); //获取目标表 
  147.    if(!is_array($disTable) && $disTable==''){echo "".$tb." not find distTable 
  148. ";return false;} 
  149.    if(!is_array($disTable)){$disTable = array($disTable);} 
  150.    foreach($disTable as $mytable){ 
  151.     echo "源表:".$tb.",导入到目的表:".$mytable." 
  152. "; 
  153.      
  154.     //删除目标表所有数据 
  155.     cls::getDB(0)->Query("delete from ".$mytable." where 1"); 
  156.     //开始导入 -  先获取可导入的字段(目标和源头一样的字段)    
  157.     $fieldsource = $this->getFieldSource($tb);   $fielddist = $this->getFieldDist($mytable); 
  158.     $rsf = $this->getImportField($fieldsource,$fielddist); 
  159.     //读取源表数据 
  160.     for($p=0;$p<1000;$p++){ 
  161.      $limit_begin = $p*1000; 
  162.      $rssource = cls::getDB(1)->getRowsNew("select * from ".$tb."  limit ".$limit_begin.",1000 ");$numsource = count($rssource); 
  163.      if($numsource == 0){break;} 
  164.      for($i=0;$i<$numsource;$i++){ 
  165.       $sqla = "insert into ".$mytable."(".implode(',',$rsf).")values(".$this->getFieldValueStr($rsf,$rssource,$i).") "
  166.       //echo $sqla." //开源软件:Cuoxin.com 
  167. "; 
  168.       cls::getDB(0)->Query($sqla); 
  169.      } 
  170.     } 
  171.      
  172.    } 
  173.     
  174.   } 
  175.  
  176.  }

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表