Page MenuHomeDevCentral

Undo mechanism
ClosedPublic

Authored by dereckson on Jul 19 2016, 23:00.
Tags
None
Referenced Files
Unknown Object (File)
Sun, Jun 30, 09:33
Unknown Object (File)
Sat, Jun 29, 19:57
Unknown Object (File)
Sat, Jun 29, 10:24
Unknown Object (File)
Mon, Jun 24, 09:16
Unknown Object (File)
Sun, Jun 23, 10:00
Unknown Object (File)
Sat, Jun 22, 12:08
Unknown Object (File)
Wed, Jun 19, 17:51
Unknown Object (File)
Mon, Jun 17, 00:22
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 Not Applicable
Unit
Tests Not Applicable

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.