Skip to content

Commit f663a23

Browse files
committed
Update build command for edition
1 parent cb7d84a commit f663a23

File tree

2 files changed

+45
-35
lines changed

2 files changed

+45
-35
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: 45 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,56 @@
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+
'publish-asset-bundles-to',
21+
'craft-edition',
22+
]);
23+
}
24+
25+
public function actionBuild(): int
1426
{
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;
27+
if (!$this->isEditionValid($this->craftEdition)) {
28+
throw new Exception('Invalid Craft CMS edition.');
29+
}
30+
31+
return $this->run('/cloud/asset-bundles/publish', [
32+
'to' => $this->publishAssetBundlesTo,
33+
]);
34+
}
35+
36+
private function isEditionValid(string $edition): bool
37+
{
38+
$craftVersion = Craft::$app->getInfo()->version;
39+
40+
// CRAFT_EDITION is enforced in these versions, so we don't need to validate
41+
if (App::env('CRAFT_EDITION') && Semver::satisfies($craftVersion, '^4.10 || ^5.2')) {
42+
return true;
43+
}
44+
45+
$editionFromProjectConfig = Craft::$app->getProjectConfig()->get('system.edition', true);
46+
47+
if (!$editionFromProjectConfig) {
48+
throw new Exception('Unable to determine the Craft CMS edition.');
49+
}
50+
51+
if ($edition !== $editionFromProjectConfig) {
52+
return false;
53+
}
54+
55+
return true;
3656
}
3757
}

0 commit comments

Comments
 (0)