Download - Content Staging in Drupal 8

Transcript
Page 1: Content Staging in Drupal 8

ADVANCED SITE BUILDING

CONTENT STAGINGIN DRUPAL 8

DICK OLSSON TWITTER: @dickolsson

Page 2: Content Staging in Drupal 8

What is content staging?

What we want from the solution

How it's (being) built for Drupal 8

Reusable protocols

Headless Drupal

AGENDA

Page 3: Content Staging in Drupal 8

Dick Olsson

Digital Engineering Manager at Pfizer

dixon_ on drupal.org

@dickolsson on Twitter

Web technologist

Drupal contributor

WHO AM I?

Page 4: Content Staging in Drupal 8

WHAT ISCONTENT STAGING?

Page 5: Content Staging in Drupal 8

SIMPLE WORKFLOW

ProdStage

Page 6: Content Staging in Drupal 8

SECURE PUBLISHING

ProdStage

Corporate firewall

Page 7: Content Staging in Drupal 8

MERGE WORKFLOW

Stage

Edit 1

Edit 2

Edit 3

Prod

Page 8: Content Staging in Drupal 8

HUB/SPOKE WORKFLOW

Editorial BD

A

C

Page 9: Content Staging in Drupal 8

RING MODEL

BD

A

C

Page 10: Content Staging in Drupal 8

Content staging

Content sharing

Replication

Syndication

IT'S SORT OF...

Page 11: Content Staging in Drupal 8

WHAT WE WANT

Page 12: Content Staging in Drupal 8

We don't want to build just a “content staging” system.

We need a generic and loosely coupled “content replication” framework capable of arbitrarily moving content between system.

WHAT WE WANT

Page 13: Content Staging in Drupal 8

Learning from the Drupal 7 implementations of UUID, Deploy and WF Tools modules.

WHAT WE WANT

Page 14: Content Staging in Drupal 8

Revisions everywhere

Conflict detection

Easier dependency management

Ad-hoc / Continuous replication

Bi-directional replication

REST API

WHAT WE WANT

Page 15: Content Staging in Drupal 8

HOW IT'S BUILT

Page 16: Content Staging in Drupal 8

Contrib:

Multiversion

Relaxed Web Services

Deploy

Core:

Serialization

Restful Web Services

Entity API

HOW IT'S BUILT

Page 17: Content Staging in Drupal 8

Tracks update sequences in order to make dependency management a lot easier.

Provides revision support for all content entities.

Tracks revision trees in a way similar to Git to support conflict detection.

multiversion.module

Page 18: Content Staging in Drupal 8

Revisions are not tracked with a UUID. A hash calculated from the actual changes is better.

This way it's easier for each server to detect conflicts without deep inspection or asking the

network.<?php

md5($this->serialize(array( $deleted, $sequence_id, $old_rev, $normalized_entity), 'json'));

multiversion.module

Page 19: Content Staging in Drupal 8

{ id: [{value: 1}], uuid: [{value: aabbcc}] _revs_info: [ {rev: 2-gghhii}, {rev: 1-ddeeff} ], _local_seq: 1, _deleted: 0,}

multiversion.module

Page 20: Content Staging in Drupal 8

CRAP instead of CRUD.

Entities are never deleted. This is needed in order to replicate deletions while also being

able to handle conflicts. Much like Git.

A “compaction” job can be run on cron to purge old revisions if needed.

multiversion.module

Page 21: Content Staging in Drupal 8

<?phpnamespace Drupal\multiversion\Entity;

class SqlContentEntityStorage extends [...] {

use SqlContentEntityTrait; //...}

multiversion.module

Page 22: Content Staging in Drupal 8

<?phpnamespace Drupal\multiversion\Entity;

class SequenceIndex implements SequenceIndexInterface {

function _construct(KeyValueFactoryInterface $kv) {} // ...}

multiversion.module

Page 23: Content Staging in Drupal 8

<?phpnamespace Drupal\multiversion\Entity;

class ConflictManager implements ConflictManagerIf { // ...}

class CompactionManager implements CompactionManagerIf { // ...}

multiversion.module

Page 24: Content Staging in Drupal 8

Provides a Restful/Relaxed JSON API.

Endpoints for all content entities and file attachments.

Endpoints for comparing revisions, starting/stopping replications and other

administrative tasks.

Drush plugin for running replications.

relaxed.module

Page 25: Content Staging in Drupal 8

<?phpnamespace Drupal\relaxed\Plugin\rest\resource;

/** * @RestResource( * id = “relaxed:doc” * ) */class DocResource extends ResourceBase { //...}

relaxed.module

Page 26: Content Staging in Drupal 8

<?phpnamespace Drupal\relaxed\Plugin\rest\resource;

/** * @RestResource( * id = “relaxed:_bulk_docs” * ) */class BulkDocsResource extends ResourceBase { //...}

relaxed.module

Page 27: Content Staging in Drupal 8

<?phpnamespace Drupal\relaxed\Plugin\rest\resource;

/** * @RestResource( * id = “relaxed:_changes” * ) */class ChangesResource extends ResourceBase { //...}

relaxed.module

Page 28: Content Staging in Drupal 8

<?phpnamespace Drupal\relaxed\Plugin\rest\resource;

/** * @RestResource( * id = “relaxed:_revs_diff” * ) */class RevsDiffResource extends ResourceBase { //...}

relaxed.module

Page 29: Content Staging in Drupal 8

A simple UI to manage replications and conflicts

deploy.module

Page 30: Content Staging in Drupal 8

1. Identify source and target by UUID

2. Get the current checkpoint from target site

3. GET /_changes?since=N from source site

4. Pass result to /_revs_diff on target site

5. Collect all missing revisions from source site

6. POST /_bulk_docs on target

7. Save new checkpoint on target site

HOW REPLICATION WORKS

Page 31: Content Staging in Drupal 8

DEMO

Page 32: Content Staging in Drupal 8

DEMO

:-(

Page 33: Content Staging in Drupal 8

The revision and conflict detection model is taken from both Git and CouchDB.

The replication protocol along with the API spec is taken from CouchDB.

REUSABLE PROTOCOLS

Page 34: Content Staging in Drupal 8

Reusing API specifications lends the framework to unexpected use cases and

that otherwise would not be possible

(CouchDB, PouchDB, TouchDB etc).

REUSABLE PROTOCOLS

Page 35: Content Staging in Drupal 8

HEADLESS DRUPAL

AngularJS

PouchDB Replication

Page 36: Content Staging in Drupal 8

Not straight port of the Drupal 7 modules.

Loosely coupled system will cover more use cases and lend itself to unexpected

ones as well.

Implementing battle tested protocols.

CONCLUSIONS

Page 37: Content Staging in Drupal 8

Andrei Jechiu (jeqq on drupal.org for working to these modules.

SPECIAL THANKS

Page 38: Content Staging in Drupal 8

FRIDAY CODE SPRINT

Follow @drupalmentoringhttps://amsterdam2014.drupal.org/sprints

Help improve Drupal: Sprint with the community on Friday.

- We have tasks for every skill set. - Mentors are available for new contributors.- An optional Friday morning workshop will help you set up community tools.

Page 39: Content Staging in Drupal 8

WHAT DID YOU THINK?

EVAULATE THIS SESSION - AMSTERDAM2014.DRUPAL.ORG/SCHEDULE

THANK YOU!

DRUPAL: dixon_ TWITTER: @dickolsson