public function testRoundtripForRegisteredNamespace()
 {
     $instance = new CircularReferenceGuard('bar');
     $instance->setMaxRecursionDepth(1);
     $this->assertEquals(0, $instance->get('Foo'));
     $instance->mark('Foo');
     $instance->mark('Foo');
     $this->assertEquals(2, $instance->get('Foo'));
     $this->assertTrue($instance->isCircularByRecursionFor('Foo'));
     $instance->unmark('Foo');
     $this->assertEquals(1, $instance->get('Foo'));
     $this->assertFalse($instance->isCircularByRecursionFor('Foo'));
     $instance->unmark('notBeenMarkedBefore');
 }
 /**
  * @since 2.5
  *
  * @param $dataItem
  *
  * @return DataItem
  */
 public function findRedirectTarget($dataItem)
 {
     if (!$dataItem instanceof DIWikiPage && !$dataItem instanceof DIProperty) {
         return $dataItem;
     }
     $hash = $dataItem->getSerialization();
     // Guard against a dataItem that points to itself
     $this->circularReferenceGuard->mark($hash);
     if (!$this->circularReferenceGuard->isCircularByRecursionFor($hash)) {
         $dataItem = $this->store->getRedirectTarget($dataItem);
     }
     $this->circularReferenceGuard->unmark($hash);
     return $dataItem;
 }
 private function doFetchResultsForRawParameters(array $rawParams)
 {
     // FIXME QueryDuration should be a property of the QueryProcessor or
     // QueryEngine but since we don't want to open the pandora's box and
     // increase issues within the current QueryProcessor implementation
     // we will track the time outside of the actual execution framework
     $queryDuration = 0;
     $start = microtime(true);
     list($this->query, $this->params) = SMWQueryProcessor::getQueryAndParamsFromFunctionParams($rawParams, SMW_OUTPUT_WIKI, SMWQueryProcessor::INLINE_QUERY, $this->showMode);
     $queryHash = $this->query->getHash();
     $this->circularReferenceGuard->mark($queryHash);
     // If we caught in a circular loop (due to a template referencing to itself)
     // then we stop here before the next query execution to avoid an infinite
     // self-reference
     if ($this->circularReferenceGuard->isCircularByRecursionFor($queryHash)) {
         return '';
     }
     $result = SMWQueryProcessor::getResultFromQuery($this->query, $this->params, SMW_OUTPUT_WIKI, SMWQueryProcessor::INLINE_QUERY);
     // FIXME Should be injected
     // A printer run its own isolated wgParser process therefore if the printer
     // or a template inclusion is used by a printer, possible extra annotations
     // need to be imported for further usage
     $this->parserData->importFromParserOutput($GLOBALS['wgParser']->getOutput());
     if ($this->applicationFactory->getSettings()->get('smwgQueryDurationEnabled')) {
         $queryDuration = microtime(true) - $start;
     }
     $this->circularReferenceGuard->unmark($queryHash);
     $this->createQueryProfile($this->query, $this->params['format']->getValue(), $queryDuration);
     return $result;
 }
 private function doFetchResultsForRawParameters(array $rawParams)
 {
     // FIXME QueryDuration should be a property of the QueryProcessor or
     // QueryEngine but since we don't want to open the pandora's box and
     // increase issues within the current QueryProcessor implementation
     // we will track the time outside of the actual execution framework
     $queryDuration = 0;
     $start = microtime(true);
     list($this->query, $this->params) = SMWQueryProcessor::getQueryAndParamsFromFunctionParams($rawParams, SMW_OUTPUT_WIKI, SMWQueryProcessor::INLINE_QUERY, $this->showMode);
     $this->query->setSubject(DIWIkiPage::newFromTitle($this->parserData->getTitle()));
     $queryHash = $this->query->getHash();
     $this->circularReferenceGuard->mark($queryHash);
     // If we caught in a circular loop (due to a template referencing to itself)
     // then we stop here before the next query execution to avoid an infinite
     // self-reference
     if ($this->circularReferenceGuard->isCircularByRecursionFor($queryHash)) {
         return '';
     }
     $result = SMWQueryProcessor::getResultFromQuery($this->query, $this->params, SMW_OUTPUT_WIKI, SMWQueryProcessor::INLINE_QUERY);
     $format = $this->params['format']->getValue();
     // FIXME Parser should be injected into the ResultPrinter
     // Enables specific formats to import its annotation data from
     // a recursive parse process in the result format
     // e.g. using ask query to search/set an invert property value
     if (isset($this->params['import-annotation']) && $this->params['import-annotation']->getValue()) {
         $this->parserData->importFromParserOutput($GLOBALS['wgParser']->getOutput());
     }
     if ($this->applicationFactory->getSettings()->get('smwgQueryDurationEnabled')) {
         $queryDuration = microtime(true) - $start;
     }
     $this->circularReferenceGuard->unmark($queryHash);
     $this->createQueryProfile($this->query, $format, $queryDuration);
     return $result;
 }
 private function doFetchResultsForRawParameters(array $rawParams)
 {
     $contextPage = $this->parserData->getSubject();
     list($query, $this->params) = SMWQueryProcessor::getQueryAndParamsFromFunctionParams($rawParams, SMW_OUTPUT_WIKI, SMWQueryProcessor::INLINE_QUERY, $this->showMode, $contextPage);
     $query->setContextPage($contextPage);
     $queryHash = $query->getHash();
     $this->circularReferenceGuard->mark($queryHash);
     // If we caught in a circular loop (due to a template referencing to itself)
     // then we stop here before the next query execution to avoid an infinite
     // self-reference
     if ($this->circularReferenceGuard->isCircularByRecursionFor($queryHash)) {
         return '';
     }
     $result = SMWQueryProcessor::getResultFromQuery($query, $this->params, SMW_OUTPUT_WIKI, SMWQueryProcessor::INLINE_QUERY);
     $format = $this->params['format']->getValue();
     // FIXME Parser should be injected into the ResultPrinter
     // Enables specific formats to import its annotation data from
     // a recursive parse process in the result format
     // e.g. using ask query to search/set an invert property value
     if (isset($this->params['import-annotation']) && $this->params['import-annotation']->getValue()) {
         $this->parserData->importFromParserOutput($GLOBALS['wgParser']->getOutput());
     }
     $this->circularReferenceGuard->unmark($queryHash);
     // In case of an query error add a marker to the subject for discoverability
     // of a failed query, don't bail-out as we can have results and errors
     // at the same time
     if ($query->getErrors() !== array()) {
         $this->addProcessingError($query->getErrors());
     }
     $this->createQueryProfile($query, $format);
     return $result;
 }