Skip to content

Commit

Permalink
fix: UnregisterLtiPortal making sure config for PersistenceThemeServi…
Browse files Browse the repository at this point in the history
…ce is valid. PortalThemeDetailProvider will return empty sting if session not from portal
  • Loading branch information
bartlomiejmarszal committed Jun 11, 2024
1 parent fe2227f commit 5cd185a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
3 changes: 1 addition & 2 deletions models/classes/theme/PortalThemeDetailProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ public function getThemeId(): string
return PortalTheme::THEME_ID;
};

$defaultTheme = new DefaultTheme();
return $defaultTheme->getId();
return '';
}

/**
Expand Down
23 changes: 19 additions & 4 deletions scripts/install/UnregisterLtiPortalTheme.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
namespace oat\taoLti\scripts\install;

use common_ext_ExtensionsManager;
use Exception;
use oat\oatbox\service\ConfigurableService;
use oat\tao\model\theme\DefaultTheme;
use oat\tao\model\theme\PortalTheme;
use oat\tao\model\theme\ThemeService;
use oat\tao\model\theme\ThemeServiceInterface;
use oat\tao\scripts\install\RegisterTaoUpdateEventListener;
use oat\taoDelivery\scripts\install\installDeliveryFields;
use oat\taoLti\models\classes\theme\PortalThemeDetailProvider;
use oat\taoLti\models\classes\theme\PortalThemeService;
Expand All @@ -44,9 +44,13 @@ public function __invoke($params = [])
/** @var common_ext_ExtensionsManager $extManager */
$extManager = $this->getServiceManager()->get(common_ext_ExtensionsManager::class);
//If taoStyles is installed, we had PersistenceThemeService used as theming.conf.php and we should still use it
if ($extManager->isInstalled('taoStyles')) {
//On taoLtiThemeService registration we migrated all configs and we may encounter some unused configs
unset($oldConfig['available']);
if ($extManager->isInstalled('taoStyles') && $service instanceof PortalThemeService) {
try {
$oldConfig = $this->validateConfig($oldConfig);
} catch (Exception $e) {
$this->getLogger()->error($e->getMessage());
return;
}
//This provider will allow to display Portal Theme
$oldConfig['themeDetailsProviders'] = [
new PortalThemeDetailProvider()
Expand Down Expand Up @@ -94,4 +98,15 @@ private function defineCurrent(array $config): array

return $config;
}

private function validateConfig(array $oldConfig): array
{
//On taoLtiThemeService registration we migrated all configs and we may encounter some unused configs
unset($oldConfig['available']);
if (!isset($oldConfig['persistence'])) {
throw new Exception('Missing previous config for PersistenceThemeService');
}

return $oldConfig;
}
}

0 comments on commit 5cd185a

Please sign in to comment.