Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove RegisterPortalTheme introduction #418

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions controller/AuthoringTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use helpers_Random;
use InterruptedActionException;
use OAT\Library\Lti1p3Core\Message\Payload\LtiMessagePayloadInterface;
use oat\tao\model\theme\ThemeService;
use oat\taoLti\models\classes\LtiException;
use oat\taoLti\models\classes\LtiMessages\LtiErrorMessage;
use oat\taoLti\models\classes\LtiService;
Expand Down
6 changes: 2 additions & 4 deletions manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,16 @@
* Copyright (c) 2013-2021 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT);
*/

use oat\ltiTestReview\controller\Review;
use oat\tao\model\accessControl\func\AccessRule;
use oat\tao\model\user\TaoRoles;
use oat\taoLti\controller\AuthoringTool;
use oat\taoLti\controller\CookieUtils;
use oat\taoLti\controller\Security;
use oat\taoLti\models\classes\LtiRoles;
use oat\taoLti\models\classes\ServiceProvider\LtiServiceProvider;
use oat\taoLti\scripts\install\CreateLti1p3RegistrationSnapshotSchema;
use oat\taoLti\scripts\install\GenerateKeys;
use oat\taoLti\scripts\install\GenerisSearchWhitelist;
use oat\taoLti\scripts\install\RegisterPortalTheme;
use oat\taoLti\scripts\install\RegisterPortalThemeDetailProvider;
use oat\taoLti\scripts\install\SetupServices;
use oat\taoLti\scripts\install\MapLtiSectionVisibility;
use oat\taoLti\scripts\update\Updater;
Expand Down Expand Up @@ -67,7 +65,7 @@
MapLtiSectionVisibility::class,
GenerisSearchWhitelist::class,
CreateLti1p3RegistrationSnapshotSchema::class,
RegisterPortalTheme::class
RegisterPortalThemeDetailProvider::class,
]
],
'update' => Updater::class,
Expand Down
2 changes: 1 addition & 1 deletion migrations/Version202406060802293772_taoLti.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function getDescription(): string

public function up(Schema $schema): void
{
$this->runAction(new RegisterPortalTheme());
// Action removed due to conflicting with multiple instance implementations.
}

public function down(Schema $schema): void
Expand Down
34 changes: 34 additions & 0 deletions migrations/Version202406101417393772_taoLti.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

namespace oat\taoLti\migrations;

use Doctrine\DBAL\Schema\Schema;
use oat\tao\scripts\tools\migrations\AbstractMigration;
use oat\taoLti\scripts\install\RegisterPortalTheme;
use oat\taoLti\scripts\install\UnregisterLtiPortalTheme;

/**
* Auto-generated Migration: Please modify to your needs!
*
* phpcs:disable Squiz.Classes.ValidClassName
*/
final class Version202406101417393772_taoLti extends AbstractMigration
{
public function getDescription(): string
{
return 'This will revert change introduced in Version202406060802293772_taoLti.php for instances
with taoStyle enabled.';
}

public function up(Schema $schema): void
{
$this->runAction(new UnregisterLtiPortalTheme());
}

public function down(Schema $schema): void
{
$this->throwIrreversibleMigrationException();
}
}
57 changes: 57 additions & 0 deletions models/classes/theme/PortalThemeDetailProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

/**
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; under version 2
* of the License (non-upgradable).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2024 (original work) Open Assessment Technologies SA;
*/

declare(strict_types=1);

namespace oat\taoLti\models\classes\theme;

use common_session_SessionManager as SessionManager;
use oat\tao\model\session\Context\TenantDataSessionContext;
use oat\tao\model\theme\DefaultTheme;
use oat\tao\model\theme\PortalTheme;
use oat\tao\model\theme\ThemeDetailsProviderInterface;
use oat\taoLti\models\classes\TaoLtiSession;

class PortalThemeDetailProvider implements ThemeDetailsProviderInterface
{
public function getThemeId(): string
{
if ($this->isSessionFromPortal()) {
return PortalTheme::THEME_ID;
};

return '';
}

/**
* @inheritDoc
*/
public function isHeadless(): bool
{
return false;
}

private function isSessionFromPortal(): bool
{
$session = SessionManager::getSession();
return $session instanceof TaoLtiSession
&& !empty($session->getContexts(TenantDataSessionContext::class));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,17 @@

namespace oat\taoLti\scripts\install;

use oat\oatbox\config\ConfigurationService;
use oat\oatbox\extension\InstallAction;
use oat\tao\model\theme\PortalTheme;
use oat\tao\model\theme\ThemeServiceInterface;
use oat\taoLti\models\classes\theme\PortalThemeService;

class RegisterPortalTheme extends InstallAction
class RegisterPortalThemeDetailProvider extends InstallAction
{
public function __invoke($params = [])
public function __invoke($params)
{
/** @var ConfigurationService $previousThemeService */
$previousThemeService = $this->getServiceManager()->get(ThemeServiceInterface::SERVICE_ID);

/** @var ThemeServiceInterface $service */
$service = $this->propagate(new PortalThemeService());
$service->setOptions($previousThemeService->getOptions());
$service->addTheme(new PortalTheme(), false);

$this->getServiceManager()->register(ThemeServiceInterface::SERVICE_ID, $service);
$service = $this->getServiceManager()->get(ThemeServiceInterface::SERVICE_ID);
$themeDetailsProviders = $service->getOption('themeDetailsProviders');
$themeDetailsProviders[] = new \oat\taoLti\models\classes\theme\PortalThemeDetailProvider();
$service->setOption('themeDetailsProviders', $themeDetailsProviders);
$this->registerService(ThemeServiceInterface::SERVICE_ID, $service);
}
}
118 changes: 118 additions & 0 deletions scripts/install/UnregisterLtiPortalTheme.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<?php

/**
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; under version 2
* of the License (non-upgradable).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2024 (original work) Open Assessment Technologies SA;
*/

declare(strict_types=1);

namespace oat\taoLti\scripts\install;

use common_ext_ExtensionsManager;
use Exception;
use oat\oatbox\extension\InstallAction;
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\taoLti\models\classes\theme\PortalThemeDetailProvider;
use oat\taoLti\models\classes\theme\PortalThemeService;
use oat\taoStyles\model\service\PersistenceThemeService;

class UnregisterLtiPortalTheme extends InstallAction
{
public function __invoke($params = [])
{
/** @var ThemeServiceInterface|ConfigurableService $service */
$service = $this->getServiceManager()->get(ThemeServiceInterface::SERVICE_ID);
$oldConfig = $service->getOptions();

//This provider will allow to display Portal Theme
if (!isset($oldConfig['themeDetailsProviders'])) {
$oldConfig['themeDetailsProviders'] = [
new PortalThemeDetailProvider()
];
}

/** @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') && $service instanceof PortalThemeService) {
try {
$oldConfig = $this->validateConfig($oldConfig);
} catch (Exception $e) {
$this->getLogger()->error($e->getMessage());
return;
}

$revertedService = $this->propagate(new PersistenceThemeService($oldConfig));
$this->getServiceManager()->register(ThemeServiceInterface::SERVICE_ID, $revertedService);
$revertedService->addTheme(new PortalTheme(), false);
$revertedService->addTheme(new DefaultTheme(), false);

return;
}

//Make sure current theme is set
if (!isset($oldConfig['current']) && !($service instanceof PersistenceThemeService)) {
$oldConfig = $this->defineCurrent($oldConfig);
}

if ($service instanceof PortalThemeService) {
$reverseService = $this->propagate(new ThemeService($oldConfig));
$this->getServiceManager()->register(ThemeServiceInterface::SERVICE_ID, $reverseService);
}

$service->setOptions($oldConfig);
$this->getServiceManager()->register(ThemeServiceInterface::SERVICE_ID, $service);
}

private function defineCurrent(array $config): array
{
if (!isset($config['available'])) {
$config['available'] = [
'default' => DefaultTheme::class,
'portal' => array(
'class' => 'oat\\tao\\model\\theme\\PortalTheme',
'options' => array()
)
];
}

if (!isset($config['available']['default'])) {
$config['available']['default'] = DefaultTheme::class;
}

if (!isset($config['current'])) {
$config['current'] = 'default';
}

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;
}
}
Loading