public function testComputeTableRowDiffForEmptyPropertyTables()
 {
     $semanticData = new SemanticData(new DIWikiPage('Foo', NS_MAIN));
     $propertyTables = array();
     $store = $this->getMockBuilder('\\SMW\\SQLStore\\SQLStore')->setMethods(array('getPropertyTables'))->getMock();
     $store->expects($this->any())->method('getPropertyTables')->will($this->returnValue($propertyTables));
     $instance = new PropertyTableRowDiffer($store);
     $result = $instance->computeTableRowDiffFor(42, $semanticData);
     $this->assertInternalType('array', $result);
 }
 public function testCompositePropertyTableDiffIteratorWithUnknownFixedProperty()
 {
     $propertyTable = $this->getMockBuilder('\\SMW\\SQLStore\\TableDefinition')->disableOriginalConstructor()->getMock();
     $propertyTable->expects($this->once())->method('usesIdSubject')->will($this->returnValue(true));
     $propertyTable->expects($this->once())->method('isFixedPropertyTable')->will($this->returnValue(true));
     $propertyTable->expects($this->once())->method('getFixedProperty')->will($this->returnValue('_UNKNOWN_FIXED_PROPERTY'));
     $semanticData = new SemanticData(new DIWikiPage('Foo', NS_MAIN));
     $propertyTables = array($propertyTable);
     $store = $this->getMockBuilder('\\SMW\\SQLStore\\SQLStore')->setMethods(array('getPropertyTables'))->getMock();
     $store->expects($this->any())->method('getPropertyTables')->will($this->returnValue($propertyTables));
     $instance = new PropertyTableRowDiffer($store);
     $instance->resetCompositePropertyTableDiff();
     $result = $instance->computeTableRowDiffFor(42, $semanticData);
     $this->assertInstanceOf('\\SMW\\SQLStore\\CompositePropertyTableDiffIterator', $instance->getCompositePropertyTableDiff());
     $this->assertEmpty($instance->getCompositePropertyTableDiff()->getFixedPropertyRecords());
 }
 /**
  * Update the store to contain the given data, without taking any
  * subobject data into account.
  *
  * @since 1.8
  * @param SMWSemanticData $data
  */
 protected function doFlatDataUpdate(SMWSemanticData $data)
 {
     $subject = $data->getSubject();
     if ($this->store->canUseUpdateFeature(SMW_TRX_UPDATE)) {
         $this->store->getConnection()->beginTransaction(__METHOD__);
     }
     // Take care of redirects
     $redirects = $data->getPropertyValues(new SMWDIProperty('_REDI'));
     if (count($redirects) > 0) {
         $redirect = end($redirects);
         // at most one redirect per page
         $this->updateRedirects($subject->getDBkey(), $subject->getNamespace(), $redirect->getDBkey(), $redirect->getNameSpace());
         // Stop here:
         // * no support for annotations on redirect pages
         // * updateRedirects takes care of deleting any previous data
         $this->store->getConnection()->commitTransaction(__METHOD__);
         return;
     } else {
         $this->updateRedirects($subject->getDBkey(), $subject->getNamespace());
     }
     // Take care of the sortkey
     $sortkeyDataItems = $data->getPropertyValues(new SMWDIProperty('_SKEY'));
     $sortkeyDataItem = end($sortkeyDataItems);
     if ($sortkeyDataItem instanceof SMWDIBlob) {
         $sortkey = $sortkeyDataItem->getString();
     } else {
         // default sortkey
         $sortkey = $subject->getSortKey();
     }
     // #649 Be consistent about how sortkeys are stored therefore always
     // normalize even for usages like {{DEFAULTSORT: Foo_bar }}
     $sortkey = str_replace('_', ' ', $sortkey);
     // Always make an ID; this also writes sortkey and namespace data
     $sid = $this->store->getObjectIds()->makeSMWPageID($subject->getDBkey(), $subject->getNamespace(), $subject->getInterwiki(), $subject->getSubobjectName(), true, $sortkey, true);
     // Take care of all remaining property table data
     list($deleteRows, $insertRows, $newHashes) = $this->propertyTableRowDiffer->computeTableRowDiffFor($sid, $data);
     $this->writePropertyTableUpdates($sid, $deleteRows, $insertRows, $newHashes);
     if ($redirects === array() && $subject->getSubobjectName() === '') {
         $dataItemFromId = $this->store->getObjectIds()->getDataItemForId($sid);
         // If for some reason the internal redirect marker is still set but no
         // redirect annotations are known then do update the interwiki field
         if ($dataItemFromId !== null && $dataItemFromId->getInterwiki() === SMW_SQL3_SMWREDIIW) {
             $this->store->getObjectIds()->updateInterwikiField($sid, $subject);
         }
     }
     // Update caches (may be important if jobs are directly following this call)
     $this->setSemanticDataCache($sid, $data);
     $this->store->getConnection()->commitTransaction(__METHOD__);
     // TODO Make overall diff SMWSemanticData containers and return them.
     // This can only be done here, since the $deleteRows/$insertRows
     // alone do not have enough information to compute this later (sortkey
     // and redirects may also change).
 }