国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

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