<commit_before><?php
namespace MOC\Varnish\Controller;

use MOC\Varnish\Service\ContentCacheFlusherService;
use MOC\Varnish\Service\VarnishBanService;
use TYPO3\Flow\Annotations as Flow;
use TYPO3\Flow\Error\Message;
use TYPO3\Flow\Http\Client\CurlEngine;
use TYPO3\Flow\Http\Uri;
use TYPO3\Flow\Http\Request;
use TYPO3\Neos\Domain\Model\Site;
use TYPO3\Neos\Domain\Service\ContentContext;
use TYPO3\Neos\Domain\Service\ContentDimensionPresetSourceInterface;

class VarnishCacheController extends \TYPO3\Neos\Controller\Module\AbstractModuleController {

	/**
	 * @Flow\Inject
	 * @var \TYPO3\TYPO3CR\Domain\Service\NodeTypeManager
	 */
	protected $nodeTypeManager;

	/**
	 * @Flow\Inject
	 * @var \TYPO3\Neos\Domain\Service\ContentContextFactory
	 */
	protected $contextFactory;

	/**
	 * @Flow\Inject
	 * @var \TYPO3\Neos\Domain\Service\NodeSearchService
	 */
	protected $nodeSearchService;

	/**
	 * @Flow\Inject
	 * @var \TYPO3\Neos\Domain\Repository\SiteRepository
	 */
	protected $siteRepository;

	/**
	 * @Flow\Inject
	 * @var ContentDimensionPresetSourceInterface
	 */
	protected $contentDimensionPresetSource;

	/**
	 * @return void
	 */
	public function indexAction() {
		$this->view->assign('activeSites', $this->siteRepository->findOnline());
	}

