diff --git a/dedebiz b/dedebiz index fc6b2966..e99cd851 100755 --- a/dedebiz +++ b/dedebiz @@ -9,6 +9,7 @@ * @license https://www.dedebiz.com/license * @link https://www.dedebiz.com */ +define("DEDE_CLITOOLS", TRUE); define('DEDE_ENVIRONMENT', 'production'); define('DEBUG_LEVEL', FALSE); //如果设置为TRUE则会打印执行SQL的时间和标签加载时间方便调试 //切换工作目录到/src @@ -17,6 +18,9 @@ if (!file_exists($workDir . "/system/common.inc.php")) { DedeCli::error("检查目录是否正确"); exit; } +if (!file_exists($workDir."/data/config.cache.inc.php")) { + require_once($workDir."/install/config.cache.inc.php"); +} require_once($workDir . "/system/common.inc.php"); require_once(DEDEINC . "/libraries/cli.class.php"); chdir($workDir); @@ -288,7 +292,9 @@ if (count($argv) > 1 && ($argv[1] == "serv" || $argv[1] == "s")) { $offFiles = array(); //TODO 命令行自动更新 } else if (count($argv) > 1 && ($argv[1] == "quick" || $argv[1] == "q")){ - define("DEDEINC", $workDir."/system"); + if (!defined('DEDEINC')) { + define("DEDEINC", $workDir."/system"); + } require_once(DEDEINC . "/libraries/cli.class.php"); //快速开始一个用于开发的DedeBIZ环境,基于SQLite无其他依赖 if (file_exists($workDir."/data/DedeBIZ.db")) { @@ -329,7 +335,7 @@ if (count($argv) > 1 && ($argv[1] == "serv" || $argv[1] == "s")) { $baseurl = "http://127.0.0.1:8088"; $indexUrl = "/"; $cmspath = ""; - $webname = "DedeBIZ本地测试开发站点"; + $webname = "穆云智能"; $adminmail = "admin@dedebiz.com"; $fp = fopen($workDir."/install/config.cache.inc.php","r"); $configStr2 = fread($fp,filesize($workDir."/install/config.cache.inc.php")); @@ -355,23 +361,7 @@ if (count($argv) > 1 && ($argv[1] == "serv" || $argv[1] == "s")) { { $query .= $line."\n"; $query = str_replace('#@__',$dbprefix,$query); - $query = preg_replace('/character set (.*?) /i','',$query); - $query = str_replace('unsigned','',$query); - $query = str_replace('TYPE=MyISAM','',$query); - $query = preg_replace ('/TINYINT\(([\d]+)\)/i','INTEGER',$query); - $query = preg_replace ('/mediumint\(([\d]+)\)/i','INTEGER',$query); - $query = preg_replace ('/smallint\(([\d]+)\)/i','INTEGER',$query); - $query = preg_replace('/int\(([\d]+)\)/i','INTEGER',$query); - $query = preg_replace('/auto_increment/i','PRIMARY KEY AUTOINCREMENT',$query); - $query = preg_replace('/, KEY(.*?)MyISAM;/','',$query); - $query = preg_replace('/, KEY(.*?);/',');',$query); - $query = preg_replace('/, UNIQUE KEY(.*?);/',');',$query); - $query = preg_replace('/set\(([^\)]*?)\)/','varchar',$query); - $query = preg_replace('/enum\(([^\)]*?)\)/','varchar',$query); - if (preg_match("/PRIMARY KEY AUTOINCREMENT/",$query)) { - $query = preg_replace('/,([\t\s ]+)PRIMARY KEY \(`([0-9a-zA-Z]+)`\)/i','',$query); - $query = str_replace(', PRIMARY KEY (`id`)','',$query); - } + $query = ConvertMysqlToSqlite($query); @$db->exec($query); $query=''; } else if (!preg_match("#^(\/\/|--)#", $line)) { @@ -453,35 +443,51 @@ if (count($argv) > 1 && ($argv[1] == "serv" || $argv[1] == "s")) { } require_once($workDir . "/system/common.inc.php"); require_once(DEDEINC . "/libraries/cli.class.php"); - $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','','','')"; - if (!$dsql->ExecuteNoneQuery($in_query)) { - DedeCli::error("保存目录数据时失败,请检查您的输入资料是否存在问题"); - } - $typeid = $dsql->GetLastID(); - DedeCli::write("开始生成测试数据..."); - for ($i=0; $i < 30000; $i++) { - DedeCli::showProgress(ceil(($i / 30000) * 100), 100); - $now = time(); - $arcID = GetIndexKey(0, $typeid, $now, 1, $now, 1); - if (empty($arcID)) { - DedeCli::error("无法获得主键,因此无法进行后续操作"); + for ($t=1; $t <= 10; $t++) { + $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','测试栏目{$t}','','','','','','{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','','','')"; + if (!$dsql->ExecuteNoneQuery($in_query)) { + DedeCli::error("保存目录数据时失败,请检查您的输入资料是否存在问题"); } - $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','');"; - if (!$dsql->ExecuteNoneQuery($query)) { - $gerr = $dsql->GetError(); - $dsql->ExecuteNoneQuery("DELETE FROM `#@__arctiny` WHERE id='$arcID'"); - DedeCli::error("数据保存到数据库主表`#@__archives`时出错,请检查数据库字段".str_replace('"', '', $gerr)); - } - $body = str_repeat("得德内容管理系统DedeBIZ上海穆云智能科技有限公司,天涯{$arcID}、叙述别离、老岳2025",500); - $query = "INSERT INTO `#@__addonarticle` (aid,typeid,redirecturl,templet,userip,body) VALUES ('$arcID','$typeid','','','127.0.0.1','$body')"; - if (!$dsql->ExecuteNoneQuery($query)) { - $gerr = $dsql->GetError(); - $dsql->ExecuteNoneQuery("DELETE FROM `#@__archives` WHERE id='$arcID'"); - $dsql->ExecuteNoneQuery("DELETE FROM `#@__arctiny` WHERE id='$arcID'"); - DedeCli::error("数据保存到数据库附加表时出错,请检查数据库字段".str_replace('"', '', $gerr)); + $typeid = $dsql->GetLastID(); + DedeCli::write("开始生成[测试栏目{$t}]测试数据..."); + for ($i=0; $i < 1000; $i++) { + DedeCli::showProgress(ceil(($i / 1000) * 100), 100); + $now = time(); + $arcID = GetIndexKey(0, $typeid, $now, 1, $now, 1); + if (empty($arcID)) { + DedeCli::error("无法获得主键,因此无法进行后续操作"); + } + $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','');"; + if (!$dsql->ExecuteNoneQuery($query)) { + $gerr = $dsql->GetError(); + $dsql->ExecuteNoneQuery("DELETE FROM `#@__arctiny` WHERE id='$arcID'"); + DedeCli::error("数据保存到数据库主表`#@__archives`时出错,请检查数据库字段".str_replace('"', '', $gerr)); + } + $body = str_repeat("

