Skip to content

Commit

Permalink
Merge pull request #546 from ems-project/develop
Browse files Browse the repository at this point in the history
Release 1.14.31
  • Loading branch information
theus77 committed Jan 12, 2021
2 parents 324c327 + 0811da4 commit 98c916f
Show file tree
Hide file tree
Showing 24 changed files with 181 additions and 50 deletions.
4 changes: 4 additions & 0 deletions assets/css/_ckeditor.scss
Expand Up @@ -16,3 +16,7 @@
z-index: 10051 !important;
position: absolute !important;
}

.cke_combopanel {
width:350px !important;
}
1 change: 1 addition & 0 deletions src/Controller/ChannelController.php
Expand Up @@ -37,6 +37,7 @@ public function index(Request $request): Response
$labelColumn->setRouteProperty('defaultRoute');
$labelColumn->setRouteTarget('channel_%value%');
$table->addColumn('channel.index.column.name', 'name');
$table->addColumn('channel.index.column.alias', 'alias');
$table->addColumn('channel.index.column.public', 'public', [true => 'fa fa-check']);
$table->addItemGetAction('ems_core_channel_edit', 'channel.actions.edit', 'pencil');
$table->addItemPostAction('ems_core_channel_delete', 'channel.actions.delete', 'trash', 'channel.actions.delete_confirm');
Expand Down
17 changes: 17 additions & 0 deletions src/Entity/Channel.php
Expand Up @@ -47,6 +47,13 @@ class Channel implements EntityInterface
*/
private $name;

/**
* @var string
*
* @ORM\Column(name="alias", type="string", length=255)
*/
private $alias;

/**
* @var bool
*
Expand Down Expand Up @@ -115,6 +122,16 @@ public function setName(string $name): void
$this->name = $name;
}

public function getAlias(): ?string
{
return $this->alias;
}

public function setAlias(string $alias): void
{
$this->alias = $alias;
}

public function getLabel(): ?string
{
return $this->label;
Expand Down
51 changes: 19 additions & 32 deletions src/EventListener/RequestListener.php
Expand Up @@ -60,6 +60,10 @@ public function onKernelRequest(RequestEvent $event): void
if (null === $channelName) {
continue;
}
$channelAlias = $channel->getAlias();
if (null === $channelAlias) {
continue;
}

if (
$channelName === ($matches['channel'] ?? null)
Expand All @@ -71,24 +75,27 @@ public function onKernelRequest(RequestEvent $event): void
$baseUrl = \vsprintf('%s://%s%s/channel/%s', [$request->getScheme(), $request->getHttpHost(), $request->getBasePath(), $channelName]);
$searchConfig = \json_decode($channel->getOptions()['searchConfig'] ?? '{}', true);
$attributes = \json_decode($channel->getOptions()['attributes'] ?? null, true);
if (\is_array($attributes)) {
$this->setAttributesInRequest($attributes, $request);
}

if (!$this->aliasService->hasIndex($channelName)) {
if (!$this->aliasService->hasIndex($channelAlias)) {
$this->logger->warning('log.channel.alias_not_found', [
'alias' => $channelName,
'channel' => $channel->getLabel(),
'alias' => $channelAlias,
'channel' => $channelName,
]);
continue;
}

$this->environmentHelper->addEnvironment(new Environment($channelName, [
'base_url' => \sprintf('channel/%s', $channelName),
'route_prefix' => Channel::generateChannelRoute($channelName, ''),
'regex' => \sprintf('/^%s/', \preg_quote($baseUrl, '/')),
$options = [
Environment::BASE_URL_CONFIG => \sprintf('channel/%s', $channelName),
Environment::ALIAS_CONFIG => $channelAlias,
Environment::ROUTE_PREFIX_CONFIG => Channel::generateChannelRoute($channelName, ''),
Environment::REGEX_CONFIG => \sprintf('/^%s/', \preg_quote($baseUrl, '/')),
'search_config' => $searchConfig,
]));
];

if (\is_array($attributes)) {
$options[Environment::REQUEST_CONFIG] = $attributes;
}

$this->environmentHelper->addEnvironment(new Environment($channelName, $options));
}
}

Expand Down Expand Up @@ -174,24 +181,4 @@ private function isAnonymousUser(Request $request): bool
{
return null === $request->getSession()->get('_security_main');
}

/**
* @param array<string, mixed> $attributes
*/
private function setAttributesInRequest(array $attributes, Request $request): void
{
foreach ($attributes as $name => $value) {
if (!\is_string($value)) {
$value = \json_encode($value);
if (false === $value) {
continue;
}
}
$request->attributes->set($name, $value);

if ('_locale' === $name) {
$request->setLocale($value);
}
}
}
}
1 change: 1 addition & 0 deletions src/Form/DataField/DateRangeFieldType.php
Expand Up @@ -139,6 +139,7 @@ public static function isVirtual(array $option = [])
if (!isset($option['mappingOptions'])) {
return false;
}

