-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
install craft in the same process so ENV vars are carried through
- Loading branch information
Showing
2 changed files
with
62 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
namespace markhuot\craftpest\actions; | ||
|
||
use Craft; | ||
use craft\console\Application; | ||
use craft\console\controllers\InstallController; | ||
use craft\helpers\App; | ||
use craft\helpers\ArrayHelper; | ||
|
||
class InstallCraft | ||
{ | ||
public function __invoke(): void | ||
{ | ||
$args = [ | ||
'username' => App::env('CRAFT_INSTALL_USERNAME') ?? '[email protected]', | ||
'email' => App::env('CRAFT_INSTALL_EMAIL') ?? '[email protected]', | ||
'password' => App::env('CRAFT_INSTALL_PASSWORD') ?? 'secret', | ||
'interactive' => App::env('CRAFT_INSTALL_INTERACTIVE') ?? '0', | ||
]; | ||
|
||
if (! file_exists(Craft::getAlias('@config/project/project.yaml'))) { | ||
$args = array_merge($args, [ | ||
'siteName' => App::env('CRAFT_INSTALL_SITENAME') ?? '"Craft CMS"', | ||
'siteUrl' => App::env('CRAFT_INSTALL_SITEURL') ?? 'http://localhost:8080', | ||
'language' => App::env('CRAFT_INSTALL_LANGUAGE') ?? 'en-US', | ||
]); | ||
} | ||
|
||
$getConfig = function (string $path) { | ||
if (file_exists($path)) { | ||
return require $path; | ||
} | ||
|
||
return []; | ||
}; | ||
|
||
$config = ArrayHelper::merge( | ||
$getConfig(Craft::$app->getPath()->getVendorPath().'/craftcms/cms/src/config/app.php'), | ||
$getConfig(Craft::$app->getPath()->getVendorPath().'/craftcms/cms/src/config/app.console.php'), | ||
$getConfig(Craft::$app->getPath()->getConfigPath().'/app.php'), | ||
$getConfig(Craft::$app->getPath()->getConfigPath().'/app.console.php'), | ||
[ | ||
'id' => 'CraftCMSConsole', | ||
'name' => 'Craft CMS Console', | ||
'components' => [ | ||
'config' => Craft::$app->getConfig(), | ||
], | ||
], | ||
); | ||
unset($config['class']); | ||
|
||
Craft::createObject(InstallController::class, [ | ||
'id' => 'foo', | ||
'module' => new Application($config), | ||
'config' => $args, | ||
])->runAction('craft'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,11 +3,12 @@ | |
namespace markhuot\craftpest\test; | ||
|
||
use Craft; | ||
use craft\helpers\App; | ||
use Illuminate\Support\Collection; | ||
use markhuot\craftpest\actions\CallSeeders; | ||
use markhuot\craftpest\actions\InstallCraft; | ||
use markhuot\craftpest\interfaces\RenderCompiledClassesInterface; | ||
use Symfony\Component\Process\Process; | ||
use function markhuot\craftpest\helpers\base\service; | ||
|
||
class TestCase extends \PHPUnit\Framework\TestCase | ||
{ | ||
|
@@ -106,38 +107,7 @@ public function createApplication() | |
|
||
protected function craftInstall() | ||
{ | ||
$args = [ | ||
'--username='.(App::env('CRAFT_INSTALL_USERNAME') ?? '[email protected]'), | ||
'--email='.(App::env('CRAFT_INSTALL_EMAIL') ?? '[email protected]'), | ||
'--password='.(App::env('CRAFT_INSTALL_PASSWORD') ?? 'secret'), | ||
'--interactive='.(App::env('CRAFT_INSTALL_INTERACTIVE') ?? '0'), | ||
]; | ||
|
||
if (! file_exists(Craft::getAlias('@config/project/project.yaml'))) { | ||
$args = array_merge($args, [ | ||
'--siteName='.(App::env('CRAFT_INSTALL_SITENAME') ?? '"Craft CMS"'), | ||
'--siteUrl='.(App::env('CRAFT_INSTALL_SITEURL') ?? 'http://localhost:8080'), | ||
'--language='.(App::env('CRAFT_INSTALL_LANGUAGE') ?? 'en-US'), | ||
]); | ||
} | ||
|
||
$craftExePath = getenv('CRAFT_EXE_PATH') ?: './craft'; | ||
$process = new Process([$craftExePath, 'install', ...$args]); | ||
$process->setTty(Process::isTtySupported()); | ||
$process->setTimeout(null); | ||
$process->start(); | ||
|
||
foreach ($process as $type => $data) { | ||
if ($type === $process::OUT) { | ||
echo $data; | ||
} else { | ||
echo $data; | ||
} | ||
} | ||
|
||
if (! $process->isSuccessful()) { | ||
throw new \Exception('Failed installing Craft'); | ||
} | ||
service(InstallCraft::class)(); | ||
} | ||
|
||
protected function craftMigrateAll() | ||
|