{"id":18556870,"url":"https://github.com/erpushpinderrana/example_migrate_files","last_synced_at":"2025-05-15T13:33:39.853Z","repository":{"id":223077586,"uuid":"512611317","full_name":"erpushpinderrana/example_migrate_files","owner":"erpushpinderrana","description":"Basic Example of Migrating Drupal 7 Files into Drupal 9 Media entities","archived":false,"fork":false,"pushed_at":"2022-08-27T20:17:26.000Z","size":24,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-17T11:34:27.517Z","etag":null,"topics":["d7tod9-migration","drupal","drupal-7","drupal-9","drupal-files-migration","drupal-media-migration","drupal-migrate","drupal-migration","migration","migration-tool","pushpinderdrupal"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/erpushpinderrana.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2022-07-11T04:07:00.000Z","updated_at":"2022-07-18T00:15:16.000Z","dependencies_parsed_at":"2024-02-18T05:29:43.462Z","dependency_job_id":"b17ae275-f69d-499a-9c3c-5c1430b0720d","html_url":"https://github.com/erpushpinderrana/example_migrate_files","commit_stats":null,"previous_names":["erpushpinderrana/example_migrate_files"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erpushpinderrana%2Fexample_migrate_files","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erpushpinderrana%2Fexample_migrate_files/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erpushpinderrana%2Fexample_migrate_files/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erpushpinderrana%2Fexample_migrate_files/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/erpushpinderrana","download_url":"https://codeload.github.com/erpushpinderrana/example_migrate_files/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254349343,"owners_count":22056333,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["d7tod9-migration","drupal","drupal-7","drupal-9","drupal-files-migration","drupal-media-migration","drupal-migrate","drupal-migration","migration","migration-tool","pushpinderdrupal"],"created_at":"2024-11-06T21:33:40.076Z","updated_at":"2025-05-15T13:33:39.826Z","avatar_url":"https://github.com/erpushpinderrana.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Drupal Example Migrate Files Module - Drupal 7 Files to Drupal 9 Media Entities\nThis is just a basic Example of Migrating Drupal 7 Files into Drupal 9 Media entities. Though there are some really good contributed modules such as [Media Migration](https://www.drupal.org/project/media_migration), [Migrate File To Media](https://www.drupal.org/project/migrate_file_to_media) and [Migrate File](https://www.drupal.org/project/migrate_file) which does most of the stuff automatically/out of the box once we configure them correctly. I think for begineers sometimes it's hard to understand what's the underlyine process, hence I've created this example module to get an understanding of files migration from D7 to D9. \n\n## Basic Idea\nFiles migration is two step process. First, migrate files from D7 to D9. Second, migrate D7 files to D9 Media entities.\n\n## Example\nLet's migrate one article from D7 to D9 which include one file as well. Now first migrate associated file and subsequently the article. Assume in D7 the example article node nid is 1234 and the associated file (fid) to this node is 12.\n\nInstead of migrating all the D7 files in single shot, we can also migrate only one file at a time. It would help to determine the workflow of migration process.\n\n```\ndrush migrate:import example_files --idlist=12\n```\n```\n[notice] Processed 1 item (1 created, 0 updated, 0 failed, 0 ignored) - done with 'example_files'\n```\nOnce you run the above file migration then in your D9 site, you can check the files. For example, for my local env the path is http://drupal9.docksal/admin/content/files. That file would be there plus the actual physical D7 file/asset would be in your D9 destination directory as well.\n\nThe second step is to create the Media entity using Media Migration.\n```\ndrush migrate:import example_media_image --idlist=12\n```\n```\n[notice] Processed 1 item (1 created, 0 updated, 0 failed, 0 ignored) - done with 'example_media_image'\n```\n\nOnce you run the above migration then it will create the media entity too. The same can be checked at Media path - http://drupal9.docksal/admin/content/media\n\nLastly, migrate the example article entity.\n```\ndrush migrate-import example_article --idlist=1234 --migrate-debug\n```\n```\n[notice] Processed 1 item (1 created, 0 updated, 0 failed, 0 ignored) - done with 'example_article'\n```\n\n## Rollback commands \n```\ndrush migrate-rollback example_files --idlist=12\n```\n```\n[notice] Rolled back 1 item - done with 'example_files'\n```\n```\ndrush migrate-rollback example_media_image --idlist=12\n```\n```\n[notice] Rolled back 1 item - done with 'example_media_image'\n```\n```\ndrush migrate-rollback example_article --idlist=1234\n```\n```\n[notice] Rolled back 1 item - done with 'example_article'\n```\n\n## Handy Drush Commands.\nThe below examples are using fin because I'm using docksal locally.\n```\nfin drush pmu example_migrate_files -y \u0026\u0026 fin drush en example_migrate_files -y\n```\n```\nfin drush migrate-import example_files\n```\n```\nfin drush migrate-reset example_files\n```\n```\nfin drush migrate-rollback example_files\n```\n```\nfin drush migrate-import example_media_image\n```\n```\nfin drush migrate-reset example_media_image\n```\n```\nfin drush migrate-rollback example_media_image\n```\n```\nfin db cli --db=default 'select * from migrate_map_example_files'\n```\n```\nfin db cli --db=default 'select * from migrate_map_example_media_image'\n```\n```\nfin db cli --db=default 'show tables'\n```\n## How to Debug, if migration fails.\nEnable commented dump variable in the source file to see what file path and query is building from D7. It really helps me a lot while debugging but there are other ways too.\n - Ensure the D7 file path is valid.\n - Ensure the destination path has correct permissions.\n \n ## References\n * https://www.computerminds.co.uk/articles/migrating-drupal-7-files-drupal-8-9-media-entities\n * https://antistatique.net/en/blog/migrate-your-drupal-7-site-to-drupal-9\n * https://evolvingweb.ca/blog/drupal-8-migration-migrating-files-images-part-3\n * https://www.drupal.org/docs/drupal-apis/migrate-api/migrate-destination-plugins-examples/migrating-files-and-images\n * https://understanddrupal.com/lessons/migrating-files-and-images-drupal/\n * https://gist.github.com/jibran/8e7cd2319e873858dd49a272227a4fd2\n \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ferpushpinderrana%2Fexample_migrate_files","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ferpushpinderrana%2Fexample_migrate_files","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ferpushpinderrana%2Fexample_migrate_files/lists"}