diff --git a/.gitignore b/.gitignore
index d8a7996..9912bd5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
composer.lock
vendor/
+.idea/
diff --git a/README.md b/README.md
index 3d3d976..06af9ee 100644
--- a/README.md
+++ b/README.md
@@ -20,3 +20,6 @@ By setting the ENV var `DISABLE_CRAFT_AUTOMIGRATE=1` you disable the plugin.
By setting the ENV var `PROJECT_CONFIG_FORCE_APPLY=1` the `project-config/apply` command is executed with the `--force` flag.
+The file `config/project/project.yaml` will be removed after applying, unless you set the ENV var `KEEP_PROJECT_CONFIG=1` or composer install is running locally (interactive mode).
+This behaviour was added in `2.5.0` to prevent re-applying the Project Config in the Craft CP.
+
diff --git a/src/Plugin.php b/src/Plugin.php
index d4f898b..021a23d 100644
--- a/src/Plugin.php
+++ b/src/Plugin.php
@@ -75,7 +75,7 @@ public function runCommands(): bool
}
- if ($this->hasProjectConfigFile()) {
+ if ($this->hasProjectConfig()) {
$args = ["project-config/apply"];
if (getenv('PROJECT_CONFIG_FORCE_APPLY') == 1) {
@@ -87,6 +87,16 @@ public function runCommands(): bool
if ($cmd->run()) {
$this->io->write(PHP_EOL . "▶ Craft auto migrate [project-config/apply]");
$this->io->write(PHP_EOL . $cmd->getOutput());
+
+ // Remove project.yaml during deployment (non-interactive mode)
+ if ($this->shouldRemoveProjectConfigAfterApply()) {
+ $projectConfigFile = $this->getProjectConfigFile();
+ if (is_string($projectConfigFile) && unlink($projectConfigFile)) {
+ $this->io->write(PHP_EOL . "$projectConfigFile removed");
+ }
+ }
+
+
} else {
$this->io->writeError(PHP_EOL . "▶ Craft auto migrate [project-config/apply ERROR]");
$this->io->writeError(PHP_EOL . $cmd->getErrorOutput());
@@ -99,6 +109,14 @@ public function runCommands(): bool
return true;
}
+ protected function shouldRemoveProjectConfigAfterApply(): bool
+ {
+ if (getenv('KEEP_PROJECT_CONFIG') == 1 || $this->io->isInteractive() === true) {
+ return false;
+ }
+
+ return true;
+ }
/**
* Checks if Craft is installed by showing a help command
@@ -119,18 +137,26 @@ protected function isCraftInstalled(): bool
}
- /**
- * @return bool
- */
- protected function hasProjectConfigFile(): bool
+ protected function hasProjectConfig(): bool
{
$projectRoot = realpath(dirname(Factory::getComposerFile()));
- $pathToConfigFile = $projectRoot . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'project.yaml';
- $pathToConfigDir = $projectRoot . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'project';
+ $pathToConfigFile = implode(DIRECTORY_SEPARATOR, [$projectRoot, 'config', 'project', 'project.yaml']);
+ $pathToConfigDir = implode(DIRECTORY_SEPARATOR, [$projectRoot, 'config', 'project']);
return file_exists($pathToConfigFile) || is_dir($pathToConfigDir);
}
+ protected function getProjectConfigFile(): ?string
+ {
+ $projectRoot = realpath(dirname(Factory::getComposerFile()));
+ $projectConfigFile = implode(DIRECTORY_SEPARATOR, [$projectRoot, 'config', 'project', 'project.yaml']);
+
+ return file_exists($projectConfigFile)
+ ? $projectConfigFile
+ : null;
+
+ }
+
/**
* @inheritDoc
*/