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
+25 -23
+25 -23
View File
@@ -81,49 +81,51 @@ class pluginBluditGithub extends Plugin
public function afterPageCreate($key) public function afterPageCreate($key)
{ {
if (empty($key)) {
return;
}
try { try {
if (empty($key) || !$this->isConfigured()) {
return;
}
$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)) {
return;
}
try { try {
if (empty($key) || !$this->isConfigured()) {
return;
}
$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 {
return; if (empty($key) || !$this->isConfigured()) {
} 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, 'sha' => $sha,
'sha' => $sha, 'branch' => $this->getValue('branch'),
'branch' => $this->getValue('branch'), ]);
]); }
} catch (Throwable $e) {
$this->setStatus('Error (afterPageDelete): ' . $e->getMessage());
} }
} }