2017 © Pedro Peláez
 

craft-plugin schematic

Craft setup and sync tool

image

nerds-and-company/schematic

Craft setup and sync tool

  • Thursday, July 26, 2018
  • by nerds-and-company
  • Repository
  • 17 Watchers
  • 123 Stars
  • 11,510 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 17 Forks
  • 4 Open issues
  • 73 Versions
  • 39 % Grown

The README.md

Schematic (for Craft 3) Scrutinizer Code Quality Build Status Code Coverage Latest Stable Version Total Downloads Latest Unstable Version License

Schematic allows you to synchronize your Craft setup over multiple environments. It does this by exporting information about assets, database (fields, sections, users), locales and plugins to a YAML file that can be imported in other environments., (*1)

:exclamation: Craft 3.1 notice

Craft 3.1 brings project config that will deliver most if not all schematic functionality natively. We will continue to support schematic going forward, but it seems likely to become obsolete., (*2)

Currently Schematic will not run on Craft 3.1 or higher!, (*3)

Installation

This tool can be installed using Composer. Run the following command from the root of your project:, (*4)

composer require nerds-and-company/schematic

This will add nerds-and-company/schematic as a requirement to your project's composer.json file and install the source-code into the vendor/nerds-and-company/schematic directory., (*5)

Schematic is now available as an installable plugin in Craft. You can install it in the cp or use ./craft install/plugin schematic, (*6)

Usage

Basic usage

The most common usage pattern of this tool, to synchronize from a development to a production environment, would be:, (*7)

  1. Create a Craft project locally
  2. Set up all of the desired plugins, sections, templates, etc.
  3. Run a Schematic export locally
  4. Optionally, if a revision control system is used, commit the schema file to the local repository
  5. Deploy the Craft application to a production environment
  6. Run a Schematic import remotely

Or, to synchronize from a production to a development environment:, (*8)

  1. Run a Schematic export remotely
  2. Pull the schema file locally
  3. Optionally, if a revision control system is used, commit the schema file to the local repository
  4. Run a Schematic import locally

Exporting

An export can be created by running:, (*9)

./craft schematic/export

To skip exporting a specific of data type, exclusions can be specified in the following form:, (*10)

./craft schematic/export --exclude=volumes

Multiple exclusions can also be specified:, (*11)

./craft schematic/export --exclude=volumes,categoryGroups

The same goes for only exporting a subset of data types:, (*12)

./craft schematic/export --include=volumes,categoryGroups

