private function getPropertyTableForType($type)
 {
     $propertyTables = $this->store->getPropertyTables();
     $tableIdForType = $this->store->findTypeTableId($type);
     if (isset($propertyTables[$tableIdForType])) {
         return $propertyTables[$tableIdForType];
     }
     throw new RuntimeException("Tried to access a table that doesn't exist for {$type}.");
 }
 /**
  * @since 1.9
  */
 public function rebuild()
 {
     $this->reportMessage("Updating property statistics. This may take a while.\n");
     $this->propertyStatisticsStore->deleteAll();
     $res = $this->store->getConnection('mw.db')->select(\SMWSql3SmwIds::tableName, array('smw_id', 'smw_title'), array('smw_namespace' => SMW_NS_PROPERTY), __METHOD__);
     foreach ($res as $row) {
         $this->reportMessage('.');
         $usageCount = 0;
         foreach ($this->store->getPropertyTables() as $propertyTable) {
             if ($propertyTable->isFixedPropertyTable() && $propertyTable->getFixedProperty() !== $row->smw_title) {
                 // This table cannot store values for this property
                 continue;
             }
             $usageCount += $this->getPropertyTableRowCount($propertyTable, $row->smw_id);
         }
         $this->propertyStatisticsStore->insertUsageCount((int) $row->smw_id, $usageCount);
     }
     $propCount = $res->numRows();
     $this->store->getConnection('mw.db')->freeResult($res);
     $this->reportMessage("\nUpdated statistics for {$propCount} Properties.\n");
 }
 /**
  * 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;
 }
 private function cleanUpPropertyTablesFor($id)
 {
     $db = $this->store->getConnection('mw.db');
     foreach ($this->store->getPropertyTables() as $proptable) {
         if ($proptable->usesIdSubject()) {
             $db->delete($proptable->getName(), array('s_id' => $id), __METHOD__);
         }
         // Need to clean-up possible references in the redirect table
         if (strpos($proptable->getName(), 'fpt_redi') !== false) {
             $db->delete($proptable->getName(), array('o_id' => $id), __METHOD__);
         }
     }
     $db->delete(\SMWSql3SmwIds::TABLE_NAME, array('smw_id' => $id), __METHOD__);
 }
Exemplo n.º 5
0
 /**
  * @since 2.0
  */
 public function getPropertyTables()
 {
     return $this->baseStore->getPropertyTables();
 }