Skip to content

Commit

Permalink
delay userId querying from DI later in anonymous class (#199)
Browse files Browse the repository at this point in the history
During PHP App registration process we don't have a complete session and
other stuff queried from DI which is for some reason (I don't know why
yet) breaks its usage later.

---------

Signed-off-by: Andrey Borysenko <[email protected]>
Co-authored-by: Alexander Piskun <[email protected]>
  • Loading branch information
andrey18106 and bigcat88 authored Jan 5, 2024
1 parent 0f0c01e commit 3d56170
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

## [1.4.6 - 2024-01-0x]
## [1.4.6 - 2024-01-05]

### Fixed

- TopMenuAPI: support of params in styles/js ExApp URLs. #193 (Thanks to @splitt3r)
- NC28: FileActionsAPI wasn't working without specifying an icon. #198
- Bug introduced in the previous version, when the `userId` for some part of AppAPI became `null`. #199

## [1.4.5 - 2024-01-02]

Expand Down
2 changes: 1 addition & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ to join us in shaping a more versatile, stable, and secure app landscape.
*Your insights, suggestions, and contributions are invaluable to us.*
]]></description>
<version>1.4.5</version>
<version>1.4.6</version>
<licence>agpl</licence>
<author mail="[email protected]" homepage="https://github.com/andrey18106">Andrey Borysenko</author>
<author mail="[email protected]" homepage="https://github.com/bigcat88">Alexander Piskun</author>
Expand Down
10 changes: 7 additions & 3 deletions lib/Service/SpeechToTextService.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public function __construct(
ICacheFactory $cacheFactory,
private readonly SpeechToTextProviderMapper $mapper,
private readonly LoggerInterface $logger,
private readonly ?string $userId,
) {
$this->cache = $cacheFactory->createDistributed(Application::APP_ID . '/ex_speech_to_text_providers');
}
Expand Down Expand Up @@ -146,12 +145,13 @@ public function registerExAppSpeechToTextProviders(IRegistrationContext &$contex
* @psalm-suppress UndefinedClass, MissingDependency, InvalidReturnStatement, InvalidReturnType
*/
private function getAnonymousExAppProvider(SpeechToTextProvider $provider, IServerContainer $serverContainer, string $class): ?ISpeechToTextProviderWithId {
return new class($provider, $serverContainer, $this->userId, $class) implements ISpeechToTextProviderWithId {
return new class($provider, $serverContainer, $class) implements ISpeechToTextProviderWithId {
private ?string $userId;

public function __construct(
private SpeechToTextProvider $sttProvider,
// We need this to delay the instantiation of AppAPIService during registration to avoid conflicts
private IServerContainer $serverContainer, // TODO: Extract needed methods from AppAPIService to be able to use it everytime
private readonly ?string $userId,
private readonly string $class,
) {
}
Expand Down Expand Up @@ -203,6 +203,10 @@ public function transcribeFile(File $file, float $maxExecutionTime = 0): string
}
return $response->getBody();
}

public function setUserId(?string $userId): void {
$this->userId = $userId;
}
};
}
}
6 changes: 3 additions & 3 deletions lib/Service/TextProcessingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class TextProcessingService {
public function __construct(
ICacheFactory $cacheFactory,
private readonly TextProcessingProviderMapper $mapper,
private readonly ?string $userId,
private readonly LoggerInterface $logger,
) {
$this->cache = $cacheFactory->createDistributed(Application::APP_ID . '/ex__text_processing_providers');
Expand Down Expand Up @@ -161,12 +160,13 @@ private function getAnonymousExAppProvider(
string $className,
IServerContainer $serverContainer
): IProviderWithId {
return new class($provider, $serverContainer, $className, $this->userId) implements IProviderWithId, IProviderWithUserId {
return new class($provider, $serverContainer, $className) implements IProviderWithId, IProviderWithUserId {
private ?string $userId;

public function __construct(
private readonly TextProcessingProvider $provider,
private readonly IServerContainer $serverContainer,
private readonly string $className,
private ?string $userId,
) {
}

Expand Down

0 comments on commit 3d56170

Please sign in to comment.