Skip to content

Commit

Permalink
Merge pull request #24 from itmundi/install_craft
Browse files Browse the repository at this point in the history
Install Craft when its not installed yet
  • Loading branch information
Bob Olde Hampsink committed Dec 4, 2015
2 parents 26e7d65 + 5b12672 commit 898e1e4
Show file tree
Hide file tree
Showing 30 changed files with 901 additions and 184 deletions.
10 changes: 7 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,15 @@ before_script:
- mkdir craft/config
- echo "<?php return array('user' => 'test');" > craft/config/db.php
- mkdir craft/storage
- mkdir -p craft/plugins/schematic
- for item in *; do if [[ ! "$item" == "craft" ]]; then mv $item craft/plugins/schematic; fi; done
- composer install
- mkdir -p vendor/itmundi/schematic
- for item in *; do if [[ ! "$item" == "vendor" && ! "$item" == "craft" ]]; then mv $item vendor/itmundi/schematic; fi; done
- cd craft/app
- composer require mockery/mockery
- cd ../..

# execute tests
script: phpunit --bootstrap craft/app/tests/bootstrap.php --configuration craft/plugins/schematic/phpunit.xml.dist --coverage-clover coverage.clover craft/plugins/schematic/tests
script: phpunit --bootstrap craft/app/tests/bootstrap.php --configuration vendor/itmundi/schematic/phpunit.xml.dist --coverage-clover coverage.clover vendor/itmundi/schematic/tests

# upload coverage to scrutinizer
after_script:
Expand Down
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Make sure you have your latest export stored at `./craft/config/schema.yml`.
Then just run to import...

```
./craft/app/etc/console/yiic schematic import
./vendor/bin/schematic import
```

Optionally you can use --force to make the import delete any items which are not in the import file.
Expand All @@ -18,9 +18,18 @@ WARNING!! This will also delete any related content.
You can also generate a schema.yml with

```
./craft/app/etc/console/yiic schematic export
./vendor/bin/schematic export
```

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

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

## Overrides

