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

[Feature] Add option to Init to inject basic INI settings #172

Merged
merged 7 commits into from
May 14, 2019
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 .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 @@ -31,10 +31,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;
}
}
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
*/ ?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php /* #?ini charset="utf-8"?

[thumbnail_image]
Source=node/view/thumbnail.tpl
MatchFile=thumbnail/image.tpl
Subdir=templates
Match[class_identifier]=image

[thumbnail_image_browse]
Source=node/view/browse_thumbnail.tpl
MatchFile=thumbnail/image_browse.tpl
Subdir=templates
Match[class_identifier]=image

[embed_image]
Source=content/view/embed.tpl
MatchFile=embed_image.tpl
Subdir=templates
Match[class_identifier]=image

[embed-inline_image]
Source=content/view/embed-inline.tpl
MatchFile=embed-inline_image.tpl
Subdir=templates
Match[class_identifier]=image

[embed_node_image]
Source=node/view/embed.tpl
MatchFile=embed_image.tpl
Subdir=templates
Match[class_identifier]=image

[embed-inline_node_image]
Source=node/view/embed-inline.tpl
MatchFile=embed-inline_image.tpl
Subdir=templates
Match[class_identifier]=image
*/ ?>
Loading