Skip to content

Commit

Permalink
Merge pull request #114 from nerds-and-company/craft3
Browse files Browse the repository at this point in the history
Refactor for Craft3
  • Loading branch information
Bob Olde Hampsink authored Apr 16, 2018
2 parents ae47f3d + 9cb7956 commit 33ec048
Show file tree
Hide file tree
Showing 132 changed files with 8,023 additions and 8,057 deletions.
30 changes: 30 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# For more information about the properties used in
# this file, please see the EditorConfig documentation:
# http://editorconfig.org/

# top-most EditorConfig file
root = true

[*]
charset = utf-8
end_of_line = lf
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true

[*.php]
indent_size = 4

[*.md]
trim_trailing_whitespace = false

[package.json]
# The indent size used in the `package.json` file cannot be changed
# https://github.com/npm/npm/pull/3180#issuecomment-16336516
indent_size = 2
indent_style = space

[composer.json]
indent_size = 4
indent_style = space
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
build/
composer.lock
phpunit.xml
tests/data/test_schema_export.yml
vendor/
24 changes: 5 additions & 19 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,25 @@ language: php

# list any PHP version you want to test against
php:
# using major version aliases

# aliased to a recent 5.5.x version
- 5.5
# aliased to a recent 5.6.x version
- 5.6
# aliased to a recent 7.x version
- 7.0
- 7.1
- 7.2
# aliased to a recent hhvm version
- hhvm

# optionally set up exclutions and allowed failures in the matrix
matrix:
allow_failures:
- php: 7.0
- php: hhvm

# execute any number of scripts before the test run, custom env's are available as variables
install:
- curl -sS https://download.craftcdn.com/craft/2.6/2.6.2950/Craft-2.6.2950.zip > craft.zip
- unzip craft.zip
- rm craft.zip
- echo "<?php return ['user' => 'test'];" > craft/config/db.php
- composer install
- cd craft/app
- echo "{}" > composer.json
- composer require mockery/mockery
- cd ../..

# execute tests
script: phpunit --bootstrap tests/bootstrap.php --configuration phpunit.xml.dist --coverage-clover coverage.clover tests
script: php vendor/bin/codecept run --coverage

