first commit

This commit is contained in:
2023-09-12 21:41:04 +02:00
commit 3361a7f053
13284 changed files with 2116755 additions and 0 deletions

View File

@@ -0,0 +1,108 @@
<?php
namespace WPML\TM\ATE\Hooks;
use function WPML\Container\make;
use WPML\Element\API\Languages;
use WPML\FP\Fns;
use function WPML\FP\invoke;
use WPML\FP\Lst;
use WPML\FP\Obj;
use function WPML\FP\pipe;
use WPML\FP\Relation;
use WPML\Setup\Option;
class JobActions implements \IWPML_Action {
/** @var \WPML_TM_ATE_API $apiClient */
private $apiClient;
public function __construct( \WPML_TM_ATE_API $apiClient ) {
$this->apiClient = $apiClient;
}
public function add_hooks() {
add_action( 'wpml_tm_job_cancelled', [ $this, 'cancelJobInATE' ] );
add_action( 'wpml_tm_jobs_cancelled', [ $this, 'cancelJobsInATE' ] );
add_action( 'wpml_set_translate_everything', [ $this, 'hideJobsAfterTranslationMethodChange' ] );
add_action( 'wpml_update_active_languages', [ $this, 'hideJobsAfterRemoveLanguage' ] );
}
public function cancelJobInATE( \WPML_TM_Post_Job_Entity $job ) {
if ( $job->is_ate_editor() ) {
$this->apiClient->cancelJobs( $job->get_editor_job_id() );
}
}
/**
* @param \WPML_TM_Post_Job_Entity[]|\WPML_TM_Post_Job_Entity $jobs
*
* @return void
*/
public function cancelJobsInATE( $jobs ) {
/**
* We need this check because if we pass only one job to the hook:
* do_action( 'wpml_tm_jobs_cancelled', [ $job ] )
* then WordPress converts it to $job.
*/
if ( is_object( $jobs ) ) {
$jobs = [ $jobs ];
}
$getIds = pipe(
Fns::filter( invoke( 'is_ate_editor' ) ),
Fns::map( invoke( 'get_editor_job_id' ) )
);
$this->apiClient->cancelJobs( $getIds( $jobs ) );
}
public function hideJobsAfterRemoveLanguage( $oldLanguages ) {
$removedLanguages = Lst::diff( array_keys( $oldLanguages ), array_keys( Languages::getActive() ) );
if ( $removedLanguages ) {
$inProgressJobsSearchParams = self::getInProgressSearch()
->set_target_language( array_values( $removedLanguages ) );
$this->hideJobs( $inProgressJobsSearchParams );
Fns::map( [ Option::class, 'removeLanguageFromCompleted' ], $removedLanguages );
}
}
public function hideJobsAfterTranslationMethodChange( $translateEverythingActive ) {
if ( ! $translateEverythingActive ) {
$this->hideJobs( self::getInProgressSearch() );
}
}
private static function getInProgressSearch() {
return ( new \WPML_TM_Jobs_Search_Params() )->set_status( [
ICL_TM_WAITING_FOR_TRANSLATOR,
ICL_TM_IN_PROGRESS
] );
}
private function hideJobs( \WPML_TM_Jobs_Search_Params $jobsSearchParams ) {
$translationJobs = wpml_collect( wpml_tm_get_jobs_repository()->get( $jobsSearchParams ) )
->filter( invoke( 'is_ate_editor' ) )
->filter( invoke( 'is_automatic' ) );
$canceledInATE = $this->apiClient->hideJobs(
$translationJobs->map( invoke( 'get_editor_job_id' ) )->values()->toArray()
);
$isResponseValid = $canceledInATE && ! is_wp_error( $canceledInATE );
$jobsHiddenInATE = $isResponseValid ? Obj::propOr( [], 'jobs', $canceledInATE ) : [];
$isHiddenInATE = function ( $job ) use ( $isResponseValid, $jobsHiddenInATE ) {
return $isResponseValid && Lst::includes( $job->get_editor_job_id(), $jobsHiddenInATE );
};
$setStatus = Fns::tap( function ( \WPML_TM_Post_Job_Entity $job ) use ( $isHiddenInATE ) {
$status = $isHiddenInATE( $job ) ? ICL_TM_ATE_CANCELLED : ICL_TM_NOT_TRANSLATED;
$job->set_status( $status );
} );
$translationJobs->map( $setStatus )
->map( Fns::tap( [ make( \WPML_TP_Sync_Update_Job::class ), 'update_state' ] ) );
}
}

View File

@@ -0,0 +1,14 @@
<?php
namespace WPML\TM\ATE\Hooks;
use function WPML\Container\make;
class JobActionsFactory implements \IWPML_Backend_Action_Loader, \IWPML_Frontend_Action_Loader {
public function create() {
return \WPML_TM_ATE_Status::is_enabled_and_activated()
? new JobActions( make( \WPML_TM_ATE_API::class ) )
: null;
}
}

View File

