Default Content Deploy

A content deployment solution for Drupal that enables teams to export and import content continuously via JSON files without database transfers.

default_content_deploy
1,741 sites
85
drupal.org

インストール

Drupal 11, 10 v2.1.4
composer require 'drupal/default_content_deploy:^2.1'

概要

Default Content Deploy (DCD) は、Drupalの包括的なコンテンツデプロイソリューションを提供し、開発チームがGit経由でサイトのすべてのコンテンツをエクスポートおよびデプロイできるようにします。これにより、環境間(ローカル、ステージング、本番)でデータベースを転送する必要がなくなります。

このモジュールは、HAL(Hypertext Application Language)フォーマットを使用してエンティティをJSONファイルにシリアライズし、設定可能なコンテンツディレクトリに保存します。コンテンツは個別に、エンティティタイプ別に、すべての参照とともに、またはサイト全体を一度にエクスポートできます。インポートはタイムスタンプをインテリジェントに比較し、変更されたコンテンツのみを更新します。

DCDは、コード変更と一緒にコンテンツを自動的にデプロイする必要があるCI/CDワークフローで特に価値があります。インクリメンタルインポート、強制上書き、Layout Builderのブロックやテキストフィールドに埋め込まれたメディアを含む複雑なエンティティ関係の処理をサポートしています。

Features

  • 個々のエンティティ、エンティティタイプ、またはサイト全体のコンテンツをJSONファイルにエクスポート
  • インテリジェントなタイムスタンプベースの比較により、新しいコンテンツの上書きを回避してインポート
  • メディア、ファイル、Taxonomyターム、ユーザーなど、すべての参照を再帰的にエクスポート
  • Layout Builderのインラインブロックと参照されたブロックコンテンツのサポート
  • 処理済みテキストフィールドに埋め込まれた依存関係(CKEditorコンテンツ内の画像、メディア、エンティティ)のエクスポート
  • 管理UIから圧縮されたtar.gzアーカイブとしてエクスポートしたコンテンツをダウンロード
  • tar.gzアーカイブファイルからコンテンツをアップロードしてインポート
  • エクスポートファイルで定義された状態にすべてのコンテンツを戻す強制上書きオプション
  • CI/CD自動化を可能にするすべての操作用Drushコマンド
  • 進捗追跡付きの大規模コンテンツセットのバッチ処理
  • タイムスタンプに基づいて変更されていないコンテンツをスキップするインクリメンタルインポートモード
  • イベントサブスクライバーによるエクスポート/インポート動作のカスタマイズ用イベントシステム
  • エクスポート/インポート操作から特定のエンティティタイプをスキップ
  • インポート時のコンテンツ削除(エクスポートされたエンティティを削除対象としてマーク)
  • 特定のデプロイシナリオ向けのエンティティID保持オプション
  • 追跡とインクリメンタルエクスポート用のSearch API統合サブモジュール
  • 孤立したバッチアイテムのCronベースのガベージコレクション

Use Cases

Development Team Content Synchronization

Multiple developers working on a project can export content to the Git repository. Each developer exports their changes with 'drush dcdes', commits the JSON files, and others import with 'drush dcdi' after pulling. This eliminates the need to share database dumps and ensures content changes are version controlled alongside code.

CI/CD Automated Content Deployment

In a continuous deployment pipeline, content can be automatically deployed alongside code. The deploy script includes: git pull, drush updb -y, drush cim -y, drush cr, drush dcdi -y. This ensures staging and production environments have consistent content without manual intervention.

Default Content for Site Installation

Package default content with a custom installation profile or module. Export initial content once, commit to the repository, and have it imported automatically on every fresh installation. Perfect for demo sites, starter kits, or distribution packages.

Content Staging Workflow

Content editors create content on a staging environment. Using the Export UI or Drush commands, content is exported to files. After review, these files are deployed to production via Git, where they're imported. This provides a controlled content promotion workflow.

Site Migration and Backup

Export the entire site's content with 'drush dcdes' before major updates or migrations. The JSON files serve as a portable backup that can be imported into any Drupal installation with matching configuration, regardless of database differences.

Incremental Content Sync with Search API

Using the Search API submodule, content changes are automatically tracked. Only modified entities are exported, making it efficient for sites with large amounts of content. The Search API backend handles the complexity of determining what needs to be exported.

