diff --git a/src/Appwrite/Platform/Modules/Compute/Base.php b/src/Appwrite/Platform/Modules/Compute/Base.php index 07e09a3b89..b3740787b3 100644 --- a/src/Appwrite/Platform/Modules/Compute/Base.php +++ b/src/Appwrite/Platform/Modules/Compute/Base.php @@ -49,7 +49,6 @@ class Base extends Action $planKey ); $allowedSpecifications = $specificationValidator->getAllowedSpecifications(); - $planKey = $specificationValidator->getPlanKey(); if (empty($allowedSpecifications)) { return $fallback; diff --git a/src/Appwrite/Platform/Modules/Compute/Validator/Specification.php b/src/Appwrite/Platform/Modules/Compute/Validator/Specification.php index 8a77afef24..5f1337c97f 100644 --- a/src/Appwrite/Platform/Modules/Compute/Validator/Specification.php +++ b/src/Appwrite/Platform/Modules/Compute/Validator/Specification.php @@ -25,15 +25,6 @@ class Specification extends Validator $this->planKey = $planKey; } - public function getPlanKey(): string - { - if ($this->planKey === 'buildSpecifications' && !array_key_exists('buildSpecifications', $this->plan) && array_key_exists('runtimeSpecifications', $this->plan)) { - return 'runtimeSpecifications'; - } - - return $this->planKey; - } - /** * Get Allowed Specifications. * @@ -44,12 +35,11 @@ class Specification extends Validator public function getAllowedSpecifications(): array { $allowedSpecifications = []; - $planKey = $this->getPlanKey(); foreach ($this->specifications as $size => $values) { if ((empty($this->maxCpus) || $values['cpus'] <= $this->maxCpus) && (empty($this->maxMemory) || $values['memory'] <= $this->maxMemory)) { - if (!empty($this->plan) && array_key_exists($planKey, $this->plan)) { - if (!\in_array($size, $this->plan[$planKey])) { + if (!empty($this->plan) && array_key_exists($this->planKey, $this->plan)) { + if (!\in_array($size, $this->plan[$this->planKey])) { continue; } } diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Specifications/XList.php b/src/Appwrite/Platform/Modules/Functions/Http/Specifications/XList.php index e8177abdbd..8cbff906fa 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Specifications/XList.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Specifications/XList.php @@ -3,7 +3,6 @@ namespace Appwrite\Platform\Modules\Functions\Http\Specifications; use Appwrite\Platform\Modules\Compute\Base; -use Appwrite\Platform\Modules\Compute\Validator\Specification; use Appwrite\SDK\AuthType; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; @@ -57,7 +56,7 @@ class XList extends Base public function action(string $type, Response $response, array $plan) { $allSpecs = Config::getParam('specifications', []); - $planKey = (new Specification($plan, [], 0, 0, $type === 'builds' ? 'buildSpecifications' : 'runtimeSpecifications'))->getPlanKey(); + $planKey = $type === 'builds' ? 'buildSpecifications' : 'runtimeSpecifications'; $specs = []; foreach ($allSpecs as $spec) { diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Specifications/XList.php b/src/Appwrite/Platform/Modules/Sites/Http/Specifications/XList.php index 735e45bcdc..a4f865d859 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Specifications/XList.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Specifications/XList.php @@ -3,7 +3,6 @@ namespace Appwrite\Platform\Modules\Sites\Http\Specifications; use Appwrite\Platform\Modules\Compute\Base; -use Appwrite\Platform\Modules\Compute\Validator\Specification; use Appwrite\SDK\AuthType; use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; @@ -57,7 +56,7 @@ class XList extends Base public function action(string $type, Response $response, array $plan) { $allSpecs = Config::getParam('specifications', []); - $planKey = (new Specification($plan, [], 0, 0, $type === 'builds' ? 'buildSpecifications' : 'runtimeSpecifications'))->getPlanKey(); + $planKey = $type === 'builds' ? 'buildSpecifications' : 'runtimeSpecifications'; $specs = []; foreach ($allSpecs as $spec) { diff --git a/tests/unit/Platform/Modules/Compute/Validator/SpecificationTest.php b/tests/unit/Platform/Modules/Compute/Validator/SpecificationTest.php index 15d9961aa8..abc6296d0a 100644 --- a/tests/unit/Platform/Modules/Compute/Validator/SpecificationTest.php +++ b/tests/unit/Platform/Modules/Compute/Validator/SpecificationTest.php @@ -96,27 +96,4 @@ final class SpecificationTest extends TestCase $this->assertContains(SpecificationConstants::S_1VCPU_1GB, $allowed); $this->assertContains(SpecificationConstants::S_2VCPU_2GB, $allowed); } - - public function testGetAllowedSpecificationsWithLegacyBuildPlanLimits(): void - { - $plan = [ - 'runtimeSpecifications' => [ - SpecificationConstants::S_05VCPU_512MB, - SpecificationConstants::S_1VCPU_512MB, - ] - ]; - $validator = new Specification( - plan: $plan, - specifications: $this->specifications, - maxCpus: 0, - maxMemory: 0, - planKey: 'buildSpecifications' - ); - - $allowed = $validator->getAllowedSpecifications(); - $this->assertEquals('runtimeSpecifications', $validator->getPlanKey()); - $this->assertCount(2, $allowed); - $this->assertContains(SpecificationConstants::S_05VCPU_512MB, $allowed); - $this->assertContains(SpecificationConstants::S_1VCPU_512MB, $allowed); - } }