Problem/Motivation
Import doesn't overwrite files. Because it doesn't overwrite, it leads to files proliferating like rabbits. And when later running drush decm example_module, all the exported files are obviously disambiguated with a sequential number. i.e. public://2021-02/officer_1.jpg when originally it was just officer.jpg. And I have to git checkout content/file/*.
Steps to reproduce
See problem description.
Proposed resolution
When importing files, always force overwrite.
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #27 | default_content-3200212-27.patch | 2.29 KB | stephane aimar |
| #25 | default_content-3200212-25.patch | 2.2 KB | grimreaper |
Issue fork default_content-3200212
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #4
herved commentedHi, here's a first attempt which should fix the issue.
Should we add tests?
PS: Sorry I'm a bit lost with d.org patches vs merge requests.
Are all projects using gitlab's merge requests now?
Comment #5
heddnThis works. And there's test coverage. So LGTM.
Comment #6
kevinfunkThanks @herved. Tested and fixes the issues with files not being overridden.
Comment #7
lisa.rae commentedComment #8
andrea.cividini commentedI'm just attaching the patch here for those who may need it.
Comment #9
heddnComment #10
socialnicheguru commentedis this a duplicate of this issue as it is overwriting also, https://www.drupal.org/project/default_content/issues/2698425 ?
Comment #11
heddnThis is pretty tightly scoped to something different. It isn't about overwriting entities at all. You could even drop the DB and still experience this issue. Which is how I normally see it. I drop the db and reinstall the site and import default content. Without this patch, the files do not overwrite and I start seeing file_1.txt, file_2.txt, etc. This means that when I run the drush command to update the default content, the file entities always result in "changes" and all the files are named with some high numeric suffix.
#2698425: Do not re-import existing entities is at the entity level and is specific to re-running the installation of default on the same DB.
Comment #13
rajeshreeputra+1 RTBC
Comment #14
andypostThere's new patch after RTBC and MR
Can we make it configurable?
Comment #15
rajeshreeputrasure, will test this again and post the results
Comment #17
xurizaemonAFAICT the proposed changes here are identical to the changes proposed as of #5, at which point there was test coverage and the behaviour was more consistent. I think this is good to merge.
This appears to work as it says on the tin, which is good - it eliminates a "round trip" issue where executing
drush dcim examplewill generate a new filename for any files which already exist in the destination location, after which adrush dcem examplewill update the default content exports to append a_0suffix ... then_1, then ...👍
Comment #18
berdirTo early to require 10.3.
Comment #20
grimreaperHi,
MR rebased to have a patch appliable on the 2.0.0-alpha3.
Comment #24
grimreaperHum, strange, MR is rebased, I also tried another one with only one commit. But patch is not applicable
Idea, I think it is because of changes in .info.yml
Comment #25
grimreaperNow applicable.
Comment #26
byrond commentedI don't think this sufficiently tests that additional files were not created:The file is created during the test with file_put_contents(), so an entity for it won't exist in the database. To confirm this, I removed all but the test from the patch, and it didn't fail.Never mind. I tried on a clean site, and the patch does fail when the patch is not present and passes when it is. I misunderstood how the test was working.
Comment #27
stephane aimar commented2.0.0-beta1 patch compatibility
Comment #29
rosk0I believe it is fine to require 10.3 now, so back to RTBC based on #17.