Page MenuHomeDevCentral

Undo mechanism
ClosedPublic

Authored by dereckson on Jul 19 2016, 23:00.
Tags
None
Referenced Files
F3912748: D522.diff
Thu, Dec 19, 06:47
Unknown Object (File)
Tue, Dec 17, 05:30
Unknown Object (File)
Tue, Dec 17, 05:30
Unknown Object (File)
Tue, Dec 17, 05:30
Unknown Object (File)
Tue, Dec 17, 05:13
Unknown Object (File)
Tue, Dec 17, 05:03
Unknown Object (File)
Thu, Dec 12, 16:35
Unknown Object (File)
Thu, Dec 12, 14:27
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 745
Build 872: 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 ↗(On Diff #1274)

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

app/Undo/UndoStack.php
42

@param mixed $index

tests/Undo/UndoStackTest.php
103

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.