23 private const RIGHT =
'translate-manage';
24 private const VALID_OPS = [
'resolveMessage',
'resolveGroup' ];
26 private $groupSyncCache;
28 private $groupSyncLog;
31 parent::__construct( $mainModule, $moduleName );
32 $this->groupSyncCache = $groupSyncCache;
33 $this->groupSyncLog = LoggerFactory::getInstance(
'Translate.GroupSynchronization' );
36 public function execute() {
37 $this->checkUserRightsAny( self::RIGHT );
38 $block = $this->getUser()->getBlock();
39 if ( $block && $block->isSitewide() ) {
40 $this->dieBlocked( $block );
43 $params = $this->extractRequestParams();
44 $operation = $params[
'operation'];
45 $groupId = $params[
'group'];
46 $titleStr = $params[
'title'] ??
null;
48 $group = MessageGroups::getGroup( $groupId );
49 if ( $group ===
null ) {
50 $this->dieWithError(
'apierror-translate-invalidgroup',
'invalidgroup' );
54 if ( $operation ===
'resolveMessage' ) {
55 if ( $titleStr ===
null ) {
56 $this->dieWithError( [
'apierror-missingparam',
'title' ] );
58 $this->markAsResolved( $groupId, $titleStr );
59 } elseif ( $operation ===
'resolveGroup' ) {
60 $this->markAsResolved( $groupId );
62 }
catch ( Exception $e ) {
64 'requestParams' => $params,
65 'exceptionMessage' => $e->getMessage()
68 $this->groupSyncLog->error(
69 "Error while running: ManageGroupSynchronizationCacheActionApi::execute. Details: \n" .
70 FormatJson::encode( $data,
true )
75 'apierror-translate-operation-error',
76 wfEscapeWikiText( $e->getMessage() )
82 private function markAsResolved(
string $groupId, ?
string $messageTitle =
null ):
void {
83 if ( $messageTitle ===
null ) {
84 $currentGroupStatus = $this->groupSyncCache->markGroupAsResolved( $groupId );
85 $this->groupSyncLog->info(
86 '{user} resolved group {groupId}.',
88 'user' => $this->getUser()->getName(),
93 $this->groupSyncCache->markMessageAsResolved( $groupId, $messageTitle );
94 $currentGroupStatus = $this->groupSyncCache->syncGroupErrors( $groupId );
95 $this->groupSyncLog->info(
96 '{user} resolved message {messageTitle} in group {groupId}.',
98 'user' => $this->getUser()->getName(),
99 'groupId' => $groupId,
100 'messageTitle' => $messageTitle
105 $this->getResult()->addValue(
null, $this->getModuleName(), [
108 'groupRemainingMessageCount' => count( $currentGroupStatus->getRemainingMessages() )
113 protected function getAllowedParams() {
116 ParamValidator::PARAM_TYPE => self::VALID_OPS,
117 ParamValidator::PARAM_ISMULTI =>
false,
118 ParamValidator::PARAM_REQUIRED =>
true,
121 ParamValidator::PARAM_TYPE =>
'string',
122 ParamValidator::PARAM_REQUIRED => false
125 ParamValidator::PARAM_TYPE =>
'string',
126 ParamValidator::PARAM_REQUIRED => true
131 public function isInternal() {
135 public function needsToken() {