Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature idea: User defined Snapshots (description only snapshots) #16

Open
blueo opened this issue Aug 29, 2019 · 0 comments
Open

Feature idea: User defined Snapshots (description only snapshots) #16

blueo opened this issue Aug 29, 2019 · 0 comments

Comments

@blueo
Copy link
Collaborator

blueo commented Aug 29, 2019

Snapshots are currently great for recording standard editing activity (creation modification etc) but it would be useful to be able to create a snapshot for an action that is more of a description rather than a log of events. This is often the case when a user action might trigger several edit/write actions. For example, re-ordering blocks can trigger a number of snapshot entries like Block x Edited but it would be more useful to have a single snapshot that captures the 're-order' action.

I can achieve something like this by creating a DataObject as a 'Log' and manually creating a snapshot with it eg:

class Log extends DataObject
{
    /**
     * @var array
     */
    private static $extensions = [
        Versioned::class,
    ];
    /**
     * @var string
     */
    private static $table_name = 'SnapshotActivitiesLog';
    /**
     * @var array
     */
    private static $db = [
        'Title' => 'Varchar',
    ];
}

then:

    /**
     * Create a snapshot with a Log item to record arbitrary actions
     * in the snapshot viewer
     *
     * @param DataObject $origin
     * @return Log
     */
    public static function createLog(DataObject $origin, string $message = ''): Log
    {
        $log = Log::create();
        $log->Title = $message;
        $log->write();
        $snapshot = self::createSnapshot($log);
        $locale = Locale::getCurrentLocale();
        $snapshot->LocaleID = $locale->ID;
        $snapshot->write();
        $snapshot->Items()->add($log->createSnapshotItem());
        $snapshotItem = $origin->createSnapshotItem();
        $snapshot->Items()->add($snapshotItem);
        return $log;
    }

This creates a single snapshot with a message representing the action.

replacing multiple snapshots with a single one can also reduce the performance impact of writing multiple snapshots.

Putting this out there as there are probably other (better) ways to do this? But if it is useful I could make up a PR for the above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant