Skip to content

Commit

Permalink
Merge branch '1.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
andrerom committed May 14, 2019
2 parents dd43044 + af192de commit 0f365c6
Show file tree
Hide file tree
Showing 19 changed files with 364 additions and 36 deletions.
1 change: 1 addition & 0 deletions .php_cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ return PhpCsFixer\Config::create()
->exclude([
'vendor',
'ezpublish_legacy',
'bundle/Resources/init_ini',
])
->files()->name('*.php')
)
Expand Down
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@ before_script:
# Disable xdebug and remove memory limit to speed things up
- phpenv config-rm xdebug.ini
- echo "memory_limit=-1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
# Setup github key to avoid api rate limit (pure auth read only key, no rights, for use in ezsystems repos only)
- composer config -g github-oauth.github.com "d0285ed5c8644f30547572ead2ed897431c1fc09"
# Install packages using composer
- travis_retry composer install --dev --prefer-dist --no-interaction --no-progress $COMPOSER_FLAGS
- travis_retry composer install --prefer-dist --no-interaction --no-progress $COMPOSER_FLAGS

# execute phpunit as the script command
script:
Expand Down
4 changes: 2 additions & 2 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ _TIP:_

The Legacy Backoffice requires the `legacy_mode` option to be enabled.

This can be done in app/config/config.yml or app/config/ezplatform.yml, where `site_admin` is the name of the admin
This can be done in `app/config/config.yml` or `app/config/ezplatform.yml`, where `legacy_admin` is the name of the admin
siteaccess:

```
ez_publish_legacy:
system:
site_admin:
legacy_admin:
legacy_mode: true
```

Expand Down
97 changes: 80 additions & 17 deletions bundle/Command/LegacyInitCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Output\ConsoleOutputInterface;