See [Supported DataTypes](#Supported DataTypes), (*13)

An export will generate a schema file at config/schema.yml. The file path can be changed using the --file flag, for instance craft schematic/export --file=path/to/my-schema.yml, (*14)

Importing

To run an import with schematic, a schema file needs to be present. An import can be created by running:, (*15)

./craft schematic/import

By default schematic will look at config/schema.yml. To change the path where schematic will look for the schema file, use the --file flag., (*16)

Optionally the --force flag can be used to make the import delete any items which are not mentioned in the import file., (*17)

WARNING!! This will also delete any related content., (*18)

To skip importing a specific of data type, exclusions can be specified in the following form:, (*19)

./craft schematic/import --exclude=volumes

Multiple exclusions can also be specified:, (*20)

./craft schematic/import --exclude=volumes,categoryGroups

See [Supported DataTypes](#Supported DataTypes), (*21)

Supported DataTypes

Here is a list of all of the data types and their corresponding exclude parameter values:, (*22)

Data Type Exclude/Include Parameter
plugins plugins
Sites sites
Asset Transforms assetTransforms
Category Groups categoryGroups
Element Indexes elementIndexSettings
Email Settings emailSettings
Fields fields
General Settings generalSettings
Global Sets globalSets
Plugins plugins
Sections sections
Tag Groups tagGroups
User Settings userSettings
User Groups userGroups
Volumes volumes

Overrides and environment variables

Specific keys can be overriden by adding a key in config/override.yml and setting the corresponding environment variable. The key name in the override.yml needs to be the same as the key you want to override from schema.yml, including any parent key names., (*23)

The override file is also applied back when exporting, so your variables are not overriden by actual values. Schematic also supports passing an override file using the --override-file flag, for instance: ./craft schematic/import --override-file=path/to/your/config/override.yml., (*24)

Example

If the following override.yml is defined:, (*25)

parent:
    key_name: %KEY_VALUE%

Then the environment variable KEY_VALUE needs to be set. The value of this environment variable will override the key key_name. If the environment variable is not set Schematic will throw an error., (*26)

Environment variables can also directly be used in the schema.yml file. Beware that if you do that, they will be overriden on export by their environment variable's values., (*27)

Events

Custom converters can be injected with the EVENT_RESOLVE_CONVERTER event. This can be especially useful for importing and exporting custom field types. The converters need to implement the NerdsAndCompany\Schematic\Interfaces\ConverterInterface., (*28)

Event::on(Schematic::class, Schematic::EVENT_RESOLVE_CONVERTER, function (ConverterEvent $event) {
    if ($event->modelClass = "My\Custom\Field") {
      $event->converterClass = "My\Custom\FieldConverter";
    }
});

Custom source mappings can be injected with the EVENT_MAP_SOURCE event. This can be especially useful for importing and exporting custom sources., (*29)

Event::on(Schematic::class, Schematic::EVENT_MAP_SOURCE, function (SourceMappingEvent $event) {
    list($sourceType, $sourceFrom) = explode(':', $event->source);

    switch ($sourceType) {
        case 'plugin-source':
            $event->service = Craft::$app->customService;
            $event->method = 'getCustomModelBy';
            break;
    }
});

Caveats

Schematic uses handles to identify content. When a handle is changed in the schema file and import is run with force a new content type will be created with that handle, and the old content type will be deleted!, (*30)

It is recommended to change content type handles with craft content migrations and to run these migration before running a schematic import., (*31)

License

This project has been licensed under the MIT License (MIT). Please see License File for more information., (*32)

Changelog

CHANGELOG.md, (*33)

Credits

Inspired and based on the awesome ArtVandelay Plugin and built by these awesome individuals, (*34)

The Versions

24/07 2018

dev-fix_for_custom_element_namespaces_in_element_indexes

dev-fix_for_custom_element_namespaces_in_element_indexes

Craft setup and sync tool

  Sources   Download

MIT

The Requires

 

The Development Requires

13/07 2018

dev-craft2

dev-craft2

Craft setup and sync tool

  Sources   Download

MIT

The Requires

 

The Development Requires

13/07 2018

3.8.9

3.8.9.0

Craft setup and sync tool

  Sources   Download

MIT

The Requires

 

The Development Requires

01/06 2018

dev-export_override

dev-export_override

Craft setup and sync tool

  Sources   Download

MIT

The Requires

 

The Development Requires

01/06 2018

dev-single_sources

dev-single_sources

Craft setup and sync tool

  Sources   Download

MIT

The Requires

 

The Development Requires

01/06 2018

dev-reset_site_ids_cache

dev-reset_site_ids_cache

Craft setup and sync tool

  Sources   Download

MIT

The Requires

 

The Development Requires

29/04 2018

dev-custom-converters

dev-custom-converters

Craft setup and sync tool

  Sources   Download

MIT

The Requires

 

The Development Requires

16/04 2018

4.0.0

4.0.0.0

Craft setup and sync tool

  Sources   Download

MIT

The Requires

 

The Development Requires

01/04 2018

dev-craft3

dev-craft3

Craft setup and sync tool

  Sources   Download

MIT

The Requires

 

The Development Requires

22/02 2018

dev-reset_sections_service_cache

dev-reset_sections_service_cache

Craft setup and sync tool

  Sources   Download

MIT

The Requires

 

The Development Requires

08/01 2018

3.8.8

3.8.8.0

Craft setup and sync tool

  Sources   Download

MIT

The Requires

 

The Development Requires

13/10 2017

3.8.7

3.8.7.0

Craft setup and sync tool

  Sources   Download

MIT

The Requires

 

The Development Requires

05/09 2017

3.8.6

3.8.6.0

Craft setup and sync tool

  Sources   Download

MIT

The Requires

 

The Development Requires

29/08 2017

3.8.5

3.8.5.0

Craft setup and sync tool

  Sources   Download

MIT

The Requires

 

The Development Requires

28/06 2017

3.8.4

3.8.4.0

Craft setup and sync tool

  Sources   Download

MIT

The Requires

 

The Development Requires

28/04 2017

3.8.3

3.8.3.0

Craft setup and sync tool

  Sources   Download

MIT

The Requires

 

The Development Requires

21/04 2017

3.8.2

3.8.2.0

Craft setup and sync tool

  Sources   Download

MIT

The Requires

 

The Development Requires

19/04 2017

3.8.1

3.8.1.0

Craft setup and sync tool

  Sources   Download

MIT

The Requires

 

The Development Requires

19/04 2017

3.8.0

3.8.0.0

Craft setup and sync tool

  Sources   Download

MIT

The Requires

 

The Development Requires

14/04 2017

3.7.2

3.7.2.0

Craft setup and sync tool

  Sources   Download

MIT

The Requires

 

The Development Requires

13/04 2017

3.7.1

3.7.1.0

Craft setup and sync tool

  Sources   Download

MIT

The Requires

 

The Development Requires

12/04 2017

3.7.0

3.7.0.0

Craft setup and sync tool

  Sources   Download

MIT

The Requires

 

The Development Requires

08/03 2017

3.6.1

3.6.1.0

Craft setup and sync tool

  Sources   Download

MIT

The Requires

 

06/03 2017

3.6.0

3.6.0.0

Craft setup and sync tool

  Sources   Download

MIT

The Requires

 

09/02 2017

3.5.2

3.5.2.0

Craft setup and sync tool

  Sources   Download

MIT

The Requires

 

22/11 2016

3.5.1

3.5.1.0

Craft setup and sync tool

  Sources   Download

MIT

The Requires

 

02/11 2016

3.5.0

3.5.0.0

Craft setup and sync tool

  Sources   Download

MIT

The Requires

 

19/07 2016

3.4.3

3.4.3.0

Craft setup and sync tool

  Sources   Download

MIT

The Requires

 

19/07 2016

3.4.2

3.4.2.0

Craft setup and sync tool

  Sources   Download

MIT

The Requires

 

23/06 2016

3.4.1

3.4.1.0

Craft setup and sync tool

  Sources   Download

MIT

The Requires

 

16/06 2016

3.4.0

3.4.0.0

Craft setup and sync tool

  Sources   Download

MIT

The Requires

 

03/06 2016

3.3.2

3.3.2.0

Craft setup and sync tool

  Sources   Download

MIT

The Requires

 

23/05 2016

3.3.1

3.3.1.0

Craft setup and sync tool

  Sources   Download

MIT

The Requires

 

22/05 2016

3.3.0

3.3.0.0

Craft setup and sync tool

  Sources   Download

MIT

The Requires

 

13/05 2016

3.2.2

3.2.2.0

Craft setup and sync tool

  Sources   Download

MIT

The Requires

 

10/05 2016

3.2.1

3.2.1.0

Craft setup and sync tool

  Sources   Download

MIT

The Requires

 

05/04 2016

3.2.0

3.2.0.0

Craft setup and sync tool

  Sources   Download

MIT

The Requires

 

02/04 2016

3.1.6

3.1.6.0

Craft setup and sync tool

  Sources   Download

MIT

The Requires

 

31/03 2016

3.1.5

3.1.5.0

Craft setup and sync tool

  Sources   Download

MIT

The Requires

 

23/02 2016

3.1.4

3.1.4.0

Craft setup and sync tool

  Sources   Download

MIT

The Requires

 

22/02 2016

3.1.3

3.1.3.0

Craft setup and sync tool

  Sources   Download

MIT

The Requires

 

05/02 2016

3.1.2

3.1.2.0

Craft setup and sync tool

  Sources   Download

MIT

The Requires

 

29/01 2016

3.1.1

3.1.1.0

Craft setup and sync tool

  Sources   Download

MIT

The Requires

 

27/01 2016

3.1.0

3.1.0.0

Craft setup and sync tool

  Sources   Download

MIT

The Requires

 

07/01 2016

3.0.1

3.0.1.0

Craft setup and sync tool

  Sources   Download

MIT

The Requires

 

16/12 2015

3.0.0

3.0.0.0

Craft setup and sync tool

  Sources   Download

MIT

The Requires

 

07/12 2015
04/12 2015
29/10 2015
27/10 2015
26/10 2015
26/10 2015
22/10 2015
19/10 2015
19/10 2015
19/10 2015