Git Product home page Git Product logo

default_content_deploy's Introduction

Default content deploy

A default content deploy solution for Drupal 8.

  • Introduction
  • Requirements
  • Install
  • Configuration
  • Drush commands
  • Workflow - how to export and deploy content
  • Protecting exported content data files
  • Maintainers
  • Sponsor

Introduction

This module (DCD) provides content deployment and allows development and building sites without the need to transfer database between the sites. The development team can export and deploy all content via Git and content can be deployed to the staging servers automatically during common deploy processes. Module provides useful drush commands for export/import content. Import function can also be ran from administration interface.

Requirements

Modules

Sites config synchronization (optional)

If you are sure the export and import sites have the same configuration and you need to synchronize only content, you can skip this chapter.

You need identical site UUID for successful syncing configuration between sites. If you need to sychronize configuration, use drush config-set for set Site UUID to identical value.

Example

drush config-set "system.site" uuid 11111111-1111-1111-1111-111111111111

The best practice is to install a drush site from already existing configuration, e.g.:

for Drupal 8.5-

drush si minimal --config-dir=../config/sync

for Drupal 8.6+

drush si minimal --existing-config

Install

  • with composer

      composer require drupal/default_content_deploy
    
  • with drush

      drush en default_content_deploy 
    

Configuration

Set DCD content directory in settings.php. We recommend to place directory outside of the document root. If no configuration is found, directory is created automatically at 'public://content_{hash_salt_derived_key};

Example

// Relative path.
$settings['default_content_deploy_content_directory'] = '../content';
// Absolute path.
$settings['default_content_deploy_content_directory'] = '/var/dcd/content';

Drush commands

Module provides many useful shortcuts for export content and one very important command for deploy content. You can export only one entity, bunch of entities, entities by type or export whole site at once.

If a wrong content entity type is entered, module displays a list of all content entity types available on the site as hint.

drush default-content-deploy:export, drush dcde

Exports a single entity or group of entities with no references.

Arguments

  • entity_type - Entity type (e.g. node, user, taxonomy/term, custom_entity_type...)

Options

  • entity_id - ID of entity for export.
  • bundle - Entity bundle, e.g. content type for nodes.
  • skip_entities - ID of entity to skip.

Examples

drush dcde node

Export all nodes.

drush dcde node --bundle=page

Export all nodes with bundle (content type) page.

drush dcde node --bundle=page,article --entity_id=2,3,4

Export all nodes with bundle page or article plus nodes with entity id 2, 3 and 4.

drush dcde node --bundle=page,article --skip_entities=5,7

Export all nodes with bundle page or article and skip nodes with entity id 5 and 7.

drush dcde node --skip_entities=5,7

Export all nodes and skip nodes with entity id 5 and 7.

drush default-content-deploy:export-with-references, drush dcder

Exports a single entity or group of entities with all references.

If a wrong content entity type is entered, module displays a list of all content entity types available on the site as hint.

The options are identical in drush dcde.

Arguments

  • entity_type - Entity type (e.g. node, user, taxonomy/term…)

Options

  • entity_id - ID of entity for export.
  • bundle - Entity bundle, e.g. content type for nodes.
  • skip_entities - ID of entity to skip.

Examples

drush dcder node

Export all nodes with references

drush dcder node --bundle=page

Export all nodes with references with bundle page

drush dcder node --bundle=page,article --entity_id=2,3,4

Export all nodes with references with bundle page or article plus nodes with entitiy id 2, 3 and 4.

drush dcder node --bundle=page,article --skip_entities=5,7

Export all nodes with references with bundle page or article and skip nodes with entity id 5 and 7.

drush dcder node --skip_entities=5,7

Export all nodes and skip nodes with references with entity id 5 and 7.

drush default-content-deploy:export-site, drush dcdes

Exports a whole site content + path aliases. You can exclude entities by their type. Use 'drush dcd-entity-list' for list of all content entities on this system.

Options

  • skip_entity_type - entity types to exclude from export.

Examples

drush dcdes

Export complete website.

drush dcdes --skip_entity_type=node,user

Export complete website but skip nodes and users.

drush default-content-deploy:export-aliases, drush dcdea

Exports URL aliases.

Example

drush dcdea
Export url aliases.

drush default-content-deploy:import-aliases, drush dcdia

Import URL aliases.

Example

drush dcdia
Import url aliases.

drush default-content-deploy:import, drush dcdi

Deploy (import/create/update/replace) content from all exported files.

JSON files with exported content is expected in the directory defined in $settings['default_content_deploy_content_directory']. It can be defined in the settings.php. See example in the Configuration section above.

