国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

509 Zeilen
21KB

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