ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Change to _prepare_data() method in EE 2.2

June 23, 2011 12:12pm

Subscribe [2]
  • #1 / Jun 23, 2011 12:12pm

    Electric Putty

    88 posts

    Hello,

    We have been working on an Add-on call Better Workflow which creates draft versions of entries so they can be edited independently from the live site.

    We interact with a whole bunch of hooks through the publishing process and have, until now, been using the revision_post data available to make a copy of the entry.

    Having installed EE2.2 we have discovered that once the _prepare_data() method has been called in the api_channel_entries all third party data is removed from the revision_post which means our copy is incomplete (The new code starts at line 1591).

    First off, can I ask why the change? Does keeping the revision_post data intact cause issues down the line?

    Secondly, and more importantly, if you have removed this now, perhaps the revision_post was never meant to include all the data from an entry. If this is the case we have clearly based some of our add-on on an unstable foundation.

    We now need to try and resolve this issue and want to be sure that whatever route we take is future proof. If we try and reinstate the third party data in the revision_post will this cause problems? Are you planning any future changes to the publish process in general or the way you handle the revision_post data in particular?

    Any help or advice on this would be very useful.

    Thanks and best wishes,
    Malcolm

  • #2 / Jun 23, 2011 10:34pm

    Robin Sowell

    13255 posts

    Looks like a very useful add on!  Sorry these changes have put a crimp in your plans- let’s see what we can figure it out.

    First part is easy- the change was to address two specific bugs:

    *Fixed a bug (#15863) where entry dates did not display correctly when using a saved revision.
    *Fixed a bug (#15347) where file fields did not display saved data when viewing a revision.
    *Altered the saved entry revision data to store custom field data after custom field ‘save’ processing.

    Basically?  If we saved it w/out prepping it?  There was a problem reconstructing the data based on the saved revision data.  If we saved the data after it was prepped, we were dealing with data in the same format we’d have it from an edit and not have to do anything special for revisions.

    That said- I’m less clear on what’s been lost from revision_post.  Just looking at the code, it will overwrite existing in such a way that reflects what would be stored on an edit.  But sounds like more is getting dropped.

  • #3 / Jun 24, 2011 6:25am

    Electric Putty

    88 posts

    Hi Robin,

    Many thanks for your reply. We had understood that a revision was a ‘snap shot’ of an entry at a given moment; as in a single block of data which contained everything needed to re-create it.

    This particular issue is concerned with third-party field types which stored their data in proprietary tables (Playa, Matrix, et al).

    In EE 2.2, before the _prepare_data() method is called, the revision_post data in the array contains everything submitted from the form. So, for example, if we had a Matrix field the data for this would look something like this:

    ["field_id_3"]=>
      array(3) {
        ["row_order"]=>
        array(2) {
          [0]=>
          string(8) "row_id_6"
          [1]=>
          string(9) "row_new_0"
        }
        ["row_id_6"]=>
        array(3) {
          ["col_id_1"]=>
          string(19) "One man went to moe"
          ["col_id_2"]=>
          string(19) "2011-06-15 09:39 AM"
          ["col_id_3"]=>
          array(1) {
            ["selections"]=>
            array(2) {
              [0]=>
              string(0) ""
              [1]=>
              string(1) "4"
            }
          }
        }
        ["row_new_0"]=>
        array(3) {
          ["col_id_1"]=>
          string(19) "Two men went to moe"
          ["col_id_2"]=>
          string(18) "2011-06-22 9:40 AM"
          ["col_id_3"]=>
          array(1) {
            ["selections"]=>
            array(2) {
              [0]=>
              string(0) ""
              [1]=>
              string(1) "2"
            }
          }
        }
      }

    Now, in EE2.2, within the _prepare_data() method all third-party data is removed from the revision_post array by the field’s save() methods, e.g. line 1589 of Api_challen_entries.php

    $data[$field_name] = $this->EE->api_channel_fields->apply('save', array($data[$field_name]));

    so coming back from this method all we are left with in our revision_post array is:

    ["field_id_3"]=>
      string(1) "1"

    So, if this data is stored in the revision table it will be represent an incomplete entry.

    My logic may be off here, but it looks as though if an entry was subsequently edited again deleting the third-party data, and you then wanted to roll back to a previous revision, that revision would not contain the *old* third-party data as this had not been stored anywhere. Is this not a potential issue with EE’s native revisions (with third party content) now?

    For our Add-on we have found a way of caching the revision_post data using the entry_submission_start hook and re-instating it later. This seems to work but is clearly at odds with the native EE revision behaviour as it stands in 2.2.

    I guess I have two questions:

    1. Have I misunderstood the way EE revisions work and is there another method of retrieving third party data from an earlier version other than from the data saved in the revisions table?

    2. If we base our draft version on the revision_post data as it exists when the entry_submission_start hook is executed, are we going to run into problems down the line?

    I hope this all makes sense. I’m more than happy to write this up more completely if it helps.

    Many thanks and best wishes,

    Malcolm

  • #4 / Jun 24, 2011 9:11am

    Electric Putty

    88 posts

    Hi again Robin,

    I thought I’d do some tests to check my hypothesis on revision and third party data; it does look as though there is an issue with third-party data in EE 2.2.

    By removing this from the revision_post array it doesn’t get saved in the revisions table, so when you try and roll back to a earlier revision which had third party data which has subsequently been deleted, that data is not there.

    We made a video to illustrate the steps we took to create this, I hope this helps clarify things:

    http://vimeo.com/25549467

    I guess this is a bug, although I’m not 100% sure if revisions officially support third-party data. Certainly third party support has been one of the biggest challenges we’ve had to over come.

    Please let me know if you need any more info on this.

    Thanks and best wishes,

    Malcolm

  • #5 / Jun 24, 2011 4:04pm

    Robin Sowell

    13255 posts

    Wow- appreciate the detailed response, Malcolm.  And quick question- are you in the Developer Preview Program?  If not, I’d suggest applying.  You’ve clearly got useful incites to offer.

    K- used to be, revisions just saved the post array.  At a more theoretical level?  Agreed- I think it is supposed to represent a snapshot.  And thinking on it- even our own Relationships could have a problem- because it’s just storing the id of the related entry.  So if that entry is deleted- you end up w/pretty much same problem you would w/the matrix table and no matching id number.  In the case of relationships, it’s even more complicated because all that data on the entry that it’s related to isn’t sent in the post at all.  So capturing the post won’t help a lick.

    Which is a very long way of saying… we need to fine tune and it’s not a small project.

    For the short term- is your workaround sufficient?  If it’s not, short term we could add a ‘raw’ field and if we replace with the post save data keep a ‘raw’ copy as well.  If that makes sense.  I don’t think long term that’s sufficient and we may need to add some methods to the file fields to get a better snapshot of the full data involved in the entry.

    I’ll add a story to our backlog noting we need to revisit and link to this thread, which does a pretty good job of laying out the problem.  The final solution?  Will likely take some time, I think.  Working out how it should work and all the permutations is the hard part.  So to answer another of your questions- yes, I think we are going to have to change things around a bit but it won’t be soon and it will be done w/developers in mind.

    Does that sound like a plan?  And how critical is it to get the full raw data available asap?  Like I say- don’t think it would be hard to include in a brutish way short term.  On flip side, if you can work around it, we won’t rush on what would likely be a temp fix.

    (And yell if you sign up for Dev Preview- might be worth revisiting the issue there as well.)

  • #6 / Jun 27, 2011 8:27am

    Electric Putty

    88 posts

    Hi Robin,

    Thanks for your email. Yes, we are part of the Developer Preview Program and have been posting issues / comments on that forum.

    Your right about native EE relationships, these will be effected in exactly the same way.

    Our workaround is going to be fine for now, so, as far as we’re concerned at least, you don’t need to make an immediate changes to the data handling in the publish process.

    Moving forward I would be very interested in learning more about the way you intend to handle this. Obviously it will directly effect what we’re doing.

    Thanks again and best wishes,

    Malcolm

  • #7 / Jun 27, 2011 11:53am

    Robin Sowell

    13255 posts

    We definitely need some theoretical work put in on the revisions- I’ve got a story in for the 2.3 sprint
    “As an EE third party dev, I would like access to the full ‘snapshot’ of saved data in the revision table so that I can reconstruct matrix db fields and such not in the standard channel_data table.”

    Can’t swear it will make it IN for 2.3, but I’d like us doing some groundwork on it by then at the very least.  And I made a note to bounce some ideas off of you- helps to have the perspective of someone elbows deep in using it 😉.  And glad you’re in the Dev preview- I think that will prove useful to all concerned going forward!

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases