Skip to content

Commit d974f48

Browse files
authored
Merge pull request #45 from craftcms/feature/update-build-command
Update build command for edition
2 parents cb7d84a + a2044d5 commit d974f48

File tree

3 files changed

+42
-64
lines changed

3 files changed

+42
-64
lines changed

src/Helper.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -177,16 +177,6 @@ public static function base64UrlEncode(string $data): string
177177
return rtrim($base64Url, '=');
178178
}
179179

180-
public static function validateProjectTypeForEdition(string $projectType, string $edition): bool
181-
{
182-
// TODO: replace with enums
183-
if (!$edition || ($projectType === 'team' && $edition === 'pro')) {
184-
return false;
185-
}
186-
187-
return true;
188-
}
189-
190180
public static function makeGatewayApiRequest(iterable $headers): ResponseInterface
191181
{
192182
if (!Helper::isCraftCloud()) {

src/cli/controllers/BuildController.php

Lines changed: 42 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,53 @@
22

33
namespace craft\cloud\cli\controllers;
44

5+
use Composer\Semver\Semver;
56
use Craft;
67
use craft\console\Controller;
7-
use Illuminate\Support\Collection;
8-
use samdark\log\PsrMessage;
9-
use yii\console\ExitCode;
8+
use craft\helpers\App;
9+
use yii\console\Exception;
1010

1111
class BuildController extends Controller
1212
{
13-
public function actionIndex(string $json): int
13+
public $defaultAction = 'build';
14+
public ?string $publishAssetBundlesTo = null;
15+
public string $craftEdition = '';
16+
17+
public function options($actionID): array
18+
{
19+
return array_merge(parent::options($actionID), [
20+
'publishAssetBundlesTo',
21+
'craftEdition',
22+
]);
23+
}
24+
25+
public function actionBuild(): int
26+
{
27+
$this->validateEdition($this->craftEdition);
28+
29+
return $this->run('/cloud/asset-bundles/publish', [
30+
'to' => $this->publishAssetBundlesTo,
31+
]);
32+
}
33+
34+
private function validateEdition(string $edition): void
1435
{
15-
$options = json_decode($json, true);
16-
$exitCode = ExitCode::OK;
17-
18-
Collection::make([
19-
'cloud/validate/project-type',
20-
'cloud/asset-bundles/publish',
21-
])->each(function(string $command) use ($options, &$exitCode) {
22-
$params = $options[$command] ?? [];
23-
$exitCode = $this->run("/$command", $params);
24-
25-
if ($exitCode !== ExitCode::OK) {
26-
Craft::error(new PsrMessage('Command failed.', [
27-
'command' => $command,
28-
'params' => $params,
29-
]));
30-
31-
return false;
32-
}
33-
});
34-
35-
return $exitCode;
36+
$craftVersion = Craft::$app->getVersion();
37+
$editionFromEnv = App::env('CRAFT_EDITION');
38+
39+
// CRAFT_EDITION is enforced in these versions, so we don't need to validate
40+
if ($editionFromEnv && Semver::satisfies($craftVersion, '^4.10 || ^5.2')) {
41+
return;
42+
}
43+
44+
$editionFromProjectConfig = Craft::$app->getProjectConfig()->get('system.edition', true);
45+
46+
if (!$editionFromProjectConfig || !$edition) {
47+
throw new Exception('Unable to determine the Craft CMS edition.');
48+
}
49+
50+
if ($edition !== $editionFromProjectConfig) {
51+
throw new Exception("This Craft Cloud project is only valid for the Craft CMS edition “{$edition}”.");
52+
}
3653
}
3754
}

src/cli/controllers/ValidateController.php

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)