Enhance error handling and configuration checks in afterPageCreate, afterPageModify, and afterPageDelete methods

This commit is contained in:
interlope committed 2026-06-01 17:11:41 +02:00
1 parent 1d525023a3
commit 17e18e4b39
1 file changed
+13 -11
+13 -11
View File
@@ -81,43 +81,42 @@ class pluginBluditGithub extends Plugin
public function afterPageCreate($key) public function afterPageCreate($key)
{ {
if (empty($key)) { try {
if (empty($key) || !$this->isConfigured()) {
return; return;
} }
try {
$page = new Page($key); $page = new Page($key);
if ($this->shouldExport($page)) { if ($this->shouldExport($page)) {
$this->exportPage($page); $this->exportPage($page);
} }
} catch (Exception $e) { } catch (Throwable $e) {
// page not found $this->setStatus('Error (afterPageCreate): ' . $e->getMessage());
} }
} }
public function afterPageModify($key) public function afterPageModify($key)
{ {
if (empty($key)) { try {
if (empty($key) || !$this->isConfigured()) {
return; return;
} }
try {
$page = new Page($key); $page = new Page($key);
if ($this->shouldExport($page)) { if ($this->shouldExport($page)) {
$this->exportPage($page); $this->exportPage($page);
} }
} catch (Exception $e) { } catch (Throwable $e) {
// page not found $this->setStatus('Error (afterPageModify): ' . $e->getMessage());
} }
} }
public function afterPageDelete($key) public function afterPageDelete($key)
{ {
if (!$this->isConfigured() || empty($key)) { try {
if (empty($key) || !$this->isConfigured()) {
return; return;
} }
$filePath = $this->getFilePath($key); $filePath = $this->getFilePath($key);
$sha = $this->getFileSha($filePath); $sha = $this->getFileSha($filePath);
if ($sha) { if ($sha) {
$this->githubRequest('DELETE', '/contents/' . $filePath, [ $this->githubRequest('DELETE', '/contents/' . $filePath, [
'message' => 'Delete: ' . $key, 'message' => 'Delete: ' . $key,
@@ -125,6 +124,9 @@ class pluginBluditGithub extends Plugin
'branch' => $this->getValue('branch'), 'branch' => $this->getValue('branch'),
]); ]);
} }
} catch (Throwable $e) {
$this->setStatus('Error (afterPageDelete): ' . $e->getMessage());
}
} }
// --- Private --- // --- Private ---