Skip to content

Commit

Permalink
project-config/sync command, plus apply yawl changes in app/migrate
Browse files Browse the repository at this point in the history
resolves #3510
  • Loading branch information
brandonkelly committed Nov 30, 2018
1 parent 80355ea commit 37064bb
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 1 deletion.
8 changes: 8 additions & 0 deletions CHANGELOG-v3.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Release Notes for Craft CMS 3.x

## Unreleased

### Added
- Added a new `project-config/sync` console command. ([#3510](https://github.com/craftcms/cms/issues/3510))

### Changed
- The `app/migrate` web action now applies pending `project.yaml` changes, if the `useProjectConfigFile` config setting is enabled.

## 3.1.0-beta.4 - 2018-11-30

### Changed
Expand Down
46 changes: 46 additions & 0 deletions src/console/controllers/ProjectConfigController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
/**
* @link https://craftcms.com/
* @copyright Copyright (c) Pixel & Tonic, Inc.
* @license https://craftcms.github.io/license/
*/

namespace craft\console\controllers;

use Craft;
use craft\helpers\Console;
use yii\console\Controller;
use yii\console\ExitCode;

/**
* Manages the project config.
*
* @author Pixel & Tonic, Inc. <[email protected]>
* @since 3.1
*/
class ProjectConfigController extends Controller
{
/**
* Syncs the project config.
*
* @return int
*/
public function actionSync(): int
{
if (!Craft::$app->getConfig()->getGeneral()->useProjectConfigFile) {
$this->stdout('Craft is not configured to use project.yaml. Please enable the \'useProjectConfigFile\' config setting in config/general.php.' . PHP_EOL, Console::FG_YELLOW);
return ExitCode::OK;
}

$this->stdout('Applying changes from project.yaml... ', Console::FG_YELLOW);
try {
Craft::$app->getProjectConfig()->applyYamlChanges();
} catch (\Throwable $e) {
$this->stderr('error: ' . $e->getMessage() . PHP_EOL, Console::FG_RED);
return ExitCode::UNSPECIFIED_ERROR;
}

$this->stdout('done' . PHP_EOL, Console::FG_GREEN);
return ExitCode::OK;
}
}
8 changes: 7 additions & 1 deletion src/controllers/AppController.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ public function actionCheckForUpdates(): Response
}

/**
* Creates a DB backup (if configured to do so) and runs any pending Craft, plugin, & content migrations in one go.
* Creates a DB backup (if configured to do so), runs any pending Craft,
* plugin, & content migrations, and syncs `project.yaml` changes in one go.
*
* This action can be used as a post-deploy webhook with site deployment
* services (like [DeployBot](https://deploybot.com/)) to minimize site
Expand Down Expand Up @@ -163,6 +164,11 @@ public function actionMigrate()
// Run the migrations
$updatesService->runMigrations($handles);

// Sync project.yaml?
if ($generalConfig->useProjectConfigFile) {
Craft::$app->getProjectConfig()->applyYamlChanges();
}

$transaction->commit();
} catch (\Throwable $e) {
$transaction->rollBack();
Expand Down

0 comments on commit 37064bb

Please sign in to comment.