Page MenuHomeDevCentral

Undo mechanism
ClosedPublic

Authored by dereckson on Jul 19 2016, 23:00.
Tags
None
Referenced Files
Unknown Object (File)
Thu, Jul 4, 14:11
Unknown Object (File)
Thu, Jul 4, 10:37
Unknown Object (File)
Wed, Jul 3, 15:42
Unknown Object (File)
Wed, Jul 3, 15:42
Unknown Object (File)
Wed, Jul 3, 15:42
Unknown Object (File)
Wed, Jul 3, 14:16
Unknown Object (File)
Wed, Jul 3, 14:06
Unknown Object (File)
Sun, Jun 30, 09:33
Subscribers
None

Details

Summary

We want to allow users to immediately cancel destructive operations.
An undo link or button is probably more convenient for most users
than an "are you sure?" confirmation.

For destructive operations, we first considered soft deletes. Yet,
http://rdingwall.com/2009/11/20/the-trouble-with-soft-delete/ make
a strong case against soft deletes.

We so provide a way to store undoable operations in a stack:

  • the UndoStore is a class to store an undoable object
  • the Undoable interface defines an object with undo capability
  • the WithUndo trait implements Undoable, with default UndoStore options. It works well for Eloquent models when you want to restore with ->save() after a ->delete().
  • the UndoStack is a LIFO collection of UndoStore instances

The workflow is so:

  1. Put the destructive operation's subject into an UndoStore instance
  2. Push the UndoStore instance to the stack
  3. Be sure we've a reference to this stack somewhere, e.g. in session

This stack is stored in the session, accessible through any Controller
through the UndoesOperations trait.

The SplDoublyLinkedList has been chosen as it's lightweight in memory,
well serializable, iterable as LIFO.

Compatibility with plain PHP / Symfony SessionInterface / Laravel has
been a special consideration to design this solution.

Test Plan
  • Unit tests
  • Implemented to undo external sources unlink in D445

Diff Detail

Repository
rGROVE Auth Grove
Lint
Lint Passed
Unit
Tests Passed
Branch
undo
Build Status
Buildable 744
Build 871: arc lint + arc unit

Event Timeline

dereckson retitled this revision from to Undo mechanism.
dereckson updated this object.
dereckson edited the test plan for this revision. (Show Details)
dereckson added a reviewer: dereckson.
dereckson added inline comments.
app/Undo/UndoDelete.php
6

This is now session agnostic, as that's for UndoStack

app/Undo/UndoStack.php
41

@param mixed $index

tests/Undo/UndoStackTest.php
102

extraneous character

dereckson marked 3 inline comments as done.
dereckson edited edge metadata.

UndoDelete → WithUndo / Addressed previous coments.

dereckson edited edge metadata.
This revision is now accepted and ready to land.Jul 20 2016, 01:16
dereckson edited edge metadata.
This revision was automatically updated to reflect the committed changes.