24 private const RIGHT =
'translate-manage';
25 private const VALID_OPS = [
'resolveMessage',
'resolveGroup' ];
27 private LoggerInterface $groupSyncLog;
29 public function __construct(
34 parent::__construct( $mainModule, $moduleName );
35 $this->groupSyncCache = $groupSyncCache;
39 public function execute() {
40 $this->checkUserRightsAny( self::RIGHT );
41 $block = $this->getUser()->getBlock();
42 if ( $block && $block->isSitewide() ) {
43 $this->dieBlocked( $block );
46 $params = $this->extractRequestParams();
47 $operation = $params[
'operation'];
48 $groupId = $params[
'group'];
49 $titleStr = $params[
'title'] ??
null;
51 $group = MessageGroups::getGroup( $groupId );
52 if ( $group ===
null ) {
53 $this->dieWithError(
'apierror-translate-invalidgroup',
'invalidgroup' );
57 if ( $operation ===
'resolveMessage' ) {
58 if ( $titleStr ===
null ) {
59 $this->dieWithError( [
'apierror-missingparam',
'title' ] );
61 $this->markAsResolved( $groupId, $titleStr );
62 } elseif ( $operation ===
'resolveGroup' ) {
63 $this->markAsResolved( $groupId );
65 }
catch ( Exception $e ) {
67 'requestParams' => $params,
68 'exceptionMessage' => $e->getMessage()
71 $this->groupSyncLog->error(
72 "Error while running: ManageGroupSynchronizationCacheActionApi::execute. Details: \n" .
73 FormatJson::encode( $data,
true )
78 'apierror-translate-operation-error',
79 wfEscapeWikiText( $e->getMessage() )
85 private function markAsResolved(
string $groupId, ?
string $messageTitle =
null ):
void {
86 if ( $messageTitle ===
null ) {
87 $currentGroupStatus = $this->groupSyncCache->markGroupAsResolved( $groupId );
88 $this->groupSyncLog->info(
89 '{user} resolved group {groupId}.',
91 'user' => $this->getUser()->getName(),
96 $this->groupSyncCache->markMessageAsResolved( $groupId, $messageTitle );
97 $currentGroupStatus = $this->groupSyncCache->syncGroupErrors( $groupId );
98 $this->groupSyncLog->info(
99 '{user} resolved message {messageTitle} in group {groupId}.',
101 'user' => $this->getUser()->getName(),
102 'groupId' => $groupId,
103 'messageTitle' => $messageTitle
108 $this->getResult()->addValue(
null, $this->getModuleName(), [
111 'groupRemainingMessageCount' => count( $currentGroupStatus->getRemainingMessages() )
116 protected function getAllowedParams() {
119 ParamValidator::PARAM_TYPE => self::VALID_OPS,
120 ParamValidator::PARAM_ISMULTI =>
false,
121 ParamValidator::PARAM_REQUIRED =>
true,
124 ParamValidator::PARAM_TYPE =>
'string',
125 ParamValidator::PARAM_REQUIRED => false
128 ParamValidator::PARAM_TYPE =>
'string',
129 ParamValidator::PARAM_REQUIRED => true
134 public function isInternal() {
138 public function needsToken() {