From b44f6a29574861905de345e4e44152f53f8f8f8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Fri, 13 Mar 2026 12:00:16 +0100 Subject: [PATCH] fix: Remove static vars in TaskProcessing, TextProcessing, TextToImage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- lib/private/TaskProcessing/Db/Task.php | 8 ++++---- lib/private/TaskProcessing/Db/TaskMapper.php | 16 ++++++++-------- lib/private/TextProcessing/Db/Task.php | 8 ++++---- lib/private/TextProcessing/Db/TaskMapper.php | 6 +++--- lib/private/TextProcessing/Manager.php | 17 ++++++++++------- lib/private/TextToImage/Db/Task.php | 8 ++++---- lib/private/TextToImage/Db/TaskMapper.php | 6 +++--- 7 files changed, 36 insertions(+), 33 deletions(-) diff --git a/lib/private/TaskProcessing/Db/Task.php b/lib/private/TaskProcessing/Db/Task.php index 4a874b7fdb7..97badb58021 100644 --- a/lib/private/TaskProcessing/Db/Task.php +++ b/lib/private/TaskProcessing/Db/Task.php @@ -76,12 +76,12 @@ class Task extends Entity { /** * @var string[] */ - public static array $columns = ['id', 'last_updated', 'type', 'input', 'output', 'status', 'user_id', 'app_id', 'custom_id', 'completion_expected_at', 'error_message', 'progress', 'webhook_uri', 'webhook_method', 'scheduled_at', 'started_at', 'ended_at', 'allow_cleanup', 'user_facing_error_message', 'include_watermark']; + public const array COLUMNS = ['id', 'last_updated', 'type', 'input', 'output', 'status', 'user_id', 'app_id', 'custom_id', 'completion_expected_at', 'error_message', 'progress', 'webhook_uri', 'webhook_method', 'scheduled_at', 'started_at', 'ended_at', 'allow_cleanup', 'user_facing_error_message', 'include_watermark']; /** * @var string[] */ - public static array $fields = ['id', 'lastUpdated', 'type', 'input', 'output', 'status', 'userId', 'appId', 'customId', 'completionExpectedAt', 'errorMessage', 'progress', 'webhookUri', 'webhookMethod', 'scheduledAt', 'startedAt', 'endedAt', 'allowCleanup', 'userFacingErrorMessage', 'includeWatermark']; + public const array FIELDS = ['id', 'lastUpdated', 'type', 'input', 'output', 'status', 'userId', 'appId', 'customId', 'completionExpectedAt', 'errorMessage', 'progress', 'webhookUri', 'webhookMethod', 'scheduledAt', 'startedAt', 'endedAt', 'allowCleanup', 'userFacingErrorMessage', 'includeWatermark']; public function __construct() { // add types in constructor @@ -108,9 +108,9 @@ class Task extends Entity { } public function toRow(): array { - return array_combine(self::$columns, array_map(function ($field) { + return array_combine(self::COLUMNS, array_map(function ($field) { return $this->{'get' . ucfirst($field)}(); - }, self::$fields)); + }, self::FIELDS)); } public static function fromPublicTask(OCPTask $task): self { diff --git a/lib/private/TaskProcessing/Db/TaskMapper.php b/lib/private/TaskProcessing/Db/TaskMapper.php index 544fefa40d2..4e5e1c4695a 100644 --- a/lib/private/TaskProcessing/Db/TaskMapper.php +++ b/lib/private/TaskProcessing/Db/TaskMapper.php @@ -38,7 +38,7 @@ class TaskMapper extends QBMapper { */ public function find(int $id): Task { $qb = $this->db->getQueryBuilder(); - $qb->select(Task::$columns) + $qb->select(Task::COLUMNS) ->from($this->tableName) ->where($qb->expr()->eq('id', $qb->createPositionalParameter($id))); return $this->findEntity($qb); @@ -53,7 +53,7 @@ class TaskMapper extends QBMapper { */ public function findOldestScheduledByType(array $taskTypes, array $taskIdsToIgnore): Task { $qb = $this->db->getQueryBuilder(); - $qb->select(Task::$columns) + $qb->select(Task::COLUMNS) ->from($this->tableName) ->where($qb->expr()->eq('status', $qb->createPositionalParameter(\OCP\TaskProcessing\Task::STATUS_SCHEDULED, IQueryBuilder::PARAM_INT))) ->setMaxResults(1) @@ -85,7 +85,7 @@ class TaskMapper extends QBMapper { */ public function findByIdAndUser(int $id, ?string $userId): Task { $qb = $this->db->getQueryBuilder(); - $qb->select(Task::$columns) + $qb->select(Task::COLUMNS) ->from($this->tableName) ->where($qb->expr()->eq('id', $qb->createPositionalParameter($id))); if ($userId === null) { @@ -105,7 +105,7 @@ class TaskMapper extends QBMapper { */ public function findByUserAndTaskType(?string $userId, ?string $taskType = null, ?string $customId = null): array { $qb = $this->db->getQueryBuilder(); - $qb->select(Task::$columns) + $qb->select(Task::COLUMNS) ->from($this->tableName) ->where($qb->expr()->eq('user_id', $qb->createPositionalParameter($userId))); if ($taskType !== null) { @@ -126,7 +126,7 @@ class TaskMapper extends QBMapper { */ public function findUserTasksByApp(?string $userId, string $appId, ?string $customId = null): array { $qb = $this->db->getQueryBuilder(); - $qb->select(Task::$columns) + $qb->select(Task::COLUMNS) ->from($this->tableName) ->where($qb->expr()->eq('user_id', $qb->createPositionalParameter($userId))) ->andWhere($qb->expr()->eq('app_id', $qb->createPositionalParameter($appId))); @@ -151,7 +151,7 @@ class TaskMapper extends QBMapper { ?string $userId, ?string $taskType = null, ?string $appId = null, ?string $customId = null, ?int $status = null, ?int $scheduleAfter = null, ?int $endedBefore = null): array { $qb = $this->db->getQueryBuilder(); - $qb->select(Task::$columns) + $qb->select(Task::COLUMNS) ->from($this->tableName); // empty string: no userId filter @@ -205,7 +205,7 @@ class TaskMapper extends QBMapper { */ public function getTasksToCleanup(int $timeout, bool $force = false): \Generator { $qb = $this->db->getQueryBuilder(); - $qb->select(Task::$columns) + $qb->select(Task::COLUMNS) ->from($this->tableName) ->where($qb->expr()->lt('last_updated', $qb->createPositionalParameter($this->timeFactory->getDateTime()->getTimestamp() - $timeout))); if (!$force) { @@ -244,7 +244,7 @@ class TaskMapper extends QBMapper { */ public function findNOldestScheduledByType(array $taskTypes, array $taskIdsToIgnore, int $numberOfTasks) { $qb = $this->db->getQueryBuilder(); - $qb->select(Task::$columns) + $qb->select(Task::COLUMNS) ->from($this->tableName) ->where($qb->expr()->eq('status', $qb->createPositionalParameter(\OCP\TaskProcessing\Task::STATUS_SCHEDULED, IQueryBuilder::PARAM_INT))) ->setMaxResults($numberOfTasks) diff --git a/lib/private/TextProcessing/Db/Task.php b/lib/private/TextProcessing/Db/Task.php index b7df44ae838..1bb018415ee 100644 --- a/lib/private/TextProcessing/Db/Task.php +++ b/lib/private/TextProcessing/Db/Task.php @@ -46,12 +46,12 @@ class Task extends Entity { /** * @var string[] */ - public static array $columns = ['id', 'last_updated', 'type', 'input', 'output', 'status', 'user_id', 'app_id', 'identifier', 'completion_expected_at']; + public const array COLUMNS = ['id', 'last_updated', 'type', 'input', 'output', 'status', 'user_id', 'app_id', 'identifier', 'completion_expected_at']; /** * @var string[] */ - public static array $fields = ['id', 'lastUpdated', 'type', 'input', 'output', 'status', 'userId', 'appId', 'identifier', 'completionExpectedAt']; + public const array FIELDS = ['id', 'lastUpdated', 'type', 'input', 'output', 'status', 'userId', 'appId', 'identifier', 'completionExpectedAt']; public function __construct() { // add types in constructor @@ -68,9 +68,9 @@ class Task extends Entity { } public function toRow(): array { - return array_combine(self::$columns, array_map(function ($field) { + return array_combine(self::COLUMNS, array_map(function ($field) { return $this->{'get' . ucfirst($field)}(); - }, self::$fields)); + }, self::FIELDS)); } public static function fromPublicTask(OCPTask $task): Task { diff --git a/lib/private/TextProcessing/Db/TaskMapper.php b/lib/private/TextProcessing/Db/TaskMapper.php index cafcae24362..a0d51d34c77 100644 --- a/lib/private/TextProcessing/Db/TaskMapper.php +++ b/lib/private/TextProcessing/Db/TaskMapper.php @@ -37,7 +37,7 @@ class TaskMapper extends QBMapper { */ public function find(int $id): Task { $qb = $this->db->getQueryBuilder(); - $qb->select(Task::$columns) + $qb->select(Task::COLUMNS) ->from($this->tableName) ->where($qb->expr()->eq('id', $qb->createPositionalParameter($id))); return $this->findEntity($qb); @@ -53,7 +53,7 @@ class TaskMapper extends QBMapper { */ public function findByIdAndUser(int $id, ?string $userId): Task { $qb = $this->db->getQueryBuilder(); - $qb->select(Task::$columns) + $qb->select(Task::COLUMNS) ->from($this->tableName) ->where($qb->expr()->eq('id', $qb->createPositionalParameter($id))); if ($userId === null) { @@ -73,7 +73,7 @@ class TaskMapper extends QBMapper { */ public function findUserTasksByApp(string $userId, string $appId, ?string $identifier = null): array { $qb = $this->db->getQueryBuilder(); - $qb->select(Task::$columns) + $qb->select(Task::COLUMNS) ->from($this->tableName) ->where($qb->expr()->eq('user_id', $qb->createPositionalParameter($userId))) ->andWhere($qb->expr()->eq('app_id', $qb->createPositionalParameter($appId))); diff --git a/lib/private/TextProcessing/Manager.php b/lib/private/TextProcessing/Manager.php index 15a6823d7ee..85e2db1221f 100644 --- a/lib/private/TextProcessing/Manager.php +++ b/lib/private/TextProcessing/Manager.php @@ -44,7 +44,10 @@ class Manager implements IManager { /** @var ?IProvider[] */ private ?array $providers = null; - private static array $taskProcessingCompatibleTaskTypes = [ + /** + * @var array + */ + private const array COMPATIBLE_TASK_TYPES = [ FreePromptTaskType::class => TextToText::ID, HeadlineTaskType::class => TextToTextHeadline::ID, SummaryTaskType::class => TextToTextSummary::ID, @@ -93,7 +96,7 @@ class Manager implements IManager { public function hasProviders(): bool { // check if task processing equivalent types are available $taskTaskTypes = $this->taskProcessingManager->getAvailableTaskTypes(); - foreach (self::$taskProcessingCompatibleTaskTypes as $textTaskTypeClass => $taskTaskTypeId) { + foreach (self::COMPATIBLE_TASK_TYPES as $textTaskTypeClass => $taskTaskTypeId) { if (isset($taskTaskTypes[$taskTaskTypeId])) { return true; } @@ -118,7 +121,7 @@ class Manager implements IManager { // check if task processing equivalent types are available $taskTaskTypes = $this->taskProcessingManager->getAvailableTaskTypes(); - foreach (self::$taskProcessingCompatibleTaskTypes as $textTaskTypeClass => $taskTaskTypeId) { + foreach (self::COMPATIBLE_TASK_TYPES as $textTaskTypeClass => $taskTaskTypeId) { if (isset($taskTaskTypes[$taskTaskTypeId])) { $tasks[$textTaskTypeClass] = true; } @@ -138,9 +141,9 @@ class Manager implements IManager { public function runTask(OCPTask $task): string { // try to run a task processing task if possible $taskTypeClass = $task->getType(); - if (isset(self::$taskProcessingCompatibleTaskTypes[$taskTypeClass]) && isset($this->taskProcessingManager->getAvailableTaskTypes()[self::$taskProcessingCompatibleTaskTypes[$taskTypeClass]])) { + if (isset(self::COMPATIBLE_TASK_TYPES[$taskTypeClass]) && isset($this->taskProcessingManager->getAvailableTaskTypes()[self::COMPATIBLE_TASK_TYPES[$taskTypeClass]])) { try { - $taskProcessingTaskTypeId = self::$taskProcessingCompatibleTaskTypes[$taskTypeClass]; + $taskProcessingTaskTypeId = self::COMPATIBLE_TASK_TYPES[$taskTypeClass]; $taskProcessingTask = new \OCP\TaskProcessing\Task( $taskProcessingTaskTypeId, ['input' => $task->getInput()], @@ -227,8 +230,8 @@ class Manager implements IManager { $task->setStatus(OCPTask::STATUS_SCHEDULED); $providers = $this->getPreferredProviders($task); $equivalentTaskProcessingTypeAvailable = ( - isset(self::$taskProcessingCompatibleTaskTypes[$task->getType()]) - && isset($this->taskProcessingManager->getAvailableTaskTypes()[self::$taskProcessingCompatibleTaskTypes[$task->getType()]]) + isset(self::COMPATIBLE_TASK_TYPES[$task->getType()]) + && isset($this->taskProcessingManager->getAvailableTaskTypes()[self::COMPATIBLE_TASK_TYPES[$task->getType()]]) ); if (count($providers) === 0 && !$equivalentTaskProcessingTypeAvailable) { throw new PreConditionNotMetException('No LanguageModel provider is installed that can handle this task'); diff --git a/lib/private/TextToImage/Db/Task.php b/lib/private/TextToImage/Db/Task.php index 3ae8a72392a..09155d17690 100644 --- a/lib/private/TextToImage/Db/Task.php +++ b/lib/private/TextToImage/Db/Task.php @@ -49,12 +49,12 @@ class Task extends Entity { /** * @var string[] */ - public static array $columns = ['id', 'last_updated', 'input', 'status', 'user_id', 'app_id', 'identifier', 'number_of_images', 'completion_expected_at']; + public const array COLUMNS = ['id', 'last_updated', 'input', 'status', 'user_id', 'app_id', 'identifier', 'number_of_images', 'completion_expected_at']; /** * @var string[] */ - public static array $fields = ['id', 'lastUpdated', 'input', 'status', 'userId', 'appId', 'identifier', 'numberOfImages', 'completionExpectedAt']; + public const array FIELDS = ['id', 'lastUpdated', 'input', 'status', 'userId', 'appId', 'identifier', 'numberOfImages', 'completionExpectedAt']; public function __construct() { // add types in constructor @@ -70,9 +70,9 @@ class Task extends Entity { } public function toRow(): array { - return array_combine(self::$columns, array_map(function ($field) { + return array_combine(self::COLUMNS, array_map(function ($field) { return $this->{'get' . ucfirst($field)}(); - }, self::$fields)); + }, self::FIELDS)); } public static function fromPublicTask(OCPTask $task): Task { diff --git a/lib/private/TextToImage/Db/TaskMapper.php b/lib/private/TextToImage/Db/TaskMapper.php index f500443f70b..58cec7b5a65 100644 --- a/lib/private/TextToImage/Db/TaskMapper.php +++ b/lib/private/TextToImage/Db/TaskMapper.php @@ -38,7 +38,7 @@ class TaskMapper extends QBMapper { */ public function find(int $id): Task { $qb = $this->db->getQueryBuilder(); - $qb->select(Task::$columns) + $qb->select(Task::COLUMNS) ->from($this->tableName) ->where($qb->expr()->eq('id', $qb->createPositionalParameter($id))); return $this->findEntity($qb); @@ -54,7 +54,7 @@ class TaskMapper extends QBMapper { */ public function findByIdAndUser(int $id, ?string $userId): Task { $qb = $this->db->getQueryBuilder(); - $qb->select(Task::$columns) + $qb->select(Task::COLUMNS) ->from($this->tableName) ->where($qb->expr()->eq('id', $qb->createPositionalParameter($id))); if ($userId === null) { @@ -74,7 +74,7 @@ class TaskMapper extends QBMapper { */ public function findUserTasksByApp(?string $userId, string $appId, ?string $identifier = null): array { $qb = $this->db->getQueryBuilder(); - $qb->select(Task::$columns) + $qb->select(Task::COLUMNS) ->from($this->tableName) ->where($qb->expr()->eq('user_id', $qb->createPositionalParameter($userId))) ->andWhere($qb->expr()->eq('app_id', $qb->createPositionalParameter($appId)));