Tips

  • Place the content directory outside the document root for security (e.g., ../content relative to web root)
  • Use --verbose flag with Drush commands to see detailed progress and entity-level information during import/export
  • For large sites, use the --changes-since option to export only recently modified content
  • Export users first when setting up a new environment to ensure UUID synchronization for admin and anonymous users
  • The _thumbs folder contains lightweight metadata files for faster incremental import scanning
  • Use 'drush dcd-entity-list' to see all available entity types before exporting
  • Commit exported content files to Git with meaningful commit messages for traceability
  • Test imports on a staging environment before deploying to production
  • The Search API submodule provides automatic export on entity save, ideal for continuous content export workflows

Technical Details

Admin Pages 3
Default Content Deploy settings /admin/config/development/dcd

Configure global settings for content export and import operations including the content directory path, entity types to skip, and serialization options.

Default Content Deploy - Import /admin/config/development/dcd/import

Import content from JSON files stored in the content directory or from an uploaded archive file. Equivalent to drush dcdi command.

Default Content Deploy - Export /admin/config/development/dcd/export

Export content to JSON files in the content directory or download as a compressed archive. Equivalent to drush dcde/dcder/dcdes commands.

権限 2
Import content

Allows user to import any exported content via UI. It will overwrite existing content. Restricted access permission.

Export content

Allows user to export any content via UI. Restricted access permission.

Hooks 2
hook_hal_type_uri_alter

Alters the HAL type URI during serialization. DCD uses this to create portable URIs in format [ENTITY_TYPE]/[BUNDLE].

hook_hal_relation_uri_alter

Alters the HAL relation URI during serialization. DCD uses this to create portable URIs in format relation/[ENTITY_TYPE]/[BUNDLE]/[FIELD].

Drush Commands 9
drush default-content-deploy:export <entity_type>

Exports a single entity or group of entities without references. Exports entities as JSON files to the content directory.

drush default-content-deploy:export-with-references <entity_type>

Exports entities along with all their referenced entities recursively. Includes media, files, taxonomy terms, users, and other referenced content.

drush default-content-deploy:export-site

Exports all content on the entire site. Useful for full site backups or initial content deployment setup.

drush default-content-deploy:import

Imports content from JSON files in the content directory. Creates new entities or updates existing ones based on UUID matching.

drush default-content-deploy:uuid-info <entity_type> <id>

Displays the UUID value of a specific entity. Useful for identifying entities for export.

drush default-content-deploy:entity-list

Displays all content entity types available on the site. Useful for determining valid entity_type arguments.

drush default-content-deploy:get-last-import-timestamp

Get the last import timestamp stored in state for a content folder. Used for incremental import tracking.

drush default-content-deploy:set-last-import-timestamp <timestamp>

Set the last import timestamp in state for a content folder. Useful for resetting incremental import state.

drush default-content-deploy:sync-thumbs

Synchronize the thumbs (metadata) folder from the content directory. Creates optimized metadata files for faster incremental imports.

Troubleshooting 7
Import fails with 'Translated field denormalization creates duplicate values' errors

Apply the patch from https://www.drupal.org/files/issues/2023-04-05/2904423-90.patch to address the HAL module issue with translated fields.

Entity timestamps are modified during import on Drupal 10

Apply the core patch from https://www.drupal.org/project/drupal/issues/2329253 to preserve entity timestamps. Drupal 11 includes this fix natively.

Exported content files are accessible from the web

Move the content directory outside the document root (recommended) or add .htaccess (Apache) or nginx location rules to deny access to JSON files in the content directory.

Referenced entities are not being exported

Use 'drush dcder' instead of 'drush dcde' to export with references. Check that the referenced entity types are not listed in 'skip_entity_types' configuration.

Import skips entities even though they were exported

The import compares timestamps and skips entities where the file is older than the database. Use --force-override flag to import regardless of timestamps.

Entity IDs change after import

By design, DCD uses UUIDs for entity identification. Entity IDs may change during import. If preserving IDs is critical, use the --preserve-ids flag (may cause conflicts with existing entities).

Conflict with better_normalizers module

The better_normalizers module is incompatible with DCD. Remove it before using Default Content Deploy.

Security Notes 5
  • Exported JSON files may contain sensitive data. Always place the content directory outside the document root or protect it with web server configuration.
  • The import permission allows overwriting any existing content. Grant this permission only to trusted administrators.
  • User password hashes are included in user entity exports. Ensure the content directory is not publicly accessible.
  • When importing from uploaded archives, validate the source to prevent importing malicious content.
  • The module operates with administrator privileges during import/export to access all entity data.