Skip to content

Commit

Permalink
implement default guard
Browse files Browse the repository at this point in the history
  • Loading branch information
solverat committed Jul 14, 2019
1 parent 977fd0e commit 8da4f7a
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/DsWebCrawlerBundle/DsWebCrawlerBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class DsWebCrawlerBundle extends AbstractPimcoreBundle

const PACKAGE_NAME = 'dachcom-digital/dynamic-search-data-provider-crawler';

const PROVIDER_NAME = 'webCrawler';
const PROVIDER_NAME = 'web_crawler';

/**
* @param ContainerBuilder $container
Expand Down
22 changes: 22 additions & 0 deletions src/DsWebCrawlerBundle/Guard/DefaultDataResourceGuard.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace DsWebCrawlerBundle\Guard;

use DsWebCrawlerBundle\DsWebCrawlerBundle;
use DynamicSearchBundle\Guard\ContextGuardInterface;
use DynamicSearchBundle\Normalizer\Resource\ResourceMetaInterface;

class DefaultDataResourceGuard implements ContextGuardInterface
{
/**
* {@inheritdoc}
*/
public function isValidateDataResource(string $contextName, string $dataProviderName, array $dataProviderOptions, ResourceMetaInterface $resourceMeta, $resource)
{
if ($dataProviderName !== DsWebCrawlerBundle::PROVIDER_NAME) {
return true;
}

return true;
}
}
2 changes: 2 additions & 0 deletions src/DsWebCrawlerBundle/Provider/CrawlerDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ public function provideSingle(ContextDataInterface $contextData, ResourceMetaInt
throw new ProviderException('resource option "path" must be set to provide single data.', DsWebCrawlerBundle::PROVIDER_NAME);
}

$this->configuration['path'] = $options['path'];

$this->crawlerService->initSingleCrawl($resourceMeta, $contextData->getName(), $contextData->getContextDispatchType(), $this->configuration);
$this->crawlerService->process();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ protected function extractHtml(DOMDocument $doc)
*/
protected function log($level, $message)
{
$this->logger->log($level, $message, 'http_response_html', $this->contextData->getName());
$contextName = $this->contextData instanceof ContextDataInterface ? $this->contextData->getName() : '--';
$this->logger->log($level, $message, 'http_response_html', $contextName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ protected function getAssetMeta(DataResource $resource)
*/
protected function log($level, $message)
{
$this->logger->log($level, $message, 'http_response_pdf', $this->contextData->getName());
$contextName = $this->contextData instanceof ContextDataInterface ? $this->contextData->getName() : '--';
$this->logger->log($level, $message, 'http_response_pdf', $contextName);
}
}
10 changes: 10 additions & 0 deletions src/DsWebCrawlerBundle/Resources/config/services/guard.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
services:

_defaults:
autowire: true
autoconfigure: true
public: false

DsWebCrawlerBundle\Guard\DefaultDataResourceGuard:
tags:
- {name: dynamic_search.context_guard }

0 comments on commit 8da4f7a

Please sign in to comment.