Important rules for import content

  • Imported entity is determined by UUID (it can be either new or already existing).
  • ID of entity is preserved, so entity can not change its ID.
  • Non-existing entity (the new one) is created with exported ID.
  • Existing entity is updated only if imported entity is newer (by timestamp of the last entity change).
    • The user entity update causes lose of the user password because it is not present in the imported JSON file. You can preserve the existing user password using the --preserve-password option.
  • Imported entity with the same or older time than the current existing entity is skipped.
  • If a file entity does not have an existing file, the file will be created. The file will be recreated even if there is a existing file entity, but its file has been deleted.
  • If the new entity ID is already occupied by some existing entity, it is skipped.
  • This behavior can be changed by parameter --force-update or --force-override

drush dcdi --force-update

  • Existing entity (has same ID, but different UUID) is replaced by the imported entity (the old entity is deleted and a new entity with the same ID is created from imported JSON file). The UUID is replaced.
  • If the user entity is replaced, an existing password is lost.

drush dcdi --force-override

  • All existing content will be overridden. Locally updated default content will be reverted to the state defined in a content directory.

drush dcdi --verbose

  • Print detailed information about importing entities.

Examples

drush dcdi
drush dcdi --force-update
drush dcdi --verbose
drush dcdi --verbose --force-update
drush dcdi --verbose --force-override
drush dcdi --verbose --force-update --force-override
drush dcdi --verbose --force-update --force-override --preserve-password
drush dcdi --force-update --force-override -y

Run import process form UI

If you can not use Drush, go to page /admin/config/development/dcd-import. Check "Import content" permission.

drush default-content-deploy:uuid-info, drush dcd-uuid-info

Display current values of System Site, Admin and Anonymous UUIDs, Admin name.

Example

drush dcd-uuid-info

drush default-content-deploy:entity-list, drush dcd-entity-list

Displays all current content entity types.

Example

drush dcd-entity-list

Team workflow - how to synchronize configuration and content between sites

Even though the DCD module does not necessarily require that the sites have identical site UUID, it is logical that transferring entities from one site to another requires identical configuration of entities (e.g. identical fields in identically named bundles). That is why we include configuration synchronization to the teamworkflow.

There are many articles about export/import configuration, so this is only a sumarization of the most important things.

Initiate project and Synchronize site configurations

Developer 1 (first pusher)

provides the first copy of a project. He must:

  1. Create Drupal 8 project

  2. Set identical information for the whole development team (e.g. save them to default.settings.php)

  3. Set identical directory for config management ($config_directories['sync'])

  4. Set identical directory for content export/import ($config['content'])

  5. Set identical file or value for Drupal salt ($settings['hash_salt']), e.g.:

    $settings['hash_salt'] = file_get_contents('../config/salt/salt.txt');
    
  6. Install Drupal project (use the same installation profile, e.g. minimal)

  7. Set (or get) Site UUID and share the value with the team. Identical Site UUID is neccessary for sharing Drupal configuration files.

     drush config-get "system.site" uuid
     
     drush config-set "system.site" uuid "112233…8899"
    
  8. Install Default Content Deploy module and optionally the File entity module for exporting files like images.

  9. Export configuration drush cex

  10. Prepare team Git repository and push the project files into it.

  11. Share necessary information with other developers.

Developer 2 - n-th (pullers)

install clones of the project. They must:

  1. Clone project from the Git repository

  2. Set identical information (identical setting in settings.php)

  3. Common directory for config management ($config_directories['sync'])

  4. Common directory for content export/import ($settings['default_content_deploy_content_directory'])

  5. Common file or value for Drupal salt ($settings['hash_salt'])

  6. Install Drupal with the same installation profile

  7. Set Site UUID to identical value.

     drush config-set "system.site" uuid "112233…8899"
    
  8. Import configuration

     drush cim
    

Export and import content

For successful syncing content between sites, you need to have identical UUIDs for Admin user and Anonymous user (and for others users too if you have them). These values will be synced automatically during DCD import process if the user entities are exported, so we recommend to start exporting content with all references.

Developer pusher

  1. Creates some testing content

  2. Export content. There are many ways to export content via drush, from one entity to the entire site (the easiest way).

     drush dcdes
    
  3. Commit and push exported files to common Git repository

     git commit
     git push
    

Developer puller

  1. Pull changes from the git repository

     git pull
    
  2. Simply import content

     drush dcdi --force-update
    

This command warns a user about entities in conflict. You can use --verbose option (-v) for more detailed information. We recomend more aggressive way which ensures that all content entities will be synchronized with the source. This option also rewrites already created content and updates UUID for core user entity. See detailed explanation in the Important Import rules.

Common team workflow

Developer pusher

1. drush cex
2. drush dcdes
3. git commit
4. git push

Developer puller

1. git pull
2. drush updb
4. drush cim
5. drush dcdi --force-update

Jenkins and tools for continous development / integration

Imagine Jenkins like one of the developers in the puller role but with no interaction capability. His workflow can look like this:

1. git pull
2. drush updb -y
3. drush cim -y
4. drush cr
5. drush dcdi --force-update -y

Protecting exported content data files

