Logical Theme System: Add theme event to hook into system activity event #2905

Closed
opened 2026-02-05 05:41:34 +03:00 by OVERLORD · 0 comments
Owner

Originally created by @ssddanbrown on GitHub (Jul 13, 2022).

This would allow custom logic to run upon any system activity being logged which opens up a bunch of additional possibilities via a single theme system event type.

Example Usage

An example would be that you could listen to page_update system events to then dump out the page HTML content to the local file-system upon every update as a secondary backup flat-file storage system for content.

<?php

use BookStack\Actions\ActivityType;
use BookStack\Entities\Models\Page;
use BookStack\Facades\Theme;
use BookStack\Theming\ThemeEvents;

Theme::listen(ThemeEvents::ACTIVITY_LOGGED, function (string $activityType, $detail) {

    if (!$detail instanceof Page) {
        return;
    }

    $validTypes = [ActivityType::PAGE_UPDATE, ActivityType::PAGE_CREATE];
    if (!in_array($activityType, $validTypes)) {
        return;
    }

    $outPath = "/output/directory/{$detail->id}.html";
    file_put_contents($outPath, $detail->html);
});
Originally created by @ssddanbrown on GitHub (Jul 13, 2022). This would allow custom logic to run upon any system activity being logged which opens up a bunch of additional possibilities via a single theme system event type. ### Example Usage An example would be that you could listen to page_update system events to then dump out the page HTML content to the local file-system upon every update as a secondary backup flat-file storage system for content. ```php <?php use BookStack\Actions\ActivityType; use BookStack\Entities\Models\Page; use BookStack\Facades\Theme; use BookStack\Theming\ThemeEvents; Theme::listen(ThemeEvents::ACTIVITY_LOGGED, function (string $activityType, $detail) { if (!$detail instanceof Page) { return; } $validTypes = [ActivityType::PAGE_UPDATE, ActivityType::PAGE_CREATE]; if (!in_array($activityType, $validTypes)) { return; } $outPath = "/output/directory/{$detail->id}.html"; file_put_contents($outPath, $detail->html); }); ```
OVERLORD added the 🔨 Feature Request🏭 Back-End labels 2026-02-05 05:41:34 +03:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/BookStack#2905