Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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 lib/BackgroundJob/HookRetryJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class HookRetryJob extends QueuedJob
* Constructor for HookRetryJob
*
* @param ITimeFactory $time Time factory
* @param MagicMapper $objectEntityMapper Object mapper
* @param MagicMapper $objectEntityMapper Object mapper
* @param SchemaMapper $schemaMapper Schema mapper
* @param WorkflowEngineRegistry $engineRegistry Engine registry
* @param CloudEventFormatter $cloudEventFormatter CloudEvent formatter
Expand Down
6 changes: 4 additions & 2 deletions lib/Controller/ConfigurationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1242,7 +1242,8 @@ private function importFromSource(callable $fetchConfig, array $params, string $

$configuration = $this->configurationMapper->insert($configuration);

$msg = '[ConfigurationController] Created configuration'." entity with ID {$configuration->getId()} for app {$appId}";
$configId = $configuration->getId();
$msg = "[ConfigurationController] Created configuration entity with ID {$configId} for app {$appId}";
$this->logger->info(
message: $msg,
context: ['file' => __FILE__, 'line' => __LINE__]
Expand All @@ -1267,7 +1268,8 @@ private function importFromSource(callable $fetchConfig, array $params, string $
// But we need to save the sync status.
$this->configurationMapper->update($configuration);

$msg = '[ConfigurationController] Successfully imported'." configuration {$configuration->getTitle()} from {$sourceType}";
$configTitle = $configuration->getTitle();
$msg = "[ConfigurationController] Successfully imported configuration {$configTitle} from {$sourceType}";
$this->logger->info(
message: $msg,
context: ['file' => __FILE__, 'line' => __LINE__]
Expand Down
14 changes: 7 additions & 7 deletions lib/Controller/DeletedController.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@
/**
* Constructor for the DeletedController
*
* @param string $appName The name of the app
* @param IRequest $request The request object
* @param MagicMapper $objectEntityMapper The object entity mapper
* @param RegisterMapper $registerMapper The register mapper
* @param SchemaMapper $schemaMapper The schema mapper
* @param ObjectService $objectService The object service
* @param IUserSession $userSession The user session
* @param string $appName The name of the app
* @param IRequest $request The request object
* @param MagicMapper $objectEntityMapper The object entity mapper
* @param RegisterMapper $registerMapper The register mapper
* @param SchemaMapper $schemaMapper The schema mapper
* @param ObjectService $objectService The object service
* @param IUserSession $userSession The user session
*
* @return void
*/
Expand Down Expand Up @@ -260,13 +260,13 @@
try {
// Get total deleted count.
$totalDeleted = $this->objectEntityMapper->countAll(
_filters: ['@self.deleted' => 'IS NOT NULL'],

Check failure on line 263 in lib/Controller/DeletedController.php

View workflow job for this annotation

GitHub Actions / quality / PHP Quality (psalm)

InvalidNamedArgument

lib/Controller/DeletedController.php:263:17: InvalidNamedArgument: Parameter $_filters does not exist on function OCA\OpenRegister\Db\MagicMapper::countAll (see https://psalm.dev/238)

Check failure on line 263 in lib/Controller/DeletedController.php

View workflow job for this annotation

GitHub Actions / quality / PHP Quality (psalm)

InvalidNamedArgument

lib/Controller/DeletedController.php:263:17: InvalidNamedArgument: Parameter $_filters does not exist on function OCA\OpenRegister\Db\MagicMapper::countAll (see https://psalm.dev/238)
);

// Get deleted today count.
$today = (new DateTime())->format('Y-m-d');
$deletedToday = $this->objectEntityMapper->countAll(
_filters: [

Check failure on line 269 in lib/Controller/DeletedController.php

View workflow job for this annotation

GitHub Actions / quality / PHP Quality (psalm)

InvalidNamedArgument

lib/Controller/DeletedController.php:269:17: InvalidNamedArgument: Parameter $_filters does not exist on function OCA\OpenRegister\Db\MagicMapper::countAll (see https://psalm.dev/238)

Check failure on line 269 in lib/Controller/DeletedController.php

View workflow job for this annotation

GitHub Actions / quality / PHP Quality (psalm)

InvalidNamedArgument

lib/Controller/DeletedController.php:269:17: InvalidNamedArgument: Parameter $_filters does not exist on function OCA\OpenRegister\Db\MagicMapper::countAll (see https://psalm.dev/238)
'@self.deleted' => 'IS NOT NULL',
'@self.deleted.deleted' => '>='.$today,
],
Expand All @@ -275,7 +275,7 @@
// Get deleted this week count.
$weekAgo = (new DateTime())->modify('-7 days')->format('Y-m-d');
$deletedThisWeek = $this->objectEntityMapper->countAll(
_filters: [

Check failure on line 278 in lib/Controller/DeletedController.php

View workflow job for this annotation

GitHub Actions / quality / PHP Quality (psalm)

InvalidNamedArgument

lib/Controller/DeletedController.php:278:17: InvalidNamedArgument: Parameter $_filters does not exist on function OCA\OpenRegister\Db\MagicMapper::countAll (see https://psalm.dev/238)

Check failure on line 278 in lib/Controller/DeletedController.php

View workflow job for this annotation

GitHub Actions / quality / PHP Quality (psalm)

InvalidNamedArgument

lib/Controller/DeletedController.php:278:17: InvalidNamedArgument: Parameter $_filters does not exist on function OCA\OpenRegister\Db\MagicMapper::countAll (see https://psalm.dev/238)
'@self.deleted' => 'IS NOT NULL',
'@self.deleted.deleted' => '>='.$weekAgo,
],
Expand Down
18 changes: 13 additions & 5 deletions lib/Controller/HealthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,18 @@ public function index(): JSONResponse
// Check filesystem.
$checks['filesystem'] = $this->checkFilesystem();
if ($checks['filesystem'] !== 'ok') {
$status = ($status === 'error') ? 'error' : 'degraded';
if ($status === 'error') {
$status = 'error';
} else {
$status = 'degraded';
}
}

$httpStatus = ($status === 'ok') ? Http::STATUS_OK : Http::STATUS_SERVICE_UNAVAILABLE;
if ($status === 'ok') {
$httpStatus = Http::STATUS_OK;
} else {
$httpStatus = Http::STATUS_SERVICE_UNAVAILABLE;
}

return new JSONResponse(
[
Expand Down Expand Up @@ -109,7 +117,7 @@ private function checkDatabase(): string
return 'ok';
} catch (\Exception $e) {
$this->logger->error('[HealthController] Database check failed', ['error' => $e->getMessage()]);
return 'failed: ' . $e->getMessage();
return 'failed: '.$e->getMessage();
}
}//end checkDatabase()

Expand All @@ -121,7 +129,7 @@ private function checkDatabase(): string
private function checkFilesystem(): string
{
try {
$tmpFile = sys_get_temp_dir() . '/openregister_health_' . getmypid();
$tmpFile = sys_get_temp_dir().'/openregister_health_'.getmypid();
$written = file_put_contents($tmpFile, 'health');
if ($written === false) {
return 'failed: cannot write to temp directory';
Expand All @@ -131,7 +139,7 @@ private function checkFilesystem(): string

return 'ok';
} catch (\Exception $e) {
return 'failed: ' . $e->getMessage();
return 'failed: '.$e->getMessage();
}
}//end checkFilesystem()

Expand Down
30 changes: 15 additions & 15 deletions lib/Controller/MetricsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ private function collectMetrics(): string

$lines[] = '# HELP openregister_info Application information';
$lines[] = '# TYPE openregister_info gauge';
$lines[] = 'openregister_info{version="' . $version . '",php_version="' . $phpVersion . '"} 1';
$lines[] = 'openregister_info{version="'.$version.'",php_version="'.$phpVersion.'"} 1';
$lines[] = '';

// App up gauge.
Expand All @@ -101,40 +101,40 @@ private function collectMetrics(): string
$lines[] = '';

// Registers total.
$registersTotal = $this->countTable('openregister_registers');
$registersTotal = $this->countTable(table: 'openregister_registers');
$lines[] = '# HELP openregister_registers_total Total number of registers';
$lines[] = '# TYPE openregister_registers_total gauge';
$lines[] = 'openregister_registers_total ' . $registersTotal;
$lines[] = 'openregister_registers_total '.$registersTotal;
$lines[] = '';

// Schemas total.
$schemasTotal = $this->countTable('openregister_schemas');
$schemasTotal = $this->countTable(table: 'openregister_schemas');
$lines[] = '# HELP openregister_schemas_total Total number of schemas';
$lines[] = '# TYPE openregister_schemas_total gauge';
$lines[] = 'openregister_schemas_total ' . $schemasTotal;
$lines[] = 'openregister_schemas_total '.$schemasTotal;
$lines[] = '';

// Objects total (by register and schema).
$lines[] = '# HELP openregister_objects_total Total objects by register and schema';
$lines[] = '# TYPE openregister_objects_total gauge';
$lines[] = '# HELP openregister_objects_total Total objects by register and schema';
$lines[] = '# TYPE openregister_objects_total gauge';
$objectCounts = $this->getObjectCountsByRegisterAndSchema();
foreach ($objectCounts as $row) {
$register = $this->sanitizeLabel($row['register_name'] ?? 'unknown');
$schema = $this->sanitizeLabel($row['schema_name'] ?? 'unknown');
$register = $this->sanitizeLabel(value: $row['register_name'] ?? 'unknown');
$schema = $this->sanitizeLabel(value: $row['schema_name'] ?? 'unknown');
$count = (int) $row['object_count'];
$lines[] = 'openregister_objects_total{register="' . $register . '",schema="' . $schema . '"} ' . $count;
$lines[] = 'openregister_objects_total{register="'.$register.'",schema="'.$schema.'"} '.$count;
}

$lines[] = '';

// Search requests total (from metrics table if it exists).
$searchCount = $this->countMetricsByType('search_');
$searchCount = $this->countMetricsByType(typePrefix: 'search_');
$lines[] = '# HELP openregister_search_requests_total Total search requests';
$lines[] = '# TYPE openregister_search_requests_total counter';
$lines[] = 'openregister_search_requests_total ' . $searchCount;
$lines[] = 'openregister_search_requests_total '.$searchCount;
$lines[] = '';

return implode("\n", $lines) . "\n";
return implode("\n", $lines)."\n";
}//end collectMetrics()

/**
Expand All @@ -156,7 +156,7 @@ private function countTable(string $table): int

return (int) ($row['cnt'] ?? 0);
} catch (\Exception $e) {
$this->logger->warning('[MetricsController] Failed to count table ' . $table, ['error' => $e->getMessage()]);
$this->logger->warning('[MetricsController] Failed to count table '.$table, ['error' => $e->getMessage()]);
return 0;
}
}//end countTable()
Expand Down Expand Up @@ -201,7 +201,7 @@ private function countMetricsByType(string $typePrefix): int
$qb = $this->db->getQueryBuilder();
$qb->select($qb->func()->count('*', 'cnt'))
->from('openregister_metrics')
->where($qb->expr()->like('metric_type', $qb->createNamedParameter($typePrefix . '%')));
->where($qb->expr()->like('metric_type', $qb->createNamedParameter($typePrefix.'%')));

$result = $qb->executeQuery();
$row = $result->fetch();
Expand Down
36 changes: 18 additions & 18 deletions lib/Controller/ObjectsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,21 +93,21 @@
/**
* Constructor for the ObjectsController
*
* @param string $appName The name of the app
* @param IRequest $request The request object
* @param IAppConfig $config The app configuration object
* @param IAppManager $appManager The app manager
* @param ContainerInterface $container The DI container
* @param RegisterMapper $registerMapper The register mapper
* @param SchemaMapper $schemaMapper The schema mapper
* @param AuditTrailMapper $auditTrailMapper The audit trail mapper
* @param ObjectService $objectService The object service
* @param IUserSession $userSession The user session
* @param IGroupManager $groupManager The group manager
* @param ExportService $exportService The export service
* @param ImportService $importService The import service
* @param WebhookService $webhookService The webhook service (optional)
* @param LoggerInterface $logger The logger (optional)
* @param string $appName The name of the app
* @param IRequest $request The request object
* @param IAppConfig $config The app configuration object
* @param IAppManager $appManager The app manager
* @param ContainerInterface $container The DI container
* @param RegisterMapper $registerMapper The register mapper
* @param SchemaMapper $schemaMapper The schema mapper
* @param AuditTrailMapper $auditTrailMapper The audit trail mapper
* @param ObjectService $objectService The object service
* @param IUserSession $userSession The user session
* @param IGroupManager $groupManager The group manager
* @param ExportService $exportService The export service
* @param ImportService $importService The import service
* @param WebhookService $webhookService The webhook service (optional)
* @param LoggerInterface $logger The logger (optional)
*
* @return void
*
Expand Down Expand Up @@ -525,7 +525,7 @@
'offset' => $offset,
'page' => $page,
'filters' => $params,
'sort' => $this->normalizeOrderParameter($params['order'] ?? $params['_order'] ?? []),
'sort' => $this->normalizeOrderParameter(order: $params['order'] ?? $params['_order'] ?? []),
'_search' => ($params['_search'] ?? null),
'_extend' => $this->normalizeExtendParameter(extend: $params['extend'] ?? $params['_extend'] ?? null),
'_fields' => ($params['fields'] ?? $params['_fields'] ?? null),
Expand Down Expand Up @@ -955,8 +955,8 @@
$rbac = filter_var($params['rbac'] ?? true, FILTER_VALIDATE_BOOLEAN);
// Check both _multi and multi params (URL uses _multi, but we also support multi).
$multiExplicitlySet = isset($params['_multi']) || isset($params['multi']);
$multi = filter_var($params['_multi'] ?? $params['multi'] ?? true, FILTER_VALIDATE_BOOLEAN);
$deleted = filter_var($params['deleted'] ?? false, FILTER_VALIDATE_BOOLEAN);
$multi = filter_var($params['_multi'] ?? $params['multi'] ?? true, FILTER_VALIDATE_BOOLEAN);
$deleted = filter_var($params['deleted'] ?? false, FILTER_VALIDATE_BOOLEAN);

// Check if magic mapping is enabled for this register+schema.
$registerEntity = $resolved['registerEntity'] ?? null;
Expand Down Expand Up @@ -2304,7 +2304,7 @@
$deleteHandler = $objectService->getDeleteHandler();
$analysis = $deleteHandler->canDelete($objectEntity);

return new JSONResponse(data: $analysis->toArray(), statusCode: 200);

Check failure on line 2307 in lib/Controller/ObjectsController.php

View workflow job for this annotation

GitHub Actions / quality / PHP Quality (psalm)

UndefinedClass

lib/Controller/ObjectsController.php:2307:43: UndefinedClass: Class, interface or enum named OCA\OpenRegister\Dto\DeletionAnalysis does not exist (see https://psalm.dev/019)

Check failure on line 2307 in lib/Controller/ObjectsController.php

View workflow job for this annotation

GitHub Actions / quality / PHP Quality (psalm)

UndefinedClass

lib/Controller/ObjectsController.php:2307:43: UndefinedClass: Class, interface or enum named OCA\OpenRegister\Dto\DeletionAnalysis does not exist (see https://psalm.dev/019)
} catch (\OCP\AppFramework\Db\DoesNotExistException $exception) {
return new JSONResponse(data: ['error' => 'Object not found'], statusCode: 404);
} catch (\Exception $exception) {
Expand Down
9 changes: 6 additions & 3 deletions lib/Controller/RegistersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class RegistersController extends Controller
* @param string $appName Application name
* @param IRequest $request HTTP request object
* @param RegisterService $registerService Register service for business logic
* @param MagicMapper $objectEntityMapper Object entity mapper for database operations
* @param MagicMapper $objectEntityMapper Object entity mapper for database operations
* @param UploadService $uploadService Upload service for file uploads
* @param LoggerInterface $logger Logger for error tracking
* @param IUserSession $userSession User session service
Expand Down Expand Up @@ -303,7 +303,9 @@ public function index(): JSONResponse
schemas: $expandedSchemas
);

$msg = '[RegistersController] Schema counts for register '.$register['id'].': '.json_encode($schemaCounts);
$registerId = $register['id'];
$countsJson = json_encode($schemaCounts);
$msg = "[RegistersController] Schema counts for register {$registerId}: {$countsJson}";
$this->logger->debug(
message: $msg,
context: ['file' => __FILE__, 'line' => __LINE__]
Expand All @@ -326,7 +328,8 @@ public function index(): JSONResponse
$schema['stats'] = [
'objects' => $schemaCounts[$schemaId],
];
$msg = '[RegistersController] Set stats for schema '."{$schemaId}: ".json_encode($schema['stats']);
$statsJson = json_encode($schema['stats']);
$msg = "[RegistersController] Set stats for schema {$schemaId}: {$statsJson}";
$this->logger->debug(
message: $msg,
context: ['file' => __FILE__, 'line' => __LINE__]
Expand Down
2 changes: 1 addition & 1 deletion lib/Controller/SchemasController.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
* @param IRequest $request HTTP request object
* @param IAppConfig $config App configuration for settings
* @param SchemaMapper $schemaMapper Schema mapper for database operations
* @param MagicMapper $objectEntityMapper Object entity mapper for object queries
* @param MagicMapper $objectEntityMapper Object entity mapper for object queries
* @param DownloadService $downloadService Download service for file downloads
* @param UploadService $uploadService Upload service for file uploads
* @param AuditTrailMapper $auditTrailMapper Audit trail mapper for log statistics
Expand Down Expand Up @@ -222,7 +222,7 @@

// Batch-load all statistics in 3 queries instead of N*2 queries.
$registerCounts = $this->schemaMapper->getRegisterCountPerSchema();
$objectStats = $this->objectEntityMapper->getStatisticsGroupedBySchema(schemaIds: $schemaIds);

Check failure on line 225 in lib/Controller/SchemasController.php

View workflow job for this annotation

GitHub Actions / quality / PHP Quality (psalm)

UndefinedMethod

lib/Controller/SchemasController.php:225:58: UndefinedMethod: Method OCA\OpenRegister\Db\MagicMapper::getStatisticsGroupedBySchema does not exist (see https://psalm.dev/022)

Check failure on line 225 in lib/Controller/SchemasController.php

View workflow job for this annotation

GitHub Actions / quality / PHP Quality (psalm)

UndefinedMethod

lib/Controller/SchemasController.php:225:58: UndefinedMethod: Method OCA\OpenRegister\Db\MagicMapper::getStatisticsGroupedBySchema does not exist (see https://psalm.dev/022)
$logStats = $this->auditTrailMapper->getStatisticsGroupedBySchema(schemaIds: $schemaIds);

foreach ($schemasArr as &$schema) {
Expand Down
12 changes: 6 additions & 6 deletions lib/Db/AbstractObjectMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ abstract class AbstractObjectMapper
* @param Register|null $register Optional register to filter by.
* @param Schema|null $schema Optional schema to filter by.
* @param bool $includeDeleted Whether to include deleted objects.
* @param bool $_rbac Whether to apply RBAC checks (default: true).
* @param bool $_multitenancy Whether to apply multitenancy filtering (default: true).
* @param bool $_rbac Whether to apply RBAC checks (default: true).
* @param bool $_multitenancy Whether to apply multitenancy filtering (default: true).
*
* @return ObjectEntity The found object.
*
Expand Down Expand Up @@ -300,8 +300,8 @@ abstract public function getFacetableFieldsFromSchemas(array $baseQuery=[]): arr
*
* @param array $query Query parameters.
* @param string|null $activeOrgUuid Active organisation UUID.
* @param bool $_rbac Whether to apply RBAC checks.
* @param bool $_multitenancy Whether to apply multitenancy filtering.
* @param bool $_rbac Whether to apply RBAC checks.
* @param bool $_multitenancy Whether to apply multitenancy filtering.
* @param array|null $ids Array of IDs or UUIDs to filter by.
* @param string|null $uses Value that must be present in relations.
*
Expand All @@ -325,8 +325,8 @@ abstract public function searchObjects(
*
* @param array $query Query parameters.
* @param string|null $activeOrgUuid Active organisation UUID.
* @param bool $_rbac Whether to apply RBAC checks.
* @param bool $_multitenancy Whether to apply multitenancy filtering.
* @param bool $_rbac Whether to apply RBAC checks.
* @param bool $_multitenancy Whether to apply multitenancy filtering.
* @param array|null $ids Array of IDs or UUIDs to filter by.
* @param string|null $uses Value that must be present in relations.
*
Expand Down
4 changes: 2 additions & 2 deletions lib/Db/AuditTrailMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class AuditTrailMapper extends QBMapper
/**
* Constructor for the AuditTrailMapper
*
* @param IDBConnection $db The database connection
* @param IDBConnection $db The database connection
* @param \Psr\Container\ContainerInterface $container DI container for lazy mapper resolution
*/
public function __construct(
Expand Down Expand Up @@ -439,7 +439,7 @@ public function revertObject($identifier, $until=null, bool $overwriteVersion=fa
{
// Get the current object (lazy-resolved to avoid circular DI).
$objectMapper = $this->container->get(MagicMapper::class);
$object = $objectMapper->find($identifier);
$object = $objectMapper->find($identifier);

// Get audit trail entries until the specified point.
$auditTrails = $this->findByObjectUntil(
Expand Down
Loading
Loading