PluginProbe
Easy Invoice – Invoice Generator, PDF Quotes & Payments / 2.3.3
Easy Invoice – Invoice Generator, PDF Quotes & Payments v2.3.3
2.4.0 2.4.1 2.3.8 2.3.7 2.3.6 2.3.5 2.3.4 2.3.3 2.3.2 2.3.1 2.2.0 2.1.21 2.1.20 2.1.19 2.1.18 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.13 2.1.14 2.1.15 2.1.16 2.1.2 All 57 releases
easy-invoice / includes / Migration / MigrationStatus.php

MigrationStatus.php in Easy Invoice – Invoice Generator, PDF Quotes & Payments 2.3.3, at includes/Migration/MigrationStatus.php

296 lines 10.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Migration Status for Easy Invoice
4 *
5 * @package EasyInvoice
6 * @subpackage Migration
7 * @since 2.0.0
8 */
9
10 namespace EasyInvoice\Migration;
11
12 /**
13 * Migration status class.
14 *
15 * Provides comprehensive migration status and information.
16 *
17 * @since 2.0.0
18 */
19 class MigrationStatus {
20
21 /**
22 * Get comprehensive migration status.
23 *
24 * @since 2.0.0
25 * @return array
26 */
27 public static function get_status() {
28 $old_data = MigrationTest::check_old_plugin_data();
29 $test_results = MigrationTest::test_all_migrations();
30
31 return [
32 'migration_needed' => self::is_migration_needed($old_data),
33 'old_data_summary' => [
34 'options' => count($old_data['options']),
35 'post_types' => $old_data['post_types'],
36 'meta_fields' => $old_data['meta'],
37 ],
38 'migration_components' => [
39 'options_migration' => [
40 'status' => 'ready',
41 'description' => 'Options migration component is ready',
42 'old_options_found' => count($old_data['options']),
43 ],
44 'post_type_migration' => [
45 'status' => 'ready',
46 'description' => 'Post type migration component is ready',
47 'old_post_types_found' => array_keys($old_data['post_types']),
48 ],
49 'meta_migration' => [
50 'status' => 'ready',
51 'description' => 'Meta migration component is ready',
52 'meta_fields_found' => $old_data['meta'],
53 ],
54 ],
55 'recommendations' => self::get_recommendations($old_data, $test_results),
56 'migration_steps' => self::get_migration_steps(),
57 ];
58 }
59
60 /**
61 * Check if migration is needed.
62 *
63 * @since 2.0.0
64 * @param array $old_data
65 * @return bool
66 */
67 private static function is_migration_needed($old_data) {
68 return !empty($old_data['options']) ||
69 !empty($old_data['post_types']) ||
70 !empty($old_data['meta']);
71 }
72
73 /**
74 * Get migration recommendations.
75 *
76 * @since 2.0.0
77 * @param array $old_data
78 * @param array $test_results
79 * @return array
80 */
81 private static function get_recommendations($old_data, $test_results) {
82 $recommendations = [];
83
84 if (empty($old_data['options']) && empty($old_data['post_types']) && empty($old_data['meta'])) {
85 $recommendations[] = 'No old plugin data found. Migration is not needed.';
86 } else {
87 $recommendations[] = 'Old plugin data found. Migration is recommended.';
88
89 if (!empty($old_data['options'])) {
90 $recommendations[] = sprintf('Found %d old options that need migration.', count($old_data['options']));
91 }
92
93 if (!empty($old_data['post_types'])) {
94 $recommendations[] = sprintf('Found old post types: %s', implode(', ', array_keys($old_data['post_types'])));
95 }
96
97 if (!empty($old_data['meta'])) {
98 $meta_count = 0;
99 foreach ($old_data['meta'] as $post_type => $meta_fields) {
100 $meta_count += count($meta_fields);
101 }
102 $recommendations[] = sprintf('Found %d meta fields that need migration.', $meta_count);
103 }
104 }
105
106 if (!$test_results['overall']) {
107 $recommendations[] = 'Warning: Some migration tests failed. Please check migration components.';
108 }
109
110 return $recommendations;
111 }
112
113 /**
114 * Get migration steps.
115 *
116 * @since 2.0.0
117 * @return array
118 */
119 private static function get_migration_steps() {
120 return [
121 [
122 'step' => 1,
123 'title' => 'Options Migration',
124 'description' => 'Migrate plugin options from old structure to new structure',
125 'status' => 'pending',
126 'details' => [
127 'Old options will be mapped to new option names',
128 'Option values will be transformed if needed',
129 'Old options will be preserved as backup',
130 ]
131 ],
132 [
133 'step' => 2,
134 'title' => 'Post Type Migration',
135 'description' => 'Migrate custom post types and their data',
136 'status' => 'pending',
137 'details' => [
138 'easy-invoice → easy_invoice',
139 'easy-invoice-quotes → easy_quote',
140 'easy-invoice-payment → easy_payment',
141 'Post meta will be migrated with post types',
142 ]
143 ],
144 [
145 'step' => 3,
146 'title' => 'Meta Data Migration',
147 'description' => 'Migrate post meta data to new structure',
148 'status' => 'pending',
149 'details' => [
150 'Meta keys will be prefixed with _easy_invoice_',
151 'Meta values will be transformed if needed',
152 'Old meta will be preserved as backup',
153 ]
154 ],
155 [
156 'step' => 4,
157 'title' => 'Verification',
158 'description' => 'Verify all data has been migrated correctly',
159 'status' => 'pending',
160 'details' => [
161 'Check that all options are accessible',
162 'Verify post types are working correctly',
163 'Test meta data retrieval',
164 'Ensure no data loss occurred',
165 ]
166 ],
167 ];
168 }
169
170 /**
171 * Get detailed migration report.
172 *
173 * @since 2.0.0
174 * @return array
175 */
176 public static function get_detailed_report() {
177 $status = self::get_status();
178 $old_data = MigrationTest::check_old_plugin_data();
179
180 return [
181 'summary' => $status,
182 'old_data_details' => [
183 'options' => $old_data['options'],
184 'post_types' => $old_data['post_types'],
185 'meta' => $old_data['meta'],
186 ],
187 'migration_mappings' => [
188 'options' => self::get_options_mappings(),
189 'post_types' => self::get_post_type_mappings(),
190 'meta' => self::get_meta_mappings(),
191 ],
192 'estimated_time' => self::estimate_migration_time($old_data),
193 'backup_recommendation' => 'Always backup your database before running migration.',
194 ];
195 }
196
197 /**
198 * Get options mappings.
199 *
200 * @since 2.0.0
201 * @return array
202 */
203 private static function get_options_mappings() {
204 return [
205 'Business Settings' => [
206 'easy_invoice_business_name' => 'easy_invoice_company_name',
207 'easy_invoice_business_address' => 'easy_invoice_company_address',
208 'easy_invoice_business_logo' => 'easy_invoice_company_logo',
209 ],
210 'Invoice Settings' => [
211 'easy_invoice_invoice_number' => 'easy_invoice_next_invoice_number',
212 'easy_invoice_number_prefix' => 'easy_invoice_invoice_prefix',
213 ],
214 'Quote Settings' => [
215 'easy_invoice_quote_number' => 'easy_invoice_next_quote_number',
216 'easy_invoice_quote_number_prefix' => 'easy_invoice_quote_prefix',
217 ],
218 'Payment Settings' => [
219 'easy_invoice_payment_gateway_paypal_email' => 'easy_invoice_paypal_email',
220 ],
221 'Email Settings' => [
222 'easy_invoice_email_from_address' => 'easy_invoice_email_from_address',
223 'easy_invoice_email_from_name' => 'easy_invoice_email_from_name',
224 ],
225 ];
226 }
227
228 /**
229 * Get post type mappings.
230 *
231 * @since 2.0.0
232 * @return array
233 */
234 private static function get_post_type_mappings() {
235 return [
236 'easy-invoice' => 'easy_invoice',
237 'easy-invoice-quotes' => 'easy_quote',
238 'easy-invoice-payment' => 'easy_payment',
239 ];
240 }
241
242 /**
243 * Get meta mappings.
244 *
245 * @since 2.0.0
246 * @return array
247 */
248 private static function get_meta_mappings() {
249 return [
250 'easy-invoice' => [
251 'invoice_status' => '_easy_invoice_status',
252 'invoice_number' => '_easy_invoice_number',
253 'client_email' => '_easy_invoice_customer_email',
254 'client_name' => '_easy_invoice_customer_name',
255 ],
256 'easy-invoice-quotes' => [
257 'quote_status' => '_easy_invoice_quote_status',
258 'quote_number' => '_easy_invoice_quote_number',
259 'client_email' => '_easy_invoice_quote_customer_email',
260 'client_name' => '_easy_invoice_quote_customer_name',
261 ],
262 'easy-invoice-payment' => [
263 'payment_amount' => '_easy_invoice_payment_amount',
264 'payment_method' => '_easy_invoice_payment_method',
265 'payment_status' => '_easy_invoice_payment_status',
266 ],
267 ];
268 }
269
270 /**
271 * Estimate migration time.
272 *
273 * @since 2.0.0
274 * @param array $old_data
275 * @return string
276 */
277 private static function estimate_migration_time($old_data) {
278 $total_items = count($old_data['options']);
279
280 foreach ($old_data['post_types'] as $post_type => $count) {
281 $total_items += $count;
282 }
283
284 foreach ($old_data['meta'] as $post_type => $meta_fields) {
285 $total_items += count($meta_fields);
286 }
287
288 if ($total_items < 100) {
289 return 'Less than 1 minute';
290 } elseif ($total_items < 1000) {
291 return '1-5 minutes';
292 } else {
293 return '5-15 minutes';
294 }
295 }
296 }