1313use OCA \AppAPI \AppInfo \Application ;
1414use OCA \AppAPI \Db \TaskProcessing \TaskProcessingProvider ;
1515use OCA \AppAPI \Db \TaskProcessing \TaskProcessingProviderMapper ;
16+ use OCA \AppAPI \Service \AppAPIService ;
17+ use OCA \AppAPI \Service \ExAppService ;
1618use OCP \AppFramework \Bootstrap \IRegistrationContext ;
1719use OCP \AppFramework \Db \DoesNotExistException ;
1820use OCP \AppFramework \Db \MultipleObjectsReturnedException ;
2325use OCP \TaskProcessing \EShapeType ;
2426use OCP \TaskProcessing \IProvider ;
2527use OCP \TaskProcessing \ITaskType ;
28+ use OCP \TaskProcessing \ITriggerableProvider ;
2629use OCP \TaskProcessing \ShapeDescriptor ;
2730use OCP \TaskProcessing \ShapeEnumValue ;
2831use Psr \Log \LoggerInterface ;
@@ -31,6 +34,9 @@ class TaskProcessingService {
3134 private ?ICache $ cache = null ;
3235 private ?array $ registeredProviders = null ;
3336
37+ private AppAPIService $ appAPIService ;
38+ private ExAppService $ exAppService ;
39+
3440 public function __construct (
3541 ICacheFactory $ cacheFactory ,
3642 private readonly TaskProcessingProviderMapper $ mapper ,
@@ -41,6 +47,14 @@ public function __construct(
4147 }
4248 }
4349
50+ public function setAppAPIService (AppAPIService $ appAPIService ): void {
51+ $ this ->appAPIService = $ appAPIService ;
52+ }
53+
54+ public function setExAppService (ExAppService $ exAppService ): void {
55+ $ this ->exAppService = $ exAppService ;
56+ }
57+
4458 /**
4559 * Get list of registered TaskProcessing providers (only for enabled ExApps)
4660 *
@@ -241,7 +255,7 @@ public function registerExAppTaskProcessingProviders(IRegistrationContext $conte
241255 $ className = '\\OCA \\AppAPI \\' . $ exAppProvider ->getAppId () . '\\' . $ exAppProvider ->getName ();
242256
243257 try {
244- $ provider = $ this ->getAnonymousExAppProvider (json_decode ($ exAppProvider ->getProvider (), true , flags: JSON_THROW_ON_ERROR ));
258+ $ provider = $ this ->getAnonymousExAppProvider (json_decode ($ exAppProvider ->getProvider (), true , flags: JSON_THROW_ON_ERROR ), $ exAppProvider -> getAppId () );
245259 } catch (JsonException $ e ) {
246260 $ this ->logger ->debug ('Failed to register ExApp TaskProcessing provider ' , ['exAppId ' => $ exAppProvider ->getAppId (), 'taskType ' => $ exAppProvider ->getName (), 'exception ' => $ e ]);
247261 continue ;
@@ -261,10 +275,14 @@ public function registerExAppTaskProcessingProviders(IRegistrationContext $conte
261275 */
262276 public function getAnonymousExAppProvider (
263277 array $ provider ,
278+ string $ appId ,
264279 ): IProvider {
265- return new class ($ provider ) implements IProvider {
280+ return new class ($ provider, $ appId , $ this -> exAppService , $ this -> appAPIService ) implements IProvider, ITriggerableProvider {
266281 public function __construct (
267282 private readonly array $ provider ,
283+ private readonly string $ appId ,
284+ private readonly ExAppService $ exAppService ,
285+ private readonly AppAPiService $ appAPIService
268286 ) {
269287 }
270288
@@ -280,6 +298,14 @@ public function getTaskTypeId(): string {
280298 return $ this ->provider ['task_type ' ];
281299 }
282300
301+ public function trigger (): void {
302+ $ exApp = $ this ->exAppService ->getExApp ($ this ->appId );
303+ if ($ exApp === null ) {
304+ return ;
305+ }
306+ $ this ->appAPIService ->requestToExApp ($ exApp , '/trigger? ' . http_build_query (['providerId ' => $ this ->provider ['id ' ]]));
307+ }
308+
283309 public function getExpectedRuntime (): int {
284310 return $ this ->provider ['expected_runtime ' ];
285311 }
0 commit comments