From f5d2e9f65bf91d24f921f067cd0cfd2661c2a891 Mon Sep 17 00:00:00 2001 From: Benn Oshrin Date: Thu, 13 Nov 2025 13:02:10 -0500 Subject: [PATCH] Various fixes for CloneCommand (CFM-127) --- .../ApiConnector/src/Model/Table/ApiSourcesTable.php | 2 +- app/plugins/CoreServer/src/Model/Table/SqlServersTable.php | 5 +++++ app/src/Command/CloneCommand.php | 5 ++++- app/src/Lib/Traits/PluggableModelTrait.php | 2 +- app/src/Lib/Traits/UpsertTrait.php | 2 +- app/src/Model/Table/GroupsTable.php | 1 + app/src/Model/Table/TypesTable.php | 6 +++--- 7 files changed, 16 insertions(+), 7 deletions(-) diff --git a/app/availableplugins/ApiConnector/src/Model/Table/ApiSourcesTable.php b/app/availableplugins/ApiConnector/src/Model/Table/ApiSourcesTable.php index 7b59ca2a6..dd8df9d0d 100644 --- a/app/availableplugins/ApiConnector/src/Model/Table/ApiSourcesTable.php +++ b/app/availableplugins/ApiConnector/src/Model/Table/ApiSourcesTable.php @@ -62,7 +62,7 @@ public function initialize(array $config): void { $this->belongsTo('ExternalIdentitySources'); $this->belongsTo('ApiUsers'); - $this->hasMany('ApiConnector.ApiSourceEntities') + $this->hasMany('ApiConnector.ApiSourceEndpoints') ->setDependent(true) ->setCascadeCallbacks(true); $this->hasMany('ApiConnector.ApiSourceRecords') diff --git a/app/plugins/CoreServer/src/Model/Table/SqlServersTable.php b/app/plugins/CoreServer/src/Model/Table/SqlServersTable.php index a5ad9c46f..7e14e836b 100644 --- a/app/plugins/CoreServer/src/Model/Table/SqlServersTable.php +++ b/app/plugins/CoreServer/src/Model/Table/SqlServersTable.php @@ -36,6 +36,7 @@ use Cake\ORM\Table; use Cake\Validation\Validator; use CoreServer\Lib\Enum\RdbmsTypeEnum; +use \App\Lib\Enum\SuspendableStatusEnum; class SqlServersTable extends Table { use \App\Lib\Traits\AutoViewVarsTrait; @@ -129,6 +130,10 @@ public function connect(int $serverId, string $name): bool { // Pull our configuration via the parent Server object. $server = $this->Servers->get($serverId, contain: ['SqlServers']); + if($server->status != SuspendableStatusEnum::Active) { + throw new \InvalidArgumentException(__d('error', 'inactive', [__d('controller', 'Servers', [1]), $serverId])); + } + $dbmap = [ RdbmsTypeEnum::MariaDB => 'Mysql', RdbmsTypeEnum::MySQL => 'Mysql', diff --git a/app/src/Command/CloneCommand.php b/app/src/Command/CloneCommand.php index 2ad415067..98a57a934 100644 --- a/app/src/Command/CloneCommand.php +++ b/app/src/Command/CloneCommand.php @@ -419,7 +419,10 @@ protected function cloneEntity( // doing an upsert, but spread out over multiple steps in order to allow table specific // callbocks to manipulate the prepared entity. - $query = $TargetTable->find()->where(['co_id' => $targetCoId, 'uuid' => $original->uuid]); + $query = $TargetTable->find()->where([ + $TargetTable->getAlias().'.co_id' => $targetCoId, + $TargetTable->getAlias().'.uuid' => $original->uuid + ]); $targetRelated = $related; diff --git a/app/src/Lib/Traits/PluggableModelTrait.php b/app/src/Lib/Traits/PluggableModelTrait.php index cba0868fd..46c7015ae 100644 --- a/app/src/Lib/Traits/PluggableModelTrait.php +++ b/app/src/Lib/Traits/PluggableModelTrait.php @@ -90,7 +90,7 @@ public function afterMarshal( */ public function checkCloneDependencies( - EntityInterface $original, + \Cake\Datasource\EntityInterface $original, string $targetDataSource='default' ) { // Verify the plugin in use is active in the target database. If we're on the same diff --git a/app/src/Lib/Traits/UpsertTrait.php b/app/src/Lib/Traits/UpsertTrait.php index 95debdedc..cac03b7a7 100644 --- a/app/src/Lib/Traits/UpsertTrait.php +++ b/app/src/Lib/Traits/UpsertTrait.php @@ -89,7 +89,7 @@ public function upsert( public function upsertOrFail( array $data, array $whereClause, - array $options + array $options=[] ): \Cake\Datasource\EntityInterface { return $this->upsert($data, $whereClause, true, $options); } diff --git a/app/src/Model/Table/GroupsTable.php b/app/src/Model/Table/GroupsTable.php index bba1cd34f..c98cebae7 100644 --- a/app/src/Model/Table/GroupsTable.php +++ b/app/src/Model/Table/GroupsTable.php @@ -1444,6 +1444,7 @@ public function validationDefault(Validator $validator): Validator { ]); $validator->allowEmptyString('owner_group_id'); + $this->registerClonableValidation($validator, $schema); return $validator; } diff --git a/app/src/Model/Table/TypesTable.php b/app/src/Model/Table/TypesTable.php index 81278227b..42a3cd024 100644 --- a/app/src/Model/Table/TypesTable.php +++ b/app/src/Model/Table/TypesTable.php @@ -264,9 +264,9 @@ public function buildRules(RulesChecker $rules): RulesChecker { public function getTypeId(int $coId, string $attribute, string $value): int { $t = $this->find() ->where([ - 'Types.co_id' => $coId, - 'Types.attribute' => $attribute, - 'Types.value' => $value + $this->getAlias().'.co_id' => $coId, + $this->getAlias().'.attribute' => $attribute, + $this->getAlias().'.value' => $value ]) ->firstOrFail();