Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function bootstrap(): void
$this->addPlugin($p->plugin);
}
}
catch(\Cake\Database\Exception\DatabaseException $e) {
catch(\Cake\Database\Exception\QueryException | \Cake\Database\Exception\DatabaseException $e) {
// Most likely we are performing the initial database setup and
// the plugins table is missing.
}
Expand Down
12 changes: 6 additions & 6 deletions app/src/Command/SetupCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public function execute(Arguments $args, ConsoleIo $io)
'co_id' => $co_id,
'status' => SuspendableStatusEnum::Active
],
['validate' => false]);
['validate' => false, 'skipNormalization' => true]);

$person->names = [$coTable->People->Names->newEntity([
'type_id' => $coTable->Types->getTypeId(coId: $co_id,
Expand All @@ -158,7 +158,7 @@ public function execute(Arguments $args, ConsoleIo $io)
'family' => $sn,
'primary_name' => true
],
['validate' => false])];
['validate' => false, 'skipNormalization' => true])];

$person->identifiers = [$coTable->People->Identifiers->newEntity([
'type_id' => $coTable->Types->getTypeId(coId: $co_id,
Expand All @@ -168,7 +168,7 @@ public function execute(Arguments $args, ConsoleIo $io)
'login' => true,
'status' => SuspendableStatusEnum::Active
],
['validate' => false])];
['validate' => false, 'skipNormalization' => true])];

$person->person_roles = [$coTable->People->PersonRoles->newEntity([
'affiliation_type_id' => $coTable->Types->getTypeId(coId: $co_id,
Expand All @@ -177,18 +177,18 @@ public function execute(Arguments $args, ConsoleIo $io)
'title' => __d('command', 'se.person_role.title'),
'status' => SuspendableStatusEnum::Active
],
['validate' => false])];
['validate' => false, 'skipNormalization' => true])];

$g = $coTable->Groups->find('adminGroup', co_id: $co_id)->firstOrFail();

$person->group_members = [
$coTable->People->GroupMembers->newEntity(
['group_id' => $g->id],
['validate' => false]
['validate' => false, 'skipNormalization' => true]
),
$coTable->People->GroupMembers->newEntity(
['group_id' => $g->owners_group_id],
['validate' => false]
['validate' => false, 'skipNormalization' => true]
)
];

Expand Down
8 changes: 7 additions & 1 deletion app/src/Model/Behavior/NormalizationBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,14 @@ public function beforeMarshal(Event $event, ArrayObject $data, ArrayObject $opti
// We need the CO for the record in order to find the appropriate configuration(s) to use,
// but for that we need $data in entity form.

$entityOptions = [];
foreach($options as $k => $v) {
$entityOptions[$k] = $v;
}
$entityOptions['skipNormalization'] = true;

// This will recurse, so make sure to break the loop
$entity = $Table->newEntity((array)$data, options: ['skipNormalization' => true]);
$entity = $Table->newEntity((array)$data, options: $entityOptions);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we could more concisely use something like

$Table->newEntity((array)$data, options: array_merge($options, ['skipNormalization' => trp.]));

?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@benno since we are going compact, we should better use the unpacking:

$entity = $Table->newEntity(
    (array)$data,
    options: [...$options, 'skipNormalization' => true]
);

since the skipNormalization is placed after the $options it will always override whatever $options have.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The source has been updated to use the unpacking approach.


$coId = $Table->calculateCoForRecord($entity);

Expand Down