*/ public function hashesFor( int $postId, string $locale ): array { $stored = get_post_meta( $postId, self::metaKey( $locale ), true ); if ( ! is_array( $stored ) ) { return array(); } return array_values( array_filter( $stored, 'is_string' ) ); } /** * Запоминает набор строк текущего успешного сохранения. * * @param int $postId Идентификатор записи. * @param string $locale Целевой язык. * @param list $hashes Hex uniq_hash сохранённых строк. */ public function save( int $postId, string $locale, array $hashes ): void { update_post_meta( $postId, self::metaKey( $locale ), array_values( array_unique( $hashes ) ) ); } /** * Строки, которых не было в прошлом слепке — новые или изменившиеся с * последнего массового перевода. Чистая функция. * * @param list $currentHashes Хеши, найденные сейчас. * @param list $previousHashes Хеши из прошлого слепка. * @return array Множество хешей для быстрой проверки `isset()`. */ public static function changed( array $currentHashes, array $previousHashes ): array { $previous = array_fill_keys( $previousHashes, true ); $changed = array(); foreach ( $currentHashes as $hash ) { if ( ! isset( $previous[ $hash ] ) ) { $changed[ $hash ] = true; } } return $changed; } /** * Ключ postmeta для языка. Чистая функция. * * @param string $locale Целевой язык. */ private static function metaKey( string $locale ): string { return self::metaPrefix() . $locale; } }