DedeBIZ系统基于PHP7版本开发,具有很强的可扩展性,并且采用GPLv2协议完全开放源代码。DedeBIZ支持采用现流行的Go语言设计开发,拥有简单易用、灵活扩展特性之外更安全、高效。模板设计制作简单,一直是系统一大特点,延续之前标签,同时采用响应式模板引擎Bootstrap作为系统模板渲染引擎,让搭建跨终端和移动端全媒体站点更简单。

",5); + $query = "INSERT INTO `#@__addonarticle` (aid,typeid,redirecturl,templet,userip,body) VALUES ('$arcID','$typeid','','','127.0.0.1','$body')"; + if (!$dsql->ExecuteNoneQuery($query)) { + $gerr = $dsql->GetError(); + $dsql->ExecuteNoneQuery("DELETE FROM `#@__archives` WHERE id='$arcID'"); + $dsql->ExecuteNoneQuery("DELETE FROM `#@__arctiny` WHERE id='$arcID'"); + DedeCli::error("数据保存到数据库附加表时出错,请检查数据库字段".str_replace('"', '', $gerr)); + } + InsertTags("天涯{$arcID},穆云智能", $arcID); } - InsertTags("天涯{$arcID},穆云智能", $arcID); } + $dsql->SetQuery("SELECT id,reid,channeltype,issend,typename FROM `#@__arctype`"); + $dsql->Execute(); + $cacheFile = DEDEDATA.'/cache/inc_catalog_base.inc'; + $fp = fopen($cacheFile, 'w'); + $phph = '?'; + $fpHeader = "<{$phph}php\r\nglobal \$cfg_Cs;\r\n\$cfg_Cs=array();\r\n"; + fwrite($fp, $fpHeader); + while ($row = $dsql->GetObject()) { + //typename缓存起来 + $row->typename = base64_encode($row->typename); + fwrite($fp, "\$cfg_Cs[{$row->id}]=array({$row->reid},{$row->channeltype},{$row->issend},'{$row->typename}');\r\n"); + } + fwrite($fp, "{$phph}>"); + fclose($fp); DedeCli::write("成功生成所有测试数据"); } else if(count($argv) > 1 && ($argv[1] =="pwd")){ DedeCli::write("请选择需要更改密码的用户名:"); @@ -505,7 +511,93 @@ if (count($argv) > 1 && ($argv[1] == "serv" || $argv[1] == "s")) { $query = "UPDATE `#@__member` SET $pwdm WHERE mid='$id'"; $dsql->ExecuteNoneQuery($query); DedeCli::write("成功修改密码"); -} else if(count($argv) > 1 && ($argv[1] =="make_filehash")){ +} else if(count($argv) > 1 && ($argv[1] =="clean")){ + // 当前功能仅开发方便清空构建站点测试用,常规情况下慎用 + function deleteDirectory($dir) { + if (!is_dir($dir)) { + return false; + } + $files = array_diff(scandir($dir), array('.', '..')); + foreach ($files as $file) { + $path = $dir . '/' . $file; + if (is_dir($path)) { + deleteDirectory($path); + } else { + unlink($path); + } + } + return rmdir($dir); + } + $isClean = DedeCli::prompt('确认清空站点资源,将会删除所有配置内容请谨慎使用(y:是,n:否)?'); + if (strtolower($isClean) == 'y') { + $directory = $workDir.'/data'; + // 删除data下的文件 + if ($handle = opendir($directory)) { + // 遍历目录中的所有文件和文件夹 + while (false !== ($entry = readdir($handle))) { + if ($entry != "." && $entry != "..") { + $fullPath = $directory . '/' . $entry; + // 匹配文件夹规则 + if (is_dir($fullPath) && preg_match('/^sessions_|^updatefile_/', $entry)) { + // 删除文件夹及其内容 + deleteDirectory($fullPath); + } elseif (is_file($fullPath) && preg_match('/.*_safe\.txt$|.*\.db$|.*\.php|.*\.inc/', $entry)) { + unlink($fullPath); + } + } + } + // 关闭目录 + closedir($handle); + } + + if ($handle = opendir($directory."/backupdata")) { + // 遍历目录中的所有文件和文件夹 + while (false !== ($entry = readdir($handle))) { + if ($entry != "." && $entry != "..") { + $fullPath = $directory . '/backupdata/' . $entry; + if (is_file($fullPath) && preg_match('/.*\.txt$/', $entry)) { + unlink($fullPath); + } + } + } + // 关闭目录 + closedir($handle); + } + if ($handle = opendir($directory."/tplcache")) { + // 遍历目录中的所有文件和文件夹 + while (false !== ($entry = readdir($handle))) { + if ($entry != "." && $entry != "..") { + $fullPath = $directory . '/tplcache/' . $entry; + if (is_file($fullPath) && preg_match('/.*\.inc$|.*\.txt$/', $entry)) { + unlink($fullPath); + } + } + } + // 关闭目录 + closedir($handle); + } + if ($handle = opendir($directory.'/cache')) { + // 遍历目录中的所有文件和文件夹 + while (false !== ($entry = readdir($handle))) { + if ($entry != "." && $entry != "..") { + $fullPath = $directory . '/cache/' . $entry; + // 匹配文件夹规则 + if (is_dir($fullPath) && preg_match('/^mask_|CSS|diggCache|HTML|memberlogin|tagjsonq|update|URI/', $entry)) { + // 删除文件夹及其内容 + deleteDirectory($fullPath); + } elseif (is_file($fullPath) && preg_match('/.*\.inc|.*\.dat/', $entry)) { + unlink($fullPath); + } + } + } + // 关闭目录 + closedir($handle); + } + unlink($workDir.'/install/install_lock.txt'); + DedeCli::write("站点清除成功"); + } + +} else if(count($argv) > 1 && ($argv[1] =="make_filehash")){ $gitFiles = shell_exec('git ls-files'); // 将输出的字符串按行拆分成数组 $fileList = explode("\n", trim($gitFiles));