| @@ -2,12 +2,16 @@ | ||
| 2 | 2 | /** |
| 3 | 3 | * Stream command for WP-CLI |
| 4 | 4 | * |
| 5 | 5 | * @see https://github.com/wp-cli/wp-cli |
| 6 | + * @package WP_Stream | |
| 6 | 7 | */ |
| 7 | 8 | |
| 8 | 9 | namespace WP_Stream; |
| 9 | 10 | |
| 11 | +/** | |
| 12 | + * Class - CLI | |
| 13 | + */ | |
| 10 | 14 | class CLI extends \WP_CLI_Command { |
| 11 | 15 | |
| 12 | 16 | /** |
| 13 | 17 | * Query a set of Stream records. |
| @@ -85,10 +89,13 @@ | ||
| 85 | 89 | * wp stream query --user_role__not_in=administrator --date_after=2015-01-01T12:00:00 |
| 86 | 90 | * wp stream query --user_id=1 --action=login --records_per_page=50 --fields=created |
| 87 | 91 | * |
| 88 | 92 | * @see WP_Stream_Query |
| 89 | - * @see https://github.com/wp-stream/stream/wiki/WP-CLI-Command | |
| 90 | - * @see https://github.com/wp-stream/stream/wiki/Query-Reference | |
| 93 | + * @see https://github.com/xwp/stream/wiki/WP-CLI-Command | |
| 94 | + * @see https://github.com/xwp/stream/wiki/Query-Reference | |
| 95 | + * | |
| 96 | + * @param array $args Unused. | |
| 97 | + * @param array $assoc_args Fields to return data for. | |
| 91 | 98 | */ |
| 92 | 99 | public function query( $args, $assoc_args ) { |
| 93 | 100 | unset( $args ); |
| 94 | 101 | |
| @@ -120,13 +127,13 @@ | ||
| 120 | 127 | $query_args['fields'] = implode( ',', $fields ); |
| 121 | 128 | |
| 122 | 129 | $records = wp_stream_get_instance()->db->query( $query_args ); |
| 123 | 130 | |
| 124 | - // Make structure Formatter compatible | |
| 131 | + // Make structure Formatter compatible. | |
| 125 | 132 | foreach ( (array) $records as $key => $record ) { |
| 126 | 133 | $formatted_records[ $key ] = array(); |
| 127 | 134 | |
| 128 | - // Catch any fields missing in records | |
| 135 | + // Catch any fields missing in records. | |
| 129 | 136 | foreach ( $fields as $field ) { |
| 130 | 137 | if ( ! array_key_exists( $field, $record ) ) { |
| 131 | 138 | $record->$field = null; |
| 132 | 139 | } |
| @@ -151,11 +158,11 @@ | ||
| 151 | 158 | } |
| 152 | 159 | |
| 153 | 160 | if ( 'json_pretty' === $assoc_args['format'] ) { |
| 154 | 161 | if ( version_compare( PHP_VERSION, '5.4', '<' ) ) { |
| 155 | - \WP_CLI::line( wp_stream_json_encode( $formatted_records ) ); // xss ok | |
| 162 | + \WP_CLI::line( wp_stream_json_encode( $formatted_records ) ); // xss ok. | |
| 156 | 163 | } else { |
| 157 | - \WP_CLI::line( wp_stream_json_encode( $formatted_records, JSON_PRETTY_PRINT ) ); // xss ok | |
| 164 | + \WP_CLI::line( wp_stream_json_encode( $formatted_records, JSON_PRETTY_PRINT ) ); // xss ok. | |
| 158 | 165 | } |
| 159 | 166 | } |
| 160 | 167 | |
| 161 | 168 | if ( 'csv' === $assoc_args['format'] ) { |
| @@ -175,10 +182,10 @@ | ||
| 175 | 182 | |
| 176 | 183 | /** |
| 177 | 184 | * Convert any field to a flat array. |
| 178 | 185 | * |
| 179 | - * @param string $name The output array element name | |
| 180 | - * @param mixed $object Any value to be converted to an array | |
| 186 | + * @param string $name The output array element name. | |
| 187 | + * @param mixed $object Any value to be converted to an array. | |
| 181 | 188 | * |
| 182 | 189 | * @return array The flat array |
| 183 | 190 | */ |
| 184 | 191 | private function format_field( $name, $object ) { |
| @@ -199,11 +206,9 @@ | ||
| 199 | 206 | |
| 200 | 207 | /** |
| 201 | 208 | * Convert an array of flat records to CSV |
| 202 | 209 | * |
| 203 | - * @param array $array The input array of records | |
| 204 | - * | |
| 205 | - * @return string The CSV output | |
| 210 | + * @param array $array The input array of records. | |
| 206 | 211 | */ |
| 207 | 212 | private function csv_format( $array ) { |
| 208 | 213 | $output = fopen( 'php://output', 'w' ); // @codingStandardsIgnoreLine Clever output for WP CLI using php://output |
| 209 | 214 | |