private function tryFindMatchResultFor($hash, $dataValue)
 {
     $descriptionFactory = $this->queryFactory->newDescriptionFactory();
     $contextPage = $dataValue->getContextPage();
     // Exclude the current page from the result match to check whether another
     // page matches the condition and if so then the value can no longer be
     // assigned and is not unique
     $description = $descriptionFactory->newConjunction(array($descriptionFactory->newFromDataValue($dataValue), $descriptionFactory->newValueDescription($contextPage, null, SMW_CMP_NEQ)));
     $query = $this->queryFactory->newQuery($description);
     $query->setLimit(1);
     $dataItems = $this->cachedPropertyValuesPrefetcher->queryPropertyValuesFor($query);
     if (!is_array($dataItems) || $dataItems === array()) {
         // No other assignments were found therefore it is assumed that at
         // the time of the query request, the "contextPage" holds a unique
         // value for the property
         $page = $contextPage;
     } else {
         $page = end($dataItems);
     }
     // Create a linked list so that when the subject is altered or deleted
     // the related uniqueness container can be removed as well
     $blobStore = $this->cachedPropertyValuesPrefetcher->getBlobStore();
     $container = $blobStore->read($this->cachedPropertyValuesPrefetcher->getRootHashFrom($page));
     $container->addToLinkedList($hash);
     $blobStore->save($container);
     return $page;
 }
 public function testQueryPropertyValuesFor()
 {
     $expected = array(DIWikiPage::newFromText('Foo'));
     $queryResult = $this->getMockBuilder('\\SMWQueryResult')->disableOriginalConstructor()->getMock();
     $queryResult->expects($this->atLeastOnce())->method('getResults')->will($this->returnValue($expected));
     $this->store->expects($this->any())->method('getQueryResult')->will($this->returnValue($queryResult));
     $query = $this->getMockBuilder('\\SMWQuery')->disableOriginalConstructor()->getMock();
     $instance = new CachedPropertyValuesPrefetcher($this->store, $this->blobStore);
     $this->assertEquals($expected, $instance->queryPropertyValuesFor($query));
 }
 /**
  * @since 2.4
  *
  * @param string $displayTitle
  *
  * @return DIProperty|false
  */
 public function getPropertyFromDisplayTitle($displayTitle)
 {
     $descriptionFactory = new DescriptionFactory();
     $description = $descriptionFactory->newSomeProperty(new DIProperty('_DTITLE'), $descriptionFactory->newValueDescription(new DIBlob($displayTitle)));
     $query = new Query($description);
     $query->setLimit(1);
     $dataItems = $this->cachedPropertyValuesPrefetcher->queryPropertyValuesFor($query);
     if (is_array($dataItems) && $dataItems !== array()) {
         $dataItem = end($dataItems);
         // Cache results as a linked list attached to
         // the property so that it can be purged all together
         return new DIProperty($dataItem->getDBKey());
     }
     return false;
 }