Expand All @@ -24,6 +25,7 @@ protected function configure()
new InputArgument('src', InputArgument::OPTIONAL, 'The src directory for legacy files', 'src/legacy_files'),
]
)
->addOption('ini', null, InputOption::VALUE_NONE, 'Inits basic INI settings for scenarios where adding legacy bridge to existing platform setup (mainly for testing use)')
->setDescription('Inits Platform installation for legacy usage')
->setHelp(
<<<EOT
Expand Down Expand Up @@ -52,15 +54,18 @@ protected function execute(InputInterface $input, OutputInterface $output)
$this->updateComposeJson($output);
$this->enableBundles($output);
$this->enableRoutes($output);
$this->generateINI($input, $output);

$output->writeln(<<<'EOT'
<options=bold,underscore>All steps completed!</options>
<options=bold,underscore>All steps completed!</>
You can now check changes done and start to move over any legacy files (see above).
One done you can run the following command to setup symlinks, dump assets, (...):
Once done you can run the following command to setup symlinks, dump assets, (...):
- <info>composer symfony-scripts</info>
- <info>git add src/legacy_files</info>

EOT
);
}
Expand All @@ -75,9 +80,9 @@ protected function createDirectories(InputInterface $input, OutputInterface $out
$filesystem = $this->getContainer()->get('filesystem');

$filesystem->mkdir([
'src/AppBundle/ezpublish_legacy',
$srcArg,
"$srcArg/design",
"$srcArg/AppBundle/ezpublish_legacy",
"$srcArg/settings",
"$srcArg/settings/override",
"$srcArg/settings/siteaccess",
Expand Down Expand Up @@ -222,28 +227,86 @@ protected function enableBundles(OutputInterface $output)

protected function enableRoutes(OutputInterface $output)
{
$errOutput = $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output;
if (!$text = file_get_contents('app/config/routing.yml')) {
if (!$this->appendConditionally(
'app/config/routing.yml',
'@EzPublishLegacyBundle/Resources/config/routing.yml',
<<<'EOT'
# NOTE: ALWAYS keep this at the end of your routing rules so native symfony routes have precedence
# To avoid legacy REST pattern overriding possible eZ Platform REST routes and so on.
_ezpublishLegacyRoutes:
resource: '@EzPublishLegacyBundle/Resources/config/routing.yml'

EOT
)) {
$errOutput = $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output;
$errOutput->writeln('<error>Error: Unable to load app/config/routing.yml</error>');
}
}

protected function generateINI(InputInterface $input, OutputInterface $output)
{
if (!$input->getOption('ini')) {
return;
}

$changed = false;
if (stripos($text, 'resource: @EzPublishLegacyBundle/Resources/config/routing.yml') === false) {
// Add routes to the end of routes file
$text .= <<<'EOT'
/**
* @var \Symfony\Component\Filesystem\Filesystem
*/
$filesystem = $this->getContainer()->get('filesystem');
$srcArg = rtrim($input->getArgument('src'), '/');
$filesystem->mirror(
__DIR__ . '/../Resources/init_ini',
"$srcArg/settings"
);

# NOTE: ALWAYS keep this at the end of your routing rules so native symfony routes have precedence
# To avoid legacy REST pattern overriding possible eZ Platform REST routes and so on.
_ezpublishLegacyRoutes:
resource: '@EzPublishLegacyBundle/Resources/config/routing.yml'
EOT;
$changed = true;
if (!$this->appendConditionally(
'app/config/ezplatform.yml',
'legacy_mode: true',
<<<'EOT'
# To use legacy_admin, make sure it's also present in siteaccess.list & siteaccess.groups.site_group above
ez_publish_legacy:
system:
legacy_admin:
legacy_mode: true
# Example of setting view and module layout settings
# site:
# templating:
# view_layout: "@ezdesign/view_pagelayout.html.twig"
# module_layout: "@ezdesign/module_pagelayout.html.twig"

EOT
)) {
$errOutput = $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output;
$errOutput->writeln('<error>Error: Unable to load app/config/ezplatform.yml</error>');
}

if ($changed) {
file_put_contents('app/config/routing.yml', $text);
$output->writeln('');
$output->writeln('<comment>INI generated: To use legacy_admin, add it to siteaccess.list and siteaccess.groups.site_group in `app/config/ezplatform.yml`</comment>');
}

/**
* Append $config to $file if it does not have $contains.
*
* @param string $file
* @param string $contains
* @param string $config
*
* @return bool False if file was not found
*/
private function appendConditionally($file, $contains, $config)
{
if (!$text = file_get_contents($file)) {
return false;
}

// Unless file already contains $test, append $config to the file content
if (stripos($text, $contains) === false) {
$text .= $config;
file_put_contents($file, $text);
}

return true;
}
}
17 changes: 15 additions & 2 deletions bundle/EventListener/RequestListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,23 @@ public function onKernelRequest(GetResponseEvent $event)
}

try {
$apiUser = $this->repository->getUserService()->loadUser($session->get('eZUserLoggedInID'));
$legacyUserId = (int)$session->get('eZUserLoggedInID');
$token = $this->tokenStorage->getToken();

// Check if token is already legacy token, and user already loaded by Platform
if ($token instanceof LegacyToken &&
$token->getUser() instanceof User &&
$token->getUser()->getAPIUserReference()->getUserId() === $legacyUserId &&
$this->repository->getCurrentUserReference()->getUserId() === $legacyUserId
) {
// All seems ok, we can skip loading anything here
return;
}

// Load user and set as current
$apiUser = $this->repository->getUserService()->loadUser($legacyUserId);
$this->repository->setCurrentUser($apiUser);

$token = $this->tokenStorage->getToken();
if ($token instanceof TokenInterface) {
$token->setUser(new User($apiUser));
// Don't embed if we already have a LegacyToken, to avoid nested session storage.
Expand Down
29 changes: 19 additions & 10 deletions bundle/LegacyMapper/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,16 +285,7 @@ private function getMultiSiteSettings()
return $result;
}

$pathPrefix = '';

try {
$pathPrefix = trim($this->urlAliasGenerator->getPathPrefixByRootLocationId($rootLocationId), '/');
} catch (Exception $e) {
// Ignore any errors
// Most probable cause for error is database not being ready yet,
// i.e. initial install of the project which includes eZ Publish Legacy
}

$pathPrefix = $this->loadPathPrefix($rootLocationId);
$pathPrefixExcludeItems = array_map(
static function ($value) {
return trim($value, '/');
Expand Down Expand Up @@ -328,4 +319,22 @@ private function getClusterSettings()

return $clusterSettings;
}

private function loadPathPrefix($rootLocationId)
{
// If root location is 2 we know path is empty, so we can skip loading location + urlAlias data
if ($rootLocationId === 2) {
return '';
}

try {
return trim($this->urlAliasGenerator->getPathPrefixByRootLocationId($rootLocationId), '/');
} catch (Exception $e) {
// Ignore any errors
// Most probable cause for error is database not being ready yet,
// i.e. initial install of the project which includes eZ Publish Legacy
}

return '';
}
}
9 changes: 9 additions & 0 deletions bundle/Resources/init_ini/override/ezoe.ini.append.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php /* #?ini charset="utf-8"?
[EditorSettings]
Plugins[]=ezemotions
[EditorLayout]
Buttons[]=emotions
*/ ?>
90 changes: 90 additions & 0 deletions bundle/Resources/init_ini/override/site.ini.append.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?php /* #?ini charset="utf-8"?
[DatabaseSettings]
Charset=utf8mb4
[FileSettings]
VarDir=var/site
[ExtensionSettings]
ActiveExtensions[]
ActiveExtensions[]=ezjscore
ActiveExtensions[]=ezoe
ActiveExtensions[]=ezformtoken
ActiveExtensions[]=ezstarrating
ActiveExtensions[]=ezgmaplocation
ActiveExtensions[]=ezdemo
ActiveExtensions[]=ezwt
ActiveExtensions[]=ezflow
ActiveExtensions[]=ezie
ActiveExtensions[]=ezodf
ActiveExtensions[]=ezprestapiprovider
ActiveExtensions[]=ezmultiupload
ActiveExtensions[]=ezautosave
ActiveExtensions[]=ezmbpaex
# Optional, see: https://packagist.org/packages/ezsystems/eztags-ls
#ActiveExtensions[]=eztags
## Some recommended bundles/extensions for use with legacy bridge setups:
# Extra features to reuse code from Symfony in legacy: https://packagist.org/packages/netgen/ngsymfonytools
#ActiveExtensions[]=ngsymfonytools
# Use SolrBundle from legacy: https://packagist.org/packages/netgen/ezplatformsearch
#ActiveExtensions[]=ezplatformsearch
# Edit eZ Platform richtext in raw xml on legacy: https://packagist.org/packages/netgen/richtext-datatype-bundle
#ActiveExtensions[]=ezrichtext
[Session]
SessionNameHandler=custom
[SiteSettings]
DefaultAccess=site
SiteList[]
SiteList[]=site
SiteList[]=legacy_admin
RootNodeDepth=1
[UserSettings]
LogoutRedirect=/
[SiteAccessSettings]
CheckValidity=false
AvailableSiteAccessList[]
AvailableSiteAccessList[]=site
AvailableSiteAccessList[]=legacy_admin
MatchOrder=uri
HostMatchMapItems[]
[RegionalSettings]
TranslationSA[]
[MailSettings]
Transport=sendmail
AdminEmail=
EmailSender=
[EmbedViewModeSettings]
AvailableViewModes[]
AvailableViewModes[]=embed
AvailableViewModes[]=embed-inline
InlineViewModes[]
InlineViewModes[]=embed-inline
# TIP: Below are settings that could make sense to invert for debug needs during legacy development.
# Especially [TemplateSettings]DevelopmentMode to not have to clear cache every time you change a template.
[DesignSettings]
DesignLocationCache=enabled
[DebugSettings]
DebugOutput=disabled
DebugRedirection=disabled
[TemplateSettings]
DevelopmentMode=disabled
ShowUsedTemplates=disabled
Debug=disabled
*/ ?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php /* #?ini charset="utf-8"?
[VersionView]
AvailableSiteDesignList[]
AvailableSiteDesignList[]=site
*/ ?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php /* #?ini charset="utf-8"?
[TreeMenu]
Dynamic=enabled
ShowClasses[]=frontpage
ShowClasses[]=blog
*/ ?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php /* #?ini charset="utf-8"?
[DashboardSettings]
DashboardBlocks[]
DashboardBlocks[]=pending_list
DashboardBlocks[]=drafts
DashboardBlocks[]=latest_content
DashboardBlocks[]=all_latest_content
*/ ?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php /* #?ini charset="utf8"?
[EditorSettings]
SkinVariant=silver
*/ ?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php /* #?ini charset="utf-8"?
[TagSettings]
TagPresets[mini]=Simple formatting
*/ ?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php /* #?ini charset="utf-8"?
[IconSettings]
Theme=crystal-admin
Size=normal
*/ ?>
Loading

0 comments on commit 0f365c6

Please sign in to comment.