Skip to content

Commit

Permalink
Merge branch 'develop' into add/users-last-seen
Browse files Browse the repository at this point in the history
  • Loading branch information
rinatkhaziev authored Jan 9, 2024
2 parents bebe719 + 3aeebf8 commit b70f9a2
Show file tree
Hide file tree
Showing 13 changed files with 284 additions and 143 deletions.
19 changes: 19 additions & 0 deletions 001-core/privacy.php
Original file line number Diff line number Diff line change
Expand Up @@ -457,3 +457,22 @@ function delete_old_export_files() {
}
}
}

/**
* Disable crawling for go-vip.co and go-vip.net domains.
*
* @param string $output The robots.txt content.
* @return string The modified robots.txt content.
*/
function vip_convenience_domain_robots_txt( $output ) {
$host = strtolower( $_SERVER['HTTP_HOST'] ?? '' ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
if ( false !== strpos( $host, '.go-vip.co' ) || false !== strpos( $host, '.go-vip.net' ) ) {
$output = "# Crawling is blocked for go-vip.co and go-vip.net domains\n";
$output .= "User-agent: *\n";
$output .= "Disallow: /\n";
}

return $output;
}
// phpcs:ignore WordPressVIPMinimum.Hooks.RestrictedHooks.robots_txt
add_filter( 'robots_txt', __NAMESPACE__ . '\vip_convenience_domain_robots_txt' );
8 changes: 4 additions & 4 deletions __tests__/e2e/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion __tests__/e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"@playwright/test": "^1.39.0",
"asana-phrase": "^0.0.8",
"eslint": "^8.51.0",
"eslint-plugin-playwright": "^0.20.0",
"eslint-plugin-playwright": "^0.21.0",
"playwright": "^1.39.0",
"typescript": "^5.2.2"
}
Expand Down
18 changes: 9 additions & 9 deletions files/class-vip-filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,14 @@ public function filter_validate_file( $file ) {
$upload_path = trailingslashit( $this->get_upload_path() );
$file_path = $upload_path . $file_name;

// TODO: run through unique filename?
$check_type = $this->validate_file_type( $file_path );
if ( is_wp_error( $check_type ) ) {
$file['error'] = $check_type->get_error_message();
$check_file_name = $this->validate_file_name( $file_path );
if ( is_wp_error( $check_file_name ) ) {
$file['error'] = $check_file_name->get_error_message();

return $file;
} elseif ( $check_file_name !== $file_name ) {
$file['name'] = $check_file_name;
$file_path = $upload_path . $check_file_name;
}

$check_length = $this->validate_file_path_length( $file_path );
Expand Down Expand Up @@ -221,9 +222,9 @@ protected function validate_file_path_length( $file_path ) {
*
* @param string $file_path Path starting with /wp-content/uploads
*
* @return WP_Error|bool True if filetype is supported. Else WP_Error.
* @return WP_Error|string Unique Filename string if filetype is supported. Else WP_Error.
*/
protected function validate_file_type( $file_path ) {
protected function validate_file_name( $file_path ) {
$result = $this->stream_wrapper->client->get_unique_filename( $file_path );

if ( is_wp_error( $result ) ) {
Expand All @@ -235,10 +236,9 @@ protected function validate_file_type( $file_path ) {
E_USER_WARNING
);
}
return $result;
}

return true;
return $result;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion search/elasticpress-next
3 changes: 2 additions & 1 deletion search/includes/classes/class-search.php
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,8 @@ protected function load_commands() {
WP_CLI::add_command( 'vip-search queue', __NAMESPACE__ . '\Commands\QueueCommand' );
WP_CLI::add_command( 'vip-search index-versions', __NAMESPACE__ . '\Commands\VersionCommand' );
WP_CLI::add_command( 'vip-search documents', __NAMESPACE__ . '\Commands\DocumentCommand' );
WP_CLI::add_command( 'vip-search', __NAMESPACE__ . '\Commands\CoreCommand' );
$vip_search_core_command = new \Automattic\VIP\Search\Commands\CoreCommand( new \ElasticPress\Command() );
WP_CLI::add_command( 'vip-search', $vip_search_core_command );
}
}

Expand Down
162 changes: 135 additions & 27 deletions search/includes/classes/commands/class-corecommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@
use WP_CLI\Utils;
use ElasticPress\Elasticsearch;

use function Automattic\VIP\Logstash\log2logstash;

/**
* Core commands for interacting with VIP Search
*
* @package Automattic\VIP\Search
*/
class CoreCommand extends \ElasticPress\Command {
class CoreCommand {
private $ep_command;

public function __construct( \ElasticPress\Command $ep_command ) {
$this->ep_command = $ep_command;
}

private function verify_arguments_compatibility( $assoc_args ) {
if ( array_key_exists( 'version', $assoc_args ) && array_key_exists( 'using-versions', $assoc_args ) ) {
WP_CLI::error( 'The --version argument is not allowed when specifying --using-versions' );
Expand Down Expand Up @@ -221,9 +225,6 @@ protected function maybe_setup_index_version( $assoc_args ) {
* @param array $assoc_args Associative CLI args.
*/
public function index( $args, $assoc_args ) {
if ( isset( $assoc_args['setup'] ) && $assoc_args['setup'] ) {
self::confirm_destructive_operation( $assoc_args );
}
$this->verify_arguments_compatibility( $assoc_args );

$using_versions = $assoc_args['using-versions'] ?? false;
Expand Down Expand Up @@ -294,6 +295,10 @@ public function index( $args, $assoc_args ) {

WP_CLI::line( WP_CLI::colorize( '%CRun took: ' . ( round( microtime( true ) - $start, 3 ) ) . '%n' ) );
} else {
if ( isset( $assoc_args['setup'] ) && $assoc_args['setup'] ) {
self::confirm_destructive_operation( $assoc_args );
}

// Unset our arguments since they don't exist in ElasticPress and causes
// an error for indexing operations exclusively for some reason.
unset( $assoc_args['version'] );
Expand Down Expand Up @@ -337,7 +342,7 @@ public function index( $args, $assoc_args ) {
*/
public function put_mapping( $args, $assoc_args ) {
self::confirm_destructive_operation( $assoc_args );
parent::put_mapping( $args, $assoc_args );
$this->ep_command->put_mapping( $args, $assoc_args );
}

/**
Expand Down Expand Up @@ -383,11 +388,11 @@ public function get_index_settings( $args, $assoc_args ) {
* Throw error when delete-index command is attempted to be used.
*
* @subcommand delete-index
*
*
* @param array $args Positional CLI args.
* @param array $assoc_args Associative CLI args.
*/
public function delete_index( $args, $assoc_args ) {
public function delete_index( $args, $assoc_args ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed
WP_CLI::error( 'Please use index versioning to manage your indices: https://docs.wpvip.com/how-tos/vip-search/version-with-enterprise-search/' );
}

Expand All @@ -411,12 +416,8 @@ public static function confirm_destructive_operation( array $assoc_args ) {
* Return all index names as a JSON object.
*
* @subcommand get-indexes
*
* @param array $args Positional CLI args.
* @param array $assoc_args Associative CLI args.
*/
public function get_indexes( $args, $assoc_args ) {

public function get_indexes( $args, $assoc_args ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed
$indexes = $this->list_indexes();

if ( is_wp_error( $indexes ) ) {
Expand All @@ -434,7 +435,7 @@ public function get_indexes( $args, $assoc_args ) {
* @param array $args Positional CLI args.
* @param array $assoc_args Associative CLI args.
*/
public function get_mapping( $args, $assoc_args ) {
public function get_mapping( $args, $assoc_args ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed
$index_names = (array) ( isset( $assoc_args['index-name'] ) ? $assoc_args['index-name'] : $this->list_indexes() );

$path = join( ',', $index_names ) . '/_mapping';
Expand Down Expand Up @@ -464,8 +465,7 @@ public function activate_feature( $args, $assoc_args ) {
WP_CLI::error( "The feature {$args[0]} is not currently supported." );
}

array_unshift( $args, 'elasticpress', 'activate-feature' );
WP_CLI::run_command( $args, $assoc_args );
$this->ep_command->activate_feature( $args, $assoc_args );
}

/**
Expand Down Expand Up @@ -500,19 +500,15 @@ public function deactivate_feature( $args, $assoc_args ) {
WP_CLI::confirm( "Are you sure you want to deactivate $args[0]? This will break all search-related functionality!" );
}

array_unshift( $args, 'elasticpress', 'deactivate-feature' );
WP_CLI::run_command( $args, $assoc_args );
$this->ep_command->deactivate_feature( $args, $assoc_args );
}

/**
* Get the last indexed post ID on an incomplete indexing operation.
*
* @subcommand get-last-indexed-post-id
*
* @param array $args Positional CLI args.
* @param array $assoc_args Associative CLI args.
*/
public function get_last_indexed_post_id( $args, $assoc_args ) {
public function get_last_indexed_post_id( $args, $assoc_args ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed
$search = \Automattic\VIP\Search\Search::instance();

$last_id = get_option( $search::LAST_INDEXED_POST_ID_OPTION );
Expand All @@ -528,11 +524,8 @@ public function get_last_indexed_post_id( $args, $assoc_args ) {
* Clean the ep_feature_settings individual blog option if it exists for sites with EP_IS_NETWORK.
*
* @subcommand clean-ep-feature-settings
*
* @param array $args Positional CLI args.
* @param array $assoc_args Associative CLI args.
*/
public function clean_ep_feature_settings( $args, $assoc_args ) {
public function clean_ep_feature_settings( $args, $assoc_args ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed
if ( is_multisite() && defined( 'EP_IS_NETWORK' ) && true === constant( 'EP_IS_NETWORK' ) ) {
$delete_option = delete_option( 'ep_feature_settings' );
if ( $delete_option ) {
Expand All @@ -544,4 +537,119 @@ public function clean_ep_feature_settings( $args, $assoc_args ) {
WP_CLI::error( 'Not a multisite or EP_IS_NETWORK is not enabled!' );
}
}

/**
* Stop the current indexing operation.
*
* @subcommand stop-indexing
*
* @param array $args Positional CLI args.
* @param array $assoc_args Associative CLI args.
*/
public function stop_indexing( $args, $assoc_args ) {
$this->ep_command->stop_indexing( $args, $assoc_args );
}

/**
* List features (either active or all).
*
* ## OPTIONS
*
* [--all]
* : Show all registered features
*
* @subcommand list-features
* @param array $args Positional CLI args.
* @param array $assoc_args Associative CLI args.
*/
public function list_features( $args, $assoc_args ) {
$this->ep_command->list_features( $args, $assoc_args );
}

/**
* Recreates the alias index which points to every index in the network.
*
* Map network alias to every index in the network for every non-global indexable
*
* @subcommand recreate-network-alias
* @param array $args Positional CLI args.
* @param array $assoc_args Associative CLI args.
*/
public function recreate_network_alias( $args, $assoc_args ) {
$this->ep_command->recreate_network_alias( $args, $assoc_args );
}

/**
* Clear a sync/index process.
*
* If an index was stopped prematurely and won't start again, this will clear this cached data such that a new index can start.
*
* @subcommand clear-index
* @alias delete-transient
*/
public function clear_index( $args, $assoc_args ) {
$this->ep_command->clear_index( $args, $assoc_args );
}

/**
* Returns the status of an ongoing index operation in JSON array.
*
* Returns the status of an ongoing index operation in JSON array with the following fields:
* indexing | boolean | True if index operation is ongoing or false
* items_indexed | integer | Total number of items indexed
* total_items | integer | Total number of items indexed or -1 if not yet determined
*
* ## OPTIONS
*
* [--pretty]
* : Use this flag to render a pretty-printed version of the JSON response.
*
* @subcommand get-indexing-status
* @param array $args Positional CLI args.
* @param array $assoc_args Associative CLI args.
*/
public function get_indexing_status( $args, $assoc_args ) {
$this->ep_command->get_indexing_status( $args, $assoc_args );
}

/**
* Returns a JSON array with the results of the last CLI index (if present) or an empty array.
*
* ## OPTIONS
*
* [--clear]
* : Clear the `ep_last_cli_index` option.
*
* [--pretty]
* : Use this flag to render a pretty-printed version of the JSON response.
*
* @subcommand get-last-index
* @param array $args Positional CLI args.
* @param array $assoc_args Associative CLI args.
*/
public function get_last_index( $args, $assoc_args ) {
$this->ep_command->get_last_cli_index( $args, $assoc_args );
}

/**
* Get the algorithm version.
*
* Get the value of the `ep_search_algorithm_version` option, or
* `default` if empty.
*
* @subcommand get-algorithm-version
*/
public function get_algorithm_version( $args, $assoc_args ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed
$version = apply_filters( 'ep_search_algorithm_version', get_option( 'ep_search_algorithm_version', '3.5' ) );
WP_CLI::line( $version );
}

/**
* Get stats on the current index.
*
* @subcommand stats
*/
public function get_stats( $args, $assoc_args ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed
$this->ep_command->stats();
}
}
Loading

0 comments on commit b70f9a2

Please sign in to comment.