Skip to content

Commit

Permalink
Merge pull request #43 from itmundi/craft-constants-env-variables
Browse files Browse the repository at this point in the history
Craft constants env variables
  • Loading branch information
bvangennep committed Apr 5, 2016
2 parents 0a8499d + f651998 commit e29dd90
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 19 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ Optional environment variables (similar to the [PHP constants](https://craftcms.
- CRAFT_STORAGE_PATH
- CRAFT_TEMPLATES_PATH
- CRAFT_TRANSLATIONS_PATH
- CRAFT_ENVIRONMENT


### Importing
Expand Down Expand Up @@ -170,6 +169,10 @@ This project has been licensed under the MIT License (MIT). Please see [License

## Changelog

###3.2.0###
- Added ability to set craft constants through env variables (thanks to @roelvanhintum)
- Fixed assetsource fieldlayout backwards compatibility

###3.1.6###
- Adds install and more detailed usage documentation

Expand Down
31 changes: 15 additions & 16 deletions bin/schematic
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,21 @@ use NerdsAndCompany\Schematic\Console\App;
*/

// Use environment variables from the cli.
if (getenv('CRAFT_BASE_PATH')) define('CRAFT_BASE_PATH', getenv('CRAFT_BASE_PATH'));
if (getenv('CRAFT_APP_PATH')) define('CRAFT_APP_PATH', getenv('CRAFT_APP_PATH'));
if (getenv('CRAFT_CONFIG_PATH')) define('CRAFT_CONFIG_PATH', getenv('CRAFT_CONFIG_PATH'));
if (getenv('CRAFT_PLUGINS_PATH')) define('CRAFT_PLUGINS_PATH', getenv('CRAFT_PLUGINS_PATH'));
if (getenv('CRAFT_STORAGE_PATH')) define('CRAFT_STORAGE_PATH', getenv('CRAFT_STORAGE_PATH'));
if (getenv('CRAFT_TEMPLATES_PATH')) define('CRAFT_TEMPLATES_PATH', getenv('CRAFT_TEMPLATES_PATH'));
if (getenv('CRAFT_TRANSLATIONS_PATH')) define('CRAFT_TRANSLATIONS_PATH', getenv('CRAFT_TRANSLATIONS_PATH'));
if (getenv('CRAFT_ENVIRONMENT')) define('CRAFT_ENVIRONMENT', getenv('CRAFT_ENVIRONMENT'));

defined('CRAFT_BASE_PATH') || define('CRAFT_BASE_PATH', __DIR__.'/../../../../craft/');
defined('CRAFT_APP_PATH') || define('CRAFT_APP_PATH', CRAFT_BASE_PATH.'app/');
defined('CRAFT_CONFIG_PATH') || define('CRAFT_CONFIG_PATH', CRAFT_BASE_PATH.'config/');
defined('CRAFT_PLUGINS_PATH') || define('CRAFT_PLUGINS_PATH', CRAFT_BASE_PATH.'plugins/');
defined('CRAFT_STORAGE_PATH') || define('CRAFT_STORAGE_PATH', CRAFT_BASE_PATH.'storage/');
defined('CRAFT_TEMPLATES_PATH') || define('CRAFT_TEMPLATES_PATH', CRAFT_BASE_PATH.'templates/');
defined('CRAFT_TRANSLATIONS_PATH') || define('CRAFT_TRANSLATIONS_PATH', CRAFT_BASE_PATH.'translations/');
$craftBasePath = getenv('CRAFT_BASE_PATH') ? getenv('CRAFT_BASE_PATH') : __DIR__.'/../../../../craft/';
$craftAppPath = getenv('CRAFT_APP_PATH') ? getenv('CRAFT_APP_PATH') : $craftBasePath.'app/';
$craftConfigPath = getenv('CRAFT_CONFIG_PATH') ? getenv('CRAFT_CONFIG_PATH') : $craftBasePath.'config/';
$craftPluginsPath = getenv('CRAFT_PLUGINS_PATH') ? getenv('CRAFT_PLUGINS_PATH') : $craftBasePath.'plugins/';
$craftStoragePath = getenv('CRAFT_STORAGE_PATH') ? getenv('CRAFT_STORAGE_PATH') : $craftBasePath.'storage/';
$craftTemplatesPath = getenv('CRAFT_TEMPLATES_PATH') ? getenv('CRAFT_TEMPLATES_PATH') : $craftBasePath.'templates/';
$craftTranslationsPath = getenv('CRAFT_TRANSLATIONS_PATH') ? getenv('CRAFT_TRANSLATIONS_PATH') : $craftBasePath.'translations/';

defined('CRAFT_BASE_PATH') || define('CRAFT_BASE_PATH', $craftBasePath);
defined('CRAFT_APP_PATH') || define('CRAFT_APP_PATH', $craftAppPath);
defined('CRAFT_CONFIG_PATH') || define('CRAFT_CONFIG_PATH', $craftConfigPath);
defined('CRAFT_PLUGINS_PATH') || define('CRAFT_PLUGINS_PATH', $craftPluginsPath);
defined('CRAFT_STORAGE_PATH') || define('CRAFT_STORAGE_PATH', $craftStoragePath);
defined('CRAFT_TEMPLATES_PATH') || define('CRAFT_TEMPLATES_PATH', $craftTemplatesPath);
defined('CRAFT_TRANSLATIONS_PATH') || define('CRAFT_TRANSLATIONS_PATH', $craftTranslationsPath);
defined('CRAFT_ENVIRONMENT') || define('CRAFT_ENVIRONMENT', 'console');

/*
Expand Down
6 changes: 4 additions & 2 deletions src/Services/AssetSources.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,10 @@ private function populateAssetSource($assetHandle, array $assetSourceDefinition)
'settings' => $assetSourceDefinition['settings'],
]);

$fieldLayout = Craft::app()->schematic_fields->getFieldLayout($assetSourceDefinition['fieldLayout']);
$assetSource->setFieldLayout($fieldLayout);
if (array_key_exists('fieldLayout', $assetSourceDefinition)) {
$fieldLayout = Craft::app()->schematic_fields->getFieldLayout($assetSourceDefinition['fieldLayout']);
$assetSource->setFieldLayout($fieldLayout);
}

return $assetSource;
}
Expand Down

0 comments on commit e29dd90

Please sign in to comment.