diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2025-05-15 16:32:59 +0200 |
---|---|---|
committer | Christoph Wurst <christoph@winzerhof-wurst.at> | 2025-05-15 16:32:59 +0200 |
commit | 0fec4a3c7a882be9c96b9c54b2899380d89ad099 (patch) | |
tree | 6b3fa789e97907d2a2d24bb0763aae1ae78a7abf | |
parent | 4aa4972550bec08faf477113f223475f7fb3e5d2 (diff) | |
download | nextcloud-server-fix/cron/no-constructor-without-args.tar.gz nextcloud-server-fix/cron/no-constructor-without-args.zip |
fix(cron): do not build job classes with constructor argsfix/cron/no-constructor-without-args
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
-rw-r--r-- | lib/private/BackgroundJob/JobList.php | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/lib/private/BackgroundJob/JobList.php b/lib/private/BackgroundJob/JobList.php index 0d88200cff7..199beace1f1 100644 --- a/lib/private/BackgroundJob/JobList.php +++ b/lib/private/BackgroundJob/JobList.php @@ -18,6 +18,7 @@ use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\IConfig; use OCP\IDBConnection; use Psr\Log\LoggerInterface; +use ReflectionClass; use function get_class; use function json_encode; use function min; @@ -310,7 +311,12 @@ class JobList implements IJobList { } catch (QueryException $e) { if (class_exists($row['class'])) { $class = $row['class']; - $job = new $class(); + $reflectedClass = new ReflectionClass($row['class']); + $constructor = $reflectedClass->getConstructor(); + if ($constructor === null || $constructor->getNumberOfParameters() === 0) { + $job = new $class(); + } + $this->logger->warning('failed to create instance of background job: ' . $row['class'] . ' (with fallback)', ['app' => 'cron', 'exception' => $e]); } else { $this->logger->warning('failed to create instance of background job: ' . $row['class'], ['app' => 'cron', 'exception' => $e]); // Remove job from disabled app or old version of an app |