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

Reference: https://www.drupal.org/core/beta-changes
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:
  • BC break for anything using the public properties: code will need to convert to the methods
  • BC break for anything (mis)using properties that should not really be public: will require minor refactoring
  • BC break for alternate implementations of a given entity interface (rare/probably nonexistent): they will need to implement the new methods

But impact will be greater than the disruption, so it is allowed in the beta.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

daffie’s picture

I would like to get this fixed. So I will do a good review for posted patches.

daffie’s picture

Issue summary: View changes

The class variables $id, $label, $row, $source, $process, $load, $destination, $idMap, $sourceIds, $destinationIds, $highWaterProperty, $systemOfRecord, $sourceRowStatus, $trackLastImported and $migration_dependencies need to become protected.

daffie’s picture

Issue tags: -Novice

This is probable not for a novice.

rpayanm’s picture

Status: Active » Needs review
FileSize
3.51 KB

Status: Needs review » Needs work

The last submitted patch, 4: 2384529-4.patch, failed testing.

rpayanm’s picture

Status: Needs work » Needs review
FileSize
5.05 KB

Round 1

Status: Needs review » Needs work

The last submitted patch, 6: 2384529-6.patch, failed testing.

daffie’s picture

@rpayanm: Just to make sure that you know there is a link that will show you which tests failed. It is the word "VIEW".

rpayanm’s picture

@daffie I know, thank you!
Let me continue with this work :)

rpayanm’s picture

Status: Needs work » Needs review
FileSize
5.83 KB

Let me see...

Status: Needs review » Needs work

The last submitted patch, 10: 2384529-10.patch, failed testing.

Status: Needs work » Needs review

rpayanm queued 10: 2384529-10.patch for re-testing.

Status: Needs review » Needs work

The last submitted patch, 10: 2384529-10.patch, failed testing.

Status: Needs work » Needs review

rpayanm queued 10: 2384529-10.patch for re-testing.

Status: Needs review » Needs work

The last submitted patch, 10: 2384529-10.patch, failed testing.

rpayanm’s picture

Status: Needs work » Needs review
FileSize
5.96 KB

Status: Needs review » Needs work

The last submitted patch, 16: 2384529-16.patch, failed testing.

hussainweb’s picture

Status: Needs work » Needs review
FileSize
6.82 KB

Starting with a reroll first.

Status: Needs review » Needs work

The last submitted patch, 18: 2384529-18.patch, failed testing.

hussainweb’s picture

Status: Needs work » Needs review
FileSize
1.68 KB
8.49 KB

There 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.

daffie’s picture

Status: Needs review » Reviewed & tested by the community

It 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.

chx’s picture

Assigned: Unassigned » benjy
Status: Reviewed & tested by the community » Needs review

*cough*

daffie’s picture

Status: Needs review » Reviewed & tested by the community

@chx: Can you come up with a better season for removing the RTBC status of this issue beside:

*cough*
chx’s picture

Status: Reviewed & tested by the community » Needs review

I 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?

daffie’s picture

@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.

benjy’s picture

Assigned: benjy » Unassigned
Status: Needs review » Needs work

I'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:

  • $process - Because it's already used by the load plugin and will be a common one to change from contrib in hook_entity_alter() and such.
  • $systemOfRecord - We don't use this yet, but the D7 module did, and it had a getter.
  • $trackLastImported - Used by Sql, lets add a getter.
  • $source and $destination are both used by Drush. Not sure if that's enough of a reason to add the methods here though since they might get confused with getSourcePlugin().
+++ b/core/modules/migrate/src/Entity/Migration.php
@@ -144,14 +144,14 @@ class Migration extends ConfigEntityBase implements MigrationInterface, Requirem
+  protected $destinationIds = FALSE;

Can we change this while we're at it to default to an empty array?

daffie’s picture

@benjy Thank you for your response to this issue. Just to make sure what you would like:

  1. For the $process variable a getter and a setter.
  2. For the $systemOfRecord variable a getter.
  3. For the $trackLastImported variable a getter.
  4. For the $source variable you would like?
  5. For the $destination variable 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.

hussainweb’s picture

Status: Needs work » Needs review
FileSize
9.21 KB
12.29 KB

Getting 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.

benjy’s picture

For 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 have used the parent method get() or set() in the getters and setters. Do you think I should directly access the properties?

I think we should access the properties directly, I can't see any reason not to.

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?

Out of scope here, open a new issue if you want to discuss that further. It seems like a reasonable proposal.

daffie’s picture

Issue summary: View changes
Status: Needs review » Needs work

Updated the issue summary with the to be added new methods for the Migration class.

Methods to be added to the Migration class

getProcess();
setProcess(array $process);
getSystemOfRecord();
setSystemOfRecord($systemOfRecord);
isTrackLastImported();
setTrackLastImported($trackLastImported);
hussainweb’s picture

Issue summary: View changes
Status: Needs work » Needs review
FileSize
3.38 KB
13.28 KB

I 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.

daffie’s picture

Issue summary: View changes
Status: Needs review » Needs work

@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.

hussainweb’s picture

@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 the get('source') calls from getSource(), 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?

hussainweb’s picture

And I forgot to mention migration_dependencies. The same argument as source property applies there too. Should we just change it to get('migration_dependencies') now?

benjy’s picture

