Skip to content

Commit aae4998

Browse files
Vitexusclaude
andcommitted
fix(credential-type): use 'prototype' column instead of 'class', cast version to int
The credential_type DB table uses 'prototype' not 'class'; inserting with the wrong key caused SQLSTATE[42S22]. Also fixes version truncation warning by casting the string version from the prototype to int before INSERT. feat(credential): add --field KEYWORD:VALUE option to credential:update Allows setting credential field values (stored in credata) directly from the CLI without needing the web UI. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 7ddd7c5 commit aae4998

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

src/Command/Credential/UpdateCommand.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ protected function configure(): void
3636
->addOption('id', null, InputOption::VALUE_REQUIRED, 'Credential ID')
3737
->addOption('name', null, InputOption::VALUE_REQUIRED, 'Credential name')
3838
->addOption('company-id', null, InputOption::VALUE_REQUIRED, 'Company ID')
39-
->addOption('credential-type-id', null, InputOption::VALUE_REQUIRED, 'Credential Type ID');
39+
->addOption('credential-type-id', null, InputOption::VALUE_REQUIRED, 'Credential Type ID')
40+
->addOption('field', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Credential field as KEYWORD:VALUE (repeatable)');
4041
}
4142

4243
protected function execute(InputInterface $input, OutputInterface $output): int
@@ -89,12 +90,26 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8990
$data['credential_type_id'] = (int) $credentialTypeId;
9091
}
9192

93+
foreach ($input->getOption('field') as $fieldArg) {
94+
$colonPos = strpos($fieldArg, ':');
95+
96+
if ($colonPos === false) {
97+
$format === 'json' ? $this->jsonError($output, "Invalid --field format, expected KEYWORD:VALUE: {$fieldArg}") : $output->writeln("<error>Invalid --field format, expected KEYWORD:VALUE: {$fieldArg}</error>");
98+
99+
return self::FAILURE;
100+
}
101+
102+
$data[substr($fieldArg, 0, $colonPos)] = substr($fieldArg, $colonPos + 1);
103+
}
104+
92105
if (empty($data)) {
93106
$format === 'json' ? $this->jsonError($output, 'No fields to update') : $output->writeln('<error>No fields to update</error>');
94107

95108
return self::FAILURE;
96109
}
97110

111+
$data['credential_type_id'] = $data['credential_type_id'] ?? $credential->getDataValue('credential_type_id');
112+
98113
try {
99114
$credential->updateToSQL($data, ['id' => $id]);
100115
$format === 'json' ? $this->jsonSuccess($output, 'Credential updated successfully', ['credential_id' => (int) $id, 'updated' => true]) : $output->writeln('<info>Credential updated successfully</info>');

src/Command/CredentialType/CreateCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
5656
}
5757

5858
$credType = new CredentialType();
59-
$data = ['company_id' => (int) $companyId, 'class' => $className, 'name' => $proto['name'] ?? $className, 'uuid' => $proto['uuid'] ?? null, 'version' => $proto['version'] ?? '1.0'];
59+
$data = ['company_id' => (int) $companyId, 'prototype' => $className, 'name' => $proto['name'] ?? $className, 'uuid' => $proto['uuid'] ?? null, 'version' => (int) ($proto['version'] ?? 1)];
6060
$result = $credType->insertToSQL($data);
6161

6262
if ($result) {

0 commit comments

Comments
 (0)