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.0 3.6.1 3.6.2 3.6.3 3.6.4 3.7.0 3.7.1 3.7.2 3.7.3 3.7.4 3.8.0 3.8.1 3.8.2 3.8.3 3.9.0 3.9.1 3.9.10 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.8 3.9.9
tutor / migrations / ProcessByWcMigrator.php
tutor / migrations Last commit date
Contracts 9 months ago BatchProcessor.php 9 months ago Migration.php 9 months ago ProcessByWcMigrator.php 9 months ago QuizAttemptMigrator.php 9 months ago
ProcessByWcMigrator.php
162 lines
1 <?php
2 /**
3 * Since Tutor 3.0.0 all wc earnings store in tutor_earnings table with 'Tutor' in process_by column.
4 * This migration will update all wc earnings process_by column to 'woocommerce'.
5 *
6 * @package Tutor
7 * @author Themeum <support@themeum.com>
8 * @link https://themeum.com
9 * @since 3.8.2
10 */
11
12 namespace Tutor\Migrations;
13
14 use TUTOR\Earnings;
15 use Tutor\Helpers\QueryHelper;
16 use Tutor\Migrations\Contracts\BulkProcessor;
17
18 /**
19 * Class ProcessByWcMigrator
20 *
21 * @since 3.8.2
22 */
23 class ProcessByWcMigrator extends BatchProcessor implements BulkProcessor {
24 /**
25 * Name of the migration
26 *
27 * @since 3.8.2
28 *
29 * @var string
30 */
31 protected $name = 'Process By WC Migration';
32
33 /**
34 * Action
35 *
36 * @since 3.8.2
37 *
38 * @var string
39 */
40 protected $action = 'process_by_wc_migrator';
41
42 /**
43 * Batch size
44 *
45 * @since 3.8.2
46 *
47 * @var integer
48 */
49 protected $batch_size = 1000;
50
51 /**
52 * Schedule interval.
53 *
54 * @since 3.8.2
55 *
56 * @var integer
57 */
58 protected $schedule_interval = 10;
59
60 /**
61 * Get the total count of the data to be processed
62 *
63 * @since 3.8.2
64 *
65 * @return int
66 */
67 protected function get_total_items() : int {
68 $primary_table = 'tutor_earnings te';
69 $joining_tables = array(
70 array(
71 'table' => 'wc_orders_meta wcom',
72 'on' => 'te.order_id = wcom.order_id',
73 'type' => 'INNER',
74 ),
75 );
76
77 $where = array(
78 'te.process_by' => Earnings::PROCESS_BY_TUTOR,
79 'wcom.meta_key' => '_is_tutor_order_for_course',
80 );
81
82 $total_items = QueryHelper::get_joined_count(
83 $primary_table,
84 $joining_tables,
85 $where,
86 array(),
87 'te.earning_id'
88 );
89
90 return $total_items;
91 }
92
93 /**
94 * Get items to batch process.
95 *
96 * @since 3.8.2
97 *
98 * @param int $offset offset.
99 * @param int $limit limit.
100 *
101 * @return array
102 */
103 protected function get_items( $offset, $limit ) : array {
104 $primary_table = 'tutor_earnings te';
105 $joining_tables = array(
106 array(
107 'table' => 'wc_orders_meta wcom',
108 'on' => 'te.order_id = wcom.order_id',
109 'type' => 'INNER',
110 ),
111 );
112
113 $where = array(
114 'te.process_by' => Earnings::PROCESS_BY_TUTOR,
115 'wcom.meta_key' => '_is_tutor_order_for_course',
116 );
117
118 $response = QueryHelper::get_joined_data(
119 $primary_table,
120 $joining_tables,
121 array( 'te.*' ),
122 $where,
123 array(),
124 'te.earning_id',
125 $limit,
126 $offset,
127 'DESC'
128 );
129
130 $items = $response['total_count'] > 0 ? $response['results'] : array();
131
132 return $items;
133 }
134
135 /**
136 * Process a batch of items
137 *
138 * @since 3.8.2
139 *
140 * @param array $items items.
141 *
142 * @return void
143 */
144 public function process_items( $items ) : void {
145 $ids = wp_list_pluck( $items, 'earning_id' );
146 $data = array( 'process_by' => Earnings::PROCESS_BY_WOOCOMMERCE );
147 $where = array( 'earning_id' => $ids );
148 QueryHelper::update( 'tutor_earnings', $data, $where );
149 }
150
151 /**
152 * On migration complete event.
153 *
154 * @since 3.8.2
155 *
156 * @return void
157 */
158 protected function on_complete() {
159 error_log( 'Process by WC migration completed!' );
160 }
161 }
162