@@ -0,0 +1,40 @@
<?php
namespace WPML\TM\ATE\Hooks;
use WPML\TM\ATE\ReturnedJobsQueue;
class ReturnedJobActions implements \IWPML_Action {
/** @var callable :: int->string->void */
private $addToQueue;
/** @var callable :: int->string->void */
private $remove_translation_duplicate_status;
/**
* @param callable $addToQueue
* @param callable $removeTranslationDuplicateStatus
*/
public function __construct( callable $addToQueue, callable $removeTranslationDuplicateStatus ) {
$this->addToQueue = $addToQueue;
$this->remove_translation_duplicate_status = $removeTranslationDuplicateStatus;
}
public function add_hooks() {
add_action( 'init', [ $this, 'addToQueue' ] );
}
public function addToQueue() {
if ( isset( $_GET['ate_original_id'] ) ) {
$ateJobId = (int) $_GET['ate_original_id'];
if ( isset( $_GET['complete'] ) ) {
call_user_func( $this->addToQueue, $ateJobId, ReturnedJobsQueue::STATUS_COMPLETED );
call_user_func( $this->remove_translation_duplicate_status, $ateJobId );
} elseif ( isset( $_GET['back'] ) ) {
call_user_func( $this->addToQueue, $ateJobId, ReturnedJobsQueue::STATUS_BACK );
}
}
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace WPML\TM\ATE\Hooks;
use WPML\TM\ATE\ReturnedJobsQueue;
use function WPML\Container\make;
use function WPML\FP\partialRight;
class ReturnedJobActionsFactory implements \IWPML_Backend_Action_Loader, \IWPML_REST_Action_Loader {
public function create() {
$ateJobs = make( \WPML_TM_ATE_Jobs::class );
$add = partialRight( [ ReturnedJobsQueue::class, 'add' ], [ $ateJobs, 'get_wpml_job_id' ] );
$removeTranslationDuplicateStatus = partialRight( [ ReturnedJobsQueue::class, 'removeJobTranslationDuplicateStatus' ], [ $ateJobs, 'get_wpml_job_id' ] );
return new ReturnedJobActions( $add, $removeTranslationDuplicateStatus );
}
}

View File

@@ -0,0 +1,38 @@
<?php
/**
* @author OnTheGo Systems
*/
class WPML_TM_AMS_Synchronize_Actions_Factory implements IWPML_Backend_Action_Loader {
/**
* @return IWPML_Action|IWPML_Action[]|null
*/
public function create() {
if ( WPML_TM_ATE_Status::is_enabled_and_activated() ) {
$ams_api = WPML\Container\make( WPML_TM_AMS_API::class );
global $wpdb;
$user_query_factory = new WPML_WP_User_Query_Factory();
$wp_roles = wp_roles();
$translator_records = new WPML_Translator_Records( $wpdb, $user_query_factory, $wp_roles );
$manager_records = new WPML_Translation_Manager_Records( $wpdb, $user_query_factory, $wp_roles );
$admin_translators = new WPML_Translator_Admin_Records( $wpdb, $user_query_factory, $wp_roles );
$user_records = new WPML_TM_AMS_Users( $manager_records, $translator_records, $admin_translators );
$user_factory = new WPML_WP_User_Factory();
$translator_activation_records = new WPML_TM_AMS_Translator_Activation_Records( new WPML_WP_User_Factory() );
return new WPML_TM_AMS_Synchronize_Actions(
$ams_api,
$user_records,
$user_factory,
$translator_activation_records,
$manager_records,
$translator_records
);
}
return null;
}
}

View File

@@ -0,0 +1,115 @@
<?php
/**
* @author OnTheGo Systems
*/
class WPML_TM_AMS_Synchronize_Actions implements IWPML_Action {
const ENABLED_FOR_TRANSLATION_VIA_ATE = 'wpml_enabled_for_translation_via_ate';
/**
* @var WPML_TM_AMS_API
*/
private $ams_api;
/**
* @var WPML_TM_AMS_Users
*/
private $ams_user_records;
/**
* @var WPML_WP_User_Factory $user_factory
*/
private $user_factory;
/**
* @var WPML_TM_AMS_Translator_Activation_Records
*/
private $translator_activation_records;
/** @var WPML_Translation_Manager_Records */
private $tm_records;
/** @var WPML_Translator_Records */
private $translator_records;
/** @var int[] */
private $deletedManagerIds = [];
/** @var int[] */
private $deletedTranslatorIds = [];
public function __construct(
WPML_TM_AMS_API $ams_api,
WPML_TM_AMS_Users $ams_user_records,
WPML_WP_User_Factory $user_factory,
WPML_TM_AMS_Translator_Activation_Records $translator_activation_records,
WPML_Translation_Manager_Records $tm_records,
WPML_Translator_Records $translator_records
) {
$this->ams_api = $ams_api;
$this->ams_user_records = $ams_user_records;
$this->user_factory = $user_factory;
$this->translator_activation_records = $translator_activation_records;
$this->tm_records = $tm_records;
$this->translator_records = $translator_records;
}
public function add_hooks() {
add_action( 'wpml_tm_ate_synchronize_translators', array( $this, 'synchronize_translators' ) );
add_action( 'wpml_update_translator', array( $this, 'synchronize_translators' ) );
add_action( 'wpml_tm_ate_synchronize_managers', array( $this, 'synchronize_managers' ) );
add_action( 'wpml_tm_ate_enable_subscription', array( $this, 'enable_subscription' ) );
add_action( 'delete_user', array( $this, 'prepare_user_deleted' ), 10, 1 );
add_action( 'deleted_user', array( $this, 'user_changed' ), 10, 1 );
add_action( 'profile_update', array( $this, 'user_changed' ), 10, 1 );
}
/**
* @throws \InvalidArgumentException
*/
public function synchronize_translators() {
$result = $this->ams_api->synchronize_translators( $this->ams_user_records->get_translators() );
if ( ! is_wp_error( $result ) ) {
$this->translator_activation_records->update( isset( $result['translators'] ) ? $result['translators'] : array() );
}
}
/**
* @throws \InvalidArgumentException
*/
public function synchronize_managers() {
$this->ams_api->synchronize_managers( $this->ams_user_records->get_managers() );
}
public function enable_subscription( $user_id ) {
$user = $this->user_factory->create( $user_id );
if ( ! $user->get_meta( self::ENABLED_FOR_TRANSLATION_VIA_ATE ) ) {
$this->ams_api->enable_subscription( $user->user_email );
$user->update_meta( self::ENABLED_FOR_TRANSLATION_VIA_ATE, true );
}
}
/**
* @param int $user_id
*/
public function prepare_user_deleted( $user_id ) {
if ( $this->tm_records->does_user_have_capability( $user_id ) ) {
$this->deletedManagerIds[] = $user_id;
}
if ( $this->translator_records->does_user_have_capability( $user_id ) ) {
$this->deletedTranslatorIds[] = $user_id;
}
}
/**
* @param int $user_id
*/
public function user_changed( $user_id ) {
if ( in_array( $user_id, $this->deletedManagerIds ) || $this->tm_records->does_user_have_capability( $user_id ) ) {
$this->synchronize_managers();
}
if ( in_array( $user_id, $this->deletedTranslatorIds ) || $this->translator_records->does_user_have_capability( $user_id ) ) {
$this->synchronize_translators();
}
}
}

View File

@@ -0,0 +1,8 @@
<?php
class WPML_TM_AMS_Synchronize_Users_On_Access_Denied_Factory implements IWPML_Backend_Action_Loader {
public function create() {
return new WPML_TM_AMS_Synchronize_Users_On_Access_Denied();
}
}

View File

@@ -0,0 +1,89 @@
<?php
class WPML_TM_AMS_Synchronize_Users_On_Access_Denied {
const ERROR_MESSAGE = 'Authentication error, please contact your translation manager to check your subscription';
/** @var WPML_TM_AMS_Synchronize_Actions */
private $ams_synchronize_actions;
/** @var WPML_TM_ATE_Jobs */
private $ate_jobs;
public function add_hooks() {
if ( WPML_TM_ATE_Status::is_enabled_and_activated() ) {
add_action( 'init', array( $this, 'catch_access_error' ) );
}
}
public function catch_access_error() {
if ( ! $this->ate_redirected_due_to_lack_of_access() ) {
return;
}
$this->get_ams_synchronize_actions()->synchronize_translators();
if ( ! isset( $_GET['ate_job_id'] ) ) {
return;
}
$wpml_job_id = $this->get_ate_jobs()->get_wpml_job_id( $_GET['ate_job_id'] );
if ( ! $wpml_job_id ) {
return;
}
$url = admin_url(
'admin.php?page='
. WPML_TM_FOLDER
. '/menu/translations-queue.php&job_id='
. $wpml_job_id
);
wp_safe_redirect( $url, 302, 'WPML' );
}
/**
* @return bool
*/
private function ate_redirected_due_to_lack_of_access() {
return isset( $_GET['message'] ) && false !== strpos( $_GET['message'], self::ERROR_MESSAGE );
}
/**
* @return IWPML_Action|IWPML_Action[]|WPML_TM_AMS_Synchronize_Actions
*/
private function get_ams_synchronize_actions() {
if ( ! $this->ams_synchronize_actions ) {
$factory = new WPML_TM_AMS_Synchronize_Actions_Factory();
$this->ams_synchronize_actions = $factory->create();
}
return $this->ams_synchronize_actions;
}
/**
* @return WPML_TM_ATE_Jobs
*/
private function get_ate_jobs() {
if ( ! $this->ate_jobs ) {
$ate_jobs_records = wpml_tm_get_ate_job_records();
$this->ate_jobs = new WPML_TM_ATE_Jobs( $ate_jobs_records );
}
return $this->ate_jobs;
}
/**
* @param WPML_TM_AMS_Synchronize_Actions $ams_synchronize_actions
*/
public function set_ams_synchronize_actions( WPML_TM_AMS_Synchronize_Actions $ams_synchronize_actions ) {
$this->ams_synchronize_actions = $ams_synchronize_actions;
}
/**
* @param WPML_TM_ATE_Jobs $ate_jobs
*/
public function set_ate_jobs( WPML_TM_ATE_Jobs $ate_jobs ) {
$this->ate_jobs = $ate_jobs;
}
}

View File

@@ -0,0 +1,21 @@
<?php
class WPML_TM_ATE_API_Error {
public function log( $message ) {
$wpml_admin_notices = wpml_get_admin_notices();
$notice = new WPML_Notice(
WPML_TM_ATE_Jobs_Actions::RESPONSE_ATE_ERROR_NOTICE_ID,
sprintf(
__( 'There was a problem communicating with ATE: %s ', 'wpml-translation-management' ),
'(<i>' . $message . '</i>)'
),
WPML_TM_ATE_Jobs_Actions::RESPONSE_ATE_ERROR_NOTICE_GROUP
);
$notice->set_css_class_types( array( 'warning' ) );
$notice->add_capability_check( array( 'manage_options', 'wpml_manage_translation_management' ) );
$notice->set_flash();
$wpml_admin_notices->add_notice( $notice );
}
}

View File

@@ -0,0 +1,11 @@
<?php
class WPML_TM_ATE_Job_Data_Fallback_Factory implements IWPML_Backend_Action_Loader, IWPML_REST_Action_Loader {
/**
* @return WPML_TM_ATE_Job_Data_Fallback
*/
public function create() {
return \WPML\Container\make( '\WPML_TM_ATE_Job_Data_Fallback' );
}
}

View File

@@ -0,0 +1,39 @@
<?php
use WPML\TM\ATE\JobRecords;
class WPML_TM_ATE_Job_Data_Fallback implements IWPML_Action {
/** @var WPML_TM_ATE_API */
private $ate_api;
/**
* @param WPML_TM_ATE_API $ate_api
*/
public function __construct( WPML_TM_ATE_API $ate_api ) {
$this->ate_api = $ate_api;
}
public function add_hooks() {
add_filter( 'wpml_tm_ate_job_data_fallback', array( $this, 'get_data_from_api' ), 10, 2 );
}
/**
* @param array $data
* @param int $wpml_job_id
*
* @return array
*/
public function get_data_from_api( array $data, $wpml_job_id ) {
$response = $this->ate_api->get_jobs_by_wpml_ids( array( $wpml_job_id ) );
if ( ! $response || is_wp_error( $response ) ) {
return $data;
}
if ( ! isset( $response->{$wpml_job_id}->ate_job_id ) ) {
return $data;
}
return array( JobRecords::FIELD_ATE_JOB_ID => $response->{$wpml_job_id}->ate_job_id );
}
}

View File

@@ -0,0 +1,75 @@
<?php
use function WPML\Container\make;
use WPML\TM\ATE\ReturnedJobsQueue;
/**
* Factory class for \WPML_TM_ATE_Jobs_Actions.
*
* @package wpml\tm
*
* @author OnTheGo Systems
*/
class WPML_TM_ATE_Jobs_Actions_Factory implements IWPML_Backend_Action_Loader, \IWPML_REST_Action_Loader {
/**
* The instance of \WPML_Current_Screen.
*
* @var WPML_Current_Screen
*/
private $current_screen;
/**
* It returns an instance of \WPML_TM_ATE_Jobs_Actions or null if ATE is not enabled and active.
*
* @return \WPML_TM_ATE_Jobs_Actions|null
* @throws \Auryn\InjectionException
*/
public function create() {
$ams_ate_factories = wpml_tm_ams_ate_factories();
if ( WPML_TM_ATE_Status::is_enabled_and_activated() ) {
$sitepress = $this->get_sitepress();
$current_screen = $this->get_current_screen();
$ate_api = $ams_ate_factories->get_ate_api();
$records = wpml_tm_get_ate_job_records();
$ate_jobs = new WPML_TM_ATE_Jobs( $records );
$translator_activation_records = new WPML_TM_AMS_Translator_Activation_Records( new WPML_WP_User_Factory() );
return new WPML_TM_ATE_Jobs_Actions(
$ate_api,
$ate_jobs,
$sitepress,
$current_screen,
$translator_activation_records
);
}
return null;
}
/**
* The global instance of \Sitepress.
*
* @return SitePress
*/
private function get_sitepress() {
global $sitepress;
return $sitepress;
}
/**
* It gets the instance of \WPML_Current_Screen.
*
* @return \WPML_Current_Screen
*/
private function get_current_screen() {
if ( ! $this->current_screen ) {
$this->current_screen = new WPML_Current_Screen();
}
return $this->current_screen;
}
}

View File

@@ -0,0 +1,538 @@
<?php
use WPML\API\Sanitize;
use WPML\FP\Fns;
use WPML\FP\Json;
use WPML\FP\Logic;
use WPML\FP\Lst;
use WPML\FP\Obj;
use WPML\FP\Str;
use WPML\FP\Relation;
use WPML\TM\API\Jobs;
use WPML\FP\Wrapper;
use WPML\Settings\PostType\Automatic;
use WPML\Setup\Option;
use WPML\TM\ATE\JobRecords;
use WPML\TM\ATE\Log\Storage;
use WPML\TM\ATE\Log\Entry;
use function WPML\FP\partialRight;
use function WPML\FP\pipe;
use WPML\TM\API\ATE\LanguageMappings;
use WPML\Element\API\Languages;
/**
* @author OnTheGo Systems
*/
class WPML_TM_ATE_Jobs_Actions implements IWPML_Action {
const RESPONSE_ATE_NOT_ACTIVE_ERROR = 403;
const RESPONSE_ATE_DUPLICATED_SOURCE_ID = 417;
const RESPONSE_ATE_UNEXPECTED_ERROR = 500;
const RESPONSE_ATE_ERROR_NOTICE_ID = 'ate-update-error';
const RESPONSE_ATE_ERROR_NOTICE_GROUP = 'default';
const CREATE_ATE_JOB_CHUNK_WORDS_LIMIT = 2000;
/**
* @var WPML_TM_ATE_API
*/
private $ate_api;
/**
* @var WPML_TM_ATE_Jobs
*/
private $ate_jobs;
/**
* @var WPML_TM_AMS_Translator_Activation_Records
*/
private $translator_activation_records;
/** @var bool */
private $is_second_attempt_to_get_jobs_data = false;
/**
* @var SitePress
*/
private $sitepress;
/**
* @var WPML_Current_Screen
*/
private $current_screen;
/**
* WPML_TM_ATE_Jobs_Actions constructor.
*
* @param \WPML_TM_ATE_API $ate_api
* @param \WPML_TM_ATE_Jobs $ate_jobs
* @param \SitePress $sitepress
* @param \WPML_Current_Screen $current_screen
* @param \WPML_TM_AMS_Translator_Activation_Records $translator_activation_records
*/
public function __construct(
WPML_TM_ATE_API $ate_api,
WPML_TM_ATE_Jobs $ate_jobs,
SitePress $sitepress,
WPML_Current_Screen $current_screen,
WPML_TM_AMS_Translator_Activation_Records $translator_activation_records
) {
$this->ate_api = $ate_api;
$this->ate_jobs = $ate_jobs;
$this->sitepress = $sitepress;
$this->current_screen = $current_screen;
$this->translator_activation_records = $translator_activation_records;
}
public function add_hooks() {
add_action( 'wpml_added_translation_job', [ $this, 'added_translation_job' ], 10, 2 );
add_action( 'wpml_added_translation_jobs', [ $this, 'added_translation_jobs' ], 10, 2 );
add_action( 'admin_notices', [ $this, 'handle_messages' ] );
add_filter( 'wpml_tm_ate_jobs_data', [ $this, 'get_ate_jobs_data_filter' ], 10, 2 );
add_filter( 'wpml_tm_ate_jobs_editor_url', [ $this, 'get_editor_url' ], 10, 3 );
}
public function handle_messages() {
if ( $this->current_screen->id_ends_with( WPML_TM_FOLDER . '/menu/translations-queue' ) ) {
if ( array_key_exists( 'message', $_GET ) ) {
if ( array_key_exists( 'ate_job_id', $_GET ) ) {
$ate_job_id = filter_var( $_GET['ate_job_id'], FILTER_SANITIZE_NUMBER_INT );
$this->resign_job_on_error( $ate_job_id );
}
$message = Sanitize::stringProp( 'message', $_GET );
?>
<div class="error notice-error notice otgs-notice">
<p><?php echo $message; ?></p>
</div>
<?php
}
}
}
/**
* @param int $job_id
* @param string $translation_service
*
* @throws \InvalidArgumentException
* @throws \RuntimeException
*/
public function added_translation_job( $job_id, $translation_service ) {
$this->added_translation_jobs( array( $translation_service => array( $job_id ) ) );
}
/**
* @param array $jobs
* @param int|null $sentFrom
*
* @return bool|void
* @throws \InvalidArgumentException
* @throws \RuntimeException
*/
public function added_translation_jobs( array $jobs, $sentFrom = null ) {
$oldEditor = wpml_tm_load_old_jobs_editor();
$job_ids = Fns::reject( [ $oldEditor, 'shouldStickToWPMLEditor' ], Obj::propOr( [], 'local', $jobs ) );
if ( ! $job_ids ) {
return;
}
$jobs = Fns::map( 'wpml_tm_create_ATE_job_creation_model', $job_ids );
$responses = Fns::map(
Fns::unary( partialRight( [ $this, 'create_jobs' ], $sentFrom ) ),
$this->getChunkedJobs( $jobs )
);
$created_jobs = $this->getResponsesJobs( $responses, $jobs );
if ( $created_jobs ) {
$created_jobs = $this->map_response_jobs( $created_jobs );
$this->ate_jobs->warm_cache( array_keys( $created_jobs ) );
foreach ( $created_jobs as $wpml_job_id => $ate_job_id ) {
$this->ate_jobs->store( $wpml_job_id, [ JobRecords::FIELD_ATE_JOB_ID => $ate_job_id ] );
$oldEditor->set( $wpml_job_id, WPML_TM_Editors::ATE );
$translationJob = wpml_tm_load_job_factory()->get_translation_job( $wpml_job_id, false, 0, true );
$jobType = $this->getJobType( $translationJob );
wpml_tm_load_job_factory()->update_job_data(
$wpml_job_id,
[ 'automatic' => $jobType === 'auto' ? 1 : 0 ]
);
if ( $sentFrom === Jobs::SENT_RETRY ) {
Jobs::setStatus( $wpml_job_id, ICL_TM_WAITING_FOR_TRANSLATOR );
}
}
$message = __( '%1$s jobs added to the Advanced Translation Editor.', 'wpml-translation-management' );
$this->add_message( 'updated', sprintf( $message, count( $created_jobs ) ), 'wpml_tm_ate_create_job' );
} else {
if ( Lst::includes( $sentFrom, [ Jobs::SENT_AUTOMATICALLY, Jobs::SENT_RETRY ] ) ) {
if ( $sentFrom === Jobs::SENT_RETRY ) {
$updateJob = function ($jobId) {
Jobs::incrementRetryCount($jobId);
$this->logRetryError( $jobId );
};
} else {
$updateJob = function ( $jobId ) use ( $oldEditor ) {
$this->logError( $jobId );
$translationJob = wpml_tm_load_job_factory()->get_translation_job( $jobId, false, 0, true );
$jobType = $this->getJobType( $translationJob );
if ( $jobType === 'auto' ) {
Jobs::setStatus( $jobId, ICL_TM_ATE_NEEDS_RETRY );
$oldEditor->set( $jobId, WPML_TM_Editors::ATE );
wpml_tm_load_job_factory()->update_job_data( $jobId, [ 'automatic' => 1 ] );
}
};
}
wpml_collect( $job_ids )->map( $updateJob );
}
$this->add_message(
'error',
__(
'Jobs could not be created in Advanced Translation Editor. Please try again or contact the WPML support for help.',
'wpml-translation-management'
),
'wpml_tm_ate_create_job'
);
}
}
private function map_response_jobs( $responseJobs ) {
$result = [];
foreach ( $responseJobs as $rid => $ate_job_id ) {
$jobId = \WPML\TM\API\Job\Map::fromRid( $rid );
if ( $jobId ) {
$result[ $jobId ] = $ate_job_id;
}
}
return $result;
}
/**
* @param string $type
* @param string $message
* @param string|null $id
*/
private function add_message( $type, $message, $id = null ) {
do_action( 'wpml_tm_basket_add_message', $type, $message, $id );
}
/**
* @param array $jobsData
* @param int|null $sentFrom
*
* @return mixed
* @throws \InvalidArgumentException
*/
public function create_jobs( array $jobsData, $sentFrom ) {
$setJobType = Logic::ifElse( Fns::always( $sentFrom ), Obj::assoc( 'job_type', $sentFrom ), Fns::identity() );
list( $existing, $new ) = Lst::partition(
pipe( Obj::propOr( null, 'existing_ate_id' ), Logic::isNotNull() ),
$jobsData['jobs']
);
$isAuto = Relation::propEq( 'type', 'auto', $jobsData );
return Wrapper::of( [ 'jobs' => $new, 'existing_jobs' => Lst::pluck( 'existing_ate_id', $existing ) ] )
->map( Obj::assoc( 'auto_translate', $isAuto && Option::shouldTranslateEverything() ) )
->map( Obj::assoc( 'preview', $isAuto && Option::shouldBeReviewed() ) )
->map( $setJobType )
->map( 'wp_json_encode' )
->map( Json::toArray() )
->map( [ $this->ate_api, 'create_jobs' ] )
->get();
}
/**
* After implementation of wpmltm-3211 and wpmltm-3391, we should not find missing ATE IDs anymore.
* Some code below seems dead but we'll keep it for now in case we are missing a specific context.
*
* @link https://onthegosystems.myjetbrains.com/youtrack/issue/wpmltm-3211
* @link https://onthegosystems.myjetbrains.com/youtrack/issue/wpmltm-3391
*/
private function get_ate_jobs_data( array $translation_jobs ) {
$ate_jobs_data = array();
$skip_getting_data = false;
$ate_jobs_to_create = array();
$this->ate_jobs->warm_cache( wpml_collect( $translation_jobs )->pluck( 'job_id' )->toArray() );
foreach ( $translation_jobs as $translation_job ) {
if ( $this->is_ate_translation_job( $translation_job ) ) {
$ate_job_id = $this->get_ate_job_id( $translation_job->job_id );
// Start of possibly dead code.
if ( ! $ate_job_id ) {
$ate_jobs_to_create[] = $translation_job->job_id;
$skip_getting_data = true;
}
// End of possibly dead code.
if ( ! $skip_getting_data ) {
$ate_jobs_data[ $translation_job->job_id ] = [ 'ate_job_id' => $ate_job_id ];
}
}
}
// Start of possibly dead code.
if (
! $this->is_second_attempt_to_get_jobs_data &&
$ate_jobs_to_create &&
$this->added_translation_jobs( array( 'local' => $ate_jobs_to_create ) )
) {
$ate_jobs_data = $this->get_ate_jobs_data( $translation_jobs );
$this->is_second_attempt_to_get_jobs_data = true;
}
// End of possibly dead code.
return $ate_jobs_data;
}
/**
* @param string $default_url
* @param int $job_id
* @param null|string $return_url
*
* @return string
* @throws \InvalidArgumentException
*/
public function get_editor_url( $default_url, $job_id, $return_url = null ) {
$isUserActivated = $this->translator_activation_records->is_current_user_activated();
if ( $isUserActivated || is_admin() ) {
$ate_job_id = $this->ate_jobs->get_ate_job_id( $job_id );
if ( $ate_job_id ) {
if ( ! $return_url ) {
$return_url = add_query_arg(
array(
'page' => WPML_TM_FOLDER . '/menu/translations-queue.php',
'ate-return-job' => $job_id,
),
admin_url( '/admin.php' )
);
}
$ate_job_url = $this->ate_api->get_editor_url( $ate_job_id, $return_url );
if ( $ate_job_url && ! is_wp_error( $ate_job_url ) ) {
return $ate_job_url;
}
}
}
return $default_url;
}
/**
* @param $ignore
* @param array $translation_jobs
*
* @return array
*/
public function get_ate_jobs_data_filter( $ignore, array $translation_jobs ) {
return $this->get_ate_jobs_data( $translation_jobs );
}
private function get_ate_job_id( $job_id ) {
return $this->ate_jobs->get_ate_job_id( $job_id );
}
/**
* @param mixed $response
*
* @throws \RuntimeException
*/
protected function check_response_error( $response ) {
if ( is_wp_error( $response ) ) {
$code = 0;
$message = $response->get_error_message();
if ( $response->error_data && is_array( $response->error_data ) ) {
foreach ( $response->error_data as $http_code => $error_data ) {
$code = $error_data[0]['status'];
$message = '';
switch ( (int) $code ) {
case self::RESPONSE_ATE_NOT_ACTIVE_ERROR:
$wp_admin_url = admin_url( 'admin.php' );
$mcsetup_page = add_query_arg(
array(
'page' => WPML_TM_FOLDER . WPML_Translation_Management::PAGE_SLUG_SETTINGS,
'sm' => 'mcsetup',
),
$wp_admin_url
);
$mcsetup_page .= '#ml-content-setup-sec-1';
$resend_link = '<a href="' . $mcsetup_page . '">'
. esc_html__( 'Resend that email', 'wpml-translation-management' )
. '</a>';
$message .= '<p>'
. esc_html__( 'WPML cannot send these documents to translation because the Advanced Translation Editor is not fully set-up yet.', 'wpml-translation-management' )
. '</p><p>'
. esc_html__( 'Please open the confirmation email that you received and click on the link inside it to confirm your email.', 'wpml-translation-management' )
. '</p><p>'
. $resend_link
. '</p>';
break;
case self::RESPONSE_ATE_DUPLICATED_SOURCE_ID:
case self::RESPONSE_ATE_UNEXPECTED_ERROR:
default:
$message = '<p>'
. __( 'Advanced Translation Editor error:', 'wpml-translation-management' )
. '</p><p>'
. $error_data[0]['message']
. '</p>';
}
$message = '<p>' . $message . '</p>';
}
}
/** @var WP_Error $response */
throw new RuntimeException( $message, $code );
}
}
/**
* @param $ate_job_id
*/
private function resign_job_on_error( $ate_job_id ) {
$job_id = $this->ate_jobs->get_wpml_job_id( $ate_job_id );
if ( $job_id ) {
wpml_load_core_tm()->resign_translator( $job_id );
}
}
/**
* @param $translation_job
*
* @return bool
*/
private function is_ate_translation_job( $translation_job ) {
return 'local' === $translation_job->translation_service
&& WPML_TM_Editors::ATE === $translation_job->editor;
}
/**
* @param array $responses
* @param \WPML_TM_ATE_Models_Job_Create[] $sentJobs
*
* @return array
*/
private function getResponsesJobs( $responses, $sentJobs ) {
$jobs = [];
foreach ( $responses as $response ) {
try {
$this->check_response_error( $response );
if ( $response && isset( $response->jobs ) ) {
$jobs = $jobs + (array) $response->jobs;
}
} catch ( RuntimeException $ex ) {
do_action( 'wpml_tm_basket_add_message', 'error', $ex->getMessage() );
}
}
$existingJobs = wpml_collect( $sentJobs )
->filter( Obj::prop( 'existing_ate_id' ) )
->map( Obj::pick( [ 'source_id', 'existing_ate_id' ] ) )
->keyBy( 'source_id' )
->map( Obj::prop( 'existing_ate_id' ) )
->toArray();
return $jobs + $existingJobs;
}
/**
* @param \WPML_TM_ATE_Models_Job_Create[] $jobs
*
* @return array
*/
private function getChunkedJobs( $jobs ) {
$chunkedJobs = [];
$currentChunk = -1;
$currentWordCount = 0;
$chunkType = 'auto';
$newChunk = function( $chunkType ) use ( &$chunkedJobs, &$currentChunk, &$currentWordCount ) {
$currentChunk ++;
$currentWordCount = 0;
$chunkedJobs[ $currentChunk ] = [ 'type' => $chunkType, 'jobs' => [] ];
};
$newChunk( $chunkType );
foreach ( $jobs as $job ) {
/** @var WPML_Element_Translation_Job $translationJob */
$translationJob = wpml_tm_load_job_factory()->get_translation_job( $job->id, false, 0, true );
if ( $translationJob ) {
if ( ! Obj::prop( 'existing_ate_id', $job ) ) {
$currentWordCount += $translationJob->estimate_word_count();
}
$jobType = $this->getJobType( $translationJob );
if ( $jobType !== $chunkType ) {
$chunkType = $jobType;
$newChunk( $chunkType );
}
if ( $currentWordCount > self::CREATE_ATE_JOB_CHUNK_WORDS_LIMIT && count( $chunkedJobs[ $currentChunk ] ) > 0 ) {
$newChunk( $chunkType );
}
}
$chunkedJobs[ $currentChunk ]['jobs'] [] = $job;
}
$hasJobs = pipe( Obj::prop( 'jobs' ), Lst::length() );
return Fns::filter( $hasJobs, $chunkedJobs );
}
/**
* @param int $jobId
*/
private function logRetryError( $jobId ) {
$job = Jobs::get( $jobId );
if ( $job && $job->ate_comm_retry_count ) {
Storage::add( Entry::retryJob( $jobId,
[
'retry_count' => $job->ate_comm_retry_count
]
) );
}
}
/**
* @param int $jobId
*/
private function logError( $jobId ) {
$job = Jobs::get( $jobId );
if ( $job ) {
Storage::add( Entry::retryJob( $jobId, [
'retry_count' => 0,
'comment' => 'Sending job to ate failed, queued to be sent again.',
]
) );
}
}
private function getJobType( $translationJob ) {
$document = $translationJob->get_original_document();
if ( ! $document || $document instanceof WPML_Package ) {
return 'manual';
} else {
return $translationJob->get_source_language_code() === Languages::getDefaultCode() &&
Jobs::isEligibleForAutomaticTranslations( $translationJob->get_id() ) ? 'auto' : 'manual';
}
}
}

View File

@@ -0,0 +1,22 @@
<?php
/**
* @todo Perhaps this class is redundant
*
* @author OnTheGo Systems
*/
class WPML_TM_ATE_Jobs_Store_Actions_Factory implements IWPML_Backend_Action_Loader {
/**
* @return IWPML_Action|IWPML_Action[]|null
*/
public function create() {
if ( WPML_TM_ATE_Status::is_enabled() ) {
$ate_jobs_records = wpml_tm_get_ate_job_records();
$ate_jobs = new WPML_TM_ATE_Jobs( $ate_jobs_records );
return new WPML_TM_ATE_Jobs_Store_Actions( $ate_jobs );
}
}
}

View File

@@ -0,0 +1,36 @@
<?php
/**
* @todo The hook 'wpml_tm_ate_jobs_store' seems to be never used so this class and its factory may be obsolete
*
* @author OnTheGo Systems
*/
class WPML_TM_ATE_Jobs_Store_Actions implements IWPML_Action {
/**
* @var WPML_TM_ATE_Jobs
*/
private $ate_jobs;
/**
* WPML_TM_ATE_Jobs_Actions constructor.
*
* @param WPML_TM_ATE_Jobs $ate_jobs
*/
public function __construct( WPML_TM_ATE_Jobs $ate_jobs ) {
$this->ate_jobs = $ate_jobs;
}
public function add_hooks() {
add_action( 'wpml_tm_ate_jobs_store', array( $this, 'store' ), 10, 2 );
}
/**
* @param int $wpml_job_id
* @param array $ate_job_data
*
* @return array|null
*/
public function store( $wpml_job_id, $ate_job_data ) {
return $this->ate_jobs->store( $wpml_job_id, $ate_job_data );
}
}

View File

@@ -0,0 +1,21 @@
<?php
/**
* @author OnTheGo Systems
*/
class WPML_TM_ATE_Post_Edit_Actions_Factory implements IWPML_Backend_Action_Loader {
/**
* @return IWPML_Action|IWPML_Action[]|null
*/
public function create() {
$tm_ate = new WPML_TM_ATE();
$endpoints = WPML\Container\make( 'WPML_TM_ATE_AMS_Endpoints' );
if ( $tm_ate->is_translation_method_ate_enabled() ) {
return new WPML_TM_ATE_Post_Edit_Actions( $endpoints );
}
return null;
}
}

View File

@@ -0,0 +1,28 @@
<?php
/**
* @author OnTheGo Systems
*/
class WPML_TM_ATE_Post_Edit_Actions implements IWPML_Action {
private $endpoints;
/**
* WPML_TM_ATE_Jobs_Actions constructor.
*
* @param WPML_TM_ATE_AMS_Endpoints $endpoints
*/
public function __construct( WPML_TM_ATE_AMS_Endpoints $endpoints ) {
$this->endpoints = $endpoints;
}
public function add_hooks() {
add_filter( 'allowed_redirect_hosts', array( $this, 'allowed_redirect_hosts' ) );
}
public function allowed_redirect_hosts( $hosts ) {
$hosts[] = $this->endpoints->get_AMS_host();
$hosts[] = $this->endpoints->get_ATE_host();
return $hosts;
}
}

View File

@@ -0,0 +1,21 @@
<?php
/**
* @author OnTheGo Systems
*/
class WPML_TM_ATE_Required_Actions_Base {
private $ate_enabled;
protected function is_ate_enabled() {
if ( null === $this->ate_enabled ) {
$tm_settings = wpml_get_setting_filter( null, 'translation-management' );
$doc_translation_method = null;
if ( array_key_exists( 'doc_translation_method', $tm_settings ) ) {
$doc_translation_method = $tm_settings['doc_translation_method'];
}
$this->ate_enabled = $doc_translation_method === ICL_TM_TMETHOD_ATE;
}
return $this->ate_enabled;
}
}

View File

@@ -0,0 +1,25 @@
<?php
/**
* \WPML_TM_ATE_Translator_Login factory.
*
* @author OnTheGo Systems
*
* NOTE: This uses the Frontend loader because is_admin() returns false during wp_login
*/
class WPML_TM_ATE_Translator_Login_Factory implements IWPML_Frontend_Action_Loader {
/**
* It returns an instance of WPML_TM_ATE_Translator_Login is ATE is enabled and active.
*
* @return \WPML_TM_ATE_Translator_Logine|\IWPML_Frontend_Action_Loader|null
*/
public function create() {
if ( WPML_TM_ATE_Status::is_enabled_and_activated() ) {
return WPML\Container\make( WPML_TM_ATE_Translator_Login::class );
}
return null;
}
}

View File

@@ -0,0 +1,43 @@
<?php
/**
* @author OnTheGo Systems
*/
class WPML_TM_ATE_Translator_Login implements IWPML_Action {
/** @var WPML_TM_AMS_Translator_Activation_Records */
private $translator_activation_records;
/** @var WPML_Translator_Records */
private $translator_records;
/** @var WPML_TM_AMS_API */
private $ams_api;
public function __construct(
WPML_TM_AMS_Translator_Activation_Records $translator_activation_records,
WPML_Translator_Records $translator_records,
WPML_TM_AMS_API $ams_api
) {
$this->translator_activation_records = $translator_activation_records;
$this->translator_records = $translator_records;
$this->ams_api = $ams_api;
}
public function add_hooks() {
add_action( 'wp_login', array( $this, 'wp_login' ), 10, 2 );
}
public function wp_login( $user_login, $user ) {
if ( $this->translator_records->does_user_have_capability( $user->ID ) ) {
$result = $this->ams_api->is_subscription_activated( $user->user_email );
if ( ! is_wp_error( $result ) ) {
$this->translator_activation_records->set_activated(
$user->user_email,
$result
);
}
}
}
}

View File

@@ -0,0 +1,54 @@
<?php
use WPML\API\Sanitize;
class WPML_TM_ATE_Translator_Message_Classic_Editor_Factory implements IWPML_Backend_Action_Loader, IWPML_AJAX_Action_Loader {
/**
* @return \WPML_TM_ATE_Translator_Message_Classic_Editor|\IWPML_Action|null
*/
public function create() {
global $wpdb;
if ( $this->is_ajax_or_translation_queue() && $this->is_ate_enabled_and_manager_wizard_completed() && ! $this->is_editing_old_translation_and_te_is_used_for_old_translation() ) {
$email_twig_factory = wpml_tm_get_email_twig_template_factory();
return new WPML_TM_ATE_Translator_Message_Classic_Editor(
new WPML_Translation_Manager_Records(
$wpdb,
wpml_tm_get_wp_user_query_factory(),
wp_roles()
),
wpml_tm_get_wp_user_factory(),
new WPML_TM_ATE_Request_Activation_Email(
new WPML_TM_Email_Notification_View( $email_twig_factory->create() )
)
);
}
return null;
}
/**
* @return bool
*/
private function is_editing_old_translation_and_te_is_used_for_old_translation() {
return Sanitize::stringProp( 'job_id', $_GET )
&& get_option( WPML_TM_Old_Jobs_Editor::OPTION_NAME ) === WPML_TM_Editors::WPML; }
/**
* @return bool
*/
private function is_ate_enabled_and_manager_wizard_completed() {
return WPML_TM_ATE_Status::is_enabled_and_activated() && (bool) get_option( WPML_TM_Wizard_Options::WIZARD_COMPLETE_FOR_MANAGER, false );
}
/**
* @return bool
*/
private function is_ajax_or_translation_queue() {
return wpml_is_ajax() || WPML_TM_Page::is_translation_queue();
}
}

View File

@@ -0,0 +1,126 @@
<?php
use WPML\DocPage;
class WPML_TM_ATE_Translator_Message_Classic_Editor implements IWPML_Action {
const ACTION = 'wpml_ate_translator_classic_editor';
const USER_OPTION = 'wpml_ate_translator_classic_editor_minimized';
/** @var WPML_Translation_Manager_Records */
private $translation_manager_records;
/** @var WPML_WP_User_Factory */
private $user_factory;
/** @var WPML_TM_ATE_Request_Activation_Email */
private $activation_email;
public function __construct(
WPML_Translation_Manager_Records $translation_manager_records,
WPML_WP_User_Factory $user_factory,
WPML_TM_ATE_Request_Activation_Email $activation_email
) {
$this->translation_manager_records = $translation_manager_records;
$this->user_factory = $user_factory;
$this->activation_email = $activation_email;
}
public function add_hooks() {
add_action( 'wpml_tm_editor_messages', array( $this, 'classic_editor_message' ) );
add_action( 'wp_ajax_' . self::ACTION, array( $this, 'handle_ajax' ) );
}
public function classic_editor_message() {
$main_message = esc_html__( "This site can use WPML's Advanced Translation Editor, but you did not receive permission to use it. You are still translating with WPML's classic translation editor. Please ask your site's Translation Manager to enable the Advanced Translation Editor for you.", 'wpml-translation-management' );
$learn_more = esc_html__( "Learn more about WPML's Advanced Translation Editor", 'wpml-translation-management' );
$short_message = esc_html__( 'Advanced Translation Editor is disabled.', 'wpml-translation-management' );
$more = esc_html__( 'More', 'wpml-translation-management' );
$request_activation = esc_html__( 'Request activation from', 'wpml-translation-management' );
$link = DocPage::aboutATE();
$show_minimized = (bool) $this->user_factory->create_current()->get_option( self::USER_OPTION );
?>
<div
class="notice notice-info otgs-notice js-classic-editor-notice"
data-nonce="<?php echo wp_create_nonce( self::ACTION ); ?>"
data-action="<?php echo self::ACTION; ?>"
<?php
if ( $show_minimized ) {
?>
style="display: none" <?php } ?>
>
<p><?php echo $main_message; ?></p>
<p><a href="<?php echo esc_attr( $link ); ?>" class="wpml-external-link" target="_blank"><?php echo $learn_more; ?></a></p>
<p>
<a class="button js-request-activation"><?php echo $request_activation; ?></a> <?php $this->output_translation_manager_list(); ?>
</p>
<p class="js-email-sent" style="display: none"></p>
<a class="js-minimize otgs-notice-toggle">
<?php esc_html_e( 'Minimize', 'wpml-translation-management' ); ?>
</a>
</div>
<div
class="notice notice-info otgs-notice js-classic-editor-notice-minimized"
<?php
if ( ! $show_minimized ) {
?>
style="display: none" <?php } ?>
>
<p><?php echo $short_message; ?> <a class="js-maximize"><?php echo $more; ?></a></p>
</div>
<?php
}
private function output_translation_manager_list() {
$translation_managers = $this->translation_manager_records->get_users_with_capability();
?>
<select class="js-translation-managers">
<?php
foreach ( $translation_managers as $translation_manager ) {
$display_name = $translation_manager->user_login . ' (' . $translation_manager->user_email . ')';
?>
<option
value="<?php echo $translation_manager->ID; ?> "><?php echo $display_name; ?></option>
<?php } ?>
</select>
<?php
}
public function handle_ajax() {
if ( wp_verify_nonce( $_POST['nonce'], self::ACTION ) ) {
$current_user = $this->user_factory->create_current();
switch ( $_POST['command'] ) {
case 'minimize':
$current_user->update_option( self::USER_OPTION, true );
wp_send_json_success( array( 'message' => '' ) );
case 'maximize':
$current_user->update_option( self::USER_OPTION, false );
wp_send_json_success( array( 'message' => '' ) );
case 'requestActivation':
$manager = $this->user_factory->create( (int) $_POST['manager'] );
if ( $this->activation_email->send_email( $manager, $current_user ) ) {
$message = sprintf(
esc_html__( 'An email has been sent to %s', 'wpml-translation-management' ),
$manager->user_login
);
} else {
$message = sprintf(
esc_html__( 'Sorry, the email could not be sent to %s for an unknown reason.', 'wpml-translation-management' ),
$manager->user_login
);
}
wp_send_json_success( array( 'message' => $message ) );
}
}
}
}

View File

@@ -0,0 +1,8 @@
<?php
class WPML_TM_Old_Editor_Factory implements IWPML_Backend_Action_Loader, IWPML_AJAX_Action_Loader {
public function create() {
return new WPML_TM_Old_Editor();
}
}

View File

@@ -0,0 +1,50 @@
<?php
class WPML_TM_Old_Editor implements IWPML_Action {
const ACTION = 'icl_ajx_custom_call';
const CUSTOM_AJAX_CALL = 'icl_doc_translation_method';
const NOTICE_ID = 'wpml-translation-management-old-editor';
const NOTICE_GROUP = 'wpml-translation-management';
public function add_hooks() {
add_action( self::ACTION, array( $this, 'handle_custom_ajax_call' ), 10, 2 );
}
public function handle_custom_ajax_call( $call, $data ) {
if ( self::CUSTOM_AJAX_CALL === $call ) {
if ( ! isset( $data[ WPML_TM_Old_Jobs_Editor::OPTION_NAME ] ) ) {
return;
}
$old_editor = $data[ WPML_TM_Old_Jobs_Editor::OPTION_NAME ];
if ( ! in_array( $old_editor, array( WPML_TM_Editors::WPML, WPML_TM_Editors::ATE ), true ) ) {
return;
}
update_option( WPML_TM_Old_Jobs_Editor::OPTION_NAME, $old_editor );
if ( WPML_TM_Editors::WPML === $old_editor && $this->is_ate_enabled_and_manager_wizard_completed() ) {
$text = __( 'You activated the Advanced Translation Editor for this site, but you are updating an old translation. WPML opened the Standard Translation Editor, so you can update this translation. When you translate new content, you\'ll get the Advanced Translation Editor with all its features. To change your settings, go to WPML Settings.', 'sitepress' );
$notice = new WPML_Notice( self::NOTICE_ID, $text, self::NOTICE_GROUP );
$notice->set_css_class_types( 'notice-info' );
$notice->set_dismissible( true );
$notice->add_display_callback( 'WPML_TM_Page::is_translation_editor_page' );
wpml_get_admin_notices()->add_notice( $notice, true );
} else {
wpml_get_admin_notices()->remove_notice( self::NOTICE_GROUP, self::NOTICE_ID );
}
}
}
/**
* @return bool
*/
private function is_ate_enabled_and_manager_wizard_completed() {
return WPML_TM_ATE_Status::is_enabled_and_activated() && (bool) get_option( WPML_TM_Wizard_Options::WIZARD_COMPLETE_FOR_MANAGER, false );
}
}