23 private const RIGHT =
'translate-manage';
24 private const VALID_OPS = [
'resolveMessage',
'resolveGroup' ];
26 private LoggerInterface $groupSyncLog;
29 parent::__construct( $mainModule, $moduleName );
30 $this->groupSyncCache = $groupSyncCache;
31 $this->groupSyncLog = LoggerFactory::getInstance(
'Translate.GroupSynchronization' );
34 public function execute() {
35 $this->checkUserRightsAny( self::RIGHT );
36 $block = $this->getUser()->getBlock();
37 if ( $block && $block->isSitewide() ) {
38 $this->dieBlocked( $block );
41 $params = $this->extractRequestParams();
42 $operation = $params[
'operation'];
43 $groupId = $params[
'group'];
44 $titleStr = $params[
'title'] ??
null;
46 $group = MessageGroups::getGroup( $groupId );
47 if ( $group ===
null ) {
48 $this->dieWithError(
'apierror-translate-invalidgroup',
'invalidgroup' );
52 if ( $operation ===
'resolveMessage' ) {
53 if ( $titleStr ===
null ) {
54 $this->dieWithError( [
'apierror-missingparam',
'title' ] );
56 $this->markAsResolved( $groupId, $titleStr );
57 } elseif ( $operation ===
'resolveGroup' ) {
58 $this->markAsResolved( $groupId );
60 }
catch ( Exception $e ) {
62 'requestParams' => $params,
63 'exceptionMessage' => $e->getMessage()
66 $this->groupSyncLog->error(
67 "Error while running: ManageGroupSynchronizationCacheActionApi::execute. Details: \n" .
68 FormatJson::encode( $data,
true )
73 'apierror-translate-operation-error',
74 wfEscapeWikiText( $e->getMessage() )
80 private function markAsResolved(
string $groupId, ?
string $messageTitle =
null ):
void {
81 if ( $messageTitle ===
null ) {
82 $currentGroupStatus = $this->groupSyncCache->markGroupAsResolved( $groupId );
83 $this->groupSyncLog->info(
84 '{user} resolved group {groupId}.',
86 'user' => $this->getUser()->getName(),
91 $this->groupSyncCache->markMessageAsResolved( $groupId, $messageTitle );
92 $currentGroupStatus = $this->groupSyncCache->syncGroupErrors( $groupId );
93 $this->groupSyncLog->info(
94 '{user} resolved message {messageTitle} in group {groupId}.',
96 'user' => $this->getUser()->getName(),
97 'groupId' => $groupId,
98 'messageTitle' => $messageTitle
103 $this->getResult()->addValue(
null, $this->getModuleName(), [
106 'groupRemainingMessageCount' => count( $currentGroupStatus->getRemainingMessages() )
111 protected function getAllowedParams() {
114 ParamValidator::PARAM_TYPE => self::VALID_OPS,
115 ParamValidator::PARAM_ISMULTI =>
false,
116 ParamValidator::PARAM_REQUIRED =>
true,
119 ParamValidator::PARAM_TYPE =>
'string',
120 ParamValidator::PARAM_REQUIRED => false
123 ParamValidator::PARAM_TYPE =>
'string',
124 ParamValidator::PARAM_REQUIRED => true
129 public function isInternal() {
133 public function needsToken() {