Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch '5.2'
* 5.2:
  [DashboardBundle] Mark google analytics helper service as public (#2410)
  [NodeBundle] Start page reorder weight at 1 instead of 0 (#2411)
  [TranslatorBundle] csv export creates garbage on special signs (#2409)
  [NodeSearchBundle] fix #2380 childs of structurenodes never get indexed (#2395)
  • Loading branch information
Devolicious committed Mar 26, 2019
2 parents bc35919 + dcba9d7 commit 499283f
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 20 deletions.
2 changes: 2 additions & 0 deletions src/Kunstmaan/DashboardBundle/Resources/config/services.yml
Expand Up @@ -35,6 +35,7 @@ services:
kunstmaan_dashboard.helper.google.analytics.service:
class: 'Kunstmaan\DashboardBundle\Helper\Google\Analytics\ServiceHelper'
arguments: ['@kunstmaan_dashboard.helper.google.client']
public: true

# config helper
kunstmaan_dashboard.helper.google.analytics.config:
Expand All @@ -46,3 +47,4 @@ services:
kunstmaan_dashboard.helper.google.analytics.query:
class: 'Kunstmaan\DashboardBundle\Helper\Google\Analytics\QueryHelper'
arguments: ['@kunstmaan_dashboard.helper.google.analytics.service', '@kunstmaan_dashboard.helper.google.analytics.config']
public: true
Expand Up @@ -747,7 +747,7 @@ public function reorderAction(Request $request)
$nodes[] = $node;
}

$weight = 0;
$weight = 1;
foreach ($nodes as $node) {
$newParentId = isset($changeParents[$node->getId()]) ? $changeParents[$node->getId()] : null;
if ($newParentId) {
Expand Down
Expand Up @@ -2,7 +2,9 @@

namespace Kunstmaan\NodeSearchBundle\EventListener;

use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Event\LifecycleEventArgs;
use Kunstmaan\NodeBundle\Entity\Node;
use Kunstmaan\NodeBundle\Entity\NodeTranslation;
use Kunstmaan\NodeBundle\Entity\StructureNode;
use Kunstmaan\NodeBundle\Event\NodeEvent;
Expand All @@ -18,27 +20,38 @@ class NodeIndexUpdateEventListener implements NodeIndexUpdateEventListenerInterf
/** @var ContainerInterface */
private $container;

/** @var EntityManagerInterface */
private $em;

/** @var NodePagesConfiguration */
private $nodePagesConfiguration;

/** @var array */
private $entityChangeSet;

/**
* @param ContainerInterface $container
*/
public function __construct(/* NodePagesConfiguration */ $nodePagesConfiguration)
public function __construct(/* NodePagesConfiguration */
$nodePagesConfiguration, /* EntityManagerInterface */
$em = null)
{
if ($nodePagesConfiguration instanceof ContainerInterface) {
@trigger_error(sprintf('Passing the container as the first argument of "%s" is deprecated in KunstmaanNodeSearchBundle 5.2 and will be removed in KunstmaanNodeSearchBundle 6.0. Inject the "%s" service instead.', __CLASS__, 'kunstmaan_node_search.search_configuration.node'), E_USER_DEPRECATED);

$this->container = $nodePagesConfiguration;
$this->nodePagesConfiguration = $this->container->get('kunstmaan_node_search.search_configuration.node');

if (null === $em) {
$this->em = $this->container->get('doctrine.orm.default_entity_manager');
}

return;
}

if (!($em instanceof EntityManagerInterface)) {
@trigger_error(sprintf('Passing null or something other than an entitymanagerinterface as the second argument of "%s" is deprecated in KunstmaanNodeSearchBundle 5.2 and will be removed in KunstmaanNodeSearchBundle 6.0. Inject the "%s" service instead.', __CLASS__, 'doctrine.orm.default_entity_manager'), E_USER_DEPRECATED);
}

$this->nodePagesConfiguration = $nodePagesConfiguration;
$this->em = $em;
}

/**
Expand Down Expand Up @@ -127,11 +140,32 @@ public function delete(NodeEvent $event)
private function hasOfflineParents(NodeTranslation $nodeTranslation)
{
$lang = $nodeTranslation->getLang();
foreach ($nodeTranslation->getNode()->getParents() as $node) {
$nodeNT = $node->getNodeTranslation($lang, true);
if ($nodeNT && !$nodeNT->isOnline() && !$nodeNT instanceof StructureNode) {
return true;
$node = $nodeTranslation->getNode();
if (null !== $this->em) {
$em = $this->em;
} else {
$lang = $nodeTranslation->getLang();
foreach ($nodeTranslation->getNode()->getParents() as $node) {
$nodeNT = $node->getNodeTranslation($lang, true);
if ($nodeNT && !$nodeNT->isOnline()) {
return true;
}
}
return false;
}

foreach ($node->getParents() as $parent) {
$parentNodeTranslation = $parent->getNodeTranslation($lang, true);
if (null === $parentNodeTranslation) {
continue;
}
$parentRef = $parentNodeTranslation->getRef($em);
// Continue looping unless we find an offline page that is not a StructureNode
if ($parentRef instanceof StructureNode || $parentNodeTranslation->isOnline()) {
continue;
}

return true;
}

return false;
Expand Down
Expand Up @@ -4,7 +4,7 @@ parameters:
services:
kunstmaan_node_search.node_index_update.listener:
class: '%kunstmaan_node_search.node_index_update.listener.class%'
arguments: ['@kunstmaan_node_search.search_configuration.node']
arguments: ['@kunstmaan_node_search.search_configuration.node', '@doctrine.orm.default_entity_manager']
tags:
- { name: doctrine.event_listener, event: preUpdate, method: preUpdate }
- { name: kernel.event_listener, event: kunstmaan_node.postPublish, method: onPostPublish }
Expand Down
Expand Up @@ -2,6 +2,8 @@

namespace Kunstmaan\NodeSearchBundle\Tests\EventListener;

use Doctrine\ORM\EntityManager;
use Kunstmaan\NodeBundle\Entity\AbstractPage;
use Kunstmaan\NodeBundle\Entity\Node;
use Kunstmaan\NodeBundle\Entity\NodeTranslation;
use Kunstmaan\NodeBundle\Entity\StructureNode;
Expand All @@ -14,8 +16,11 @@ class NodeIndexUpdateEventListenerTest extends TestCase
{
public function testUpdateOfChildPageWithStructuredNodeParent()
{
$parentNodeTranslation = $this->createMock(StructureNode::class);
$parentNodeTranslation->method('isOnline')->willReturn(false);
$parentPage = $this->createMock(StructureNode::class);

$parentNodeTranslation = $this->createMock(NodeTranslation::class);
$parentNodeTranslation->method('getRef')->willReturn($parentPage);
$parentNodeTranslation->method('isOnline')->willReturn(true);

$parentNode = $this->createMock(Node::class);
$parentNode->method('getNodeTranslation')->willReturn($parentNodeTranslation);
Expand All @@ -34,17 +39,23 @@ public function testUpdateOfChildPageWithStructuredNodeParent()

$nodeEvent->method('getNodeTranslation')->willReturn($nodeTranslation);

$listener = new NodeIndexUpdateEventListener($this->getSearchConfiguration(true));
$em = $this->createMock(EntityManager::class);
$listener = new NodeIndexUpdateEventListener($this->getSearchConfiguration(true), $em);
$listener->onPostPersist($nodeEvent);
}

public function testUpdateOfChildPageWithStructuredNodeParentAndOfflineParent()
{
$parentNodeTranslation = $this->createMock(StructureNode::class);
$parentNodeTranslation->method('isOnline')->willReturn(false);
$parentPage = $this->createMock(StructureNode::class);

$parentNodeTranslation = $this->createMock(NodeTranslation::class);
$parentNodeTranslation->method('getRef')->willReturn($parentPage);
$parentNodeTranslation->method('isOnline')->willReturn(true);

$parentPageNotStructured = $this->createMock(AbstractPage::class);
$parentNodeTranslation2 = $this->createMock(NodeTranslation::class);
$parentNodeTranslation2->method('isOnline')->willReturn(false);
$parentNodeTranslation->method('getRef')->willReturn($parentPageNotStructured);

$parentNode1 = $this->createMock(Node::class);
$parentNode1->method('getNodeTranslation')->willReturn($parentNodeTranslation);
Expand All @@ -66,14 +77,17 @@ public function testUpdateOfChildPageWithStructuredNodeParentAndOfflineParent()

$nodeEvent->method('getNodeTranslation')->willReturn($nodeTranslation);

$listener = new NodeIndexUpdateEventListener($this->getSearchConfiguration(false));
$em = $this->createMock(EntityManager::class);
$listener = new NodeIndexUpdateEventListener($this->getSearchConfiguration(false), $em);
$listener->onPostPersist($nodeEvent);
}

public function testUpdateOfChildPageWithOfflineParent()
{
$parentPage = $this->createMock(AbstractPage::class);
$parentNodeTranslation = $this->createMock(NodeTranslation::class);
$parentNodeTranslation->method('isOnline')->willReturn(false);
$parentNodeTranslation->method('getRef')->willReturn($parentPage);

$parentNode = $this->createMock(Node::class);
$parentNode->method('getNodeTranslation')->willReturn($parentNodeTranslation);
Expand All @@ -90,14 +104,17 @@ public function testUpdateOfChildPageWithOfflineParent()

$nodeEvent->method('getNodeTranslation')->willReturn($nodeTranslation);

$listener = new NodeIndexUpdateEventListener($this->getSearchConfiguration(false));
$em = $this->createMock(EntityManager::class);
$listener = new NodeIndexUpdateEventListener($this->getSearchConfiguration(false), $em);
$listener->onPostPersist($nodeEvent);
}

public function testUpdateOfChildPageWithOnlineParent()
{
$parentPage = $this->createMock(AbstractPage::class);
$parentNodeTranslation = $this->createMock(NodeTranslation::class);
$parentNodeTranslation->method('isOnline')->willReturn(true);
$parentNodeTranslation->method('getRef')->willReturn($parentPage);

$parentNode = $this->createMock(Node::class);
$parentNode->method('getNodeTranslation')->willReturn($parentNodeTranslation);
Expand All @@ -114,7 +131,8 @@ public function testUpdateOfChildPageWithOnlineParent()

$nodeEvent->method('getNodeTranslation')->willReturn($nodeTranslation);

$listener = new NodeIndexUpdateEventListener($this->getSearchConfiguration(true));
$em = $this->createMock(EntityManager::class);
$listener = new NodeIndexUpdateEventListener($this->getSearchConfiguration(true), $em);
$listener->onPostPersist($nodeEvent);
}

Expand All @@ -124,7 +142,8 @@ public function testUpdateOfChildPageWithOnlineParent()
*/
public function testContainerDeprecation()
{
$listener = new NodeIndexUpdateEventListener($this->getContainer($this->getSearchConfiguration(false)));
$em = $this->createMock(EntityManager::class);
$listener = new NodeIndexUpdateEventListener($this->getContainer($this->getSearchConfiguration(false)), $em);
}

private function getContainer($searchConfigMock)
Expand Down
Expand Up @@ -42,7 +42,7 @@ public function export(array $translations)

if (isset($translation[$locale])) {
$item = $translation[$locale];
$row[] = utf8_decode($item->getText());
$row[] = $item->getText();
} else {
$row[] = '';
}
Expand Down

0 comments on commit 499283f

Please sign in to comment.