From ab5f166b112079c30f6ed1e601e10a09c4dcf75a Mon Sep 17 00:00:00 2001 From: chaideqing Date: Fri, 3 Nov 2023 07:13:59 +0000 Subject: [PATCH] * Merge commit: 91cae60535, fix bug #34221. --- module/extension/model.php | 73 ++++++++++++++++----------- module/story/view/batchclose.html.php | 2 +- 2 files changed, 45 insertions(+), 30 deletions(-) diff --git a/module/extension/model.php b/module/extension/model.php index 57a3f1d6de..388aa99029 100644 --- a/module/extension/model.php +++ b/module/extension/model.php @@ -417,12 +417,12 @@ class extensionModel extends model */ public function checkExtensionPaths($extension) { - $return = new stdclass(); - $return->result = 'ok'; - $return->errors = ''; - $return->mkdirCommands = ''; - $return->chmodCommands = ''; - $return->dirs2Created = array(); + $checkResult = new stdclass(); + $checkResult->result = 'ok'; + $checkResult->errors = ''; + $checkResult->mkdirCommands = ''; + $checkResult->chmodCommands = ''; + $checkResult->dirs2Created = array(); $appRoot = $this->app->getAppRoot(); $paths = $this->getPathsFromPackage($extension); @@ -434,32 +434,36 @@ class extensionModel extends model { if(!is_writable($path)) { - $return->errors .= sprintf($this->lang->extension->errorTargetPathNotWritable, $path) . '
'; - $return->chmodCommands .= "sudo chmod -R 777 $path
"; + $checkResult->errors .= sprintf($this->lang->extension->errorTargetPathNotWritable, $path) . '
'; + $checkResult->chmodCommands .= "sudo chmod -R 777 $path
"; } } else { $parentDir = mb_substr($path, 0, strripos($path, '/')); - if(!is_dir($path) and !mkdir($path, 0777, true)) - { - $return->errors .= sprintf($this->lang->extension->errorTargetPathNotExists, $path) . '
'; - $return->mkdirCommands .= "sudo mkdir -p $path
"; - } if(!is_writable($parentDir)) { - $return->errors .= sprintf($this->lang->extension->errorTargetPathNotWritable, $path) . '
'; - $return->chmodCommands .= "sudo chmod -R 777 $path
"; + $checkResult->errors .= sprintf($this->lang->extension->errorTargetPathNotWritable, $path) . '
'; + $checkResult->chmodCommands .= "sudo chmod -R 777 $path
"; + $checkResult->errors .= sprintf($this->lang->extension->errorTargetPathNotExists, $path) . '
'; + $checkResult->mkdirCommands .= "sudo mkdir -p $path
"; } - $return->dirs2Created[] = $path; + else if(!mkdir($path, 0777, true)) + { + $checkResult->errors .= sprintf($this->lang->extension->errorTargetPathNotExists, $path) . '
'; + $checkResult->mkdirCommands .= "sudo mkdir -p $path
"; + } + $checkResult->dirs2Created[] = $path; } } - if($return->errors) $return->result = 'fail'; - $return->mkdirCommands = empty($return->mkdirCommands) ? '' : '' . str_replace('/', DIRECTORY_SEPARATOR, $return->mkdirCommands) . ''; - $return->errors .= $this->lang->extension->executeCommands . $return->mkdirCommands; - if(PHP_OS == 'Linux') $return->errors .= empty($return->chmodCommands) ? '' : '' . $return->chmodCommands . ''; - return $return; + if($checkResult->errors) $checkResult->result = 'fail'; + + $checkResult->mkdirCommands = empty($checkResult->mkdirCommands) ? '' : '' . str_replace('/', DIRECTORY_SEPARATOR, $checkResult->mkdirCommands) . ''; + $checkResult->errors .= $this->lang->extension->executeCommands . $checkResult->mkdirCommands; + if(PHP_OS == 'Linux') $checkResult->errors .= empty($checkResult->chmodCommands) ? '' : '' . $checkResult->chmodCommands . ''; + + return $checkResult; } /** @@ -583,7 +587,7 @@ class extensionModel extends model $dirs = json_decode($extension->dirs); $files = json_decode($extension->files); $appRoot = $this->app->getAppRoot(); - $removeCommands = array(); + $commandTips = array(); /* Remove files first. */ if($files) @@ -593,13 +597,14 @@ class extensionModel extends model $file = $appRoot . $file; if(!file_exists($file)) continue; - if(!is_writable($file) or @md5_file($file) != $savedMD5) + $parentDir = mb_substr($file, 0, strripos($file, '/')); + if(!is_writable($file) || !is_writable($parentDir)) { - $removeCommands[] = PHP_OS == 'Linux' ? "rm -fr $file #changed" : "del $file :changed"; + $commandTips[] = PHP_OS == 'Linux' ? "sudo rm -fr $file" : "del $file"; } - elseif(!is_writable($file) or !@unlink($file)) + elseif(@md5_file($file) != $savedMD5) { - $removeCommands[] = PHP_OS == 'Linux' ? "rm -fr $file" : "del $file"; + $commandTips[] = PHP_OS == 'Linux' ? "sudo rm -fr $file" : "del $file"; } } } @@ -610,15 +615,25 @@ class extensionModel extends model rsort($dirs); // remove from the lower level directory. foreach($dirs as $dir) { - if(!is_dir($appRoot . $dir)) continue; - if(!is_writable($appRoot . $dir) or !rmdir($appRoot . $dir)) $removeCommands[] = PHP_OS == 'Linux' ? "rm -fr $appRoot$dir" : "rmdir $appRoot$dir /s /q"; + $path = $appRoot . $dir; + if(!is_dir($path)) continue; + + $parentDir = mb_substr($path, 0, strripos($path, '/')); + if(!is_writable($path) || !is_writable($parentDir)) + { + $commandTips[] = PHP_OS == 'Linux' ? "sudo rm -fr $appRoot$dir" : "rmdir $appRoot$dir /s /q"; + } + elseif(!rmdir($appRoot . $dir)) + { + $commandTips[] = PHP_OS == 'Linux' ? "sudo rm -fr $appRoot$dir" : "rmdir $appRoot$dir /s /q"; + } } } /* Clean model cache files. */ $this->cleanModelCache(); - return $removeCommands; + return $commandTips; } /** diff --git a/module/story/view/batchclose.html.php b/module/story/view/batchclose.html.php index 27d360827f..a67cf4a5e7 100755 --- a/module/story/view/batchclose.html.php +++ b/module/story/view/batchclose.html.php @@ -46,7 +46,7 @@ status == 'draft' ? $closedReasonList = array_diff_key($reasonList, array('cancel' => '')) : $reasonList; + $closedReasonList = $story->status == 'draft' ? array_diff_key($reasonList, array('cancel' => '')) : $reasonList; echo html::select("closedReasons[$storyID]", $closedReasonList, 'done', "class=form-control onchange=setDuplicateAndChild(this.value,$storyID) style='min-width: 80px'"); ?>