progress = $progress; $this->notices = $notices; } public function run( $requires_migration = false ) { $this->clear_migration_required(); $has_migration_ever_started = $this->progress->has_migration_ever_started(); if ( ! $this->progress->requires_migration() && $has_migration_ever_started ) { $this->build_migration_completed(); } else { if ( ! $has_migration_ever_started && $requires_migration && ! $this->progress->is_migration_incomplete() ) { $this->build_migration_required(); add_action( 'wpml-notices-scripts-enqueued', array( $this, 'admin_enqueue_scripts' ) ); return; } if ( $has_migration_ever_started && ! $this->progress->is_migration_done() ) { $this->build_migration_failed(); return; } } } public function clear_migration_required() { $this->notices->remove_notice( self::NOTICE_GROUP, self::NOTICE_MIGRATION_REQUIRED_ID ); } private function build_migration_failed() { $message = array(); $actions = array(); $title = '
'; foreach ( $this->progress->get_steps() as $step ) { $completed_step = $this->progress->get_completed_step( $step ); if ( ! $completed_step || WPML_TM_ICL20_Migration_Progress::STEP_FAILED === $completed_step ) { $error .= esc_html( sprintf( __( 'Failed step: %s', 'wpml-translation-management' ), $step ) ) . PHP_EOL; break; } } $error .= esc_html( $this->progress->get_last_migration_error() ); $error .= ''; $message[] = $error; } else { $message[] = esc_html__( 'Please wait a few minutes and try again to see if there’s a temporary problem.', 'wpml-translation-management' ); } $text = $title . '
' . implode( '
', $message ) . '
'; $button_label = __( 'Try again', 'wpml-translation-management' ); $button_url = add_query_arg( array( WPML_TM_ICL20_Migration_Support::PREFIX . 'nonce' => wp_create_nonce( WPML_TM_ICL20_Migration_Support::PREFIX . 'reset' ), WPML_TM_ICL20_Migration_Support::PREFIX . 'action' => WPML_TM_ICL20_Migration_Support::PREFIX . 'reset', ) ) . '#icl20-migration'; $retry_action = $this->notices->get_new_notice_action( $button_label, $button_url, false, false, true ); $actions[] = $retry_action; if ( $locked ) { $wpml_support_action = $this->notices->get_new_notice_action( __( 'WPML Support', 'wpml-translation-management' ), 'https://wpml.org/forums/' ); $wpml_support_action->set_link_target( '_blank' ); $actions[] = $wpml_support_action; } else { $support_url = add_query_arg( array( 'page' => WPML_PLUGIN_FOLDER . '/menu/support.php' ), admin_url( 'admin.php' ) ) . '#icl20-migration'; $action = $this->notices->get_new_notice_action( __( 'Error details', 'wpml-translation-management' ), $support_url ); $actions[] = $action; } $this->create_notice( $text, $actions ); } private function build_migration_required() { $message = array(); $actions = array(); $link_pattern = '%2$s'; $ask_us_link = sprintf( $link_pattern, 'https://wpml.org/forums/topic/im-not-sure-if-i-need-to-run-icanlocalize-migration/', esc_html__( 'Ask us', 'wpml-translation-management' ) ); $user_confirmation_label = esc_html__( 'This is indeed my production site', 'wpml-translation-management' ); $ajax_request_data = 'data-action="' . WPML_TM_ICL20_Migration_Support::PREFIX . 'user_confirm"'; $ajax_request_data .= 'data-nonce="' . wp_create_nonce( WPML_TM_ICL20_Migration_Support::PREFIX . 'user_confirm' ) . '"'; $user_confirmation_checkbox = ''; $user_confirmation_checkbox .= ''; $button_label = esc_html__( 'Start the update', 'wpml-translation-management' ); $title = '' . implode( '
', $message ) . '
'; $start_action = $this->notices->get_new_notice_action( $button_label, '#', false, false, true ); $actions[] = $start_action; $this->create_notice( $text, $actions ); } private function create_notice( $text, array $actions = array() ) { $notice = $this->notices->create_notice( self::NOTICE_MIGRATION_REQUIRED_ID, $text, self::NOTICE_GROUP ); $notice->set_css_class_types( array( 'error' ) ); $notice->set_exclude_from_pages( array( 'sitepress-multilingual-cms/menu/support.php' ) ); foreach ( $actions as $action ) { $notice->add_action( $action ); } $this->notices->add_notice( $notice ); } private function build_migration_completed() { $message = array(); $message[] = esc_html__( 'WPML updated your connection to ICanLocalize. You can continue sending content to translation.', 'wpml-translation-management' ); $text = '' . implode( '
', $message ) . '
'; $notice = $this->notices->create_notice( self::NOTICE_MIGRATION_COMPLETED_ID, $text, self::NOTICE_GROUP ); $notice->set_css_class_types( array( 'warning' ) ); $notice->set_exclude_from_pages( array( 'sitepress-multilingual-cms/menu/support.php' ) ); $notice->set_dismissible( true ); $this->notices->add_notice( $notice ); } public function admin_enqueue_scripts() { wp_enqueue_script( 'wpml-icl20-migrate-confirm', WPML_TM_URL . '/classes/ICL-20-migration/res/migration-required.js' ); } }