58 public function add(
string $name,
string $description, ?
string $languageCode ): string {
64 $aggregateGroupId = $this->generateAggregateGroupId( $name );
67 $this->messageGroupMetadata->set( $aggregateGroupId,
'name', $name );
68 $this->messageGroupMetadata->set( $aggregateGroupId,
'description', $description );
69 if ( $languageCode ) {
71 $this->messageGroupMetadata->set( $aggregateGroupId,
'sourcelanguagecode', $languageCode );
73 $this->messageGroupMetadata->setSubgroups( $aggregateGroupId, [] );
75 return $aggregateGroupId;
86 public function associate(
string $aggregateGroupId, array $newSubgroupIds ): array {
87 $existingSubgroupIds = $this->getSubgroups( $aggregateGroupId );
88 $newSubgroups = MessageGroups::getGroupsById( $newSubgroupIds );
90 $missingGroupIds = $this->findMissingGroupIds( $newSubgroups, $newSubgroupIds );
91 $invalidGroupIds = [];
92 foreach ( $newSubgroups as $subGroup ) {
93 if ( !$this->supportsAggregation( $subGroup ) ) {
94 $invalidGroupIds[] = $subGroup->getId();
98 if ( $missingGroupIds || $invalidGroupIds ) {
99 $invalidGroupIds = array_unique( array_merge( $missingGroupIds, $invalidGroupIds ) );
100 throw new AggregateGroupAssociationFailure( $invalidGroupIds );
103 $aggregateGroupLanguage = $this->messageGroupMetadata->get( $aggregateGroupId,
'sourcelanguagecode' );
104 if ( $aggregateGroupLanguage !==
false ) {
106 $sourceLanguageMismatchGroupIds = [];
107 foreach ( $newSubgroups as $subGroup ) {
108 if ( $subGroup->getSourceLanguage() !== $aggregateGroupLanguage ) {
109 $sourceLanguageMismatchGroupIds[] = $subGroup->getId();
113 if ( $sourceLanguageMismatchGroupIds ) {
114 throw new AggregateGroupLanguageMismatchException(
115 $sourceLanguageMismatchGroupIds,
116 $aggregateGroupLanguage
121 $allSubgroupIds = array_unique( array_merge( $existingSubgroupIds, $newSubgroupIds ) );
122 if ( array_diff( $newSubgroupIds, $existingSubgroupIds ) === [] ) {
127 $this->messageGroupMetadata->setSubgroups( $aggregateGroupId, $allSubgroupIds );
128 return $newSubgroupIds;
136 public function disassociate(
string $aggregateGroupId, array $subgroupIds ): array {
137 $existingSubGroupIds = $this->getSubgroups( $aggregateGroupId );
138 $remainingSubGroupIds = array_diff( $existingSubGroupIds, $subgroupIds );
139 $this->messageGroupMetadata->setSubgroups( $aggregateGroupId, $remainingSubGroupIds );
140 return array_diff( $existingSubGroupIds, $remainingSubGroupIds );
161 $this->messageGroupMetadata->preloadGroups( array_keys( $groupsPreload ), __METHOD__ );
163 $groups = MessageGroups::getAllGroups();
164 uasort( $groups, [ MessageGroups::class,
'groupLabelSort' ] );
166 foreach ( $groups as $group ) {
169 $subgroups = $this->messageGroupMetadata->getSubgroups( $group->getId() );
170 if ( $subgroups !==
null ) {
171 $aggregates[] = $group;