# upload coverage to scrutinizer
after_script:
- if [ "$TRAVIS_PHP_VERSION" != "7.0" ] && [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then wget https://scrutinizer-ci.com/ocular.phar; fi
- if [ "$TRAVIS_PHP_VERSION" != "7.0" ] && [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then php ocular.phar code-coverage:upload --format=php-clover coverage.clover; fi
- if [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then wget https://scrutinizer-ci.com/ocular.phar; fi
- if [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then php ocular.phar code-coverage:upload --format=php-clover coverage.clover; fi
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
### 4.0.0 ###
- Major refactor for craft3

### 3.8.8 ###
- Added ability to exclude datatypes on import (thanks @Zae)

Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2015-2017, Nerds & Company
Copyright (c) 2015-2018, Nerds & Company

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
Expand Down
163 changes: 31 additions & 132 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Schematic [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/nerds-and-company/schematic/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/nerds-and-company/schematic/?branch=master) [![Build Status](https://travis-ci.org/nerds-and-company/schematic.svg?branch=master)](https://travis-ci.org/nerds-and-company/schematic) [![Code Coverage](https://scrutinizer-ci.com/g/nerds-and-company/schematic/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/nerds-and-company/schematic/?branch=master) [![Latest Stable Version](https://poser.pugx.org/nerds-and-company/schematic/v/stable)](https://packagist.org/packages/nerds-and-company/schematic) [![Total Downloads](https://poser.pugx.org/nerds-and-company/schematic/downloads)](https://packagist.org/packages/nerds-and-company/schematic) [![Latest Unstable Version](https://poser.pugx.org/nerds-and-company/schematic/v/unstable)](https://packagist.org/packages/nerds-and-company/schematic) [![License](https://poser.pugx.org/nerds-and-company/schematic/license)](https://packagist.org/packages/nerds-and-company/schematic)
# Schematic (for Craft 3) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/nerds-and-company/schematic/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/nerds-and-company/schematic/?branch=master) [![Build Status](https://travis-ci.org/nerds-and-company/schematic.svg?branch=master)](https://travis-ci.org/nerds-and-company/schematic) [![Code Coverage](https://scrutinizer-ci.com/g/nerds-and-company/schematic/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/nerds-and-company/schematic/?branch=master) [![Latest Stable Version](https://poser.pugx.org/nerds-and-company/schematic/v/stable)](https://packagist.org/packages/nerds-and-company/schematic) [![Total Downloads](https://poser.pugx.org/nerds-and-company/schematic/downloads)](https://packagist.org/packages/nerds-and-company/schematic) [![Latest Unstable Version](https://poser.pugx.org/nerds-and-company/schematic/v/unstable)](https://packagist.org/packages/nerds-and-company/schematic) [![License](https://poser.pugx.org/nerds-and-company/schematic/license)](https://packagist.org/packages/nerds-and-company/schematic)

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.

Expand All @@ -10,7 +10,9 @@ This tool can be installed [using Composer](https://getcomposer.org/doc/00-intro
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. Composer will also create the executable `vendor/bin/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.

Schematic is now available as an installable plugin in Craft. You can install it in the cp or use `./craft install/plugin schematic`

## Usage

Expand All @@ -22,7 +24,7 @@ The most common usage pattern of this tool, to synchronize from a development to
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 prodcution environment
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:
Expand All @@ -37,78 +39,40 @@ Or, to synchronize from a production to a development environment:
An export can be created by running:

```
./vendor/bin/schematic export
./craft schematic/export
```

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

```
./vendor/bin/schematic export --exclude=assetSources
./craft schematic/export --exclude=volumes
```

Multiple exclusions can also be specified:

```
./vendor/bin/schematic export --exclude=assetSources --exclude=categoryGroups
./craft schematic/export --exclude=volumes,categoryGroups
```

Here is a list of all of the data types and their corresponding exclude parameter values:

| Data Type | Exlude Parameter |
| ------------- |-------------|
| Asset Sources | assetSources |
| Asset Transforms | assetTransforms |
| Category Groups | categoryGroups |
| Element Indexes | elementIndexSettings |
| Fields | fields |
| Global Sets | globalSets |
| Locales | locales |
| Plugins | plugins |
| Plugin Data | pluginData |
| Sections | sections |
| Tag Groups | tagGroups |
| Users | users |
| User Groups | userGroups |
The same goes for only exporting a subset of data types:

When craft is in a different directory than `./craft/app`, set the path with an environment variable.
For example:
```
export CRAFT_APP_PATH=./vendor/craft/app; ./bin/schematic export
./craft schematic/export --include=volumes,categoryGroups
```

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

If Craft is not installed yet, Schematic will run the installer for you. Make sure the following environment variables have been set:

- CRAFT_USERNAME
- CRAFT_EMAIL
- CRAFT_PASSWORD
- CRAFT_SITENAME
- CRAFT_SITEURL
- CRAFT_LOCALE

Optional environment variables (similar to the [PHP constants](https://craftcms.com/docs/php-constants)):
- CRAFT_BASE_PATH
- CRAFT_APP_PATH
- CRAFT_VENDOR_PATH
- CRAFT_FRAMEWORK_PATH
- CRAFT_CONFIG_PATH
- CRAFT_PLUGINS_PATH
- CRAFT_STORAGE_PATH
- CRAFT_TEMPLATES_PATH
- CRAFT_TRANSLATIONS_PATH
- CRAFT_ENVIRONMENT
See [Supported DataTypes](#Supported DataTypes)

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`

### Importing

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

```
./vendor/bin/schematic import
./craft schematic/import
```

By default schematic will look at `./craft/config/schema.yml`. To change the path where schematic will look for the schema file, use the `--file` flag.
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.

Optionally the `--force` flag can be used to make the import delete any items which are not mentioned in the import file.

Expand All @@ -117,34 +81,38 @@ Optionally the `--force` flag can be used to make the import delete any items wh
To skip importing a specific of data type, exclusions can be specified in the following form:

```
./vendor/bin/schematic import --exclude=assetSources
./craft schematic/import --exclude=volumes
```

Multiple exclusions can also be specified:

```
./vendor/bin/schematic import --exclude=assetSources --exclude=categoryGroups
./craft schematic/import --exclude=volumes,categoryGroups
```

Keys in the schema file can be overridden by passing an override file to schematic using the `--override_file` flag, for instance: `vendor/bin/schematic import --override_file=craft/config/override.yml`.

See [Supported DataTypes](#Supported DataTypes)

### Supported DataTypes

Here is a list of all of the data types and their corresponding exclude parameter values:

| Data Type | Exlude Parameter |
| Data Type | Exclude/Include Parameter |
| ------------- |-------------|
| Asset Sources | assetSources |
| plugins | plugins |
| Sites | sites |
| Asset Transforms | assetTransforms |
| Category Groups | categoryGroups |
| Element Indexes | elementIndexSettings |
| Fields | fields |
| Global Sets | globalSets |
| Locales | locales |
| Plugins | plugins |
| Plugin Data | pluginData |
| Sections | sections |
| Tag Groups | tagGroups |
| Users | users |
| UserSettings | userSettings |
| User Groups | userGroups |

Keys in the schema file can be overridden by passing an override file to schematic using the `--override_file` flag, for instance: `vendor/bin/schematic import --override_file=craft/config/override.yml`.
| Volumes | volumes |

### Overrides

Expand All @@ -163,82 +131,13 @@ Then the environment variable `SCHEMATIC_KEY_VALUE` needs to be set. The value o

### Hooks

This tool has three hooks that extending code can plug in to. An example of a project using some of these hooks is the [Schematic plugin for AmNav](https://github.com/nerds-and-company/schematic-amnav).
There are no hooks available at this time.

### Caveats

#### registerMigrationService

<table>
<tr><td>Called by</td><td><code>NerdsAndCompany\Schematic\Services\Schematic::importFromYaml()</code>, <code>NerdsAndCompany\Schematic\Services\Schematic::exportToYaml()</code></td></tr>
<tr><td>Return</td><td>An array where the keys are a name and the values are a Migration Service.</td></tr>
</table>

Gives plugins a chance to register their own Migration Services to Schematic in order to import or exports their own data.

```php
public function registerMigrationService()
{
return [
'amnav' => craft()->schematic_amNav
];
}
```

#### registerSchematicSources

<table>
<tr><td>Called by</td><td><code>NerdsAndCompany\Schematic\Services\Sources::getSource()</code></td></tr>
<tr><td>Return</td><td>An array where the keys are mapped to a value depending on the indexFrom param of the source, id or handle.</td></tr>
</table>

Gives plugins a chance to register their own Migration Services to Schematic in order to import or exports their own data.

```php
public function registerSchematicSource($indexFrom)
{
$mapping = [
'createSomething:handle1' => 'createSomething:1'
];
return $indexFrom == 'handle' ? $mapping : array_flip($mapping);
}
```

#### registerSchematicFieldModels

<table>
<tr><td>Called by</td><td><code>NerdsAndCompany\Schematic\Models\FieldFactory::build()</code></td></tr>
<tr><td>Return</td><td>An array where the keys are a the name of the fieldtype the mapping is for and the values are the <a href="http://php.net/manual/en/language.namespaces.rules.php">fully qualified name</a> of the custom field model class.
</td></tr>
</table>

Gives plugins a chance to add custom mappings to Schematic for custom field types.

```php
public function registerSchematicFieldModels()
{
return [
'fieldType' => Plugin_CustomSchematicFieldModel
];
}
```

A plugin that want to make use of this functionality needs to extend `NerdsAndCompany\Schematic\Models\Field`, for example

```php
<?php
namespace Craft;
class Plugin_CustomSchematicFieldModel extends \NerdsAndCompany\Schematic\Models\Field
{
//…
}
```

## See also
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!

For synchronizing Craft Commerce schema's, please see the [Schematic Commerce](https://github.com/nerds-and-company/schematic-commerce) package.
It is recommended to change content type handles with craft content migrations and to run these migration before running a schematic import.

## License

Expand Down
Loading

0 comments on commit 33ec048

Please sign in to comment.