return !$option['mappingOptions']['nested'] ?? false;
}

Expand Down
6 changes: 6 additions & 0 deletions src/Form/Form/ChannelType.php
Expand Up @@ -35,6 +35,12 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
'class' => 'col-md-3',
],
])
->add('alias', null, [
'required' => true,
'row_attr' => [
'class' => 'col-md-3',
],
])
->add('public', CheckboxType::class, [
'required' => false,
'row_attr' => [
Expand Down
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace Application\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20210111193919 extends AbstractMigration
{
public function up(Schema $schema): void
{
$this->abortIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.');

$this->addSql('ALTER TABLE channel ADD alias VARCHAR(255) NOT NULL');
}

public function down(Schema $schema): void
{
$this->abortIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.');

$this->addSql('ALTER TABLE channel DROP alias');
}
}
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

namespace Application\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20210111193611 extends AbstractMigration
{
public function up(Schema $schema): void
{
$this->abortIf('postgresql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'postgresql\'.');

$this->addSql('ALTER TABLE channel ADD alias VARCHAR(255)');
$this->addSql('UPDATE channel SET alias = name');
$this->addSql('ALTER TABLE channel ALTER COLUMN alias SET NOT NULL');
}

public function down(Schema $schema): void
{
$this->abortIf('postgresql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'postgresql\'.');

$this->addSql('ALTER TABLE channel DROP alias');
}
}
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

namespace Application\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20210111193957 extends AbstractMigration
{
public function up(Schema $schema): void
{
$this->abortIf('sqlite' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'sqlite\'.');

$this->addSql('ALTER TABLE channel ADD COLUMN alias VARCHAR(255) NOT NULL');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf('sqlite' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'sqlite\'.');

$this->addSql('CREATE TEMPORARY TABLE __temp__channel AS SELECT id, created, modified, name, public, label, options, order_key FROM channel');
$this->addSql('DROP TABLE channel');
$this->addSql('CREATE TABLE channel (id CHAR(36) NOT NULL --(DC2Type:uuid)
, created DATETIME NOT NULL, modified DATETIME NOT NULL, name VARCHAR(255) NOT NULL, public BOOLEAN DEFAULT \'0\' NOT NULL, label VARCHAR(255) NOT NULL, options CLOB DEFAULT NULL --(DC2Type:json)
, order_key INTEGER NOT NULL, PRIMARY KEY(id))');
$this->addSql('INSERT INTO channel (id, created, modified, name, public, label, options, order_key) SELECT id, created, modified, name, public, label, options, order_key FROM __temp__channel');
$this->addSql('DROP TABLE __temp__channel');
}
}
2 changes: 1 addition & 1 deletion src/Resources/public/css/app.bundle.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/Resources/public/css/calendar.bundle.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/Resources/public/css/criteria-table.bundle.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/Resources/public/css/criteria-view.bundle.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/Resources/public/css/edit-revision.bundle.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/Resources/public/css/hierarchical.bundle.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/Resources/public/css/i18n.bundle.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/Resources/public/css/managed-alias.bundle.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/Resources/public/css/template.bundle.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/Resources/public/css/user-profile.bundle.css

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions src/Resources/translations/EMSCoreBundle.en.yml
Expand Up @@ -387,7 +387,8 @@ channel:
index:
reorder: 'Reorder channels'
column:
name: 'Channel''s alias'
name: 'Name'
alias: 'Alias'
label: 'Label'
public: 'Public access'
title: 'List of channels'
Expand Down Expand Up @@ -492,9 +493,10 @@ form:
searchConfig: 'Search config'
form:
channel:
name: 'Channel''s alias'
name: 'Name'
alias: 'Alias'
public: 'Does this channel can be available to non-authenticated users ?'
label: 'Channel''s label'
label: 'Label'
contenttype:
json_update:
deleteExitingTemplates: 'Delete existing templates'
Expand Down
2 changes: 2 additions & 0 deletions src/Resources/views/channel/form.html.twig
Expand Up @@ -14,6 +14,8 @@
<div class="clearfix"></div>
{{ form_row(form.name) }}
<div class="clearfix"></div>
{{ form_row(form.alias) }}
<div class="clearfix"></div>
{{ form_row(form.public) }}
{% for item in form.options %}
<div class="clearfix"></div>
Expand Down
3 changes: 2 additions & 1 deletion src/Service/AliasService.php
Expand Up @@ -328,6 +328,7 @@ public function updateAlias(string $alias, array $actions): void

public function removeAlias(string $name): bool
{
$this->build();
if (!$this->hasAlias($name)) {
return false;
}
Expand All @@ -339,7 +340,7 @@ public function removeAlias(string $name): bool
$indexesToRemove[] = $index['name'];
}

$this->updateAlias($name, ['actions' => ['remove' => $indexesToRemove]]);
$this->updateAlias($name, ['remove' => $indexesToRemove]);

return true;
}
Expand Down
10 changes: 10 additions & 0 deletions src/Service/ChannelService.php
Expand Up @@ -35,6 +35,16 @@ public function update(Channel $channel): void
if (0 === $channel->getOrderKey()) {
$channel->setOrderKey($this->channelRepository->counter() + 1);
}
$encoder = new Encoder();
$name = $channel->getName();
if (null === $name) {
throw new \RuntimeException('Unexpected null name');
}
$webalized = $encoder->webalize($name);
if (null === $webalized) {
throw new \RuntimeException('Unexpected null webalized name');
}
$channel->setName($webalized);
$this->channelRepository->create($channel);
}

Expand Down
15 changes: 11 additions & 4 deletions src/Service/Mapping.php
Expand Up @@ -90,15 +90,22 @@ public function generateMapping(ContentType $contentType, $withPipeline = false)
'properties' => [],
];

if (null != $contentType->getFieldType()) {
$out['properties'] = $this->fieldTypeType->generateMapping($contentType->getFieldType(), $withPipeline);
}

if ($this->elasticsearchService->withAllMapping()) {
$out['_all'] = [
'store' => true,
'enabled' => true,
];
}

if (null != $contentType->getFieldType()) {
$out['properties'] = $this->fieldTypeType->generateMapping($contentType->getFieldType(), $withPipeline);
} elseif (\version_compare($this->elasticaService->getVersion(), '7.0') < 0) {
foreach ($out['properties'] as $name => &$options) {
if (\in_array($options['type'], ['text', 'keyword'], true)) {
$options['copy_to'] = \array_unique(\array_merge(['_all'], $options['copy_to'] ?? []));
}
}
$out['properties'] = \array_merge(['_all' => ['type' => 'text']], $out['properties']);
}

$out['properties'] = \array_merge(
Expand Down

0 comments on commit 98c916f

Please sign in to comment.