Migration class variables should not be accessed directly. Functions should be use to access the variable. For instance use getDescription() and setDescription($description) for the protected class variable description. For a boolean variable the getter function becomes isVariableName(). In object-oriented programming this is called encapsulation.
Remaining tasks
- Update the class variables and make them protected.
- Create getters and setters for frequently used get and set functionality.
- Update drupal to use the getters and setters instead of accessing variables directly.
- There are no tests required because the added functions are only getters and setters.
Methods to be added to the Migration class
getProcess();
setProcess(array $process);
getSystemOfRecord();
setSystemOfRecord($system_of_record);
isTrackLastImported();
setTrackLastImported($track_last_imported);
For more info over what should be done see the issue summary of #2016679: Expand Entity Type interfaces to provide methods, protect the properties.
Beta phase evaluation
Issue category | Bug because properties should not be public, API methods should not be allowed to be sidestepped. |
---|---|
Prioritized changes | Prioritized since it is a bug and it reduces fragility. |
Disruption | Somewhat disruptive for core as well as contributed and custom modules:
|
But impact will be greater than the disruption, so it is allowed in the beta.
Comment | File | Size | Author |
---|---|---|---|
#71 | 2384529-71.patch | 13.74 KB | rpayanm |
#71 | 2384529-interdiff.txt | 1.91 KB | rpayanm |
Comments
Comment #1
daffie CreditAttribution: daffie commentedI would like to get this fixed. So I will do a good review for posted patches.
Comment #2
daffie CreditAttribution: daffie commentedThe class variables $id, $label, $row, $source, $process, $load, $destination, $idMap, $sourceIds, $destinationIds, $highWaterProperty, $systemOfRecord, $sourceRowStatus, $trackLastImported and $migration_dependencies need to become protected.
Comment #3
daffie CreditAttribution: daffie commentedThis is probable not for a novice.
Comment #4
rpayanmComment #6
rpayanmRound 1
Comment #8
daffie CreditAttribution: daffie commented@rpayanm: Just to make sure that you know there is a link that will show you which tests failed. It is the word "VIEW".
Comment #9
rpayanm@daffie I know, thank you!
Let me continue with this work :)
Comment #10
rpayanmLet me see...
Comment #16
rpayanmComment #18
hussainwebStarting with a reroll first.
Comment #20
hussainwebThere wasn't a more direct error because the check for the property was done via a isset call, which always returned FALSE after making it protected, and hence all the errors. This one change might fix most (or all) errors. Let's see.
Comment #21
daffie CreditAttribution: daffie commentedIt all looks good to me.
All class variables are set protected.
I cannot find any instances where migration class variables are accessed directly.
So for me it is RTBC.
Comment #22
chx CreditAttribution: chx commented*cough*
Comment #23
daffie CreditAttribution: daffie commented@chx: Can you come up with a better season for removing the RTBC status of this issue beside:
Comment #24
chx CreditAttribution: chx commentedI have thought we do not RTBC issues without asking the subsystem maintainer. What's the point of having a subsystem maintainer if we are making changes to the architecture he is supposed to maintain without asking him?
Comment #25
daffie CreditAttribution: daffie commented@chx: It is fine be me to let him take a look at this patch. It will be the first sub-issue of #2016679: Expand Entity Type interfaces to provide methods, protect the properties where that will be done.
Comment #26
benjy CreditAttribution: benjy commentedI'm not against making the properties protected although it does seem a bit late in the game to be making such API changes. This is also going to break the Drush runner, so it would be good if we could open a pull request for that as well.
$migration->get('property_name') is worse UX than a public property IMO. I think we should at least add the appropriate getter/setter methods to the MigrationInterface. But maybe not for all properties, since many will rarely be accessed.
I think we need methods for:
Can we change this while we're at it to default to an empty array?
Comment #27
daffie CreditAttribution: daffie commented@benjy Thank you for your response to this issue. Just to make sure what you would like:
We can change the default value for $destinationIds from FALSE to array(). When the issue goes to RTBC I will mention this change so that the committer knows this and can choose what to do with it.
Comment #28
hussainwebGetting started with feedback in #26 and #27. I'd love some feedback to proceed.
I have used the parent method get() or set() in the getters and setters. Do you think I should directly access the properties?
Lastly, I was also thinking of adding a parameter to the getMigrationDependencies() getter to get either required or optional or all migrations. Is this too much out of scope? I know there might be other concerns and have not implemented it in this patch but I'd like to know your thoughts on this.
Comment #29
benjy CreditAttribution: benjy commentedFor the $process variable a getter and a setter. - Yes
For the $systemOfRecord variable a getter - Both getter and setter.
For the $trackLastImported variable a getter - Getter and setter
For the $source variable you would like? - Leave for now
For the $destination variable you would like? - Leave for now
I think we should access the properties directly, I can't see any reason not to.
Out of scope here, open a new issue if you want to discuss that further. It seems like a reasonable proposal.
Comment #30
daffie CreditAttribution: daffie commentedUpdated the issue summary with the to be added new methods for the Migration class.
Methods to be added to the Migration class
Comment #31
hussainwebI have added the setters for trackLastImported and systemOfRecord. The getters/setters for source and destination were already implemented back in #28. I am updating the IS.
Comment #32
daffie CreditAttribution: daffie commented@hussainweb: Please use the patch from comment #20 and add the methods from comment #30. The way that the committer (alexpott) looks add this patch is that he does not want unnecessary methods to be added. Without the requested methods from benjy there are no new methods necessary for this patch. So please remove the other methods.
Comment #33
hussainweb@daffie: Quite a lot of work happened between #28 and #31 and I don't see why I should go back to #20. If we definitely shouldn't have those methods, then I can edit the patch in #28 (now #31).
Besides, we are using the get() and set() method at least for
source
property and @benjy commented earlier that that is worse UX than directly accessing the property. Are you sure that you want to revert to theget('source')
calls fromgetSource()
, especially since it is implemented now. I know we are not changing API in beta but we are already adding a lot of methods. Does adding a few more methods matter?Comment #34
hussainwebAnd I forgot to mention
migration_dependencies
. The same argument as source property applies there too. Should we just change it toget('migration_dependencies')
now?Comment #35
benjy CreditAttribution: benjy commented@hussainweb, the reason I mentioned not adding getSource() and getDestination() is because a) they're only likely to be used by core and drush and b) I thought it might cause confusion with getSourcePlugin() and getDestinationPlugin(). Do you feel strongly about adding them?
Comment #36
hussainweb@benjy: Not strongly, but we have a getSource() call in the patch. Are you okay with get('source')? If yes, then we can remove.
Plus, getSource definitely looks like a getter and I think because of the convention, it should not be confused with getSourcePlugin. I am not saying it won't happen, but it at least matches the convention. If we add another getter later and if it is not getSource due to this reason, it would be more confusing.
Instead, do you think we should rename one of the properties, if the naming convention could really be confusing?
Comment #37
benjy CreditAttribution: benjy commentedI was leaning towards not adding getSource and then adding it later if we had a reason to. As you say, getSource() is already used so lets just leave the get/set/Source/Destination methods you already have in your patch.
No, lets not rename anything.
Comment #38
daffie CreditAttribution: daffie commentedThe functions getSource(), setSource(), getDestination() and setDestination() are completely unused outside the tests. Read alexpott to get his opinion. The method getMigrationDependencies() is only used once in MigrationStorage.php. In my opinion it is better to use get('migration_dependencies'). So again, please remove those methods from the patch.
Comment #39
hussainwebI'd like to have some consensus before making the change. Also, I think getMigrationDependencies() is nice to have, even if it may not be used outside core and drush.
Comment #40
daffie CreditAttribution: daffie commentedNice to have methods will not be allowed by maintainer/committer alexpott.
Comment #41
hussainweb@daffie: I understand, but if
get('migration_dependencies')
is considered worse (as in #26), then you need the independent getter.Comment #42
hussainwebBTW, I have created a PR for drush as @benjy mentioned in #26. You can see the request at https://github.com/drush-ops/drush/pull/1076.
Comment #43
benjy CreditAttribution: benjy commentedLets remove get/set/Source/Destination as @daffie has said, alexpott requested not to have unused methods and i'm happy with get('source') for an internal usage. As I previously mentioned, I think these are less likely to be used and possibly confusing anyway.
I'd like to leave getMigrationDependencies(), I think that's worthwhile and we already use it.
Comment #44
hussainwebI'm removing get/set/Source/Destination as per #43 and earlier comments.
Comment #48
benjy CreditAttribution: benjy commentedChange to square brackets.
Lets use a strict check, eg ===
Also, i'm not sure i like this limitation, seems like something easy to mess if we added new constants.
Then I think this is ready
Comment #49
hussainwebFixing for point 1 (and in another place in the same file) and changed to strict check.
Regarding the second point, this would throw an exception if a constant is added and used (which is unlikely in this case). Assuming we add test coverage, this error will be immediately caught.
I don't feel too strongly for this check either as it is of limited use, but it does serve as some defense. The ideal way would be to encapsulate these constants in their own class/interface and type hint the parameter. That is the proper way of course, but probably an overkill here, and unlikely to get in in this beta stage. What do you think?
Comment #50
chx CreditAttribution: chx commentedWhy are we using self:: and not static:: ? That's odd.
Comment #51
hussainwebActually, I meant to use
static
and got confused and usedself
. Changing that.Comment #52
benjy CreditAttribution: benjy commentedI don't think we have tests for this stuff at all, it's mainly left over from the D7 codebase. I think we should just remove the check altogether for now.
Comment #53
benjy CreditAttribution: benjy commentedNW to remove the checks from setSystemRecord()
Comment #54
hussainwebRemoved changes as per #52 and #53.
Comment #55
benjy CreditAttribution: benjy commentedLooks good to me.
Comment #57
rpayanmrerolled
Comment #59
chx CreditAttribution: chx commentedFatal error: Cannot access protected property Drupal\migrate_drupal\Entity\Migration::$process in /var/lib/drupaltestbot/sites/default/files/checkout/core/modules/migrate_drupal/src/Plugin/migrate/load/LoadEntity.php on line 107
Comment #60
benjy CreditAttribution: benjy commentedConflicted with #2394567: File field need associated metadata during cck_field migration, should be a simple fix.
Comment #61
rpayanmlet me see
Comment #63
rpayanmOf course!
Comment #64
chx CreditAttribution: chx commentedbenjy put this to RTBC already so I put it back.
If you'd ask me, I would won't fix this. Boilerplate--
Comment #66
rpayanmrerolled
Comment #68
chx CreditAttribution: chx commentedYou might want to wait until #2348875: Improving our dump files gets in because that one conflicts as well and that one has priority.
Comment #69
hussainwebRerolling from #63. I don't have a lot of hope for this turning green but let's see.
Comment #70
daffie CreditAttribution: daffie commentedAlmost there @hussainweb.
These set-methods need to return the value $this.
Comment #71
rpayanmComment #72
benjy CreditAttribution: benjy commentedLooks good.
Comment #76
bojanz CreditAttribution: bojanz commentedComment #77
alexpott@hussainweb when you retest a patch due to random failure can you please document the reason.
Comment #78
hussainwebAh yes, I forgot to add a comment after hitting the retest link. It appeared to be a random failure in one of the tests. It was an out of memory error.
Comment #79
alexpottCommitted 1e98b16 and pushed to 8.0.x. Thanks!
Fixed the beta evaluation on commit. Thanks for adding it.
Comment #81
chx CreditAttribution: chx commentedWait a minute isn't migrate beta evaluation exempted?