Index: trunk/extensions/Wikidata/OmegaWiki/WikiDataAPI.php |
— | — | @@ -1001,19 +1001,35 @@ |
1002 | 1002 | function removeOptionAttributeOption( $optionId ) { |
1003 | 1003 | $dc = wdGetDataSetContext(); |
1004 | 1004 | $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" . |
1007 | 1018 | ' SET remove_transaction_id = ' . $transactionId . |
1008 | 1019 | ' WHERE option_id = ' . $optionId . |
1009 | 1020 | ' AND ' . getLatestTransactionRestriction( "{$dc}_option_attribute_options" ); |
1010 | | - $dbr->query( $sql ); |
| 1021 | + $dbr->query( $sql ); |
| 1022 | + } |
1011 | 1023 | |
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 | +/* |
1013 | 1028 | $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' ; |
1017 | 1032 | $dbr->query( $sql ); |
| 1033 | +*/ |
1018 | 1034 | } |
1019 | 1035 | |
1020 | 1036 | /** |
— | — | @@ -1129,11 +1145,10 @@ |
1130 | 1146 | } |
1131 | 1147 | |
1132 | 1148 | function isClass( $objectId ) { |
1133 | | - global |
1134 | | - $wgDefaultClassMids; |
1135 | | - |
| 1149 | + global $wgDefaultClassMids; |
| 1150 | + |
1136 | 1151 | $result = in_array( $objectId, $wgDefaultClassMids ); |
1137 | | - |
| 1152 | + |
1138 | 1153 | if ( !$result ) { |
1139 | 1154 | $dc = wdGetDataSetContext(); |
1140 | 1155 | $dbr = & wfGetDB( DB_SLAVE ); |
— | — | @@ -1576,8 +1591,7 @@ |
1577 | 1592 | * @param $definedMeaningId |
1578 | 1593 | */ |
1579 | 1594 | function definedMeaningExpression( $definedMeaningId ) { |
1580 | | - global |
1581 | | - $wgUser; |
| 1595 | + global $wgUser; |
1582 | 1596 | |
1583 | 1597 | $userLanguage = getLanguageIdForCode( $wgUser->getOption( 'language' ) ); |
1584 | 1598 | |