@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?

hussainweb’s picture

@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?

benjy’s picture

I 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.

Instead, do you think we should rename one of the properties, if the naming convention could really be confusing?

No, lets not rename anything.

daffie’s picture

The 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.

hussainweb’s picture

I'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.

daffie’s picture

Nice to have methods will not be allowed by maintainer/committer alexpott.

hussainweb’s picture

@daffie: I understand, but if get('migration_dependencies') is considered worse (as in #26), then you need the independent getter.

hussainweb’s picture

BTW, 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.

benjy’s picture

Lets 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.

hussainweb’s picture

Status: Needs work » Needs review
FileSize
3.83 KB
12.04 KB

I'm removing get/set/Source/Destination as per #43 and earlier comments.

Status: Needs review » Needs work

The last submitted patch, 44: 2384529-44.patch, failed testing.

Status: Needs work » Needs review

hussainweb queued 44: 2384529-44.patch for re-testing.

Status: Needs review » Needs work

The last submitted patch, 44: 2384529-44.patch, failed testing.

benjy’s picture

  1. +++ b/core/modules/migrate/src/Entity/Migration.php
    @@ -117,7 +117,7 @@ class Migration extends ConfigEntityBase implements MigrationInterface, Requirem
    +  protected $idMap = array();
    

    Change to square brackets.

  2. +++ b/core/modules/migrate/src/Entity/Migration.php
    @@ -382,4 +384,57 @@ public function isComplete() {
    +    if ($system_of_record != self::SOURCE && $system_of_record != self::DESTINATION) {
    

    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

hussainweb’s picture

Status: Needs work » Needs review
FileSize
1.21 KB
12.22 KB

Fixing 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?

chx’s picture

Why are we using self:: and not static:: ? That's odd.

hussainweb’s picture

FileSize
745 bytes
12.22 KB

Actually, I meant to use static and got confused and used self. Changing that.

benjy’s picture

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 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.

benjy’s picture

Status: Needs review » Needs work

NW to remove the checks from setSystemRecord()

hussainweb’s picture

Status: Needs work » Needs review
FileSize
718 bytes
11.95 KB

Removed changes as per #52 and #53.

benjy’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 54: 2384529-54.patch, failed testing.

rpayanm’s picture

Status: Needs work » Reviewed & tested by the community
FileSize
12.18 KB

rerolled

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 57: 2384529-57.patch, failed testing.

chx’s picture

Fatal 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

benjy’s picture

rpayanm’s picture

Status: Needs work » Needs review
FileSize
760 bytes
12.34 KB

let me see

Status: Needs review » Needs work

The last submitted patch, 61: 2384529-61.patch, failed testing.

rpayanm’s picture

Status: Needs work » Needs review
FileSize
1.09 KB
12.49 KB

Of course!

chx’s picture

Status: Needs review » Reviewed & tested by the community

benjy put this to RTBC already so I put it back.

If you'd ask me, I would won't fix this. Boilerplate--

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 63: 2384529-63.patch, failed testing.

rpayanm’s picture

Status: Needs work » Reviewed & tested by the community
FileSize
12.75 KB

rerolled

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 66: 2384529-66.patch, failed testing.

chx’s picture

You might want to wait until #2348875: Improving our dump files gets in because that one conflicts as well and that one has priority.

hussainweb’s picture

Status: Needs work » Needs review
FileSize
13.62 KB

Rerolling from #63. I don't have a lot of hope for this turning green but let's see.

daffie’s picture

Status: Needs review » Needs work

Almost there @hussainweb.

+++ b/core/modules/migrate/src/Entity/Migration.php
@@ -382,4 +384,52 @@ public function isComplete() {
+  public function setProcess(array $process) {
+    $this->process = $process;
+  }
...
+  public function setSystemOfRecord($system_of_record) {
+    $this->systemOfRecord = $system_of_record;
+  }
...
+  public function setTrackLastImported($track_last_imported) {
+    return $this->trackLastImported = (bool) $track_last_imported;
+  }

+++ b/core/modules/migrate/src/Entity/MigrationInterface.php
@@ -179,4 +179,60 @@ public function setMigrationResult($result);
+  public function setProcess(array $process);
...
+  public function setSystemOfRecord($system_of_record);
...
+  public function setTrackLastImported($track_last_imported);

These set-methods need to return the value $this.

rpayanm’s picture

Status: Needs work » Needs review
FileSize
1.91 KB
13.74 KB
benjy’s picture

Status: Needs review » Reviewed & tested by the community

Looks good.

alexpott queued 71: 2384529-71.patch for re-testing.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 71: 2384529-71.patch, failed testing.

Status: Needs work » Needs review

hussainweb queued 71: 2384529-71.patch for re-testing.

bojanz’s picture

Status: Needs review » Reviewed & tested by the community
alexpott’s picture

@hussainweb when you retest a patch due to random failure can you please document the reason.

hussainweb’s picture

Ah 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.

alexpott’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Fixed

Committed 1e98b16 and pushed to 8.0.x. Thanks!

Fixed the beta evaluation on commit. Thanks for adding it.

  • alexpott committed 1e98b16 on 8.0.x
    Issue #2384529 by hussainweb, rpayanm: Make the class variables...
chx’s picture

Wait a minute isn't migrate beta evaluation exempted?

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.