X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FStorage%2FRevisionSlots.php;h=ba9780f66b4ee419ee71345db6fd4a65ca7e4468;hb=285134ac5644fe424cf6e7df37aca5b831565641;hp=c7dcd136e08c3ca5b165afb18df289976f4d1c5a;hpb=c004cfc116eb8c677c346f3db561fc3593a8fd99;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/Storage/RevisionSlots.php b/includes/Storage/RevisionSlots.php index c7dcd136e0..ba9780f66b 100644 --- a/includes/Storage/RevisionSlots.php +++ b/includes/Storage/RevisionSlots.php @@ -202,13 +202,14 @@ class RevisionSlots { } /** - * Return all slots that are not inherited. + * Return all slots that belong to the revision they originate from (that is, + * they are not inherited from some other revision). * * @note This may cause the slot meta-data for the revision to be lazy-loaded. * * @return SlotRecord[] */ - public function getTouchedSlots() { + public function getOriginalSlots() { return array_filter( $this->getSlots(), function ( SlotRecord $slot ) { @@ -218,7 +219,8 @@ class RevisionSlots { } /** - * Return all slots that are inherited. + * Return all slots that are not not originate in the revision they belong to (that is, + * they are inherited from some other revision). * * @note This may cause the slot meta-data for the revision to be lazy-loaded. * @@ -268,4 +270,43 @@ class RevisionSlots { return true; } + /** + * Find roles for which the $other RevisionSlots object has different content + * as this RevisionSlots object, including any roles that are present in one + * but not the other. + * + * @param RevisionSlots $other + * + * @return string[] a list of slot roles that are different. + */ + public function getRolesWithDifferentContent( RevisionSlots $other ) { + if ( $other === $this ) { + return []; + } + + $aSlots = $this->getSlots(); + $bSlots = $other->getSlots(); + + ksort( $aSlots ); + ksort( $bSlots ); + + $different = array_keys( array_merge( + array_diff_key( $aSlots, $bSlots ), + array_diff_key( $bSlots, $aSlots ) + ) ); + + /** @var SlotRecord[] $common */ + $common = array_intersect_key( $aSlots, $bSlots ); + + foreach ( $common as $role => $s ) { + $t = $bSlots[$role]; + + if ( !$s->hasSameContent( $t ) ) { + $different[] = $role; + } + } + + return $different; + } + }