Closed (fixed)
Project:
Migrate Plus
Version:
8.x-4.x-dev
Component:
Plugins
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
3 Apr 2018 at 22:27 UTC
Updated:
26 Apr 2019 at 14:24 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
marvil07 commentedHere a
dom_str_replacemigrate process plugin.Also, thanks to benjifisher for some suggestions about this.
Comment #3
marvil07 commentedComment #4
marvil07 commentedAdding a parent ticket.
Comment #5
benjifisherComment #6
benjifisherThe attached patch makes several changes compared to the one in #3:
dom_str_replaceplugin).$xpathto the base class.getNodeList()with$this->xpath->query(...)nullwithNULL.init()method to the base class to set the two properties.$value instanceof \DOMDocumentin thevalidate()method, rely on the type hint of theinit()method.str_replace(),str_ireplace(), orpreg_replace().Comment #7
benjifisherOops, I used .patch instead of .txt on the interdiff.
Comment #8
benjifisherThe attached patch fixes coding standards found by the testbot.
I am attaching interdiffs comparing it to the the two previous patches (from #3 and #6).
Comment #10
benjifisherI think this should fix the failing tests.
Again, I am attaching an interdiff comparing to the patch in #3 as well as one for the previous patch.
Comment #12
benjifisherTry again. Once again, I am attaching an interdiff for the patch in #3 as well as one for my previous attempt.
Comment #14
benjifisherYou cannot catch a TypeError, so let's go back to the
$value instanceof \DOMDocumenttest.Comment #15
benjifisherComment #16
heddnAdd an issue for the follow-up.
Pass in as much context for the exception as possible. So we can print the migration and destination field, etc.
Add an issue for the follow-up.
InvalidPluginDefinitionException?
Would it make sense to use array_map and iterator_to_array?
Comment #17
benjifisher@heddn:
Thanks for the review, and for discussing this issue in person at MidCamp. I have implemented most of your recommendations.
@seecomment after the@todocomment.getPluginDefinition()? But maybe that is not really needed, since the Migrate system (or the drush commands from the Migrate Tools module) will make it clear which migration is active. I did pass$destination_propertyto theinit()method, and simply used$this->getPluginId()in the base class: once the object is instantiated, it "knows" the data of the derived class.array_map()would be useful here. I think of that as a way tp generate a new array (with the same keys as the input) by transforming the values. Here, for each$html_node, we modify$this->document, the DOMDocument object. Also, I think there could be performance problems if we usediterator_to_array(). We do not need to collect all the$html_nodeelements in a single array.For the record: as we discussed in person, the big change in error handling is that we do not catch the exceptions in (1) and (4). The reason is that these exceptions will be thrown when the migration that uses this plugin is mis-configured. In this case, it is better to stop the execution than to continue throwing errors for each row.
I also took the opportunity to expand the test coverage. We now test all of the validation checks in the constructor. I did this by removing one test method and adding a data provider, so we get more tests with only a few net lines added and less duplicated code.
Since the base class is not a plugin, I guess it should be moved to
src/fromsrc/Plugin/migrate/process/. If I do that, then would you also like me to rename the class? Perhaps DomProcessPluginBase instead of DomProcessBase?Comment #18
benjifisherThis should fix the coding standards problems.
Comment #19
marvil07 commented@benjifisher, thanks for improving the code here, and special kudos for the added tests.
@heddn, I'm glad you could review the changes.
I have been looking at the changes, and they look great.
I have only added a minor change to make the introduced parent base class abstract, which is not really needed since it does not declare a plugin, but it will leave it clear that it is meant to be extended, which also reinforces the name of the class, and follows the pattern in core for the base process plugin class.
Comment #20
heddnThis looks good. Thanks for all your contributions to migrate!
On commit I will switched from throwing an invalid argument exception to throwing a skip row exception in
init(). After thinking about this, we don't want to kill the entire migration if a single row or two isn't DOM parsable.Comment #22
heddnComment #23
heddn