mirror of
https://github.com/nextcloud/app_api.git
synced 2026-01-13 20:19:21 +00:00
fix: Fix cyclic dependency
This commit is contained in:
@ -11,6 +11,8 @@ namespace OCA\AppAPI\Controller;
|
||||
|
||||
use OCA\AppAPI\AppInfo\Application;
|
||||
use OCA\AppAPI\Attribute\AppAPIAuth;
|
||||
use OCA\AppAPI\Service\AppAPIService;
|
||||
use OCA\AppAPI\Service\ExAppService;
|
||||
use OCA\AppAPI\Service\ProvidersAI\TaskProcessingService;
|
||||
use OCP\AppFramework\Http;
|
||||
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
|
||||
@ -26,10 +28,14 @@ class TaskProcessingController extends OCSController {
|
||||
public function __construct(
|
||||
IRequest $request,
|
||||
private readonly TaskProcessingService $taskProcessingService,
|
||||
private readonly AppAPIService $appAPIService,
|
||||
private readonly ExAppService $exAppService,
|
||||
) {
|
||||
parent::__construct(Application::APP_ID, $request);
|
||||
|
||||
$this->request = $request;
|
||||
$this->taskProcessingService->setAppAPIService($this->appAPIService);
|
||||
$this->taskProcessingService->setExAppService($this->exAppService);
|
||||
}
|
||||
|
||||
#[NoCSRFRequired]
|
||||
|
||||
@ -52,6 +52,7 @@ class AppAPIService {
|
||||
private readonly HarpService $harpService,
|
||||
) {
|
||||
$this->client = $clientService->newClient();
|
||||
$this->exAppService->setAppAPIService($this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -36,6 +36,7 @@ use SimpleXMLElement;
|
||||
|
||||
class ExAppService {
|
||||
private ?ICache $cache = null;
|
||||
private AppAPIService $appAPIService;
|
||||
|
||||
public function __construct(
|
||||
private readonly LoggerInterface $logger,
|
||||
@ -66,6 +67,7 @@ class ExAppService {
|
||||
$this->cache = $cacheFactory->createDistributed(Application::APP_ID . '/service');
|
||||
}
|
||||
}
|
||||
$this->taskProcessingService->setExAppService($this);
|
||||
}
|
||||
|
||||
public function getExApp(string $appId): ?ExApp {
|
||||
@ -446,4 +448,9 @@ class ExAppService {
|
||||
$this->logger->debug(sprintf('Error while unregistering ExApp %s webhooks: %s', $appId, $e->getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
public function setAppAPIService(AppAPIService $appAPIService): void {
|
||||
$this->appAPIService = $appAPIService;
|
||||
$this->taskProcessingService->setAppAPIService($this->appAPIService);
|
||||
}
|
||||
}
|
||||
|
||||
@ -13,8 +13,8 @@ use JsonException;
|
||||
use OCA\AppAPI\AppInfo\Application;
|
||||
use OCA\AppAPI\Db\TaskProcessing\TaskProcessingProvider;
|
||||
use OCA\AppAPI\Db\TaskProcessing\TaskProcessingProviderMapper;
|
||||
use OCA\AppAPI\PublicFunctions;
|
||||
use OCA\AppAPI\Service\AppAPIService;
|
||||
use OCA\AppAPI\Service\ExAppService;
|
||||
use OCP\AppFramework\Bootstrap\IRegistrationContext;
|
||||
use OCP\AppFramework\Db\DoesNotExistException;
|
||||
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
|
||||
@ -24,8 +24,8 @@ use OCP\ICacheFactory;
|
||||
use OCP\IServerContainer;
|
||||
use OCP\TaskProcessing\EShapeType;
|
||||
use OCP\TaskProcessing\IProvider;
|
||||
use OCP\TaskProcessing\ITriggerableProvider;
|
||||
use OCP\TaskProcessing\ITaskType;
|
||||
use OCP\TaskProcessing\ITriggerableProvider;
|
||||
use OCP\TaskProcessing\ShapeDescriptor;
|
||||
use OCP\TaskProcessing\ShapeEnumValue;
|
||||
use Psr\Log\LoggerInterface;
|
||||
@ -34,17 +34,27 @@ class TaskProcessingService {
|
||||
private ?ICache $cache = null;
|
||||
private ?array $registeredProviders = null;
|
||||
|
||||
private AppAPIService $appAPIService;
|
||||
private ExAppService $exAppService;
|
||||
|
||||
public function __construct(
|
||||
ICacheFactory $cacheFactory,
|
||||
private readonly TaskProcessingProviderMapper $mapper,
|
||||
private readonly LoggerInterface $logger,
|
||||
private readonly PublicFunctions $service,
|
||||
) {
|
||||
if ($cacheFactory->isAvailable()) {
|
||||
$this->cache = $cacheFactory->createDistributed(Application::APP_ID . '/ex_task_processing_providers');
|
||||
}
|
||||
}
|
||||
|
||||
public function setAppAPIService(AppAPIService $appAPIService): void {
|
||||
$this->appAPIService = $appAPIService;
|
||||
}
|
||||
|
||||
public function setExAppService(ExAppService $exAppService): void {
|
||||
$this->exAppService = $exAppService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of registered TaskProcessing providers (only for enabled ExApps)
|
||||
*
|
||||
@ -267,11 +277,12 @@ class TaskProcessingService {
|
||||
array $provider,
|
||||
string $appId,
|
||||
): IProvider {
|
||||
return new class($provider, $appId, $this->service) implements IProvider, ITriggerableProvider {
|
||||
return new class($provider, $appId, $this->exAppService, $this->appAPIService) implements IProvider, ITriggerableProvider {
|
||||
public function __construct(
|
||||
private readonly array $provider,
|
||||
private readonly string $appId,
|
||||
private readonly PublicFunctions $service,
|
||||
private readonly ExAppService $exAppService,
|
||||
private readonly AppAPiService $appAPIService
|
||||
) {
|
||||
}
|
||||
|
||||
@ -288,7 +299,11 @@ class TaskProcessingService {
|
||||
}
|
||||
|
||||
public function trigger(): void {
|
||||
$this->service->exAppRequest($this->appId, '/trigger', params: ['providerId' => $this->provider['id']]);
|
||||
$exApp = $this->exAppService->getExApp($this->appId);
|
||||
if ($exApp === null) {
|
||||
return;
|
||||
}
|
||||
$this->appAPIService->requestToExApp($exApp, '/trigger', params: ['providerId' => $this->provider['id']]);
|
||||
}
|
||||
|
||||
public function getExpectedRuntime(): int {
|
||||
|
||||
Reference in New Issue
Block a user