X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FStorage%2FRevisionSlots.php;h=91969fc0c7c548c4838adb81a7294da95009238c;hb=a075271157d32567e894c668aa2b76138c491b95;hp=f37e722bbaa346f446bc2bc5ed56b56b22a70ac0;hpb=e8632ab0f6264851d2115a2e6338c2074b9a9b8c;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/Storage/RevisionSlots.php b/includes/Storage/RevisionSlots.php index f37e722bba..91969fc0c7 100644 --- a/includes/Storage/RevisionSlots.php +++ b/includes/Storage/RevisionSlots.php @@ -139,7 +139,7 @@ class RevisionSlots { /** * Computes the total nominal size of the revision's slots, in bogo-bytes. * - * @warn This is potentially expensive! It may cause all slot's content to be loaded + * @warning This is potentially expensive! It may cause all slot's content to be loaded * and deserialized. * * @return int @@ -181,7 +181,7 @@ class RevisionSlots { * is that slot's hash. For consistency, the combined hash of an empty set of slots * is the hash of the empty string. * - * @warn This is potentially expensive! It may cause all slot's content to be loaded + * @warning This is potentially expensive! It may cause all slot's content to be loaded * and deserialized, then re-serialized and hashed. * * @return string @@ -270,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; + } + }