Skip to content

Commit

Permalink
chore: update types
Browse files Browse the repository at this point in the history
Signed-off-by: Vitor Mattos <[email protected]>
  • Loading branch information
vitormattos authored and backportbot-libresign[bot] committed Jan 12, 2025
1 parent 13fa94a commit 4775fe6
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions lib/Migration/Version11000Date20250103005204.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,21 @@
namespace OCA\Libresign\Migration;

use Closure;
use OCA\Libresign\AppInfo\Application;
use OCP\DB\ISchemaWrapper;
use OCP\DB\Types;
use OCP\IAppConfig;
use OCP\IDBConnection;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;

class Version11000Date20250103005204 extends SimpleMigrationStep {
public function __construct(
private IAppConfig $appConfig,
private IDBConnection $connection,
) {
}

/**
* @param IOutput $output
* @param Closure(): ISchemaWrapper $schemaClosure
Expand All @@ -41,6 +50,39 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
'length' => 64,
]);
}

$qb = $this->connection->getQueryBuilder();
$items = $this->appConfig->getAllValues(Application::APP_ID);
$qb->update('appconfig')
->set('type', $qb->createParameter('type'))
->where($qb->expr()->eq('appid', $qb->createParameter('appid')))
->andWhere($qb->expr()->eq('configkey', $qb->createParameter('configkey')));
foreach ($items as $key => $value) {
if (in_array($key, ['approval_group', 'groups_request_sign', 'identify_methods', 'root_cert', 'rootCert']) && !is_array($value)) {
$qb->setParameter('type', IAppConfig::VALUE_ARRAY);
$qb->setParameter('appid', Application::APP_ID);
$qb->setParameter('configkey', $key);
$qb->executeStatement();
} elseif (in_array($key, ['add_footer', 'collect_metadata', 'identification_documents', 'make_validation_url_private', 'notify_unsigned_user', 'write_qrcode_on_footer']) && !is_bool($value)) {
$qb->setParameter('type', IAppConfig::VALUE_BOOL);
$qb->setParameter('appid', Application::APP_ID);
$qb->setParameter('configkey', $key);
$qb->executeStatement();
} elseif (in_array($key, ['expiry_in_days', 'length_of_page', 'maximum_validity']) && !is_int($value)) {
$qb->setParameter('type', IAppConfig::VALUE_INT);
$qb->setParameter('appid', Application::APP_ID);
$qb->setParameter('configkey', $key);
$qb->executeStatement();
}
}
if (array_key_exists('root_cert', $items)) {
if (!array_key_exists('rootCert', $items)) {
$value = $this->appConfig->getValueArray(Application::APP_ID, 'root_cert');
$this->appConfig->setValueArray(Application::APP_ID, 'rootCert', $value);
}
$this->appConfig->deleteKey(Application::APP_ID, 'root_cert');
}

return $schema;
}
}

0 comments on commit 4775fe6

Please sign in to comment.