	/**
	 * @param string $searchWord
	 * @param Site $selectedSite
	 * @return void
	 */
	public function searchForNodeAction($searchWord, Site $selectedSite = NULL) {
		$documentNodeTypes = $this->nodeTypeManager->getSubNodeTypes('TYPO3.Neos:Document');
		$shortcutNodeType = $this->nodeTypeManager->getNodeType('TYPO3.Neos:Shortcut');
		$nodeTypes = array_diff($documentNodeTypes, array($shortcutNodeType));
		$sites = array();
		$activeSites = $this->siteRepository->findOnline();
		foreach ($selectedSite ? array($selectedSite) : $activeSites as $site) {
			/** @var ContentContext $liveContext */
			$contextProperties = array(
				'workspaceName' => 'live',
				'currentSite' => $site
			);
			$contentDimensionCombinations = $this->contentDimensionPresetSource->getAllDimensionCombinations();
			if (count($contentDimensionCombinations) > 0) {
				$mergedContentDimensions = array();
				foreach ($contentDimensionCombinations as $contentDimensionCombination) {
					foreach ($contentDimensionCombination as $contentDimensionIdentifier => $contentDimension) {
						if (!isset($mergedContentDimensions[$contentDimensionIdentifier])) {
							$mergedContentDimensions[$contentDimensionIdentifier] = array();
						}
						$mergedContentDimensions[$contentDimensionIdentifier] = array_unique(array_merge($mergedContentDimensions[$contentDimensionIdentifier], $contentDimension));
					}
				}
				$contextProperties['dimensions'] = $mergedContentDimensions;
			}
			$liveContext = $this->contextFactory->create($contextProperties);
			$firstActiveDomain = $site->getFirstActiveDomain();
			$nodes = $this->nodeSearchService->findByProperties($searchWord, $nodeTypes, $liveContext, $liveContext->getCurrentSiteNode());
			if (count($nodes) > 0) {
				$sites[$site->getNodeName()] = array(
					'site' => $site,
					'domain' => $firstActiveDomain ? $firstActiveDomain->getHostPattern() : $this->request->getHttpRequest()->getUri()->getHost(),
					'nodes' => $nodes
				);
			}<commit_msg>[TASK] Refactor content dimension fetching to support Neos 2.0<commit_after><?php
namespace MOC\Varnish\Controller;

use MOC\Varnish\Service\ContentCacheFlusherService;
use MOC\Varnish\Service\VarnishBanService;
use TYPO3\Flow\Annotations as Flow;
use TYPO3\Flow\Error\Message;
use TYPO3\Flow\Http\Client\CurlEngine;
use TYPO3\Flow\Http\Uri;
use TYPO3\Flow\Http\Request;
use TYPO3\Neos\Domain\Model\Site;
use TYPO3\Neos\Domain\Service\ContentContext;
use TYPO3\Neos\Domain\Service\ContentDimensionPresetSourceInterface;

class VarnishCacheController extends \TYPO3\Neos\Controller\Module\AbstractModuleController {

	/**
	 * @Flow\Inject
	 * @var \TYPO3\TYPO3CR\Domain\Service\NodeTypeManager
	 */
	protected $nodeTypeManager;

	/**
	 * @Flow\Inject
	 * @var \TYPO3\Neos\Domain\Service\ContentContextFactory
	 */
	protected $contextFactory;

	/**
	 * @Flow\Inject
	 * @var \TYPO3\Neos\Domain\Service\NodeSearchService
	 */
	protected $nodeSearchService;

	/**
	 * @Flow\Inject
	 * @var \TYPO3\Neos\Domain\Repository\SiteRepository
	 */
	protected $siteRepository;

	/**
	 * @Flow\Inject
	 * @var ContentDimensionPresetSourceInterface
	 */
	protected $contentDimensionPresetSource;

	/**
	 * @return void
	 */
	public function indexAction() {
		$this->view->assign('activeSites', $this->siteRepository->findOnline());
	}

	/**
	 * @param string $searchWord
	 * @param Site $selectedSite
	 * @return void
	 */
	public function searchForNodeAction($searchWord, Site $selectedSite = NULL) {
		$documentNodeTypes = $this->nodeTypeManager->getSubNodeTypes('TYPO3.Neos:Document');
		$shortcutNodeType = $this->nodeTypeManager->getNodeType('TYPO3.Neos:Shortcut');
		$nodeTypes = array_diff($documentNodeTypes, array($shortcutNodeType));
		$sites = array();
		$activeSites = $this->siteRepository->findOnline();
		foreach ($selectedSite ? array($selectedSite) : $activeSites as $site) {
			/** @var ContentContext $liveContext */
			$contextProperties = array(
				'workspaceName' => 'live',
				'currentSite' => $site
			);
			$contentDimensionPresets = $this->contentDimensionPresetSource->getAllPresets();
			if (count($contentDimensionPresets) > 0) {
				$mergedContentDimensions = array();
				foreach ($contentDimensionPresets as $contentDimensionIdentifier => $contentDimension) {
					$mergedContentDimensions[$contentDimensionIdentifier] = array($contentDimension['default']);
					foreach ($contentDimension['presets'] as $contentDimensionPreset) {
						$mergedContentDimensions[$contentDimensionIdentifier] = array_merge($mergedContentDimensions[$contentDimensionIdentifier], $contentDimensionPreset['values']);
					}
					$mergedContentDimensions[$contentDimensionIdentifier] = array_values(array_unique($mergedContentDimensions[$contentDimensionIdentifier]));
				}
				$contextProperties['dimensions'] = $mergedContentDimensions;
			}
			$liveContext = $this->contextFactory->create($contextProperties);
			$firstActiveDomain = $site->getFirstActiveDomain();
			$nodes = $this->nodeSearchService->findByProperties($searchWord, $nodeTypes, $liveContext, $liveContext->getCurrentSiteNode());
			if (count($nodes) > 0) {
				$sites[$site->getNodeName()] = array(
					'site' => $site,
					'domain' => $firstActiveDomain ? $firstActiveDomain->getHostPattern() : $this->request->getHttpRequest()->getUri()->getHost(),
					'nodes' => $nodes
				);
			}
{'fraction_non_alphanumeric': 0.1400242204056918, 'fraction_numerical': 0.005752346351801393, 'mean_word_length': 5.304389312977099, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 67, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1214481', 'n_tokens_mistral': 2234, 'n_tokens_neox': 2026, 'n_words': 304}