Remove maintenance feature

This commit is contained in:
2026-04-03 14:53:05 +02:00
parent 946c269d42
commit d33c7a748b
11 changed files with 28 additions and 889 deletions

View File

@@ -82,12 +82,6 @@ class action_plugin_luxtools extends ActionPlugin
$this,
"handleCalendarWidgetAjax",
);
$controller->register_hook(
"AJAX_CALL_UNKNOWN",
"BEFORE",
$this,
"handleMaintenanceTaskAction",
);
$controller->register_hook(
"AJAX_CALL_UNKNOWN",
"BEFORE",
@@ -753,21 +747,8 @@ class action_plugin_luxtools extends ActionPlugin
);
}
// Render maintenance tasks
if (isset($grouped["maintenance"])) {
$title = (string) $this->getLang("chronological_maintenance_title");
if ($title === "") {
$title = "Tasks";
}
$html .= $this->renderMaintenanceSection(
$grouped["maintenance"],
$title,
$dateIso,
);
}
// Render slot3/slot4 if present
foreach (["slot3", "slot4"] as $slotKey) {
// Render slot2/slot3/slot4 if present
foreach (["slot2", "slot3", "slot4"] as $slotKey) {
if (isset($grouped[$slotKey]) && isset($slots[$slotKey])) {
$label = $slots[$slotKey]->getLabel();
$html .= $this->renderEventSection(
@@ -814,51 +795,6 @@ class action_plugin_luxtools extends ActionPlugin
"</div>";
}
/**
* Render a maintenance task section with completion buttons.
*
* @param CalendarEvent[] $events
* @param string $title
* @param string $dateIso
* @return string
*/
protected function renderMaintenanceSection(
array $events,
string $title,
string $dateIso,
): string {
$items = "";
$ajaxUrl = defined("DOKU_BASE")
? (string) DOKU_BASE . "lib/exe/ajax.php"
: "lib/exe/ajax.php";
foreach ($events as $event) {
$items .= $this->renderMaintenanceListItem($event, $ajaxUrl);
}
if ($items === "") {
return "";
}
$secToken = function_exists("getSecurityToken")
? getSecurityToken()
: "";
return '<div class="luxtools-plugin luxtools-chronological-events luxtools-chronological-maintenance"' .
' data-luxtools-ajax-url="' .
hsc($ajaxUrl) .
'"' .
' data-luxtools-sectok="' .
hsc($secToken) .
'">' .
"<h2>" .
hsc($title) .
"</h2>" .
"<ul>" .
$items .
"</ul>" .
"</div>";
}
/**
* Render a single event as a list item with popup data attributes.
*
@@ -921,215 +857,6 @@ class action_plugin_luxtools extends ActionPlugin
"</span></li>";
}
/**
* Render a maintenance task as a list item with completion button.
*
* @param CalendarEvent $event
* @param string $ajaxUrl
* @return string
*/
protected function renderMaintenanceListItem(
CalendarEvent $event,
string $ajaxUrl,
): string {
$isCompleted = $event->isCompleted();
$classes = "luxtools-maintenance-task";
if ($isCompleted) {
$classes .= " luxtools-task-completed";
}
$summaryHtml = hsc($event->summary);
// Data attributes for popup and completion
$dataAttrs = ' data-luxtools-event="1"';
$dataAttrs .= ' data-event-summary="' . hsc($event->summary) . '"';
$dataAttrs .= ' data-event-start="' . hsc($event->startIso) . '"';
if ($event->endIso !== "") {
$dataAttrs .= ' data-event-end="' . hsc($event->endIso) . '"';
}
if ($event->location !== "") {
$dataAttrs .=
' data-event-location="' . hsc($event->location) . '"';
}
if ($event->description !== "") {
$dataAttrs .=
' data-event-description="' . hsc($event->description) . '"';
}
$dataAttrs .=
' data-event-allday="' . ($event->allDay ? "1" : "0") . '"';
$dataAttrs .= ' data-event-slot="maintenance"';
$dataAttrs .= ' data-task-uid="' . hsc($event->uid) . '"';
$dataAttrs .= ' data-task-date="' . hsc($event->dateIso) . '"';
$dataAttrs .=
' data-task-recurrence="' . hsc($event->recurrenceId) . '"';
$dataAttrs .= ' data-task-status="' . hsc($event->status) . '"';
$buttonLabel = $isCompleted
? (string) $this->getLang("maintenance_task_reopen")
: (string) $this->getLang("maintenance_task_complete");
if ($buttonLabel === "") {
$buttonLabel = $isCompleted ? "Reopen" : "Complete";
}
$buttonAction = $isCompleted ? "reopen" : "complete";
$buttonHtml =
'<button type="button" class="luxtools-task-action" data-action="' .
hsc($buttonAction) .
'">' .
hsc($buttonLabel) .
"</button>";
$timeHtml = "";
if (!$event->allDay && $event->time !== "") {
$timeHtml =
'<span class="luxtools-event-time" data-luxtools-start="' .
hsc($event->startIso) .
'">' .
hsc($event->time) .
"</span> - ";
}
return '<li class="' .
hsc($classes) .
'"' .
$dataAttrs .
">" .
$timeHtml .
'<span class="luxtools-event-summary">' .
$summaryHtml .
"</span> " .
$buttonHtml .
"</li>";
}
/**
* Handle AJAX requests for marking maintenance tasks complete/reopen.
*
* @param Event $event
* @param mixed $param
* @return void
*/
public function handleMaintenanceTaskAction(Event $event, $param)
{
if ($event->data !== "luxtools_maintenance_task") {
return;
}
$event->preventDefault();
$event->stopPropagation();
header("Content-Type: application/json; charset=utf-8");
$this->sendNoStoreHeaders();
global $INPUT;
// Verify security token
if (!checkSecurityToken()) {
http_status(403);
echo json_encode([
"ok" => false,
"error" => "Security token mismatch",
]);
return;
}
$action = $INPUT->str("action"); // 'complete' or 'reopen'
$uid = $INPUT->str("uid");
$dateIso = $INPUT->str("date");
$recurrence = $INPUT->str("recurrence");
if (!in_array($action, ["complete", "reopen"], true)) {
http_status(400);
echo json_encode(["ok" => false, "error" => "Invalid action"]);
return;
}
if ($uid === "" || !ChronoID::isIsoDate($dateIso)) {
http_status(400);
echo json_encode(["ok" => false, "error" => "Missing uid or date"]);
return;
}
$slots = CalendarSlot::loadAll($this);
$maintenanceSlot = $slots["maintenance"] ?? null;
if ($maintenanceSlot === null || !$maintenanceSlot->isEnabled()) {
http_status(400);
echo json_encode([
"ok" => false,
"error" => "Maintenance calendar not configured",
]);
return;
}
$newStatus = $action === "complete" ? "COMPLETED" : "TODO";
// Update local ICS file
$localOk = false;
$file = $maintenanceSlot->getFile();
if ($file !== "" && is_file($file)) {
$localOk = IcsWriter::updateEventStatus(
$file,
$uid,
$recurrence,
$newStatus,
$dateIso,
);
}
if (!$localOk) {
http_status(500);
echo json_encode([
"ok" => false,
"error" => $this->getLang("maintenance_complete_error"),
]);
return;
}
// Clear caches so next render picks up changes
CalendarService::clearCache();
// Remote CalDAV write-back if configured
$remoteOk = true;
$remoteError = "";
if ($maintenanceSlot->hasRemoteSource()) {
try {
$caldavResult = CalDavClient::updateEventStatus(
$maintenanceSlot->getCaldavUrl(),
$maintenanceSlot->getUsername(),
$maintenanceSlot->getPassword(),
$uid,
$recurrence,
$newStatus,
$dateIso,
);
if ($caldavResult !== "") {
$remoteOk = false;
$remoteError =
$this->getLang("maintenance_remote_write_failed") .
": " .
$caldavResult;
}
} catch (Throwable $e) {
$remoteOk = false;
$remoteError =
$this->getLang("maintenance_remote_write_failed") .
": " .
$e->getMessage();
}
}
$msg =
$action === "complete"
? $this->getLang("maintenance_complete_success")
: $this->getLang("maintenance_reopen_success");
echo json_encode([
"ok" => true,
"message" => $msg,
"remoteOk" => $remoteOk,
"remoteError" => $remoteError,
]);
}
/**
* Handle AJAX requests for manual calendar sync.
*