Skip to content

Commit

Permalink
Fix minor issues
Browse files Browse the repository at this point in the history
Not using swmfgetStore() in Store3
updating counts for redirects. and small improvements to prepareDBUpdates()

Change-Id: I305b28d60c81f6425327970a57d1f409a218ed08
  • Loading branch information
nischayn22 committed Aug 3, 2012
1 parent 2293084 commit 98edd73
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
6 changes: 4 additions & 2 deletions includes/storage/SQLStore/SMW_DIHandler_Container.php
Expand Up @@ -40,7 +40,8 @@ public function getTableIndexes() {
*/
public function getWhereConds( SMWDataItem $dataItem ) {
$subject = $dataItem->getSemanticData()->getSubject();
$sid = smwfGetStore()->getSMWPageID( $subject->getDBkey(), $subject->getNamespace(), $subject->getInterwiki(), $subject->getSubobjectName() );
$store3 = new SMWSQLStore3();
$sid = $store3->getSMWPageID( $subject->getDBkey(), $subject->getNamespace(), $subject->getInterwiki(), $subject->getSubobjectName() );
return array( 'o_id' => $sid );
}

Expand All @@ -55,7 +56,8 @@ public function getWhereConds( SMWDataItem $dataItem ) {
*/
public function getInsertValues( SMWDataItem $dataItem ) {
$subject = $dataItem->getSemanticData()->getSubject();
$sid = smwfGetStore()->makeSMWPageID( $subject->getDBkey(), $subject->getNamespace(), $subject->getInterwiki(),
$store3 = new SMWSQLStore3();
$sid = $store3->makeSMWPageID( $subject->getDBkey(), $subject->getNamespace(), $subject->getInterwiki(),
$subject->getSubobjectName(), true, str_replace( '_', ' ', $subject->getDBkey() ) . $subject->getSubobjectName() );
return array( 'o_id' => $sid );
}
Expand Down
6 changes: 4 additions & 2 deletions includes/storage/SQLStore/SMW_DIHandler_WikiPage.php
Expand Up @@ -38,7 +38,8 @@ public function getTableIndexes() {
* @return array
*/
public function getWhereConds( SMWDataItem $di) {
$oid = smwfGetStore()->getSMWPageID( $di->getDBkey(), $di->getNamespace(), $di->getInterwiki(), $di->getSubobjectName() );
$store3 = new SMWSQLStore3();
$oid = $store3->getSMWPageID( $di->getDBkey(), $di->getNamespace(), $di->getInterwiki(), $di->getSubobjectName() );
return array( 'o_id' => $oid );
}

Expand All @@ -50,7 +51,8 @@ public function getWhereConds( SMWDataItem $di) {
* @return array
*/
public function getInsertValues( SMWDataItem $di ) {
$oid = smwfGetStore()->makeSMWPageID( $di->getDBkey(), $di->getNamespace(), $di->getInterwiki(), $di->getSubobjectName() );
$store3 = new SMWSQLStore3();
$oid = $store3->makeSMWPageID( $di->getDBkey(), $di->getNamespace(), $di->getInterwiki(), $di->getSubobjectName() );
return array( 'o_id' => $oid );
}

Expand Down
29 changes: 19 additions & 10 deletions includes/storage/SQLStore/SMW_SQLStore3_Writers.php
Expand Up @@ -225,19 +225,18 @@ protected function prepareDBUpdates( &$updates, SMWSemanticData $data, $sid, SMW
$tableid = SMWSQLStore3::findPropertyTableID( $property );
$proptable = $proptables[$tableid];

$dataItemId = SMWDataValueFactory::getDataItemId( $property->findPropertyTypeId() );
$diHandler = SMWDIHandlerFactory::getDataItemHandlerForDIType( $dataItemId );
///TODO check needed if subject is null (would happen if a user defined proptable with !idsubject was used on an internal object -- currently this is not possible
$uvals = $proptable->idsubject ? array( 's_id' => $sid ) :
array( 's_title' => $subject->getDBkey(), 's_namespace' => $subject->getNamespace() );
if ( $proptable->fixedproperty == false ) {
$uvals['p_id'] = $this->store->makeSMWPropertyID( $property );
}
foreach ( $data->getPropertyValues( $property ) as $di ) {
if ( $di instanceof SMWDIError ) { // error values, ignore
continue;
}
// redirects were treated above

///TODO check needed if subject is null (would happen if a user defined proptable with !idsubject was used on an internal object -- currently this is not possible
$uvals = $proptable->idsubject ? array( 's_id' => $sid ) :
array( 's_title' => $subject->getDBkey(), 's_namespace' => $subject->getNamespace() );
if ( $proptable->fixedproperty == false ) {
$uvals['p_id'] = $this->store->makeSMWPropertyID( $property );
}
$diHandler = SMWDIHandlerFactory::getDataItemHandlerForDIType( $di->getDIType() );
$uvals = array_merge( $uvals, $diHandler->getInsertValues( $di ) );

if ( !array_key_exists( $proptable->name, $updates ) ) {
Expand Down Expand Up @@ -330,8 +329,11 @@ public function changeTitle( Title $oldtitle, Title $newtitle, $pageid, $redirid
$db->insert( 'smw_redi', array( 's_title' => $oldtitle->getDBkey(),
's_namespace' => $oldtitle->getNamespace(),
'o_id' => $sid ),
__METHOD__ );
__METHOD__
);

$sql = 'UPDATE smw_stats SET usage_count = usage_count + 1 where pid = ' . $this->store->getSMWPropertyID( new SMWDIProperty( '_REDI' ) );
$db->query( $sql, __METHOD__ );
/// 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
Expand Down Expand Up @@ -486,6 +488,7 @@ public function deleteSemanticData( SMWDIWikiPage $subject ) {
*/
protected function updateRedirects( $subject_t, $subject_ns, $curtarget_t = '', $curtarget_ns = -1 ) {
global $smwgQEqualitySupport, $smwgEnableUpdateJobs;
$count = 0; //track count changes for redi property

// *** First get id of subject, old redirect target, and current (new) redirect target ***//

Expand Down Expand Up @@ -514,6 +517,7 @@ protected function updateRedirects( $subject_t, $subject_ns, $curtarget_t = '',
} elseif ( $old_tid != 0 ) { // existing redirect is changed or deleted
$db->delete( 'smw_redi',
array( 's_title' => $subject_t, 's_namespace' => $subject_ns ), __METHOD__ );
$count--;

if ( $smwgEnableUpdateJobs && ( $smwgQEqualitySupport != SMW_EQ_NONE ) ) {
// entries that refer to old target may in fact refer to subject,
Expand Down Expand Up @@ -591,6 +595,7 @@ protected function updateRedirects( $subject_t, $subject_ns, $curtarget_t = '',

$db->insert( 'smw_redi', array( 's_title' => $subject_t,
's_namespace' => $subject_ns, 'o_id' => $new_tid ), __METHOD__ );
$count++;
} else { // delete old redirect
// This case implies $old_tid != 0 (or we would have new_tid == old_tid above).
// Therefore $subject had a redirect, and it must also have an ID.
Expand All @@ -605,8 +610,12 @@ protected function updateRedirects( $subject_t, $subject_ns, $curtarget_t = '',

unset( $this->store->m_semdata[$sid] ); unset( $this->store->m_semdata[$new_tid] ); unset( $this->store->m_semdata[$old_tid] );
unset( $this->store->m_sdstate[$sid] ); unset( $this->store->m_sdstate[$new_tid] ); unset( $this->store->m_sdstate[$old_tid] );
if( $count!= 0 ) {
$sql = 'UPDATE smw_stats SET usage_count = usage_count + ' . $count . ' where pid = ' . $this->store->getSMWPropertyID( new SMWDIProperty( '_REDI' ) );
$db->query( $sql, __METHOD__ );

return ( $new_tid == 0 ) ? $sid : $new_tid;
}
}

/**
Expand Down

0 comments on commit 98edd73

Please sign in to comment.