Semantic MediaWiki and related extensions
Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
SMWSQLStore3Writers Class Reference

Public Member Functions

 __construct (SMWSQLStore3 $parentStore, $factory)
 
 deleteSubject (Title $title)
 
 doDataUpdate (SMWSemanticData $semanticData)
 
 changeTitle (Title $oldTitle, Title $newTitle, $pageId, $redirectId=0)
 

Protected Member Functions

 doFlatDataUpdate (SMWSemanticData $data)
 
 writePropertyTableUpdates ($sid, array $tablesInsertRows, array $tablesDeleteRows, array $newHashes)
 
 writePropertyTableRowUpdates (array &$propertyUseIncrements, SMWSQLStore3Table $propertyTable, array $rows, $insert)
 
 deleteRows (array $rows, SMWSQLStore3Table $propertyTable)
 
 setSemanticDataCache ($sid, SMWSemanticData $semanticData)
 
 updateRedirects ($subject_t, $subject_ns, $curtarget_t= '', $curtarget_ns=-1)
 

Static Protected Member Functions

static makeDatabaseRowKey (array $databaseRow)
 

Protected Attributes

 $store
 

Detailed Description

Class Handling all the write and update methods for SMWSQLStore3.

Note
Writing may also require some reading operations. Operations that are only needed in helper methods of this class should be implemented here, not in SMWSQLStore3Readers.
Author
Markus Krötzsch
Jeroen De Dauw
Nischay Nahata
Since
1.8

Constructor & Destructor Documentation

SMWSQLStore3Writers::__construct ( SMWSQLStore3  $parentStore,
  $factory 
)
Since
1.8
Parameters
SMWSQLStore3$parentStore
SQLStoreFactory$factory

Member Function Documentation

SMWSQLStore3Writers::changeTitle ( Title  $oldTitle,
Title  $newTitle,
  $pageId,
  $redirectId = 0 
)

Implementation of SMWStore::changeTitle(). In contrast to updateRedirects(), this function does not simply write a redirect from the old page to the new one, but also deletes all data that may already be stored for the new title (normally the new title should belong to an empty page that has no data but at least it could have a redirect to the old page), and moves all data that exists for the old title to the new location. Thus, the function executes three steps: delete data at newtitle, move data from oldtitle to newtitle, and set redirect from oldtitle to newtitle. In some cases, the goal can be achieved more efficiently, e.g. if the new title does not occur in SMW yet: then we can just change the ID records for the titles instead of changing all data tables

Note that the implementation ignores the MediaWiki IDs since this store has its own ID management. Also, the function requires that both titles are local, i.e. have empty interwiki prefix.

Todo:
Currently the sortkey is not moved with the remaining data. It is not possible to move it reliably in all cases: we cannot distinguish an unset sortkey from one that was set to the name of oldtitle. Maybe use update jobs right away?
Since
1.8
Parameters
Title$oldTitle
Title$newTitle
integer$pageId
integer$redirectId

NOTE: there is the (bad) case that the moved page is a redirect. As chains of redirects are not supported by MW or SMW, the above is maximally correct in this case too. NOTE: this temporarily leaves existing redirects to oldtitle point to newtitle as well, which will be lost after the next update. Since double redirects are an error anyway, this is not a bad behavior: everything will continue to work until the existing redirects are updated, which will hopefully be done to fix the double redirect.

SMWSQLStore3Writers::deleteRows ( array  $rows,
SMWSQLStore3Table  $propertyTable 
)
protected
SMWSQLStore3Writers::deleteSubject ( Title  $title)
See also
SMWStore::deleteSubject
Since
1.8
Parameters
Title$title
SMWSQLStore3Writers::doDataUpdate ( SMWSemanticData  $semanticData)
See also
SMWStore::doDataUpdate
Since
1.8
Parameters
SMWSemanticData$data
SMWSQLStore3Writers::doFlatDataUpdate ( SMWSemanticData  $data)
protected

Update the store to contain the given data, without taking any subobject data into account.

Since
1.8
Parameters
SMWSemanticData$data
static SMWSQLStore3Writers::makeDatabaseRowKey ( array  $databaseRow)
staticprotected

Create a string key for hashing an array of values that represents a row in the database. Used to eliminate duplicates and to support diff computation. This is not stored in the database, so it can be changed without causing any problems with legacy data.

Since
1.8
Parameters
array$databaseRow
Returns
string
SMWSQLStore3Writers::setSemanticDataCache (   $sid,
SMWSemanticData  $semanticData 
)
protected

Set the semantic data cache to hold exactly the given value for the given ID.

Since
1.8
Parameters
integer$sid
SMWSemanticData$semanticData
SMWSQLStore3Writers::updateRedirects (   $subject_t,
  $subject_ns,
  $curtarget_t = '',
  $curtarget_ns = -1 
)
protected

Helper method to write information about some redirect. Various updates can be necessary if redirects are resolved as identities in SMW. The title and namespace of the affected page and of its updated redirect target are given. The target can be empty ('') to delete any redirect. Returns the canonical ID that is now to be used for the subject.

This method does not change the ids of the affected pages, and thus it is not concerned with updates of the data that is currently stored for the subject. Normally, a subject that is a redirect will not have other data, but this method does not depend on this.

Note
Please make sure you fully understand this code before making any changes here. Keeping the redirect structure consistent is important, and errors in this code can go unnoticed for quite some time.
This method merely handles the addition or deletion of a redirect statement in the wiki. It does not assume that any page contents has been changed (e.g. moved). See changeTitle() for additional handling in this case.
Todo:
Clean up this code.
Since
1.8
Parameters
string$subject_t
integer$subject_ns
string$curtarget_t
integer$curtarget_ns
Returns
integer the new canonical ID of the subject

NOTE: $sid can be 0 here; this is useful to know since it means that fewer table updates are needed

NOTE: $old_tid and $new_tid both (intentionally) ignore further redirects: no redirect chains

NOTE: we do not update the concept cache here; this remains an offline task

SMWSQLStore3Writers::writePropertyTableRowUpdates ( array &  $propertyUseIncrements,
SMWSQLStore3Table  $propertyTable,
array  $rows,
  $insert 
)
protected

Update one property table by inserting or deleting rows, and compute the changes that this entails for the property usage counts. The given rows are inserted into the table if $insert is true; otherwise they are deleted. The property usage counts are recorded in the call-by-ref parameter $propertyUseIncrements.

The method assumes that all of the given rows are about the same subject. This is ensured by callers.

Since
1.8
Parameters
array$propertyUseIncrements
SMWSQLStore3Table$propertyTable
array$rowsarray of rows to insert/delete
boolean$insert
SMWSQLStore3Writers::writePropertyTableUpdates (   $sid,
array  $tablesInsertRows,
array  $tablesDeleteRows,
array  $newHashes 
)
protected

Update all property tables and any dependent data (hashes, statistics, etc.) by inserting/deleting the given values. The ID of the page that is updated, and the hashes of the properties must be given explicitly (the hashes could not be computed from the insert and delete data alone anyway).

It is assumed and required that the tables mentioned in $tablesInsertRows and $tablesDeleteRows are the same, and that all $rows in these datasets refer to the same subject ID.

Since
1.8
Parameters
integer$sid
array$tablesInsertRowsarray mapping table names to arrays of rows
array$tablesDeleteRowsarray mapping table names to arrays of rows
array$newHashes

Member Data Documentation

SMWSQLStore3Writers::$store
protected

The documentation for this class was generated from the following file: