Report.php
2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
namespace WPML\TM\ATE\ClonedSites;
use WPML\FP\Fns;
class Report {
/**
* @var \WPML_TM_AMS_API
*/
private $apiClient;
/**
* @var Lock
*/
private $lock;
/**
* @var \WPML_TM_ATE_Job_Repository
*/
private $ateJobsRepository;
/**
* Update jobs synchronisation
*
* @var \WPML_TP_Sync_Update_Job
*/
private $updateJobs;
/**
* @var \WPML_Translation_Job_Factory
*/
private $translationJobFactory;
/**
* @param \WPML_TM_AMS_API $apiClient
* @param Lock $lock
* @param \WPML_TM_ATE_Job_Repository $ateJobsRepository
* @param \WPML_Translation_Job_Factory $translationJobFactory
*/
public function __construct(
\WPML_TM_AMS_API $apiClient,
Lock $lock,
\WPML_TM_ATE_Job_Repository $ateJobsRepository,
\WPML_TP_Sync_Update_Job $updateJobs,
\WPML_Translation_Job_Factory $translationJobFactory
) {
$this->apiClient = $apiClient;
$this->lock = $lock;
$this->ateJobsRepository = $ateJobsRepository;
$this->updateJobs = $updateJobs;
$this->translationJobFactory = $translationJobFactory;
}
/**
* @return true|\WP_Error
*/
public function move() {
$reportResult = $this->apiClient->reportMovedSite();
$result = $this->apiClient->processMoveReport( $reportResult );
if ( $result ) {
$this->lock->unlock();
do_action( 'wpml_tm_ate_synchronize_translators' );
}
return $result;
}
/**
* @return bool
*/
public function copy() {
return $this->copyWithStrategy( 'reportCopiedSite' );
}
/**
* @param string $migrationCode
*
* @return bool
*/
public function copyWithCredit( $migrationCode ) {
return $this->copyWithStrategy( 'reportCopiedSiteWithCreditTransfer', [ $migrationCode ] );
}
/**
* @param string $copyStrategy
* @param mixed[] $arguments
*
* @return bool
*/
private function copyWithStrategy( $copyStrategy, $arguments = [] ) {
$reportResult = call_user_func_array( [ $this->apiClient, $copyStrategy ], $arguments );
$result = $this->apiClient->processCopyReportConfirmation( $reportResult );
if ( $result ) {
$jobsInProgress = $this->ateJobsRepository->get_jobs_to_sync();
/** @var \WPML_TM_Post_Job_Entity $jobInProgress */
foreach ( $jobsInProgress as $jobInProgress ) {
$jobInProgress->set_status( ICL_TM_NOT_TRANSLATED );
$this->updateJobs->update_state( $jobInProgress );
$this->translationJobFactory->delete_job_data( $jobInProgress->get_translate_job_id() );
}
$this->lock->unlock();
do_action( 'wpml_tm_ate_synchronize_translators' );
}
return $result;
}
}