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.

598 rivejä
22 KiB

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