You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

596 lines
22 KiB

4 years ago
  1. <?php
  2. namespace Home\Controller;
  3. use Think\Controller;
  4. class UpdateController extends BaseController {
  5. //升级数据库
  6. public function db(){
  7. $this->_clear_runtime();
  8. if (strtolower(C("DB_TYPE")) == 'mysql' ) {
  9. //$this->mysql();
  10. echo 'ShowDoc does not support mysql any more . https://www.showdoc.cc/help?page_id=31990 ';
  11. }
  12. elseif (strtolower(C("DB_TYPE")) == 'sqlite' ) {
  13. $this->sqlite();
  14. }
  15. $this->_clear_runtime();
  16. }
  17. public function sqlite(){
  18. //catalog表增加parent_cat_id字段
  19. if (!$this->_is_column_exist("catalog","parent_cat_id")) {
  20. $sql = "ALTER TABLE ".C('DB_PREFIX')."catalog ADD parent_cat_id INT( 10 ) NOT NULL DEFAULT '0' ;";
  21. D("catalog")->execute($sql);
  22. }
  23. //catalog表增加level字段
  24. if (!$this->_is_column_exist("catalog","level")) {
  25. $sql = "ALTER TABLE ".C('DB_PREFIX')."catalog ADD level INT( 10 ) NOT NULL DEFAULT '2' ;";
  26. D("catalog")->execute($sql);
  27. }
  28. //item表增加item_domain字段
  29. if (!$this->_is_column_exist("item","item_domain")) {
  30. $sql = "ALTER TABLE ".C('DB_PREFIX')."item ADD item_domain text NOT NULL DEFAULT '';";
  31. D("catalog")->execute($sql);
  32. }
  33. //创建user_token表
  34. $sql = "CREATE TABLE IF NOT EXISTS `user_token` (
  35. `id` INTEGER PRIMARY KEY ,
  36. `uid` int(10) NOT NULL DEFAULT '0',
  37. `token` CHAR(200) NOT NULL DEFAULT '',
  38. `token_expire` int(11) NOT NULL DEFAULT '0' ,
  39. `ip` CHAR(200) NOT NULL DEFAULT '',
  40. `addtime` int(11) NOT NULL DEFAULT '0'
  41. )";
  42. D("UserToken")->execute($sql);
  43. //创建template表
  44. $sql = "CREATE TABLE IF NOT EXISTS `template` (
  45. `id` INTEGER PRIMARY KEY ,
  46. `uid` int(10) NOT NULL DEFAULT '0',
  47. `username` CHAR(200) NOT NULL DEFAULT '',
  48. `template_title` CHAR(200) NOT NULL DEFAULT '' ,
  49. `template_content` text NOT NULL DEFAULT '',
  50. `addtime` int(11) NOT NULL DEFAULT '0'
  51. )";
  52. D("UserToken")->execute($sql);
  53. //page表增加page_comments字段
  54. if (!$this->_is_column_exist("page","page_comments")) {
  55. $sql = "ALTER TABLE ".C('DB_PREFIX')."page ADD page_comments text NOT NULL DEFAULT '' ;";
  56. D("catalog")->execute($sql);
  57. }
  58. //page_history 表增加page_comments字段
  59. if (!$this->_is_column_exist("PageHistory","page_comments")) {
  60. $sql = "ALTER TABLE ".C('DB_PREFIX')."page_history ADD page_comments text NOT NULL DEFAULT '';";
  61. D("catalog")->execute($sql);
  62. }
  63. //item_member表增加member_group_id字段
  64. if (!$this->_is_column_exist("ItemMember","member_group_id")) {
  65. $sql = "ALTER TABLE ".C('DB_PREFIX')."item_member ADD member_group_id INT( 1 ) NOT NULL DEFAULT '1' ;";
  66. D("ItemMember")->execute($sql);
  67. }
  68. //item表增加item_type字段
  69. if (!$this->_is_column_exist("Item","item_type")) {
  70. $sql = "ALTER TABLE ".C('DB_PREFIX')."item ADD item_type INT( 1 ) NOT NULL DEFAULT '1' ;";
  71. D("ItemMember")->execute($sql);
  72. }
  73. //创建options表
  74. $sql = "CREATE TABLE IF NOT EXISTS `options` (
  75. `option_id` INTEGER PRIMARY KEY ,
  76. `option_name` CHAR(200) NOT NULL UNIQUE ,
  77. `option_value` CHAR(200) NOT NULL
  78. )";
  79. D("UserToken")->execute($sql);
  80. //创建item_token表
  81. $sql = "CREATE TABLE IF NOT EXISTS `item_token` (
  82. `id` INTEGER PRIMARY KEY ,
  83. `item_id` int(11) NOT NULL DEFAULT '0' ,
  84. `api_key` CHAR(200) NOT NULL UNIQUE ,
  85. `api_token` CHAR(200) NOT NULL ,
  86. `addtime` int(11) NOT NULL DEFAULT '0' ,
  87. `last_check_time` int(11) NOT NULL DEFAULT '0'
  88. )";
  89. D("UserToken")->execute($sql);
  90. //创建item_top表
  91. $sql = "CREATE TABLE IF NOT EXISTS `item_top` (
  92. `id` INTEGER PRIMARY KEY ,
  93. `item_id` int(11) NOT NULL DEFAULT '0' ,
  94. `uid` int(11) NOT NULL DEFAULT '0' ,
  95. `addtime` int(11) NOT NULL DEFAULT '0'
  96. )";
  97. D("UserToken")->execute($sql);
  98. //item表增加is_archived字段
  99. if (!$this->_is_column_exist("Item","is_archived")) {
  100. $sql = "ALTER TABLE ".C('DB_PREFIX')."item ADD is_archived INT( 1 ) NOT NULL DEFAULT '0' ;";
  101. D("ItemMember")->execute($sql);
  102. }
  103. //管理员账户和权限
  104. if(D("User")->where("username = 'showdoc' ")->find()){
  105. D("User")->where("username = 'showdoc' ")->save(array("groupid"=> 1)) ;
  106. }else{
  107. D("User")->add(array('username'=>"showdoc" ,"groupid"=>1,'password'=>"a89da13684490eb9ec9e613f91d24d00" , 'reg_time'=>time()));
  108. }
  109. //item表增加is_del字段
  110. if (!$this->_is_column_exist("Item","is_del")) {
  111. $sql = "ALTER TABLE ".C('DB_PREFIX')."item ADD is_del INT( 1 ) NOT NULL DEFAULT '0' ;";
  112. D("ItemMember")->execute($sql);
  113. }
  114. //page表增加is_del字段
  115. if (!$this->_is_column_exist("Page","is_del")) {
  116. $sql = "ALTER TABLE ".C('DB_PREFIX')."page ADD is_del INT( 1 ) NOT NULL DEFAULT '0' ;";
  117. D("ItemMember")->execute($sql);
  118. }
  119. //创建team表
  120. $sql = "CREATE TABLE IF NOT EXISTS `team` (
  121. `id` INTEGER PRIMARY KEY ,
  122. `team_name` CHAR(200) NOT NULL DEFAULT '',
  123. `uid` int(11) NOT NULL DEFAULT '0' ,
  124. `username` CHAR(200) NOT NULL DEFAULT '',
  125. `addtime` int(11) NOT NULL DEFAULT '0' ,
  126. `last_update_time` int(11) NOT NULL DEFAULT '0'
  127. )";
  128. D("User")->execute($sql);
  129. //创建team_item表
  130. $sql = "CREATE TABLE IF NOT EXISTS `team_item` (
  131. `id` INTEGER PRIMARY KEY ,
  132. `team_id` int(11) NOT NULL DEFAULT '0' ,
  133. `item_id` int(11) NOT NULL DEFAULT '0' ,
  134. `addtime` int(11) NOT NULL DEFAULT '0' ,
  135. `last_update_time` int(11) NOT NULL DEFAULT '0'
  136. )";
  137. D("User")->execute($sql);
  138. //创建team_item_member表
  139. $sql = "CREATE TABLE IF NOT EXISTS `team_item_member` (
  140. `id` INTEGER PRIMARY KEY ,
  141. `team_id` int(11) NOT NULL DEFAULT '0' ,
  142. `item_id` int(11) NOT NULL DEFAULT '0' ,
  143. `member_group_id` int(11) NOT NULL DEFAULT '0' ,
  144. `member_uid` int(11) NOT NULL DEFAULT '0' ,
  145. `member_username` CHAR(200) NOT NULL DEFAULT '',
  146. `addtime` int(11) NOT NULL DEFAULT '0' ,
  147. `last_update_time` int(11) NOT NULL DEFAULT '0'
  148. )";
  149. D("User")->execute($sql);
  150. //创建team_member表
  151. $sql = "CREATE TABLE IF NOT EXISTS `team_member` (
  152. `id` INTEGER PRIMARY KEY ,
  153. `team_id` int(11) NOT NULL DEFAULT '0' ,
  154. `member_uid` int(11) NOT NULL DEFAULT '0' ,
  155. `member_username` CHAR(200) NOT NULL DEFAULT '',
  156. `addtime` int(11) NOT NULL DEFAULT '0' ,
  157. `last_update_time` int(11) NOT NULL DEFAULT '0'
  158. )";
  159. D("User")->execute($sql);
  160. //创建upload_file表
  161. $sql = "CREATE TABLE IF NOT EXISTS `upload_file` (
  162. `file_id` INTEGER PRIMARY KEY ,
  163. `sign` CHAR(200) NOT NULL DEFAULT '',
  164. `display_name` CHAR(200) NOT NULL DEFAULT '',
  165. `file_type` CHAR(200) NOT NULL DEFAULT '',
  166. `file_size` CHAR(200) NOT NULL DEFAULT '',
  167. `uid` int(11) NOT NULL DEFAULT '0' ,
  168. `page_id` int(11) NOT NULL DEFAULT '0' ,
  169. `item_id` int(11) NOT NULL DEFAULT '0' ,
  170. `visit_times` int(11) NOT NULL DEFAULT '0' ,
  171. `addtime` int(11) NOT NULL DEFAULT '0' ,
  172. `real_url` CHAR(200) NOT NULL DEFAULT '',
  173. `last_update_time` int(11) NOT NULL DEFAULT '0'
  174. )";
  175. D("User")->execute($sql);
  176. //创建item_sort表
  177. $sql = "CREATE TABLE IF NOT EXISTS `item_sort` (
  178. `id` INTEGER PRIMARY KEY ,
  179. `uid` int(10) NOT NULL DEFAULT '0',
  180. `item_sort_data` text NOT NULL DEFAULT '',
  181. `addtime` int(11) NOT NULL DEFAULT '0'
  182. )";
  183. D("UserToken")->execute($sql);
  184. //创建single_page表
  185. $sql = "CREATE TABLE IF NOT EXISTS `single_page` (
  186. `id` INTEGER PRIMARY KEY ,
  187. `unique_key` CHAR(200) NOT NULL DEFAULT '',
  188. `page_id` int(11) NOT NULL DEFAULT '0'
  189. )";
  190. D("User")->execute($sql);
  191. //创建captcha表
  192. $sql = "CREATE TABLE IF NOT EXISTS `captcha` (
  193. `captcha_id` INTEGER PRIMARY KEY ,
  194. `mobile` CHAR(200) NOT NULL DEFAULT '',
  195. `captcha` CHAR(200) NOT NULL DEFAULT '',
  196. `expire_time` int(11) NOT NULL DEFAULT '0'
  197. )";
  198. D("User")->execute($sql);
  199. //创建recycle表
  200. $sql = "CREATE TABLE IF NOT EXISTS `recycle` (
  201. `id` INTEGER PRIMARY KEY ,
  202. `item_id` int(11) NOT NULL DEFAULT '0',
  203. `page_id` int(11) NOT NULL DEFAULT '0',
  204. `page_title` CHAR(200) NOT NULL DEFAULT '',
  205. `del_by_uid` int(11) NOT NULL DEFAULT '0',
  206. `del_by_username` CHAR(200) NOT NULL DEFAULT '',
  207. `del_time` int(11) NOT NULL DEFAULT '0'
  208. )";
  209. D("User")->execute($sql);
  210. //创建page_lock表
  211. $sql = "CREATE TABLE IF NOT EXISTS `page_lock` (
  212. `id` INTEGER PRIMARY KEY ,
  213. `page_id` int(11) NOT NULL DEFAULT '0',
  214. `lock_uid` int(11) NOT NULL DEFAULT '0',
  215. `lock_username` CHAR(200) NOT NULL DEFAULT '',
  216. `lock_to` int(11) NOT NULL DEFAULT '0',
  217. `addtime` int(11) NOT NULL DEFAULT '0'
  218. )";
  219. D("User")->execute($sql);
  220. //item_member表增加cat_id字段
  221. if (!$this->_is_column_exist("item_member","cat_id")) {
  222. $sql = "ALTER TABLE ".C('DB_PREFIX')."item_member ADD cat_id INT( 10 ) NOT NULL DEFAULT '0' ;";
  223. D("User")->execute($sql);
  224. }
  225. //team_item_member表增加cat_id字段
  226. if (!$this->_is_column_exist("team_item_member","cat_id")) {
  227. $sql = "ALTER TABLE ".C('DB_PREFIX')."team_item_member ADD cat_id INT( 10 ) NOT NULL DEFAULT '0' ;";
  228. D("User")->execute($sql);
  229. }
  230. //创建item_variable表
  231. $sql = "CREATE TABLE IF NOT EXISTS `item_variable` (
  232. `id` INTEGER PRIMARY KEY ,
  233. `var_name` CHAR(2000) NOT NULL DEFAULT '',
  234. `var_value` CHAR(2000) NOT NULL DEFAULT '',
  235. `uid` int(11) NOT NULL DEFAULT '0',
  236. `item_id` int(11) NOT NULL DEFAULT '0',
  237. `addtime` int(11) NOT NULL DEFAULT '0'
  238. )";
  239. D("User")->execute($sql);
  240. echo "OK!\n";
  241. }
  242. private function _is_column_exist($table , $column){
  243. $has_it = false ;//是否存在该字段
  244. $columns = M($table)->getDbFields();
  245. if ($columns) {
  246. foreach ($columns as $key => $value) {
  247. if ($value == $column) {
  248. $has_it = true ;
  249. }
  250. }
  251. }
  252. return $has_it ;
  253. }
  254. private function _clear_runtime($path = RUNTIME_PATH){
  255. //给定的目录不是一个文件夹
  256. if(!is_dir($path)){
  257. return null;
  258. }
  259. $fh = opendir($path);
  260. while(($row = readdir($fh)) !== false){
  261. //过滤掉虚拟目录
  262. if($row == '.' || $row == '..'|| $row == 'index.html'){
  263. continue;
  264. }
  265. if(!is_dir($path.'/'.$row)){
  266. unlink($path.'/'.$row);
  267. }
  268. $this->_clear_runtime($path.'/'.$row);
  269. }
  270. //关闭目录句柄,否则出Permission denied
  271. closedir($fh);
  272. return true;
  273. }
  274. //转移mysql的数据到sqlite
  275. public function toSqlite(){
  276. $this->_clear_runtime();
  277. if (strtolower(C("DB_TYPE")) == 'mysql' ) {
  278. $this->mysql();
  279. $this->_moveTable("catalog");
  280. $this->_moveTable("item");
  281. $this->_moveTable("item_member");
  282. $this->_moveTable("page");
  283. $this->_moveTable("page_history");
  284. $this->_moveTable("template");
  285. $this->_moveTable("user");
  286. $this->_moveTable("user_token");
  287. $db_config = array(
  288. 'DB_TYPE' => 'Sqlite',
  289. 'DB_NAME' => 'Sqlite/showdoc.db.php',
  290. );
  291. $array = M("item")->db(2,$db_config)->select();
  292. if ($array) {
  293. echo "ok";
  294. }else{
  295. echo 'fail';
  296. }
  297. }
  298. else{
  299. echo "mysql not found";
  300. }
  301. $this->_clear_runtime();
  302. }
  303. //升级mysql数据库
  304. public function mysql(){
  305. //user表的username字段增大了长度,防止长邮箱的用户名注册不了
  306. $sql = "alter table ".C('DB_PREFIX')."user modify column username varchar(50) CHARACTER SET utf8 NOT NULL DEFAULT '' ";
  307. M("Catalog")->execute($sql);
  308. //item表增加last_update_time字段
  309. $columns = M("item")->getDbFields();
  310. if ($columns) {
  311. $has_it = 0 ;//是否存在该字段
  312. foreach ($columns as $key => $value) {
  313. if ($value == 'last_update_time') {
  314. $has_it = 1 ;
  315. }
  316. }
  317. if ($has_it === 0) {
  318. $sql = "ALTER TABLE ".C('DB_PREFIX')."item ADD last_update_time INT( 11 ) NOT NULL DEFAULT '0' COMMENT '最后更新时间';";
  319. D("Item")->execute($sql);
  320. }
  321. }
  322. //更改catalog表的order字段名为s_number
  323. $columns = M("Catalog")->getDbFields();
  324. if ($columns) {
  325. foreach ($columns as $key => $value) {
  326. if ($value == 'order') {
  327. $sql = "ALTER TABLE `".C('DB_PREFIX')."catalog` CHANGE `order` `s_number` INT( 10 ) NOT NULL DEFAULT '99' COMMENT '顺序号。数字越小越靠前。若此值全部相等时则按id排序';";
  328. M("Catalog")->execute($sql);
  329. }
  330. }
  331. }
  332. //更改page表的order字段名为s_number
  333. $columns = M("Page")->getDbFields();
  334. if ($columns) {
  335. foreach ($columns as $key => $value) {
  336. if ($value == 'order') {
  337. $sql = "ALTER TABLE `".C('DB_PREFIX')."page` CHANGE `order` `s_number` INT( 10 ) NOT NULL DEFAULT '99' COMMENT '顺序号。数字越小越靠前。若此值全部相等时则按id排序';";
  338. M("Page")->execute($sql);
  339. }
  340. }
  341. }
  342. //更改page_history表的order字段名为s_number
  343. $columns = M("PageHistory")->getDbFields();
  344. if ($columns) {
  345. foreach ($columns as $key => $value) {
  346. if ($value == 'order') {
  347. $sql = "ALTER TABLE `".C('DB_PREFIX')."page_history` CHANGE `order` `s_number` INT( 10 ) NOT NULL DEFAULT '99' COMMENT '顺序号。数字越小越靠前。若此值全部相等时则按id排序';";
  348. M("PageHistory")->execute($sql);
  349. }
  350. }
  351. }
  352. //为catalog表增加addtime索引
  353. $indexs = M("Catalog")->query(" show index from ".C('DB_PREFIX')."catalog");
  354. if ($indexs) {
  355. $has_it = 0 ;//是否存在该索引
  356. foreach ($indexs as $key => $value) {
  357. if ($value['column_name'] =='addtime') {
  358. $has_it = 1 ;
  359. }
  360. }
  361. if ($has_it === 0 ) {
  362. M("Catalog")->execute("ALTER TABLE ".C('DB_PREFIX')."catalog ADD INDEX ( `addtime` ) ;");
  363. }
  364. }
  365. //为item表增加addtime索引
  366. $indexs = M("Item")->query(" show index from ".C('DB_PREFIX')."item");
  367. if ($indexs) {
  368. $has_it = 0 ;//是否存在该索引
  369. foreach ($indexs as $key => $value) {
  370. if ($value['column_name'] =='addtime') {
  371. $has_it = 1 ;
  372. }
  373. }
  374. if ($has_it === 0 ) {
  375. M("Item")->execute("ALTER TABLE ".C('DB_PREFIX')."item ADD INDEX ( `addtime` ) ;");
  376. }
  377. }
  378. //为page表增加addtime索引
  379. $indexs = M("Page")->query(" show index from ".C('DB_PREFIX')."page");
  380. if ($indexs) {
  381. $has_it = 0 ;//是否存在该索引
  382. foreach ($indexs as $key => $value) {
  383. if ($value['column_name'] =='addtime') {
  384. $has_it = 1 ;
  385. }
  386. }
  387. if ($has_it === 0 ) {
  388. M("page")->execute("ALTER TABLE ".C('DB_PREFIX')."page ADD INDEX ( `addtime` ) ;");
  389. }
  390. }
  391. //为page_history表增加addtime索引
  392. $indexs = M("PageHistory")->query(" show index from ".C('DB_PREFIX')."page_history");
  393. if ($indexs) {
  394. $has_it = 0 ;//是否存在该索引
  395. foreach ($indexs as $key => $value) {
  396. if ($value['column_name'] =='addtime') {
  397. $has_it = 1 ;
  398. }
  399. }
  400. if ($has_it === 0 ) {
  401. M("PageHistory")->execute("ALTER TABLE ".C('DB_PREFIX')."page_history ADD INDEX ( `addtime` ) ;");
  402. }
  403. }
  404. //为page_history表增加page_id索引
  405. $indexs = M("PageHistory")->query(" show index from ".C('DB_PREFIX')."page_history");
  406. if ($indexs) {
  407. $has_it = 0 ;//是否存在该索引
  408. foreach ($indexs as $key => $value) {
  409. if ($value['column_name'] =='page_id') {
  410. $has_it = 1 ;
  411. }
  412. }
  413. if ($has_it === 0 ) {
  414. M("PageHistory")->execute("ALTER TABLE ".C('DB_PREFIX')."page_history ADD INDEX ( `page_id` ) ;");
  415. }
  416. }
  417. //catalog表增加parent_cat_id字段
  418. $columns = M("catalog")->getDbFields();
  419. if ($columns) {
  420. $has_it = 0 ;//是否存在该字段
  421. foreach ($columns as $key => $value) {
  422. if ($value == 'parent_cat_id') {
  423. $has_it = 1 ;
  424. }
  425. }
  426. if ($has_it === 0) {
  427. $sql = "ALTER TABLE ".C('DB_PREFIX')."catalog ADD parent_cat_id INT( 10 ) NOT NULL DEFAULT '0' COMMENT '上一级目录的id';";
  428. D("catalog")->execute($sql);
  429. }
  430. }
  431. //catalog表增加level字段
  432. $columns = M("catalog")->getDbFields();
  433. if ($columns) {
  434. $has_it = 0 ;//是否存在该字段
  435. foreach ($columns as $key => $value) {
  436. if ($value == 'level') {
  437. $has_it = 1 ;
  438. }
  439. }
  440. if ($has_it === 0) {
  441. $sql = "ALTER TABLE ".C('DB_PREFIX')."catalog ADD level INT( 10 ) NOT NULL DEFAULT '2' COMMENT '2为二级目录,3为三级目录';";
  442. D("catalog")->execute($sql);
  443. }
  444. }
  445. //item表增加item_domain字段
  446. $columns = M("item")->getDbFields();
  447. if ($columns) {
  448. $has_it = 0 ;//是否存在该字段
  449. foreach ($columns as $key => $value) {
  450. if ($value == 'item_domain') {
  451. $has_it = 1 ;
  452. }
  453. }
  454. if ($has_it === 0) {
  455. $sql = "ALTER TABLE ".C('DB_PREFIX')."item ADD item_domain varchar( 50 ) NOT NULL DEFAULT '' COMMENT 'item的个性域名';";
  456. D("item")->execute($sql);
  457. }
  458. }
  459. $sql = "CREATE TABLE IF NOT EXISTS `".C('DB_PREFIX')."user_token` (
  460. `id` int(10) NOT NULL AUTO_INCREMENT,
  461. `uid` int(10) NOT NULL DEFAULT '0',
  462. `token` varchar(200) NOT NULL DEFAULT '',
  463. `token_expire` int(11) NOT NULL DEFAULT '0' ,
  464. `ip` varchar(200) NOT NULL DEFAULT '',
  465. `addtime` int(11) NOT NULL DEFAULT '0',
  466. PRIMARY KEY (`id`),
  467. KEY `token` (`token`)
  468. ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='' AUTO_INCREMENT=1 ";
  469. D("User")->execute($sql);
  470. //创建template表
  471. $sql = "CREATE TABLE IF NOT EXISTS `".C('DB_PREFIX')."template` (
  472. `id` int(10) NOT NULL AUTO_INCREMENT,
  473. `uid` int(10) NOT NULL DEFAULT '0',
  474. `username` varchar(200) NOT NULL DEFAULT '',
  475. `template_title` varchar(200) NOT NULL DEFAULT '' ,
  476. `template_content` text NOT NULL ,
  477. `addtime` int(11) NOT NULL DEFAULT '0',
  478. PRIMARY KEY (`id`),
  479. KEY `uid` (`uid`)
  480. )ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='' AUTO_INCREMENT=1";
  481. D("UserToken")->execute($sql);
  482. //page表增加page_comments字段
  483. $columns = M("Page")->getDbFields();
  484. if ($columns) {
  485. $has_it = 0 ;//是否存在该字段
  486. foreach ($columns as $key => $value) {
  487. if ($value == 'page_comments') {
  488. $has_it = 1 ;
  489. }
  490. }
  491. if ($has_it === 0) {
  492. $sql = "ALTER TABLE ".C('DB_PREFIX')."page ADD page_comments varchar( 255 ) NOT NULL DEFAULT '' COMMENT '页面注释';";
  493. D("Page")->execute($sql);
  494. }
  495. }
  496. //page_history表增加page_comments字段
  497. $columns = M("PageHistory")->getDbFields();
  498. if ($columns) {
  499. $has_it = 0 ;//是否存在该字段
  500. foreach ($columns as $key => $value) {
  501. if ($value == 'page_comments') {
  502. $has_it = 1 ;
  503. }
  504. }
  505. if ($has_it === 0) {
  506. $sql = "ALTER TABLE ".C('DB_PREFIX')."page_history ADD page_comments varchar( 255 ) NOT NULL DEFAULT '' COMMENT '页面注释';";
  507. D("PageHistory")->execute($sql);
  508. }
  509. }
  510. if(D("User")->where("uid = 1 ")->find()){
  511. $db_config = array(
  512. 'DB_TYPE' => 'Sqlite',
  513. 'DB_NAME' => 'Sqlite/showdoc.db.php',
  514. );
  515. M("User")->db(2,$db_config)->where("uid = 1 ")->delete();
  516. }
  517. }
  518. private function _moveTable($table){
  519. $db_config = array(
  520. 'DB_TYPE' => 'Sqlite',
  521. 'DB_NAME' => 'Sqlite/showdoc.db.php',
  522. );
  523. $array = M($table)->select();
  524. if ($array) {
  525. foreach ($array as $key => $value) {
  526. M($table)->db(2,$db_config)->add($value);
  527. }
  528. }
  529. }
  530. }