From 98edd7389fff393d99743448741620a368c84eab Mon Sep 17 00:00:00 2001 From: nischayn22 Date: Tue, 31 Jul 2012 20:32:10 +0530 Subject: [PATCH] Fix minor issues Not using swmfgetStore() in Store3 updating counts for redirects. and small improvements to prepareDBUpdates() Change-Id: I305b28d60c81f6425327970a57d1f409a218ed08 --- .../SQLStore/SMW_DIHandler_Container.php | 6 ++-- .../SQLStore/SMW_DIHandler_WikiPage.php | 6 ++-- .../SQLStore/SMW_SQLStore3_Writers.php | 29 ++++++++++++------- 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/includes/storage/SQLStore/SMW_DIHandler_Container.php b/includes/storage/SQLStore/SMW_DIHandler_Container.php index 20af260106..dd8d311588 100644 --- a/includes/storage/SQLStore/SMW_DIHandler_Container.php +++ b/includes/storage/SQLStore/SMW_DIHandler_Container.php @@ -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 ); } @@ -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 ); } diff --git a/includes/storage/SQLStore/SMW_DIHandler_WikiPage.php b/includes/storage/SQLStore/SMW_DIHandler_WikiPage.php index 9aec53fa6b..67cd6a1926 100644 --- a/includes/storage/SQLStore/SMW_DIHandler_WikiPage.php +++ b/includes/storage/SQLStore/SMW_DIHandler_WikiPage.php @@ -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 ); } @@ -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 ); } diff --git a/includes/storage/SQLStore/SMW_SQLStore3_Writers.php b/includes/storage/SQLStore/SMW_SQLStore3_Writers.php index ee54bf21d8..fb73d0cc5e 100644 --- a/includes/storage/SQLStore/SMW_SQLStore3_Writers.php +++ b/includes/storage/SQLStore/SMW_SQLStore3_Writers.php @@ -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 ) ) { @@ -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 @@ -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 ***// @@ -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, @@ -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. @@ -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; + } } /**