国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
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.

484 lines
20KB

  1. #!/usr/bin/env php
  2. <?php
  3. /**
  4. * 命令行工具
  5. *
  6. * @version 2020年12月11日 tianya $
  7. * @package DedeBIZ.Command
  8. * @copyright Copyright (c) 2022, DedeBIZ.COM
  9. * @license https://www.dedebiz.com/license
  10. * @link https://www.dedebiz.com
  11. */
  12. define('DEDE_ENVIRONMENT', 'production');
  13. define('DEBUG_LEVEL', FALSE); //如果设置为TRUE则会打印执行SQL的时间和标签加载时间方便调试
  14. //切换工作目录到/src
  15. $workDir = dirname(__FILE__) . "/src";
  16. chdir($workDir);
  17. if (substr(php_sapi_name(), 0, 3) === 'cgi') {
  18. die("DedeBIZ:需要使用php-cli运行\n\n");
  19. }
  20. $helpStr = "
  21. NAME:
  22. DedeBIZ命令行工具
  23. USAGE:
  24. php ./dedebiz command [arguments...]
  25. COMMANDS:
  26. serv,s 运行DedeBIZ开发服务
  27. make,m 生成HTML
  28. update,u 更新到最新系统
  29. help,h Shows 帮助
  30. quick,q 快速开始一个开发环境
  31. tdata 生成测试数据
  32. WEBSITE:
  33. https://www.dedebiz.com/help/
  34. ";
  35. //将选项转化为SQL IN参数
  36. function Option2SQLin($str = "")
  37. {
  38. $str = preg_replace("#[^0-9-,]#", "", $str);
  39. $strs = explode(",", $str);
  40. foreach ($strs as $key => $si) {
  41. if (preg_match("#-#", $si)) {
  42. $tstart = 0;
  43. $tend = 0;
  44. $tss = explode("-", $si);
  45. if (intval($tss[0]) > intval($tss[1])) {
  46. $tstart = intval($tss[1]);
  47. $tend = intval($tss[0]);
  48. } else {
  49. $tstart = intval($tss[0]);
  50. $tend = intval($tss[1]);
  51. }
  52. $tmpArr = array();
  53. for ($i = $tstart; $i <= $tend; $i++) {
  54. $tmpArr[] = $i;
  55. }
  56. $strs[$key] = implode(",", $tmpArr);
  57. }
  58. }
  59. return implode(",", $strs);
  60. }
  61. function RandEncode($length=26)
  62. {
  63. $chars='abcdefghigklmnopqrstuvwxwyABCDEFGHIGKLMNOPQRSTUVWXWY0123456789';
  64. $rnd_cookieEncode='';
  65. $length = rand(28,32);
  66. $max = strlen($chars) - 1;
  67. for ($i = 0; $i < $length; $i++) {
  68. $rnd_cookieEncode .= $chars[mt_rand(0, $max)];
  69. }
  70. return $rnd_cookieEncode;
  71. }
  72. if (count($argv) > 1 && ($argv[1] == "serv" || $argv[1] == "s")) {
  73. //PHP5.4以下不支持内建服务器,用于开发调试
  74. if (phpversion() < "5.4") {
  75. die("DedeBIZ:命令行Web Server不支持\n\n");
  76. }
  77. echo "启动DedeBIZ开发环境\n\r";
  78. echo "浏览器打开 http://localhost:8088\n\r";
  79. passthru(PHP_BINARY . ' -S localhost:8088 -t' . escapeshellarg('./'));
  80. } else if (count($argv) > 1 && ($argv[1] == "make" || $argv[1] == "m")) {
  81. if (!file_exists($workDir . "/system/common.inc.php")) {
  82. DedeCli::error("检查目录是否正确");
  83. exit;
  84. }
  85. require_once($workDir . "/system/common.inc.php");
  86. require_once(DEDEINC . "/libraries/cli.class.php");
  87. //一个命令行的生成工具
  88. if (count($argv) > 2 && ($argv[2] == "arc" || $argv[2] == "a")) {
  89. //生成文档
  90. //make arc typeid=1
  91. $t1 = ExecTime();
  92. $addsql = "1=1";
  93. $typeid = Option2SQLin(DedeCli::getOption("typeid"));
  94. if (!empty($typeid)) {
  95. $addsql .= " AND typeid IN(" . $typeid . ")";
  96. }
  97. $aid = Option2SQLin(DedeCli::getOption("aid"));
  98. if (!empty($aid)) {
  99. $addsql .= " AND id IN(" . $typeid . ")";
  100. }
  101. $tt = $dsql->GetOne("SELECT COUNT(id) as dd FROM `#@__arctiny` WHERE " . $addsql);
  102. $total = intval($tt['dd']);
  103. $dsql->Execute('out', "SELECT id FROM `#@__arctiny` WHERE " . $addsql . " ORDER BY typeid ASC");
  104. $i = 0;
  105. while ($row = $dsql->GetObject('out')) {
  106. $id = $row->id;
  107. $ac = new Archives($id);
  108. $rurl = $ac->MakeHtml(0);
  109. DedeCli::showProgress(ceil(($i / $total) * 100), 100, $i, $total);
  110. $i++;
  111. }
  112. DedeCli::write("成功生成内容html");
  113. $queryTime = ExecTime() - $t1;
  114. DedeCli::write($queryTime);
  115. exit;
  116. } else if (count($argv) > 2 && ($argv[2] == "list" || $argv[2] == "l")) {
  117. //生成栏目
  118. $addsql = "1=1";
  119. $typeid = Option2SQLin(DedeCli::getOption("typeid"));
  120. if (!empty($typeid)) {
  121. $addsql .= " AND id IN(" . $typeid . ")";
  122. }
  123. $dsql->Execute('out', "SELECT id,channeltype FROM `#@__arctype` WHERE " . $addsql);
  124. $i = 0;
  125. while ($row = $dsql->GetObject('out')) {
  126. if ($row->channeltype > 0) {
  127. $lv = new ListView($row->id);
  128. } else {
  129. $lv = new SgListView($row->id);
  130. }
  131. $lv->CountRecord();
  132. DedeCli::write("开始生成列表html[id:{$row->id}]");
  133. $lv->MakeHtml('', '', 0);
  134. }
  135. exit;
  136. } else if (count($argv) > 2 && ($argv[2] == "index" || $argv[2] == "i")) {
  137. //生成首页
  138. $position = DedeCli::getOption("position");
  139. if (empty($position)) {
  140. $position = "../index.html";
  141. }
  142. if (!preg_match("#\.html$#", $position)) {
  143. DedeCli::error("位置必须以.html结尾");
  144. exit;
  145. }
  146. $homeFile = DEDEINC . "/" . $position;
  147. $homeFile = str_replace("\\", "/", $homeFile);
  148. $homeFile = str_replace("//", "/", $homeFile);
  149. $row = $dsql->GetOne("SELECT * FROM `#@__homepageset`");
  150. $templet = $row['templet'];
  151. $templet = str_replace("{style}", $cfg_df_style, $templet);
  152. $pv = new PartView();
  153. $GLOBALS['_arclistEnv'] = 'index';
  154. $pv->SetTemplet($cfg_basedir . $cfg_templets_dir . "/" . $templet);
  155. $pv->SaveToHtml($homeFile);
  156. DedeCli::write("成功生成首页html");
  157. } else if (count($argv) > 2 && ($argv[2] == "auto" || $argv[2] == "o")) {
  158. //自动生成
  159. function OptimizeData($dsql)
  160. {
  161. global $cfg_dbprefix;
  162. $tptables = array("{$cfg_dbprefix}archives", "{$cfg_dbprefix}arctiny");
  163. $dsql->SetQuery("SELECT maintable,addtable FROM `#@__channeltype` ");
  164. $dsql->Execute();
  165. while ($row = $dsql->GetObject()) {
  166. $addtable = str_replace('#@__', $cfg_dbprefix, $row->addtable);
  167. if ($addtable != '' && !in_array($addtable, $tptables)) $tptables[] = $addtable;
  168. }
  169. $tptable = '';
  170. foreach ($tptables as $t) $tptable .= ($tptable == '' ? "`{$t}`" : ",`{$t}`");
  171. $dsql->ExecuteNoneQuery(" OPTIMIZE TABLE $tptable; ");
  172. }
  173. $start = empty(DedeCli::getOption("start"))? "-1 day" : DedeCli::getOption("start");
  174. $start = strtotime($start);
  175. if (!$start) {
  176. DedeCli::error("start参数为空");
  177. exit;
  178. }
  179. //1.生成首页
  180. $pv = new PartView();
  181. $row = $pv->dsql->GetOne("SELECT * FROM `#@__homepageset` ");
  182. $templet = str_replace("{style}", $cfg_df_style, $row['templet']);
  183. $homeFile = DEDEINC . '/' . $row['position'];
  184. $homeFile = str_replace("\\", '/', $homeFile);
  185. $homeFile = preg_replace("#\/{1,}#", '/', $homeFile);
  186. if ($row['showmod'] == 1) {
  187. $pv->SetTemplet($cfg_basedir . $cfg_templets_dir . '/' . $templet);
  188. $pv->SaveToHtml($homeFile);
  189. $pv->Close();
  190. } else {
  191. if (file_exists($homeFile)) @unlink($homeFile);
  192. }
  193. DedeCli::write("成功生成首页html");
  194. //2.生成栏目
  195. $query = "SELECT DISTINCT typeid From `#@__arctiny` WHERE senddate >=" . $start . " AND arcrank>-1";
  196. $dsql->SetQuery($query);
  197. $dsql->Execute();
  198. $typeids = array();
  199. while ($row = $dsql->GetArray()) {
  200. $typeids[$row['typeid']] = 1;
  201. }
  202. if (count($typeids) > 0) {
  203. foreach ($typeids as $k => $v) {
  204. $vs = array();
  205. $vs = GetParentIds($k);
  206. if (!isset($typeidsok[$k])) {
  207. $typeidsok[$k] = 1;
  208. }
  209. foreach ($vs as $k => $v) {
  210. if (!isset($typeidsok[$v])) {
  211. $typeidsok[$v] = 1;
  212. }
  213. }
  214. }
  215. foreach ($typeidsok as $tt=> $k) {
  216. $row = $dsql->GetOne("SELECT id,channeltype FROM `#@__arctype` WHERE id=".$tt);
  217. if ($row['channeltype'] > 0) {
  218. $lv = new ListView($tt);
  219. } else {
  220. $lv = new SgListView($tt);
  221. }
  222. $lv->CountRecord();
  223. DedeCli::write("开始生成列表html[id:{$tt}]");
  224. $lv->MakeHtml('', '', 0);
  225. }
  226. DedeCli::write("成功生成列表html");
  227. }
  228. //生成文档
  229. $tt = $dsql->GetOne("SELECT COUNT(id) as dd FROM `#@__arctiny` WHERE senddate >=" . $start . " AND arcrank>-1");
  230. $total = intval($tt['dd']);
  231. $dsql->Execute('out', "SELECT id FROM `#@__arctiny` WHERE senddate >=" . $start . " AND arcrank>-1 ORDER BY typeid ASC");
  232. $i = 0;
  233. while ($row = $dsql->GetObject('out')) {
  234. $id = $row->id;
  235. $ac = new Archives($id);
  236. $rurl = $ac->MakeHtml(0);
  237. DedeCli::showProgress(ceil(($i / $total) * 100), 100);
  238. $i++;
  239. }
  240. DedeCli::write("成功生成html");
  241. //优化数据
  242. OptimizeData($dsql);
  243. DedeCli::write("成功优化数据");
  244. } else {
  245. $helpStr = "
  246. USAGE:
  247. php ./dedebiz make action [arguments...]
  248. ACTIONS:
  249. index,i 生成首页html
  250. --position 首页html位置,默认: ../index.html(相对system目录)
  251. arc,a 生成文档html
  252. --typeid 栏目id
  253. --aid 文档id
  254. list,l 生成列表html
  255. --typeid 栏目id
  256. auto,o 自动生成
  257. --start 开始时间(format:2012-03-12)
  258. tdata 生成测试数据
  259. WEBSITE:
  260. https://www.dedebiz.com/help/";
  261. DedeCli::write($helpStr);
  262. exit;
  263. }
  264. } else if (count($argv) > 1 && ($argv[1] == "update" || $argv[1] == "u")) {
  265. define("DEDEINC", $workDir."/system");
  266. require_once(DEDEINC."/dedehttpdown.class.php");
  267. require_once(DEDEINC . "/libraries/cli.class.php");
  268. //更新系统
  269. $latestURL = "https://cdn.dedebiz.com/release/latest.txt";
  270. $del = new DedeHttpDown();
  271. $del->OpenUrl($latestURL);
  272. $remoteVerStr = $del->GetHtml();
  273. $commStr = file_get_contents(DEDEINC."/common.inc.php");
  274. preg_match("#_version_detail = '([\d\.]+)'#", $commStr, $matchs);
  275. $cfg_version_detail = $localVerStr = $matchs[1];
  276. if (version_compare($localVerStr, $remoteVerStr, '>=')) {
  277. DedeCli::error("已经是最新版本,无需继续升级");
  278. exit;
  279. }
  280. $fileHashURL = "https://cdn.dedebiz.com/release/{$cfg_version_detail}.json";
  281. $del = new DedeHttpDown();
  282. $del->OpenUrl($fileHashURL);
  283. $filelist = $del->GetJSON();
  284. $offFiles = array();
  285. //TODO 命令行自动更新
  286. } else if (count($argv) > 1 && ($argv[1] == "quick" || $argv[1] == "q")){
  287. define("DEDEINC", $workDir."/system");
  288. require_once(DEDEINC . "/libraries/cli.class.php");
  289. //快速开始一个用于开发的DedeBIZ环境,基于SQLite无其他依赖
  290. if (file_exists($workDir."/data/DedeBIZ.db")) {
  291. DedeCli::write("开发环境已经初始化");
  292. echo "启动DedeBIZ开发环境\n\r";
  293. echo "浏览器打开 http://localhost:8088\n\r";
  294. passthru(PHP_BINARY . ' -S localhost:8088 -t' . escapeshellarg('./'));
  295. exit;
  296. }
  297. //初始化安装一个开发环境
  298. $db = new SQLite3($workDir.'/data/DedeBIZ.db');
  299. $fp = fopen($workDir."/install/common.inc.php","r");
  300. $configStr1 = fread($fp,filesize($workDir."/install/common.inc.php"));
  301. fclose($fp);
  302. @chmod($workDir."/data",0777);
  303. $dbtype = "sqlite";
  304. $dbhost = "";
  305. $dbname = "DedeBIZ";
  306. $dbuser = "";
  307. $dbpwd = "";
  308. $dbprefix = "dede_";
  309. $dblang = "utf8";
  310. if (!is_dir($workDir.'/data/tplcache')) {
  311. mkdir($workDir.'/data/tplcache', 0777);
  312. }
  313. //common.inc.php
  314. $configStr1 = str_replace("~dbtype~",$dbtype,$configStr1);
  315. $configStr1 = str_replace("~dbhost~",$dbhost,$configStr1);
  316. $configStr1 = str_replace("~dbname~",$dbname,$configStr1);
  317. $configStr1 = str_replace("~dbuser~",$dbuser,$configStr1);
  318. $configStr1 = str_replace("~dbpwd~",$dbpwd,$configStr1);
  319. $configStr1 = str_replace("~dbprefix~",$dbprefix,$configStr1);
  320. $configStr1 = str_replace("~dblang~",$dblang,$configStr1);
  321. $fp = fopen($workDir."/data/common.inc.php","w") or die("error,check /data writeable");
  322. fwrite($fp,$configStr1);
  323. fclose($fp);
  324. $cookieencode = RandEncode(26);
  325. $baseurl = "http://127.0.0.1:8088";
  326. $indexUrl = "/";
  327. $cmspath = "";
  328. $webname = "DedeBIZ本地测试开发站点";
  329. $adminmail = "admin@dedebiz.com";
  330. $fp = fopen($workDir."/install/config.cache.inc.php","r");
  331. $configStr2 = fread($fp,filesize($workDir."/install/config.cache.inc.php"));
  332. fclose($fp);
  333. $configStr2 = str_replace("~baseurl~",$baseurl,$configStr2);
  334. $configStr2 = str_replace("~basepath~",$cmspath,$configStr2);
  335. $configStr2 = str_replace("~indexurl~",$indexUrl,$configStr2);
  336. $configStr2 = str_replace("~cookieEncode~",$cookieencode,$configStr2);
  337. $configStr2 = str_replace("~webname~",$webname,$configStr2);
  338. $configStr2 = str_replace("~adminmail~",$adminmail,$configStr2);
  339. $fp = fopen($workDir.'/data/config.cache.inc.php','w');
  340. fwrite($fp,$configStr2);
  341. fclose($fp);
  342. $fp = fopen($workDir.'/data/config.cache.bak.php','w');
  343. fwrite($fp,$configStr2);
  344. fclose($fp);
  345. $query = '';
  346. $fp = fopen($workDir.'/install/sql-dftables.txt','r');
  347. while (!feof($fp))
  348. {
  349. $line = rtrim(fgets($fp,1024));
  350. if (preg_match("#;$#", $line))
  351. {
  352. $query .= $line."\n";
  353. $query = str_replace('#@__',$dbprefix,$query);
  354. $query = preg_replace('/character set (.*?) /i','',$query);
  355. $query = str_replace('unsigned','',$query);
  356. $query = str_replace('TYPE=MyISAM','',$query);
  357. $query = preg_replace ('/TINYINT\(([\d]+)\)/i','INTEGER',$query);
  358. $query = preg_replace ('/mediumint\(([\d]+)\)/i','INTEGER',$query);
  359. $query = preg_replace ('/smallint\(([\d]+)\)/i','INTEGER',$query);
  360. $query = preg_replace('/int\(([\d]+)\)/i','INTEGER',$query);
  361. $query = preg_replace('/auto_increment/i','PRIMARY KEY AUTOINCREMENT',$query);
  362. $query = preg_replace('/, KEY(.*?)MyISAM;/','',$query);
  363. $query = preg_replace('/, KEY(.*?);/',');',$query);
  364. $query = preg_replace('/, UNIQUE KEY(.*?);/',');',$query);
  365. $query = preg_replace('/set\(([^\)]*?)\)/','varchar',$query);
  366. $query = preg_replace('/enum\(([^\)]*?)\)/','varchar',$query);
  367. if (preg_match("/PRIMARY KEY AUTOINCREMENT/",$query)) {
  368. $query = preg_replace('/,([\t\s ]+)PRIMARY KEY \(`([0-9a-zA-Z]+)`\)/i','',$query);
  369. $query = str_replace(', PRIMARY KEY (`id`)','',$query);
  370. }
  371. @$db->exec($query);
  372. $query='';
  373. } else if (!preg_match("#^(\/\/|--)#", $line)) {
  374. $query .= $line;
  375. }
  376. }
  377. fclose($fp);
  378. //导入默认数据
  379. $query = '';
  380. $fp = fopen($workDir.'/install/sql-dfdata.txt','r');
  381. while (!feof($fp))
  382. {
  383. $line = rtrim(fgets($fp, 1024));
  384. if (preg_match("#;$#", $line)) {
  385. $query .= $line;
  386. $query = str_replace('#@__',$dbprefix,$query);
  387. $query = str_replace("\'","\"",$query);
  388. $query = str_replace('\t\n\n',"",$query);
  389. $query = str_replace('\t\n',"",$query);
  390. @$db->exec($query);
  391. $query='';
  392. } else if (!preg_match("#^(\/\/|--)#", $line)) {
  393. $query .= $line;
  394. }
  395. }
  396. fclose($fp);
  397. //更新配置
  398. $cquery = "UPDATE `{$dbprefix}sysconfig` SET value='{$baseurl}' WHERE varname='cfg_basehost';";
  399. $db->exec($cquery);
  400. $cquery = "UPDATE `{$dbprefix}sysconfig` SET value='{$cmspath}' WHERE varname='cfg_cmspath';";
  401. $db->exec($cquery);
  402. $cquery = "UPDATE `{$dbprefix}sysconfig` SET value='{$indexUrl}' WHERE varname='cfg_indexurl';";
  403. $db->exec($cquery);
  404. $cquery = "UPDATE `{$dbprefix}sysconfig` SET value='{$cookieencode}' WHERE varname='cfg_cookie_encode';";
  405. $db->exec($cquery);
  406. $cquery = "UPDATE `{$dbprefix}sysconfig` SET value='{$webname}' WHERE varname='cfg_webname';";
  407. $db->exec($cquery);
  408. $cquery = "UPDATE `{$dbprefix}sysconfig` SET value='{$adminmail}' WHERE varname='cfg_adminemail';";
  409. $db->exec($cquery);
  410. $adminuser = "admin";
  411. $adminpwd = "admin";
  412. //增加管理员帐号
  413. $pfd = "pwd";
  414. $apwd = substr(md5($adminpwd),5,20);
  415. $upwd = md5($adminpwd);
  416. if (function_exists('password_hash')) {
  417. $pfd = "pwd_new";
  418. $apwd = password_hash($adminpwd, PASSWORD_BCRYPT);
  419. $upwd = password_hash($adminpwd, PASSWORD_BCRYPT);
  420. }
  421. //增加管理员帐号
  422. $adminquery = "INSERT INTO `{$dbprefix}admin` (`id`,`usertype`,`userid`,`$pfd`,`uname`,`tname`,`email`,`typeid`,`logintime`,`loginip`) VALUES (1,10,'$adminuser','".$apwd."','admin','','',0,'".time()."','127.0.0.1');";
  423. $db->exec($adminquery);
  424. //关连前台会员帐号
  425. $adminquery = "INSERT INTO `{$dbprefix}member` (`mid`,`mtype`,`userid`,`{$pfd}`,`uname`,`sex`,`rank`,`money`,`email`,`scores`,`matt`,`face`,`safequestion`,`safeanswer`,`jointime`,`joinip`,`logintime`,`loginip`) VALUES ('1','个人','$adminuser','".$upwd."','$adminuser','男','100','0','','10000','10','','0','','".time()."','','0',''); ";
  426. $db->exec($adminquery);
  427. $adminquery = "INSERT INTO `{$dbprefix}member_person` (`mid`,`onlynet`,`sex`,`uname`,`qq`,`msn`,`tel`,`mobile`,`place`,`oldplace`,`birthday`,`star`,`income`,`education`,`height`,`bodytype`,`blood`,`vocation`,`smoke`,`marital`,`house`,`drink`,`datingtype`,`language`,`nature`,`lovemsg`,`address`,`uptime`) VALUES ('1','1','男','{$adminuser}','','','','','0','0','1980-01-01','1','0','0','160','0','0','0','0','0','0','0','0','','','','','0'); ";
  428. $db->exec($adminquery);
  429. $adminquery = "INSERT INTO `{$dbprefix}member_tj` (`mid`,`article`,`album`,`archives`,`homecount`,`pagecount`,`feedback`,`friend`,`stow`) VALUES ('1','0','0','0','0','0','0','0','0'); ";
  430. $db->exec($adminquery);
  431. $adminquery = "INSERT INTO `{$dbprefix}member_space` (`mid`,`pagesize`,`matt`,`spacename`,`spacelogo`,`spacestyle`,`sign`,`spacenews`) VALUES ('1','10','0','{$adminuser}的空间','','person','',''); ";
  432. $db->exec($adminquery);
  433. DedeCli::write("admin user:admin");
  434. DedeCli::write("admin password:admin");
  435. if (phpversion() < "5.4") {
  436. die("DedeBIZ:命令行Web Server不支持\n\n");
  437. }
  438. //写入程序安装锁
  439. file_put_contents($workDir.'/install/install_lock.txt', 'ok');
  440. echo "Start Dev Server For DedeBIZ\n\r";
  441. echo "Open http://localhost:8088\n\r";
  442. passthru(PHP_BINARY . ' -S localhost:8088 -t' . escapeshellarg('./'));
  443. exit;
  444. } else if(count($argv) > 1 && ($argv[1] =="tdata")){
  445. if (!file_exists($workDir . "/system/common.inc.php")) {
  446. DedeCli::error("检查根目录是否存在错误");
  447. exit;
  448. }
  449. require_once($workDir . "/system/common.inc.php");
  450. require_once(DEDEINC . "/libraries/cli.class.php");
  451. $in_query = "INSERT INTO `#@__arctype` (reid,topid,sortrank,typename,cnoverview,enname,enoverview,bigpic,litimg,typedir,isdefault,defaultname,issend,channeltype,tempindex,templist,temparticle,modname,namerule,namerule2,ispart,corank,description,keywords,seotitle,moresite,siteurl,sitepath,ishidden,`cross`,`crossid`,`content`,`smalltypes`) VALUES ('0','0','999','测试栏目','','','','','','{cmspath}/a/ceshilanmu','1','index.html','1','1','{style}/index_article.htm','{style}/list_article.htm','{style}/article_article.htm','default','{typedir}/{aid}.html','{typedir}/{tid}-{page}.html','0','0','测试','测试','','0','','','0','0','','','')";
  452. if (!$dsql->ExecuteNoneQuery($in_query)) {
  453. die("保存目录数据时失败,请检查您的输入资料是否存在问题");
  454. }
  455. $typeid = $dsql->GetLastID();
  456. DedeCli::write("开始生成测试数据...");
  457. for ($i=0; $i < 30000; $i++) {
  458. DedeCli::showProgress(ceil(($i / 30000) * 100), 100);
  459. $now = time();
  460. $arcID = GetIndexKey(0, $typeid, $now, 1, $now, 1);
  461. if (empty($arcID)) {
  462. die("无法获得主键,因此无法进行后续操作");
  463. }
  464. $query = "INSERT INTO `#@__archives` (id,typeid,typeid2,sortrank,flag,ismake,channel,arcrank,click,money,title,shorttitle,color,writer,source,litpic,pubdate,senddate,mid,notpost,description,keywords,filename,dutyadmin,weight) VALUES ('$arcID','$typeid','0','$now','','1','1','0','100','0','这是一篇测试文章$arcID','测试文章$arcID','','天涯','DedeBIZ','','$now','$now','1','0','测试描述','测试关键词','','1','');";
  465. if (!$dsql->ExecuteNoneQuery($query)) {
  466. $gerr = $dsql->GetError();
  467. $dsql->ExecuteNoneQuery("DELETE FROM `#@__arctiny` WHERE id='$arcID'");
  468. die("数据保存到数据库主表`#@__archives`时出错,请检查数据库字段".str_replace('"', '', $gerr));
  469. }
  470. $body = str_repeat("得德内容管理系统DedeBIZ上海穆云智能科技有限公司,天涯、叙述别离、老岳2023",500);
  471. $query = "INSERT INTO `#@__addonarticle` (aid,typeid,redirecturl,templet,userip,body) VALUES ('$arcID','$typeid','','','127.0.0.1','$body')";
  472. if (!$dsql->ExecuteNoneQuery($query)) {
  473. $gerr = $dsql->GetError();
  474. $dsql->ExecuteNoneQuery("DELETE FROM `#@__archives` WHERE id='$arcID'");
  475. $dsql->ExecuteNoneQuery("DELETE FROM `#@__arctiny` WHERE id='$arcID'");
  476. die("数据保存到数据库附加表时出错,请检查数据库字段".str_replace('"', '', $gerr));
  477. }
  478. }
  479. DedeCli::write("成功生成所有测试数据");
  480. } else {
  481. echo $helpStr;
  482. }
  483. ?>