You can override certain keys by placing a placeholder in `craft/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. The value has to start with a `%` (percentage sign) and end with one too. The correspending environment value will be `SCHEMATIC_{value_without_percentage_signs}`.
Expand Down Expand Up @@ -61,6 +70,13 @@ public function registerSchematicFieldModels()

## Changelog

###2.0.0###
- Reworked Schematic to install Craft when it's not installed yet
- Added support for site locales
- Fixed plugin installing on case-sensitive operating systems
- Fixed field context setting too late
- More verbose logging without backtrace

###1.4.0###
- Reworked importing and exporting of fields
- Added hook to allow the addition of custom logic for importing and exporting fields
Expand Down
57 changes: 0 additions & 57 deletions SchematicPlugin.php

This file was deleted.

72 changes: 72 additions & 0 deletions behaviors/SchematicBehavior.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

namespace Craft;

/**
* Schematic Behavior.
*
* Sync Craft Setups.
*
* @author Nerds & Company
* @copyright Copyright (c) 2015, Nerds & Company
* @license MIT
*
* @link http://www.nerds.company
*/
class SchematicBehavior extends AppBehavior
{
// Properties
// =========================================================================

/**
* @var
*/
private $_isInstalled;

/**
* Determines if Craft is installed by checking if the info table exists.
*
* @return bool
*/
public function isInstalled()
{
if (!isset($this->_isInstalled)) {
try {
// First check to see if DbConnection has even been initialized, yet.
if (craft()->getComponent('db')) {
// If the db config isn't valid, then we'll assume it's not installed.
if (!craft()->getIsDbConnectionValid()) {
return false;
}
} else {
return false;
}
} catch (\Exception $e) {
return false;
}

$this->_isInstalled = craft()->db->tableExists('info', false);
}

return $this->_isInstalled;
}

/**
* Tells Craft that it's installed now.
*/
public function setIsInstalled()
{
// If you say so!
$this->_isInstalled = true;
}

/**
* Schematic requires the pro edition.
*
* @return string
*/
public function getEdition()
{
return Craft::Pro;
}
}
57 changes: 57 additions & 0 deletions bin/schematic
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env php
<?php

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/');
defined('CRAFT_ENVIRONMENT') || define('CRAFT_ENVIRONMENT', 'console');

/*
* Yii command line script file configured for Craft.
*/

// fix for fcgi
defined('STDIN') or define('STDIN', fopen('php://stdin', 'r'));

ini_set('log_errors', 1);
ini_set('error_log', CRAFT_STORAGE_PATH.'runtime/logs/phperrors.log');

error_reporting(E_ALL & ~E_STRICT);
ini_set('display_errors', 1);
defined('YII_DEBUG') || define('YII_DEBUG', false);
defined('YII_TRACE_LEVEL') || define('YII_TRACE_LEVEL', 3);

require_once CRAFT_APP_PATH.'framework/yii.php';
require_once CRAFT_APP_PATH.'Craft.php';
require_once CRAFT_APP_PATH.'Info.php';

// Guzzle makes use of these PHP constants, but they aren't actually defined in some compilations of PHP.
// See http://it.blog.adclick.pt/php/fixing-php-notice-use-of-undefined-constant-curlopt_timeout_ms-assumed-curlopt_timeout_ms/
defined('CURLOPT_TIMEOUT_MS') || define('CURLOPT_TIMEOUT_MS', 155);
defined('CURLOPT_CONNECTTIMEOUT_MS') || define('CURLOPT_CONNECTTIMEOUT_MS', 156);

// Load up Composer's files
require CRAFT_APP_PATH.'vendor/autoload.php';
require __DIR__.'/../../../autoload.php';

// Disable the PHP include path
Yii::$enableIncludePath = false;

// Because CHttpRequest is one of those stupid Yii files that has multiple classes defined in it.
require_once CRAFT_APP_PATH.'framework/web/CHttpRequest.php';

// Fake server name on cli
$_SERVER['SERVER_NAME'] = getenv('CRAFT_SITENAME');

// Include our console app
require_once __DIR__.'/../consolecommands/SchematicConsoleApp.php';

Yii::setPathOfAlias('app', CRAFT_APP_PATH);
Yii::setPathOfAlias('plugins', CRAFT_PLUGINS_PATH);

$app = Yii::createApplication('Craft\SchematicConsoleApp', CRAFT_APP_PATH.'etc/config/console.php');
$app->run();
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "itmundi/schematic",
"description": "Sync Craft setups",
"description": "Craft setup and sync tool",
"authors": [
{
"name": "Bart van Gennep",
Expand Down Expand Up @@ -40,8 +40,8 @@
}
],
"license": "MIT",
"type": "craft-plugin",
"require": {
"composer/installers": "~1.0"
}
"symfony/yaml": "~2.8"
},
"bin": ["bin/schematic"]
}
33 changes: 33 additions & 0 deletions consolecommands/ExportCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Craft;

/**
* Schematic Export Command.
*
* Sync Craft Setups.
*
* @author Nerds & Company
* @copyright Copyright (c) 2015, Nerds & Company
* @license MIT
*
* @link http://www.nerds.company
*/
class ExportCommand extends BaseCommand
{
/**
* Exports the Craft datamodel.
*
* @param string $file file to write the schema to
*
* @return int
*/
public function actionIndex($file = 'craft/config/schema.yml')
{
craft()->schematic->exportToYaml($file);

Craft::log(Craft::t('Exported schema to {file}', array('file' => $file)));

return 0;
}
}
46 changes: 46 additions & 0 deletions consolecommands/ImportCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace Craft;

/**
* Schematic Import Command.
*
* Sync Craft Setups.
*
* @author Nerds & Company
* @copyright Copyright (c) 2015, Nerds & Company
* @license MIT
*
* @link http://www.nerds.company
*/
class ImportCommand extends BaseCommand
{
/**
* Imports the Craft datamodel.
*
* @param string $file yml file containing the schema definition
* @param string $override_file yml file containing the override values
* @param bool $force if set to true items not in the import will be deleted
*
* @return int
*/
public function actionIndex($file = 'craft/config/schema.yml', $override_file = 'craft/config/override.yml', $force = false)
{
if (!IOHelper::fileExists($file)) {
$this->usageError(Craft::t('File not found.'));
}

$result = craft()->schematic->importFromYaml($file, $override_file, $force);

if (!$result->hasErrors()) {
Craft::log(Craft::t('Loaded schema from {file}', array('file' => $file)));

return 0;
}

Craft::log(Craft::t('There was an error loading schema from {file}', array('file' => $file)));
print_r($result->getErrors());

return 1;
}
}
Loading

0 comments on commit 898e1e4

Please sign in to comment.