Problem/Motivation
As of #1723892: Support for revisions for entity save and delete operations the default Entity
class supports revisions. Because EntityNG
overwrites the CRUD operations we need to add revision support manually.
Dependent Issues:
#1818556: Convert nodes to the new Entity Field API
Proposed resolution
Port the functionality introduced by #1723892: Support for revisions for entity save and delete operations into EntityNG
.
Remaining tasks
User interface changes
API changes
Comment | File | Size | Author |
---|---|---|---|
#19 | EntityNG-Support-for-revisions-1831444-19.patch | 21.96 KB | das-peter |
#17 | EntityNG-Support-for-revisions-1831444-17.patch | 21.97 KB | das-peter |
#17 | interdiff-1831444-15-17.txt | 2.72 KB | das-peter |
#15 | EntityNG-Support-for-revisions-1831444-15.patch | 21.85 KB | das-peter |
#15 | interdiff-1831444-7-15.txt | 7.32 KB | das-peter |
Comments
Comment #1
das-peter CreditAttribution: das-peter commentedThe attached patch adds revision support similar to the one in the default entity classes to the entityNG classes.
After a disscusion with berdir I've decided to add the method
DatabaseStorageControllerNG::mapToRevisionStorageRecord()
this because it's likely thatdrupal_write_record()
will be replaced and with it the magic of only storing fields that are defined in the schema. Thus the$record
object should only contain properties that will match the table schema.I defined
default_langcode
inEntityTestStorageController::baseFieldDefinitions()
, was this missing or intentionally left out?While creating the patch I following questions came up:
Entity::getRevisionId()
always returnsNULL
instead checking the entity info for the the appropriate entity key?Similar questions apply to
Entity::id()
andEntity::uuid()
.EntityTestStorageController::postSave()
instead being handled in the DatabaseStorageControllerNG's CRUD methods similar to the base / revision tables?I think all the necessary meta information would be available to solve this dynamically.
Comment #2
tstoecklert
That is because in D8 (in contrast to D7 Entity API) we do not always have the entity info available. We deliberately do not load the entity info unconditionally so it does not show up in every debugged entity. Also, if an entity overrides that method with
(e.g. in the case of User) that is more performant than checking the entity info first.
Comment #3
das-peter CreditAttribution: das-peter commented@tstoeckler Thank you very much for clarifying this. No the structure makes more sense :)
The attached patch adds a new test class to test the revisioning of
EntityTest
. Currently it's just a small test class that checks if a new revision is properly stored and ifentity_revision_load()
really loads the correct data.To make this working I had to adjust the method signature of
DatabaseStorageControllerNG::mapFromStorageRecords()
the method needs to know if it has to deal with revisions.I still think that the handling of the data table should be part of
DatabaseStorageController
or at least ofDatabaseStorageControllerNG
- similar to revisions. I think even performance-wise this would be good as one query inDatabaseStorageController::buildQuery()
could handle all at once - instead having separate queries and code that deals with the result of those extra queries.Comment #4
das-peter CreditAttribution: das-peter commentedI forgot to mention that #1498674: Refactor node properties to multilingual already introduces data table support in
DatabaseStorageController
. So once this is in, if it goes in that way, we've to updateDatabaseStorageControllerNG
too.Comment #5
das-peter CreditAttribution: das-peter commentedThis follow-up contains data table and revisions support: #1833334: EntityNG: integrate a dynamic property data table handling
Comment #6
andypostLooks awesome except a few hunks
Suppose doc-block should be changed too
Not sure that we always have id() as integer
We need a separate issue for that
$settings is not used latter. better $entity = entity_create('entity_test', array('name' => 'foo','user_id' => $this->web_user->uid))
Comment #7
das-peter CreditAttribution: das-peter commented@andypost Thank you very much for your review.
Added - there was no doc-block at all :P
The revision ID has to be of type serial (autoincrement). Thus I don't think it can be something else.
I've to check with berdir if there's already an issue for that. This todo was introduced by #1723892: Support for revisions for entity save and delete operations I've just copied the code.
Changed.
Comment #9
das-peter CreditAttribution: das-peter commented#7: EntityNG-Support-for-revisions-1831444-7.patch queued for re-testing.
Comment #11
das-peter CreditAttribution: das-peter commented#7: EntityNG-Support-for-revisions-1831444-7.patch queued for re-testing.
Comment #13
das-peter CreditAttribution: das-peter commented#7: EntityNG-Support-for-revisions-1831444-7.patch queued for re-testing.
Comment #14
BerdirSorry for not reviewing this earlier :) I think this is quite close, some clean-up stuff and then I'm happy to RTBC this.
Note to reviewers.
This @todo is just taken over from the existing DatabaseStorageController revision implementation which this patch is based on.
Can we maybe have a follow-up issue for this linked in the issue summary? Which would introduce SAVED_REVISION or something like that.
Should be @param \Drupal\Core\...
The comment is unfortunately outdated (the second part). I'm quite that I had fixed this at some point but messed up a re-roll :(
Can we remove that part here and in the default implementation?
You're doing this right now to make as few changes as possible.
This will become the implementation that will actually stay, so I'd suggest to update preSaveRevision() and the existing implementation to use an object here. Otherwise, we need a follow-up to fix it once we removed the old controller.
Same here, this is an existing @todo. And same request, can we have a follow-up for this?
Wondering if we should introduce an internal helper function for this.
I'm also still not convinced that the special case support for date fields introduced in the comments issue is what we should be doing.
The problem is that the comment patch introduces special support for date fields here. And nodes will require the same, so once we convert nodes to use field type date for created/changed, we'll also need to support date here, which results in duplicated code.
Doing it right now would however unecessarly conflict with the comments patch, so.. follow-up? :)
Missing documentation for the properties and the class.
We can save an unecessary line of code if you directly do a $this->web_user = $this->drupalCreateUser().
The second comment here doesn't really feel like proper english and we can probably just leave it away.
Comment #15
das-peter CreditAttribution: das-peter commented@berdir awesome, thank you so much for the review!
#1843294: Introduce a dedicated return value whenever an entity revision is saved.
Changed.
Done, hope I removed the correct part.
As you correctly mentioned I kept the array to have as less changes as possible. I've adjusted
preSaveRevision()
to deal with an object instead.#1843298: field_attach_delete_revision() is named the wrong way round, consider renaming it.
Yes, I think this should be a follow-up once the entityNG stuff is more stable again. Maybe we can do another cleanup once the comments patch is done.
Class doc block added. Properties removed.
Done.
Removed.
I didn't run local tests let's see what the testbot says.
Comment #16
BerdirSome small nitpicks, looks RTBC to me otherwise if the bot agrees.
Maybe add a comment here to explain why we are doing this? Maybe something like "preSaveRevision() excepts an object now to be compatible with the NG storage controller".
Completely changing to an object here would probably require quite a few changes more :(
The & is no longer necessary now.
Same for the implementations.
Comment #17
das-peter CreditAttribution: das-peter commented@Berdir: Thanks again! Great to see progress here :)
Done, hope the comment is okay that way.
Currently I don't see a point to completely change to an object. And I think that could be done after December if really needed anyway ;)
Oh, indeed. Changed.
Comment #18
BerdirCast to .. no e :) Also, I think the "now" is unecessary.
Comment #19
das-peter CreditAttribution: das-peter commentedDamn! :)
Updated patch. No interdiff.
Comment #20
BerdirYes, looks good to me. This makes sure that the NG storage controller provides the same features as the old one. This adds test coverage and revision support for entity_test, which means that we can remove test_entity in favor of this as soon as this is in. Yay!
RTBC.
Comment #21
BerdirHu, what happened with that tag?
Comment #22
webchickAll of this looks great to me, apart from:
Holy heavens, that is ugly. :(
Why can't we just keep this an array throughout?
Comment #23
BerdirWe discussed this in IRC and I think I convinced webchick that this is ok like that for now, so back to RTBC.
In short, http://api.drupal.org/api/drupal/core!lib!Drupal!Core!Entity!DatabaseSto... already uses stdClass, we decided to implement this in a way that is consistent with the existing save() implementation and make only minimal adjustments to the existing saveRevision implementation because it will be removed anyway.
Comment #24
webchickYep, thanks Berdir!
We're over thresholds atm, but since we were under this weekend when this was originally RTBCed, I am cashing a raincheck. ;)
Committed and pushed to 8.x. :) YAY!
Comment #25.0
(not verified) CreditAttribution: commentedAdded dependent issue.