r77394 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r77393‎ | r77394 | r77395 >
Date:16:23, 28 November 2010
Author:kipcool
Status:deferred
Tags:
Comment:
Forbid the deletion of an option_attribute_option that is still in use (mass edit could be too dangerous since there is no easy way to revoke).
Modified paths:
  • /trunk/extensions/Wikidata/OmegaWiki/WikiDataAPI.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Wikidata/OmegaWiki/WikiDataAPI.php
@@ -1001,19 +1001,35 @@
10021002 function removeOptionAttributeOption( $optionId ) {
10031003 $dc = wdGetDataSetContext();
10041004 $dbr = wfGetDB( DB_MASTER );
1005 - $transactionId = getUpdateTransactionId() ;
1006 - $sql = "UPDATE {$dc}_option_attribute_options" .
 1005+
 1006+ // first check if the option attribute option is still in use
 1007+ $sql = "SELECT * FROM {$dc}_option_attribute_values" .
 1008+ ' WHERE option_id = ' . $optionId .
 1009+ ' AND remove_transaction_id IS NULL' ;
 1010+ $queryResult = $dbr->query( $sql );
 1011+
 1012+ if ( $dbr->numRows( $queryResult ) > 0 ) {
 1013+ echo "\nThe option $optionId cannot be deleted because it is still in use!\n" ;
 1014+ } else {
 1015+ // option not used, can proceed to delete
 1016+ $transactionId = getUpdateTransactionId() ;
 1017+ $sql = "UPDATE {$dc}_option_attribute_options" .
10071018 ' SET remove_transaction_id = ' . $transactionId .
10081019 ' WHERE option_id = ' . $optionId .
10091020 ' AND ' . getLatestTransactionRestriction( "{$dc}_option_attribute_options" );
1010 - $dbr->query( $sql );
 1021+ $dbr->query( $sql );
 1022+ }
10111023
1012 - // and remove the attribute values in the syntrans using this option.
 1024+ // alternatively to checking if the attribute option is in use
 1025+ // we could remove all the attribute values in the syntrans using this option.
 1026+ // this is however a bit dangerous (deletes too many information with just one click)
 1027+/*
10131028 $sql = "UPDATE {$dc}_option_attribute_values" .
1014 - ' SET remove_transaction_id = ' . $transactionId .
1015 - ' WHERE option_id = ' . $optionId .
1016 - ' AND remove_transaction_id IS NULL' ;
 1029+ ' SET remove_transaction_id = ' . $transactionId .
 1030+ ' WHERE option_id = ' . $optionId .
 1031+ ' AND remove_transaction_id IS NULL' ;
10171032 $dbr->query( $sql );
 1033+*/
10181034 }
10191035
10201036 /**
@@ -1129,11 +1145,10 @@
11301146 }
11311147
11321148 function isClass( $objectId ) {
1133 - global
1134 - $wgDefaultClassMids;
1135 -
 1149+ global $wgDefaultClassMids;
 1150+
11361151 $result = in_array( $objectId, $wgDefaultClassMids );
1137 -
 1152+
11381153 if ( !$result ) {
11391154 $dc = wdGetDataSetContext();
11401155 $dbr = & wfGetDB( DB_SLAVE );
@@ -1576,8 +1591,7 @@
15771592 * @param $definedMeaningId
15781593 */
15791594 function definedMeaningExpression( $definedMeaningId ) {
1580 - global
1581 - $wgUser;
 1595+ global $wgUser;
15821596
15831597 $userLanguage = getLanguageIdForCode( $wgUser->getOption( 'language' ) );
15841598

Status & tagging log