silverstripe/silverstripe-framework — pull request #3462 by tractorcow (2014-09-01 21:25:08+00:00)
Title: BUG Fix versioned failing to generate new versions

Versioned is not writing Version to _version tables for subclasses of Version dataobjects which have their own DB fields
- Fix disjoint of ID / RecordID (which should be the same)
- Fix calculation of new record version
- Fix use of empty vs !isset to check for existing version

This issue was noticed in some third party modules when using ->writeToStage without an initial ->write(), but turns out to be an issue with the inner framework.

Also oddly to note, if a dataobject subclass has the versioned extension added to itself as well as the parent class, the issue doesn't come about, which is why the test cases test both cases.

As requested I've broken this PR down into two commits; One which does the smallest fix necessary (with tests) to resolve the issue, and another which clean ups the code for readability and future maintenance.

CC @sminnee