no message
This commit is contained in:
parent
ce106d8abb
commit
8bfe7cd37b
@ -38,4 +38,114 @@ class ArticleSchema extends Base {
|
||||
return $r;
|
||||
}
|
||||
|
||||
public function show($aParam)
|
||||
{
|
||||
$xId = $aParam["aArg"][1] ?? "last";
|
||||
$sShowField = $aParam["aOption"][1] ?? "schema";
|
||||
|
||||
if ($xId == "?") {
|
||||
return "#show__[field:content] [id:last]";
|
||||
}
|
||||
|
||||
if ($xId == "last") {
|
||||
$oArticle = ModelArticleSchema::orderBy("id", "desc")->first();
|
||||
} else {
|
||||
$oArticle = ModelArticleSchema::find($xId);
|
||||
}
|
||||
|
||||
if (!$oArticle) {
|
||||
return "没找到文章";
|
||||
}
|
||||
|
||||
$sMsg = "";
|
||||
|
||||
if ($sShowField == "schema") {
|
||||
$aContentFormat = json_decode($oArticle->schema, true);
|
||||
|
||||
$sMsg = json_encode($aContentFormat, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
|
||||
} else {
|
||||
$sMsg = $oArticle->$sShowField;
|
||||
}
|
||||
|
||||
return $sMsg;
|
||||
}
|
||||
|
||||
public function del_slave($aParam)
|
||||
{
|
||||
$iId = $aParam["aArg"][1] ?? false;
|
||||
|
||||
if (!$iId) {
|
||||
return "没有id";
|
||||
}
|
||||
|
||||
if ($iId == "?") {
|
||||
return "#del [id]";
|
||||
}
|
||||
|
||||
$oArticleSchema = ModelArticleSchema::where("id", $iId)->first();
|
||||
|
||||
$r = ServiceArticleCmd::startWithO($oArticleSchema)->syncOpen()->save("del");
|
||||
|
||||
return $r->getResult();
|
||||
}
|
||||
|
||||
public function del_self($aParam)
|
||||
{
|
||||
$iId = $aParam["aArg"][1] ?? false;
|
||||
|
||||
if (!$iId) {
|
||||
return "没有id";
|
||||
}
|
||||
|
||||
if ($iId == "?") {
|
||||
return "#del [id]";
|
||||
}
|
||||
|
||||
$oArticleSchema = ModelArticleSchema::where("id", $iId)->first();
|
||||
|
||||
$aSchema = json_decode($oArticleSchema->schema, true);
|
||||
|
||||
$i = 0;
|
||||
foreach ($aSchema as $aSchemaRow) {
|
||||
if ($aSchemaRow["type"] == "img") {
|
||||
$sImgA = $this->imgPathByUrl($aSchemaRow["content"]["img"]["base"]);
|
||||
$sImgB = $this->imgPathByUrl($aSchemaRow["content"]["img"]["thumb"]);
|
||||
$i += $this->imgDelByPath($sImgA);
|
||||
$i += $this->imgDelByPath($sImgB);
|
||||
}
|
||||
}
|
||||
|
||||
$oArticleSchema->delete();
|
||||
|
||||
$sMsg = "ok,同时删除了{$i}张图片。";
|
||||
|
||||
return $sMsg;
|
||||
}
|
||||
|
||||
private function imgPathByUrl($sImgUrl)
|
||||
{
|
||||
list(, $sImgPath) = explode("upload", $sImgUrl, 2);
|
||||
|
||||
$sImgPath = "upload".$sImgPath;
|
||||
|
||||
return $sImgPath;
|
||||
}
|
||||
|
||||
private function imgDelByPath($sFilePath)
|
||||
{
|
||||
if (is_file($sFilePath) && file_exists($sFilePath)) {
|
||||
if (unlink($sFilePath)) {
|
||||
return 1;
|
||||
} else {
|
||||
$sMsg = '删除失败(可能是权限或被占用)';
|
||||
// throw new \Exception($sMsg);
|
||||
}
|
||||
} else {
|
||||
$sMsg = '文件不存在或不是普通文件';
|
||||
// throw new \Exception($sMsg);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user