Skip to content

Commit

Permalink
Additional fixes to Clone Command (CO-479)
Browse files Browse the repository at this point in the history
  • Loading branch information
Benn Oshrin committed Feb 24, 2026
1 parent 37bfc2d commit 5b9724b
Show file tree
Hide file tree
Showing 8 changed files with 334 additions and 179 deletions.
3 changes: 2 additions & 1 deletion app/availableplugins/PipelineToolkit/config/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@
"person_role_mappings_i2": { "needed": false, "columns": [ "affiliation_type_id" ] },
"person_role_mappings_i3": { "needed": false, "columns": [ "target_cou_id" ] },
"person_role_mappings_i4": { "needed": false, "columns": [ "target_affiliation_type_id" ] }
}
},
"clone_relation": true
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions app/config/schema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,8 @@
},
"indexes": {
"flanges_i1": { "columns": [ "pipeline_id" ] }
}
},
"clone_relation": true
},

"external_identity_sources": {
Expand Down Expand Up @@ -940,7 +941,8 @@
"indexes": {
"apis_i1": { "columns": [ "co_id" ] },
"apis_i2": { "needed": false, "columns": [ "api_user_id" ]}
}
},
"clonable": true
},

"traffic_detours": {
Expand Down
457 changes: 283 additions & 174 deletions app/src/Command/CloneCommand.php

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions app/src/Lib/Util/SearchUtilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@

class SearchUtilities {
// Currently, only clonable models support CRN and UUID searching.
// To add a new clonable model, see https://spaces.at.internet2.edu/x/DIBuFQ
// Because this list is used by CloneCommand, it should be sorted in dependency order.
static protected $clonableModels = [
'ApiUsers',
'Apis',
'Cous',
'Groups',
'IdentifierAssignments',
Expand Down
2 changes: 2 additions & 0 deletions app/src/Model/Entity/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,6 @@ class Api extends Entity {
'id' => false,
'slug' => false,
];

public array $_supportedMetadata = ['clonable'];
}
23 changes: 22 additions & 1 deletion app/src/Model/Table/ApisTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
class ApisTable extends Table {
use \App\Lib\Traits\AutoViewVarsTrait;
use \App\Lib\Traits\ChangelogBehaviorTrait;
use \App\Lib\Traits\ClonableTrait;
use \App\Lib\Traits\CoLinkTrait;
use \App\Lib\Traits\PermissionsTrait;
use \App\Lib\Traits\PluggableModelTrait;
Expand All @@ -56,6 +57,7 @@ class ApisTable extends Table {
public function initialize(array $config): void {
// Timestamp behavior handles created/modified updates
$this->addBehavior('Changelog');
$this->addBehavior('Clonable');
$this->addBehavior('Log');
$this->addBehavior('Timestamp');

Expand Down Expand Up @@ -102,8 +104,25 @@ public function initialize(array $config): void {
]
]);
}

/**
* Define business rules.
*
* @since COmanage Registry v5.2.0
* @param RulesChecker $rules RulesChecker object
* @return RulesChecker
*/

/**
public function buildRules(RulesChecker $rules): RulesChecker {
// AR-GMR-6 The same UUID cannot be assigned to multiple objects within the same CO.
$rules->add([$this, 'ruleUuidUnique'],
'uuidUnique',
['errorField' => 'uuid']);

return $rules;
}

/**
* Set validation rules.
*
* @since COmanage Registry v5.2.0
Expand Down Expand Up @@ -133,6 +152,8 @@ public function validationDefault(Validator $validator): Validator {
]);
$validator->notEmptyString('api_user_id');

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

return $validator;
}
}
2 changes: 1 addition & 1 deletion app/src/Model/Table/FlangesTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function initialize(array $config): void {
$this->setAutoViewVars([
'plugins' => [
'type' => 'plugin',
'pluginType' => 'pipeline'
'pluginType' => 'flange'
],
'statuses' => [
'type' => 'enum',
Expand Down
18 changes: 18 additions & 0 deletions app/src/Model/Table/PipelinesTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,24 @@ public function execute(
}
}

/**
* Get the set of hasMany related models that are to be duplicated along with
* this one, or its hasOne relations.
*
* @since COmanage Registry v5.2.0
* @return array Array of models, in contain() format
*/

public function getCloneHasMany(): array {
// When a Pipeline is cloned, we also need to clone its Flanges.
// Because (unlike other pluggable models) Flanges don't fk to co_id,
// we also need to figure out its hasOne (plugin) relations, as well
// as any hasMany relations for those plugins (eg Pipeline > Flange >
// PersonRoleMapper > PersonRoleMapping).

return ['Flanges' => $this->Flanges->getCloneHasMany()];
}

/**
* Pipeline step to create or update the External Identity Source Record.
*
Expand Down

0 comments on commit 5b9724b

Please sign in to comment.