Skip to content

Commit a2d8dd9

Browse files
committed
Add SMW::FileUpload::BeforeUpdate
A hook for the upload event to avoid having users to override the method or trigger an extra `updateStore` event which causes symptoms as described in [0]. [0] http://wikimedia.7.x6.nabble.com/Setting-new-predefined-property-tp5061956.html
1 parent 443ed38 commit a2d8dd9

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
## SMW::FileUpload::BeforeUpdate hook
2+
3+
SMW 2.4
4+
5+
```php
6+
use SMW\DataItemFactory
7+
8+
$GLOBALS['wgHooks']['SMW::FileUpload::BeforeUpdate'][] = function ( $filePage, $semanticData ) {
9+
10+
$dataItemFactory = new DataItemFactory();
11+
12+
$property = $dataItemFactory->newDIProperty( '___ext_file_sha1' );
13+
14+
$semanticData->addPropertyObjectValue(
15+
$property,
16+
$dataItemFactory->newDIBlob( $filePage->getFile()->getSha1() )
17+
);
18+
19+
$property = $dataItemFactory->newDIProperty( '___ext_file_size' );
20+
21+
$semanticData->addPropertyObjectValue(
22+
$property,
23+
$dataItemFactory->newDIBlob( $filePage->getFile()->getSize() )
24+
);
25+
26+
return true;
27+
};
28+
```

docs/technical/hooks.md

+4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ Implementing a hook should be made in consideration of the expected performance
3535
- `SMW::SQLStore::AfterDataUpdateComplete` to add processing after the update has been completed and provides `CompositePropertyTableDiffIterator` to identify entities
3636
that have been added/removed during the update. <sup>Use of `SMWSQLStore3::updateDataAfter` was deprecated with 2.3</sup>
3737

38+
### 2.4
39+
40+
- `SMW::FileUpload::BeforeUpdate` to add extra annotations before the store update is triggered
41+
3842
For implementation details and examples, see the [integration test](https://github.com/SemanticMediaWiki/SemanticMediaWiki/blob/master/tests/phpunit/Integration/SemanticMediaWikiProvidedHookInterfaceIntegrationTest.php).
3943

4044
## Other available hooks

src/MediaWiki/Hooks/FileUpload.php

+3
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ private function performUpdate() {
8686

8787
$propertyAnnotator->addAnnotation();
8888

89+
// 2.4+
90+
\Hooks::run( 'SMW::FileUpload::BeforeUpdate', array( $filePage, $parserData->getSemanticData() ) );
91+
8992
$parserData->pushSemanticDataToParserOutput();
9093
$parserData->updateStore( true );
9194

0 commit comments

Comments
 (0)