Skip to content

Commit

Permalink
Additional fixes for CloneCommand (CFM-127)
Browse files Browse the repository at this point in the history
  • Loading branch information
Benn Oshrin committed Jan 14, 2026
1 parent 2ad9ce8 commit 8e841cc
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ public function initialize(array $config): void {
$this->belongsTo('ExternalIdentitySources');
$this->belongsTo('ApiUsers');

$this->hasMany('ApiConnector.ApiSourceEndpoints')
->setDependent(true)
->setCascadeCallbacks(true);
$this->hasMany('ApiConnector.ApiSourceRecords')
->setDependent(true)
->setCascadeCallbacks(true);
Expand Down
2 changes: 1 addition & 1 deletion app/src/Command/CloneCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ protected function cloneEntity(
}

$this->io->out($original->uuid . ": Cloning " . $className . " " . $id
. " from CO " . $sourceCoId . " to CO " . $targetCoId);
. " from CO " . $sourceCoId . " to CO " . $targetCoId . " using $targetDataSource target");

// Clone any predecessor objects first. There is a default implementations in
// ClonableTrait that should cover most scenarios, so we don't need to check
Expand Down
5 changes: 4 additions & 1 deletion app/src/Lib/Util/TableUtilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,10 @@ public static function getTableWithDataSource(
if(!$aTargetTable->hasAssociation($targetAlias)) {
$m->$aType($targetAlias)
->setClassName($className)
->setForeignKey(StringUtilities::tableToForeignKey($target))
// For the relation (eg) RemoteMatchServers hasMany RemoteMatchServerAttributes
// we need to set the foreign key to match_server_id (ie what the data model has
// for match_server_attributes to fk back to match_servers)
->setForeignKey(StringUtilities::classNameToForeignKey(StringUtilities::pluginModel($tableName)))
->setCascadeCallbacks(true)
->setTarget($aTargetTable);
// Unlike PluggableTrait we don't setDependent(), it's not clear if we need to...
Expand Down
5 changes: 5 additions & 0 deletions app/src/Model/Table/CousTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,11 @@ public function buildRules(RulesChecker $rules): RulesChecker {
*/

public function localAfterSave(\Cake\Event\EventInterface $event, \Cake\Datasource\EntityInterface $entity, \ArrayObject $options) {
if(isset($options['clone']) && $options['clone']) {
// If we're in the middle of cloning, don't run setup or addDefaults
return;
}

if(!empty($entity->id)) {
if($entity->isNew()) {
// Run setup for new COU
Expand Down

0 comments on commit 8e841cc

Please sign in to comment.