Support live Caveau plan enum
This commit is contained in:
@@ -37,10 +37,45 @@ function setupJson(array $value): string
|
||||
return json_encode($value, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
|
||||
function setupEnumValues(PDO $db, string $table, string $column): array
|
||||
{
|
||||
$stmt = $db->prepare(
|
||||
'SELECT COLUMN_TYPE
|
||||
FROM information_schema.COLUMNS
|
||||
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = ? AND COLUMN_NAME = ?
|
||||
LIMIT 1'
|
||||
);
|
||||
$stmt->execute([$table, $column]);
|
||||
$type = (string)$stmt->fetchColumn();
|
||||
|
||||
if (!preg_match("/^enum\\((.*)\\)$/", $type, $matches)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$values = str_getcsv($matches[1], ',', "'");
|
||||
return array_values(array_filter(array_map('strval', $values)));
|
||||
}
|
||||
|
||||
function setupPreferredValue(array $available, array $preferred, string $fallback): string
|
||||
{
|
||||
foreach ($preferred as $value) {
|
||||
if (in_array($value, $available, true)) {
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
return $available[0] ?? $fallback;
|
||||
}
|
||||
|
||||
try {
|
||||
$db = dbnToolsDb();
|
||||
$db->beginTransaction();
|
||||
|
||||
$plan = setupPreferredValue(
|
||||
setupEnumValues($db, 'clients', 'plan'),
|
||||
['enterprise', 'sovereign', 'corporate', 'professional', 'beta', 'starter', 'trial', 'sandbox'],
|
||||
'professional'
|
||||
);
|
||||
|
||||
$client = dbnToolsFetchClient($db);
|
||||
if (!$client) {
|
||||
$apiKeyHash = hash('sha256', random_bytes(32));
|
||||
@@ -52,7 +87,7 @@ try {
|
||||
'contact_email' => $email,
|
||||
'industry' => 'Legal services',
|
||||
'country' => 'NO',
|
||||
'plan' => 'enterprise',
|
||||
'plan' => $plan,
|
||||
'api_key_hash' => $apiKeyHash,
|
||||
'api_key_prefix' => $apiKeyPrefix,
|
||||
'monthly_query_limit' => 10000,
|
||||
@@ -91,7 +126,7 @@ try {
|
||||
'contact_email' => $email,
|
||||
'industry' => 'Legal services',
|
||||
'country' => 'NO',
|
||||
'plan' => 'enterprise',
|
||||
'plan' => $plan,
|
||||
'monthly_query_limit' => 10000,
|
||||
'monthly_document_limit' => 1000,
|
||||
'monthly_user_limit' => 25,
|
||||
@@ -151,7 +186,7 @@ try {
|
||||
'Family Legal',
|
||||
'Family law corpus package for Do Better Norge legal tools.',
|
||||
'LAW',
|
||||
setupJson(['enterprise']),
|
||||
setupJson([$plan]),
|
||||
]);
|
||||
$packageId = (int)$db->lastInsertId();
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user