Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
I have tested that code:
process:
uri:
plugin: file_copy
reuse: true
source:
- source_file_path_remote
- destination_file_path
In the transform method of file_copy
process plugin the download
process plugin is called when a source file is remote. So the file is downloaded ignoring the reuse
option.
Proposed resolution
Add a new configuration key 'file_exists' that holds a value declaring what action to take when the destination file exists. The options are
replace - Replace the existing destination file
rename - Make the destination filename unique by adding '_N'
use existing - Take no action
Remaining tasks
Review
Add change record
Comment | File | Size | Author |
---|---|---|---|
#56 | 2877839-56.patch | 18.32 KB | jofitz |
#56 | interdiff-2877839-54-56.txt | 1.68 KB | jofitz |
#54 | 2877839-54.patch | 18.39 KB | jofitz |
#54 | interdiff-2877839-52-54.txt | 7.66 KB | jofitz |
#52 | 2877839-52.patch | 16.6 KB | jofitz |
Comments
Comment #2
edysmpI have a path for fix it.
Comment #3
edysmpComment #4
heddnAfter looking at that patch, it would be good to have a "test only" patch. To see the failures. Just grab the test part of the patch and add it to a new patch on that issue. Don't include the fix. We want to see the failure, to verify that we are in fact really testing things.
Comment #5
heddnAdding a tests only patch.
Comment #7
heddnClosed #2712743: File entity destination does not allow partial migrations as duplicate.
Comment #10
heddnIt looks like we have a test here. Can we get a fix patch also uploaded?
Comment #11
edysmpWorking on this.
Comment #12
edysmpThe full patch. So I am fixing test.
Comment #13
heddnLooking very good.
Nit: extra parenthesis are not needed.
Comment #14
Nebel54The patch works for me, thanks edysmp and heddn! I removed the parenthesis from the patch, as stated in #13.
Comment #15
phenaproximaI like this patch, but I think we should not use a trait for this, since it's really very specifically affecting only two process plugins. Let's convert the trait to an abstract class and have FileCopy and Download extend it.
Comment #16
jofitz CreditAttribution: jofitz at ComputerMinds commentedConverted trait to an abstract class as recommended by @phenaproxima in #15.
Comment #17
phenaproximaOnly one request here, but otherwise this is RTBC. Great work!
Let's add a __construct() here which adds default values for 'rename' and 'reuse' to the plugin configuration, just to keep things consistent across all classes which descend from this one.
I think we'll also need a change record, so I'm tagging for that.
Comment #18
jofitz CreditAttribution: jofitz at ComputerMinds commentedAdded
__construct()
. Removed a couple of redundantuse
statements.Comment #19
jofitz CreditAttribution: jofitz at ComputerMinds commentedReturning to Needs Work because it stills needs a change record.
Comment #20
phenaproximaI think we should probably remove this; it presumes implementation details of the child classes. It's sad, but in this case I think it's okay to let both FileCopy and Download bring in the file_system service themselves.
Comment #21
jofitz CreditAttribution: jofitz at ComputerMinds commentedAww, that's me trying to be too clever. Reverted.
Comment #22
jofitz CreditAttribution: jofitz at ComputerMinds commentedReturning to Needs Work because it stills needs a change record.
Comment #23
heddnBack to NR. Should hopefully be a quick turn around as we were just waiting on a CR.
Comment #24
heddnI can't do that. Back to NR.
Comment #25
quietone CreditAttribution: quietone at Acro Commerce commentedAssigning for review
Comment #26
heddnI used this recently on a migration to set the HTTP referer option in the file copy plugin config and passing that along to download. That was just a side effect. The original feature about reusing the files in the destination worked as well.
Comment #27
quietone CreditAttribution: quietone as a volunteer commentedNice change. The CR look fine as well.
Just a few thing before RTBC.
FileProcessBase signature uses 3 parameters not 4. Maybe just inject the filesystem in FileProcessBase instead.
Needs parameter description
Needs description
Needs comma at end
Comment #28
quietone CreditAttribution: quietone as a volunteer commentedShould be needs work
Comment #29
jofitz CreditAttribution: jofitz at ComputerMinds commentedEdit: styling
Comment #30
quietone CreditAttribution: quietone as a volunteer commentedThanks, I don't know how I missed phenaproxima's comment.
Off we go!
Comment #31
alexpottIt's not a download process plugin.
We need to document what the 'rename' and 'reuse' configuration mean. It's not clear.
One thing that is super confusing here is the you can't have both
That makes no sense. It'll always rename. It would be better to move something like:
(since reuse is not that clear either). This can be follow up. BUT the problem is we're adding new stuff to Download so it would be nice to make it better the first time.
Comment #32
jofitz CreditAttribution: jofitz at ComputerMinds commentedComment #33
alexpott@Jo Fitzgerald but the thing is here we're expanding the configuration options in Download plugin by adding the reuse option. That feels a shame because we're introducing complexity and configuration options that can contradict.
Comment #34
jofitz CreditAttribution: jofitz at ComputerMinds commented@alexpott I am happy to merge in the patch I have added to the follow-up, but how should the BC issues be addressed?
Comment #35
alexpottIf the 'reuse' or 'rename' options are set we trigger a deprecation notice. If the 'file_exists' option does not exist then we set it according to the 'reuse' or 'rename' options.
Comment #36
heddnNW for the last few comments.
Comment #37
jofitz CreditAttribution: jofitz at ComputerMinds commentedReplaced $configuration keys 'reuse' and 'replace' with 'file exists' as described in #31.3 and added the BC from #35.
Comment #39
jofitz CreditAttribution: jofitz at ComputerMinds commentedI don't understand the test that is now failing, FileCopyTest::testSuccessfulReuse(), so I'm finding it hard to debug. The assert on line 102 passes if
sleep(1)
is removed, but then the assert on line 108 fails.Leaving as Needs Work for someone else to investigate the test failures
Comment #40
alexpottThis should set the 'file_exists' value appropriately. Also how about
array_key_exists('reuse', $configuration)
rather thanin_array()
Comment #41
phenaproximaLet's have a change record here too, which we can refer to in the deprecation notice.
Comment #42
jofitz CreditAttribution: jofitz at ComputerMinds commentedMade the changes requested by @alexpott in #40, but I still can't work out why the test is failing. Leaving as Needs Work.
Also still needs change record.
Comment #43
jofitz CreditAttribution: jofitz at ComputerMinds commentedI made 2 silly mistakes when editing the test. Both of which are corrected in this patch.
Still needs change record.
Comment #44
quietone CreditAttribution: quietone as a volunteer commentedUpdated the IS a little bit and started a Change Record, Changes to Download and FileCopy process plugin . The CR is really rough and hopefully now that it is started someone else will improve it.
Edit: add link to CR
Comment #45
alexpottI don't think FileProcessBase needs
$file_system
These message need to end with a link to the CR.
This code should be unnecessary because the constructor guarantees
'file_exists'
is set.'file_exists'
configuration and triggers the expected deprecation notices.Comment #46
jofitz CreditAttribution: jofitz at ComputerMinds commented2. Removed file system.
3. Linked to CR.
4. Removed redundant code.
5. Added unit test for deprecation notices.
Comment #47
phenaproximaGetting close. Except for the change record, I'm not seeing much else that needs fixing here.
Superdupernit: 'unique' is indented too far.
Same here.
Usually we name data providers after the test method, so this should probably be providerSuccessfulReuse().
I think we use createMock() now...?
Nit: Let's just tag the entire class with @group legacy, rather than each individual method. There's also an empty line between the doc comment and the class declaration, and there should only be one space after 'class'.
Nit: Should be "...will trigger a deprecation notice."
We can put this stuff in a helper method to avoid repeating it twice.
I didn't know about assertArraySubset()! Nice find, and thanks!
s/throw an exception/trigger a deprecation notice.
Why is this being called?
Let's follow the existing precedent here and name the class TestFileCopy. Also, FileCopy already implements ContainerFactoryPluginInterface so I don't think we need to use it again here.
Comment #48
jofitz CreditAttribution: jofitz at ComputerMinds commentedAddressed all of @phenaproxima's points in #47.
Only the Change Record to finish now.
Comment #49
phenaproximaThis looks great. But a thing occurred to me...
So I just realized something...we don't really need getOverwriteMode(), do we? Couldn't we just set $configuration['file_exists'] to one of the FILE_EXISTS_* constants in __construct(), and use that during processing?
Also, I think we need to extend those array_key_exists() checks so that they only change $configuration['file_exists'] if the 'rename'/'replace' keys are not empty, not just if they are set (since they could be set to FALSE). We should probably cover those cases and extend the test coverage.
Comment #50
heddnTo needs work based on feedback in #49.
Comment #51
jofitz CreditAttribution: jofitz at ComputerMinds commentedWIP
Comment #52
jofitz CreditAttribution: jofitz at ComputerMinds commentedAddressed points in #49.
Comment #53
phenaproximaMan, I'm really sorry to do this.
I think we need to separate the array_key_exists() check from the empty() check. That's because we do want to trigger the deprecation notice if the array key exists at all, but we only want to change $configuration['file_exists'] if the old key is not empty.
This is incomplete; we need to process the $configuration['file_exists'] value, which can be one of 'replace', 'reuse', or 'use existing', into a FILE_EXISTS_* constant. The fact that we haven't caught this suggests that our test coverage is incomplete.
To illustrate my previous point, this should be 'file_exists' => 'rename'.
Comment #54
jofitz CreditAttribution: jofitz at ComputerMinds commentedAddressed points raised by @phenaproxima in #53.
Comment #56
jofitz CreditAttribution: jofitz at ComputerMinds commentedTest correction (similar to #53.3).
Coding standards corrections.
Comment #57
heddnAll feedback addressed. I reviewed the change records as well and made a small tweak. So that looks good. Let's move onward.
Comment #58
edysmp🤙🏼
Comment #60
alexpottAdding issue credit to all participants.
Comment #61
alexpottCommitted and pushed a6d53088df to 8.7.x and b0b64c6fa4 to 8.6.x. Thanks!
Comment #64
jofitz CreditAttribution: jofitz at ComputerMinds commentedHooray! Great to see this get over the line. Thanks to everyone who helped with the (many) reviews, especially @phenaproxima and @alexpott.