We recommend placing the content directory outside of the document root, so the exported content is well protected. In this case it will not be accessible from the web server.

If this is not possible, it could result in a security problem. Should any attacker know the UUID of desired content and also where it is stored, then he could determine the URL to obtain the desired content without permission.

Example of attacker’s URL:

http://example.com/dcd_content_dir/node/uuid.json

Secure content directory within docroot

You can secure access to content directory via .htaccess or Nginx configuration.

Example for Nginx host config:

location ~ .*/default_content_deploy_content/.*.json$ {
  return 403;
}

Example of .htaccess for Apache host.

Deny from all

Place .htaccess into content directory.

Authors and maintainers

Sponsor

This project has been sponsored by:

HBF s.r.o., http://hbf.sk/, https://www.drupal.org/hbf

HBF provides flexible easy-to-use web solutions for your company. Its mission is to help you run your business in online world with attractive and perfectly working website.

default_content_deploy's People

Contributors

jakubhnilicka avatar landsman avatar martin-klima avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

default_content_deploy's Issues

Drush commands missing on Drupal 8.4

I'm missing drush commands when using default_content_deploy on Drupal 8.4.

List of commands on Drupal 8.3:

All commands in default_content_deploy: (default_content_deploy)
default-content-deploy-export (dcde) Exports a single entity or group of entities.
default-content-deploy-export-aliases (dcdea) Exports site url aliases.
default-content-deploy-export-site (dcdes) Exports a site.
default-content-deploy-export-with-references (dcder) Exports a single entity with references.
default-content-deploy-import (dcdi) Import all the content defined in a module.
default-content-deploy-import-aliases (dcdia) Import site url aliases.
default-content-deploy-uuid-info (dcd-uuid-info) Get current System Site, Admin and Anonymous UUIDs, Admin name.

List of commands on Drupal 8.4:

default-content:
default-content:export (dce) Exports a single entity.
default-content:export-references (dcer) Exports an entity and all its referenced entities.
default-content:export-module (dcem) Exports all the content defined in a module info file.

This looks like only the drush commands from default_content are recognized.

I'm on Drupal 8.4.2, default_content 1.0.0-alpha7, default_content_deploy 1.x-dev (0f2a0d0) and drush 9.0.0-beta9.

Robo\Robo not found

I've installed dcd using composer require 'drupal/default_content_deploy:1.x-dev', when I try using command drush dcdes I get this error:

Error: Class 'Robo\Robo' not found in Drupal\default_content_deploy\DefaultContentDeployBase->logger() (line 79 of /modules/contrib/default_content_deploy/src/DefaultContentDeployBase.php) #0

Issue enabling the module

Cannot autowire service "Drupal\ibm_content_deployer\Services\ContentImporter": argument "$importer" of method "
__construct()" references interface "Drupal\default_content\ImporterInterface" but no such service exists. You s
hould maybe alias this interface to one of these existing services: "default_content.importer", "default_content
_deploy.importer".

I am running into this issue while enabling the module using drush

Return type declaration is available only in php 7

Results in

Parse error: syntax error, unexpected ':', expecting ';' or '{' in /var/www/drupal8/modules/Default-Content-Deploy/src/DefaultContentDeploy.php on line 520

on older php versions. (5.6 in my case)

https://github.com/jakubhnilicka/Default-Content-Deploy/blob/2c02a8ac7071a67fd82a573a63f903daa4c459de/src/DefaultContentDeploy.php#L520

This seems to be only thing preventing this module from running on older php versions. I suggest making code compatible. Another option is to require php7 in composer.json ;-)

Awesome module!

Exporting of access-restricted nodes not possible

I have a Drupal 8.4.4 site with one node that is only visible to authenticated users (using the content_access module), but drush dcde node says it exported 0 entities.

Default_content, on the other hand, can export said entity via drush dce node 1 --file=../content/node/1.json.

Fails to export any of custom content types

When trying to export site I don't get any of my custom content types. This is a fresh installation with a few custom contents types defined. I have more than a dozen nodes in the table and none of them are exported.
screenshot from 2017-09-30 23-53-43
I have tried several variations. For this command
drush dcdes --add_entity_type=grade,program
I get these results

Exported 0 entities of type comment.                                                                                                                                                                                                                 [success]
Exported 0 entities of type file.                                                                                                                                                                                                                    [success]
Exported 0 entities of type node.                                                                                                                                                                                                                    [success]
Exported 6 entities of type menu_link_content.                                                                                                                                                                                                       [success]
Exported 10 entities of type taxonomy_term.                                                                                                                                                                                                          [success]
Exported 2 entities of type user.                                                                                                                                                                                                                    [success]
Exported 0 entities of type paragraph.                                                                                                                                                                                                               [success]

Suggestions?

Readme is too long

Readme is more like a book...perhaps it should be hosted at readthedocs.org, or some similar place. It would be much more enjoyable!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.