Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
83.33% |
20 / 24 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| ZObjectSecondaryDataRemoval | |
83.33% |
20 / 24 |
|
50.00% |
1 / 2 |
3.04 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| doUpdate | |
82.61% |
19 / 23 |
|
0.00% |
0 / 1 |
2.02 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * WikiLambda ZObject secondary data remover for when ZObjects are deleted |
| 4 | * |
| 5 | * @file |
| 6 | * @ingroup Extensions |
| 7 | * @copyright 2020– Abstract Wikipedia team; see AUTHORS.txt |
| 8 | * @license MIT |
| 9 | */ |
| 10 | |
| 11 | namespace MediaWiki\Extension\WikiLambda\ZObjectContent; |
| 12 | |
| 13 | use MediaWiki\Deferred\DataUpdate; |
| 14 | use MediaWiki\Extension\WikiLambda\Cache\MemcachedWrapper; |
| 15 | use MediaWiki\Extension\WikiLambda\Registry\ZObjectRegistry; |
| 16 | use MediaWiki\Extension\WikiLambda\ZObjectStore; |
| 17 | use MediaWiki\Logger\LoggerFactory; |
| 18 | use MediaWiki\Title\Title; |
| 19 | use Psr\Log\LoggerInterface; |
| 20 | |
| 21 | class ZObjectSecondaryDataRemoval extends DataUpdate { |
| 22 | |
| 23 | private LoggerInterface $logger; |
| 24 | |
| 25 | /** |
| 26 | * @param Title $title |
| 27 | * @param ZObjectStore $zObjectStore |
| 28 | * @param MemcachedWrapper $zObjectCache |
| 29 | */ |
| 30 | public function __construct( |
| 31 | private readonly Title $title, |
| 32 | private readonly ZObjectStore $zObjectStore, |
| 33 | private readonly MemcachedWrapper $zObjectCache |
| 34 | ) { |
| 35 | // Non-injected items |
| 36 | $this->logger = LoggerFactory::getInstance( 'WikiLambda' ); |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Main entry point for removing all secondary data related to a ZObject. |
| 41 | * |
| 42 | * @return void |
| 43 | */ |
| 44 | public function doUpdate() { |
| 45 | $zid = $this->title->getDBkey(); |
| 46 | |
| 47 | $this->logger->info( |
| 48 | __METHOD__ . ': Removing secondary data for {zid}', |
| 49 | [ 'zid' => $zid ] |
| 50 | ); |
| 51 | |
| 52 | // Remove all secondary store data for the given ZID. |
| 53 | $this->zObjectStore->deleteZObjectLabelsByZid( $zid ); |
| 54 | $this->zObjectStore->deleteZObjectLabelConflictsByZid( $zid ); |
| 55 | $this->zObjectStore->deleteZFunctionReference( $zid ); |
| 56 | $this->zObjectStore->deleteRelatedZObjects( $zid ); |
| 57 | $this->zObjectStore->deleteZLanguageFromLanguagesCache( $zid ); |
| 58 | |
| 59 | // If the ZObject is an implementation or tester, remove its reference from the function. |
| 60 | $this->zObjectStore->removeFunctionReferenceIfImplementationOrTester( $zid ); |
| 61 | |
| 62 | // Remove all rows where the deleted ZObject is the related_zobject. |
| 63 | $this->zObjectStore->deleteRelatedZObjects( null, null, null, $zid ); |
| 64 | |
| 65 | // Clear tester result caches for this ZID. |
| 66 | $this->zObjectStore->deleteZFunctionFromZTesterResultsCache( $zid ); |
| 67 | $this->zObjectStore->deleteZImplementationFromZTesterResultsCache( $zid ); |
| 68 | $this->zObjectStore->deleteZTesterFromZTesterResultsCache( $zid ); |
| 69 | |
| 70 | // Unregister the ZID from caches and clear object cache. |
| 71 | ZObjectRegistry::unregisterZid( $zid ); |
| 72 | $cacheKey = $this->zObjectCache->makeKey( ZObjectStore::ZOBJECT_CACHE_KEY_PREFIX, $zid ); |
| 73 | $cacheResult = $this->zObjectCache->delete( $cacheKey ); |
| 74 | if ( !$cacheResult ) { |
| 75 | $this->logger->warning( |
| 76 | __METHOD__ . ': Failed to delete object cache for {zid}', |
| 77 | [ 'zid' => $zid ] |
| 78 | ); |
| 79 | } |
| 80 | } |
| 81 | } |