Skip to content

Commit

Permalink
Various fixes for CloneCommand (CFM-127)
Browse files Browse the repository at this point in the history
  • Loading branch information
Benn Oshrin committed Nov 13, 2025
1 parent 079f24b commit f5d2e9f
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
5 changes: 5 additions & 0 deletions app/plugins/CoreServer/src/Model/Table/SqlServersTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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',
Expand Down
5 changes: 4 additions & 1 deletion app/src/Command/CloneCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion app/src/Lib/Traits/PluggableModelTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/src/Lib/Traits/UpsertTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions app/src/Model/Table/GroupsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -1444,6 +1444,7 @@ public function validationDefault(Validator $validator): Validator {
]);
$validator->allowEmptyString('owner_group_id');

$this->registerClonableValidation($validator, $schema);

return $validator;
}
Expand Down
6 changes: 3 additions & 3 deletions app/src/Model/Table/TypesTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit f5d2e9f

Please sign in to comment.