<commit_before><?php

WP_CLI::add_command( 'search-replace', new Search_Replace_Command );

/**
 * Search/Replace strings in the database.
 *
 * @package wp-cli
 */
class Search_Replace_Command extends WP_CLI_Command {

	/**
	 * @synopsis <old> <new>
	 */
	public function __invoke( $args, $assoc_args ) {
		require_once WP_CLI_ROOT . '../query-iterators/class-table-iterator.php';

		global $wpdb;

		list( $old, $new ) = $args;

		$tables = $wpdb->tables( 'blog' );

		$total = 0;

		foreach ( $tables as $table ) {
			list( $primary_key, $columns ) = self::get_columns( $table );

			foreach ( $columns as $col ) {
				$count = self::handle_col( $col, $primary_key, $table, $old, $new );

				WP_CLI::line( "$table.$col: $count" );

				$total += $count;
			}
		}

		WP_CLI::success( "Made $total replacements." );<commit_msg>use \cli\Table for displaying the report<commit_after><?php

WP_CLI::add_command( 'search-replace', new Search_Replace_Command );

/**
 * Search/Replace strings in the database.
 *
 * @package wp-cli
 */
class Search_Replace_Command extends WP_CLI_Command {

	/**
	 * @synopsis <old> <new>
	 */
	public function __invoke( $args, $assoc_args ) {
		require_once WP_CLI_ROOT . '../query-iterators/class-table-iterator.php';

		global $wpdb;

		list( $old, $new ) = $args;

		$tables = $wpdb->tables( 'blog' );

		$total = 0;

		$report = array();

		foreach ( $tables as $table ) {
			list( $primary_key, $columns ) = self::get_columns( $table );

			foreach ( $columns as $col ) {
				$count = self::handle_col( $col, $primary_key, $table, $old, $new );

				$report[] = array( $table, $col, $count );

				$total += $count;
			}
		}

		$table = new \cli\Table();
		$table->setHeaders( array( 'Table', 'Column', 'Replacements' ) );
		$table->setRows( $report );
		$table->display();

		WP_CLI::success( "Made $total replacements." );
{'fraction_non_alphanumeric': 0.17903225806451614, 'fraction_numerical': 0.001075268817204301, 'mean_word_length': 3.6178660049627793, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5310118', 'n_tokens_mistral': 739, 'n_tokens_neox': 654, 'n_words': 154}