/** * Create an array of rows to insert into property tables in order to * store the given SMWSemanticData. The given $sid (subject page id) is * used directly and must belong to the subject of the data container. * Sortkeys are ignored since they are not stored in a property table * but in the ID table. * * The returned array uses property table names as keys and arrays of * table rows as values. Each table row is an array mapping column * names to values. * * @note Property tables that do not use ids as subjects are ignored. * This just excludes redirects that are handled differently anyway; * it would not make a difference to include them here. * * @since 1.8 * * @param integer $sid * @param SemanticData $semanticData * * @return array */ private function mapToInsertValueFormat($sid, SemanticData $semanticData) { $updates = array(); $subject = $semanticData->getSubject(); $propertyTables = $this->store->getPropertyTables(); foreach ($semanticData->getProperties() as $property) { $tableId = $this->store->findPropertyTableID($property); // not stored in a property table, e.g., sortkeys if ($tableId === null) { continue; } // "Notice: Undefined index" if (!isset($propertyTables[$tableId])) { throw new RuntimeException("Unable to find a property table for " . $property->getKey()); } $propertyTable = $propertyTables[$tableId]; // not using subject ids, e.g., redirects if (!$propertyTable->usesIdSubject()) { continue; } $insertValues = array('s_id' => $sid); if (!$propertyTable->isFixedPropertyTable()) { $insertValues['p_id'] = $this->store->getObjectIds()->makeSMWPropertyID($property); } foreach ($semanticData->getPropertyValues($property) as $dataItem) { if ($dataItem instanceof DIError) { // ignore error values continue; } if (!array_key_exists($propertyTable->getName(), $updates)) { $updates[$propertyTable->getName()] = array(); } $dataItemValues = $this->store->getDataItemHandlerForDIType($dataItem->getDIType())->getInsertValues($dataItem); // Ensure that the sortkey is a string if (isset($dataItemValues['o_sortkey'])) { $dataItemValues['o_sortkey'] = (string) $dataItemValues['o_sortkey']; } // Make sure to build a unique set without duplicates which could happen // if an annotation is made to a property that has a redirect pointing // to the same p_id $insertValues = array_merge($insertValues, $dataItemValues); $insertValuesHash = md5(implode('#', $insertValues)); $updates[$propertyTable->getName()][$insertValuesHash] = $insertValues; } } // Special handling of Concepts if ($subject->getNamespace() === SMW_NS_CONCEPT && $subject->getSubobjectName() == '') { $this->fetchConceptTableInserts($sid, $updates); } return $updates; }