Problem/Motivation
Is there any way to import the attachments as Media if the module from Drupal core is enabled?
The files interface in Drupal is very bad and worpress interface for the images are Media as well, it would make sense to import them as media as well in Drupal.
Steps to reproduce
Proposed resolution
Add a step for the attachment to pick if you want to import them as images or media and configure it.
Remaining tasks
Support other types of media based on the extension of the files.
User interface changes
Add an extra step with the selection about the attachments. I also made the path for the files configurable instead of being fixed to featured_image.
API changes
Data model changes
See also #3523483: import featured image as entity reference for entity reference field imports.
| Comment | File | Size | Author |
|---|---|---|---|
| #36 | 3173916-36.patch | 46.25 KB | norman.lol |
| #35 | Captura desde 2025-01-09 01-48-42.png | 57.6 KB | abarrio |
| #16 | 3173916-15-reroll.patch | 30.2 KB | hongpong |
| #11 | reroll_diff_10-11.txt | 12.11 KB | linhnm |
| #11 | 3173916-11.patch | 29.04 KB | linhnm |
Issue fork wordpress_migrate-3173916
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 #2
phjouOk first patch with support for media fields for the article image, and import the images as media.
The patch comes on top of lots of other issues, mixing the patches is a nightmare so the patch has to be applied after at least this patch:
#3173973: Pluggable extension, support contrib + custom WordPress, Yoast SEO
Comment #3
phjouI have a fork of the module since I need so many patches to this module if it helps seeing what has been modified:
https://github.com/pjoulot/wordpress_migrate
Comment #4
phjouOk I got a new patch which is pretty nice now and can start being reviewed
- Support for Audio and Document
- Allow to choose which media type you want
- The field for importing is automatically detected based on the media type you chose (MediaSource)
- You can choose the file extensions you want to match in order to import your media. The extension are automatically filled in the input in AJAX based on the extension that the field of the chosen media type supports.
The patch is still based on an advanced version of the module, you need to apply the patches listed in comment #2.
Screenshot of the interface:
Comment #5
phjouNew patch to fix a problem when the user decide to not use Media.
Comment #6
phjouComment #7
phjouJust improved the patch:
- Use the default location input
- Add support for the import of the alt of the image
Comment #8
phjouOups empty file, sorry.
Comment #9
phjouComment #10
irina matusevich commentedUpdated the patch according to the current version of the module
Comment #11
linhnm commentedRerolled patch from #10
Comment #12
hongpong commentedCan anyone else check this one out and give it RTBC? Thank you!
Comment #13
bserem commentedNone of the latest patches apply anymore. Trying to apply them by hand ends in deprecation warnings.
Comment #15
hongpong commentedI added a few type safety updates flagged in the IDE. Otherwise should be a clean re-roll against today's 8.x-3.x. i saw the WordPressMigrationGenerator "path alias generator" part, I think the reroll patch here is correct but should be double checked.
(the MR !21 is the same as this patchfile.)
I applied it using
patch -p1 < 3173916-11.patchfrom the base dir of the module as working directory. This helps deal with stuck hunk patch application. I did not test this but wanted to give people a clean spot to start again with this issue.Comment #16
hongpong commentedOops - my local 8.x-3.x was missing the latest "path alias generator" commit. re rolled again.
Comment #17
hongpong commentedsome more notices. Per !MR21 reroll . https://git.drupalcode.org/project/wordpress_migrate/-/merge_requests/21
Major - Access to an undefined property Drupal\wordpress_migrate\WordPressMigrationGenerator::$mediaAudioID.
in src/WordPressMigrationGenerator.php:167
Major - Access to an undefined property Drupal\wordpress_migrate\WordPressMigrationGenerator::$mediaDocumentID.
in src/WordPressMigrationGenerator.php:167
Major - Access to an undefined property Drupal\wordpress_migrate\WordPressMigrationGenerator::$mediaImageID.
in src/WordPressMigrationGenerator.php:167
And additional phpstan and phpcs notices.
Comment #18
hongpong commentedSome upstream changes in wordpress_migrate_ui/src/Form/ImageSelectForm.php - the merge conflict is only there, basically got similar modernization by other folks. I'm not actively going to tangle with this one more for now, but if someone else wants to hammer away on it, go ahead.
Comment #21
abarrioCreated a new MR with branch 3173916-import-as-media rebased to 8.x-3.x.
Comment #22
hongpong commentedThanks so much abarrio for rebasing. Any ideas what we can do to fix the "Access to an undefined property" stuff flagged above? That seems like the biggest flagged snag currently.
Comment #23
abarrioUploaded a fixing for the undefined property error and fixing some other coding standards on WordPressMigrationGenerator.
Comment #24
abarrioUploaded one fix for an undefined index url error when executing drush ms and changed xpath expressions on media migrations with a simpler one.
Comment #25
hongpong commentedexcellent stuff abarrio. do you think it is RTBC yet? I don't have a test xml with audio attachment to test.
Comment #26
abarrioNo, I think there is more work remaining to have it as RTBC.
I think we still need to work on:
I think with this points resolved we can proceed with this as RTBC.
Comment #27
abarrioComment #28
hongpong commentedregarding checking the xml file see #3248042: Add XML Lint to check the WordPress exports xml lint could be added to composer but i figured that would intensify requirements. as well as #3348775: WP import xml entities & security considerations for a note on other considerations.
regarding testing media types I suppose this would require a new test site altogether with the types of assets in question.
if you think we can subdivide out any portion of the patch as well (in other words if you think some standalone portion would actually be RTBC as it is), let me know. Thanks for all this!
Comment #29
abarrioMakes sense to me.
Maybe we can merge and complete this issue as a first approach and then continue working on some other issues to finish this big development part.
I think we need a meta issue with a complete list of tasks needed to finish it. If I have time this days I'll create it.
Comment #30
abarrioComment #31
hongpong commentedone small issue, unless i'm mistaken there are duplicated migration yml files in the root dir of the project on the Merge request?
Comment #32
abarriothat's completely true!!
The only yml files that needs to be there are the ones from migrations folder.
Comment #33
abarrioRemoved unnecessary yml files from MR.
As I said on #26 I think we should work on those points but maybe we can proceed with this as a first approach and them complete the development in a follow up issue.
Comment #34
hongpong commentedRegardless of the 'nice to have' like xml check, unit tests and certain code standard flags, I think we need to be assured that the migration is working correctly for most use cases.
Forgive my silly question but is "document" like PDF files and things of that nature? In other words if someone has added a plugin that allows the PDF uploads in the media library, this would cover importing those. I'm a little more familiar with the built in audio content type.
[In late Jan or early Feb i'm going to take at least a couple days to focus on this module again -- which would involve composing a new site in WP with these content types and trying to run the migrate in the patch. we could roll in before then with more clear test results but i am down to make that effort a little later.]
Comment #35
abarrioActually on each media is getting the default type and checking the extensions allowed there to get default value when configuring migration:
it is not different between types of attachment files, it is just getting them to drupal files and then converting it into media.
Comment #36
norman.lolNeed a static patch of the current state of MR 35. Thank you for your work so far 🤗
Comment #37
wotts commentedGreat! I did have to change the selector syntax from:
To:
Comment #38
hongpong commented@wotts can you say where you changed this? was it in wordpress_attachments.yml at :
Thank you.
Comment #40
hongpong commentedI muddled things and needed to put in a rebase on latest 8.x-3.x HEAD after Drupal 11 support added and refactored WordPressMigrationGenerator. going to refactor a bit to make these functions smaller. Pulled the previous MR into MR39: https://git.drupalcode.org/project/wordpress_migrate/-/merge_requests/39
Re upping what abarrio suggested if anyone wants to get in:
Comment #41
hongpong commentedK I tried to extract the media field loop however I think I missed the mark. I also extracted the MediaTypes array to the properties of the class.
Warning: Undefined array key "plugin" in Drupal\migrate\Plugin\Migration->findMigrationDependencies() (line 685 of core/modules/migrate/src/Plugin/Migration.php). (and line 688). Appears after specifying all the fields at urls like - : /admin/structure/migrate/manage/my_wp_firstmedia1/migrations - the imports are "no data found".
On Drupal 11.1.5. Tried to extract as.
and new function
Added the unset, trying to make a more clean function.
Comment #42
hongpong commentedComment #43
abarrio@hongpong Which is the status of merge? It needs more work to do or just revision?
Comment #44
hongpong commented@abarrio I haven't had the time / ability to move this along further in recent months. Hoping people can test.