-
-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add hook to pass certain extra field data from cw_requests to cw_wikis #579
base: master
Are you sure you want to change the base?
Changes from all commits
1821851
a779d8f
b1f9864
d0e118b
e762012
09671de
20ad4e3
efb6e43
6be680d
adfca99
533dd2f
b27de54
88f350b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
namespace Miraheze\CreateWiki\Hooks; | ||
|
||
interface CreateWikiCreationExtraFieldsHook { | ||
|
||
/** | ||
* @param array &$extraFields | ||
* @return void | ||
*/ | ||
public function onCreateWikiCreationExtraFields( array &$extraFields ): void; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,7 @@ class RemoteWikiFactory { | |
private array $logParams = []; | ||
private array $newRows = []; | ||
private array $hooks = []; | ||
private array $extra; | ||
|
||
private string $dbname; | ||
private string $sitename; | ||
|
@@ -104,6 +105,8 @@ public function newInstance( string $wiki ): self { | |
|
||
$this->deletedTimestamp = $row->wiki_deleted_timestamp; | ||
|
||
$this->extra = json_decode( $row->wiki_extra ?: '[]', true ); | ||
|
||
if ( $this->options->get( ConfigNames::UsePrivateWikis ) ) { | ||
$this->private = (bool)$row->wiki_private; | ||
} | ||
|
@@ -380,6 +383,28 @@ public function unMarkExperimental(): void { | |
$this->newRows['wiki_experimental'] = 0; | ||
} | ||
|
||
public function getExtraFieldData( string $field ): mixed { | ||
return $this->extra[$field] ?? null; | ||
} | ||
|
||
public function setExtraFieldData( string $field, mixed $value ): void { | ||
if ( $value !== $this->getExtraFieldData( $field ) ) { | ||
$extra = $this->extra; | ||
$extra[$field] = $value; | ||
|
||
$newExtra = json_encode( $extra ); | ||
|
||
if ( $newExtra === false ) { | ||
// Can not set invalid JSON data to wiki_extra. | ||
return; | ||
} | ||
|
||
$this->extra = $extra; | ||
$this->trackChange( $field, $this->getExtraFieldData( $field ), $value ); | ||
$this->newRows['wiki_extra'] = $newExtra; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Personal Note: This definitely needs tested with more than one field at once (calling this function more than once) as unlike RequestWiki we can't have just a set all field data at once function here, so like the first version of WikiRequestManager this may have an issue with that and will need to be tested and handled some other way if so. |
||
} | ||
} | ||
|
||
public function trackChange( string $field, mixed $oldValue, mixed $newValue ): void { | ||
$this->changes[$field] = [ | ||
'old' => $oldValue, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ALTER TABLE /*$wgDBprefix*/cw_wikis | ||
ADD COLUMN wiki_extra LONGTEXT NULL AFTER wiki_experimental; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Early return?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typically I like early returns but decided not to here as my plan is to eventually make RemoteWikiFactory more similar to how WikiRequestManager works which means it being more inline with that here makes it a tiny bit easier down the line which is why I decided against it. But I guess it wouldn't be horrible to early return also...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright then, feel free to resolve this conversation if you decide not to early return