@@ -15,95 +15,95 @@ |
||
15 | 15 | class EE_DMS_4_5_0_invoice_settings extends EE_Data_Migration_Script_Stage |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * Just initializes the status of the migration |
|
20 | - */ |
|
21 | - public function __construct() |
|
22 | - { |
|
23 | - $this->_pretty_name = __('Update Invoice Gateway Settings', 'event_espresso'); |
|
24 | - parent::__construct(); |
|
25 | - } |
|
18 | + /** |
|
19 | + * Just initializes the status of the migration |
|
20 | + */ |
|
21 | + public function __construct() |
|
22 | + { |
|
23 | + $this->_pretty_name = __('Update Invoice Gateway Settings', 'event_espresso'); |
|
24 | + parent::__construct(); |
|
25 | + } |
|
26 | 26 | |
27 | 27 | |
28 | 28 | |
29 | - /** |
|
30 | - * _count_records_to_migrate |
|
31 | - * Counts the records to migrate; the public version may cache it |
|
32 | - * |
|
33 | - * @access protected |
|
34 | - * @return int |
|
35 | - */ |
|
36 | - protected function _count_records_to_migrate() |
|
37 | - { |
|
38 | - return 1; |
|
39 | - } |
|
29 | + /** |
|
30 | + * _count_records_to_migrate |
|
31 | + * Counts the records to migrate; the public version may cache it |
|
32 | + * |
|
33 | + * @access protected |
|
34 | + * @return int |
|
35 | + */ |
|
36 | + protected function _count_records_to_migrate() |
|
37 | + { |
|
38 | + return 1; |
|
39 | + } |
|
40 | 40 | |
41 | 41 | |
42 | 42 | |
43 | - /** |
|
44 | - * _migration_step |
|
45 | - * |
|
46 | - * @access protected |
|
47 | - * @param int $num_items |
|
48 | - * @throws EE_Error |
|
49 | - * @return int number of items ACTUALLY migrated |
|
50 | - * @throws InvalidDataTypeException |
|
51 | - */ |
|
52 | - protected function _migration_step($num_items = 1) |
|
53 | - { |
|
54 | - // if this isn't set then something is really wrong |
|
55 | - if (! EE_Config::instance()->gateway instanceof EE_Gateway_Config) { |
|
56 | - throw new EE_Error(__('It appears the Event Espresso Core Configuration is not setup correctly.', 'event_espresso')); |
|
57 | - } |
|
58 | - $invoice_settings = isset(EE_Config::instance()->gateway->payment_settings['Invoice']) ? EE_Config::instance()->gateway->payment_settings['Invoice'] : null; |
|
59 | - if (! $invoice_settings) { |
|
60 | - $this->add_error(__('Could not migrate EE4.4 invoice settings to EE4.5 because they didnt exist', 'event_espresso')); |
|
61 | - } else { |
|
62 | - $invoice_settings['template_payment_instructions'] = $invoice_settings['pdf_instructions']; |
|
63 | - $invoice_settings['template_invoice_payee_name'] = $invoice_settings['payable_to']; |
|
64 | - $invoice_settings['template_invoice_address'] = $invoice_settings['payment_address']; |
|
65 | - $invoice_settings['template_invoice_email'] = ''; |
|
66 | - $invoice_settings['template_invoice_tax_number'] = ''; |
|
67 | - unset($invoice_settings['pdf_instructions']); |
|
68 | - unset($invoice_settings['payable_to']); |
|
69 | - unset($invoice_settings['payment_address']); |
|
70 | - EE_Config::instance()->gateway->payment_settings['Invoice'] = $invoice_settings; |
|
71 | - EE_Config::instance()->update_espresso_config(false, false); |
|
43 | + /** |
|
44 | + * _migration_step |
|
45 | + * |
|
46 | + * @access protected |
|
47 | + * @param int $num_items |
|
48 | + * @throws EE_Error |
|
49 | + * @return int number of items ACTUALLY migrated |
|
50 | + * @throws InvalidDataTypeException |
|
51 | + */ |
|
52 | + protected function _migration_step($num_items = 1) |
|
53 | + { |
|
54 | + // if this isn't set then something is really wrong |
|
55 | + if (! EE_Config::instance()->gateway instanceof EE_Gateway_Config) { |
|
56 | + throw new EE_Error(__('It appears the Event Espresso Core Configuration is not setup correctly.', 'event_espresso')); |
|
57 | + } |
|
58 | + $invoice_settings = isset(EE_Config::instance()->gateway->payment_settings['Invoice']) ? EE_Config::instance()->gateway->payment_settings['Invoice'] : null; |
|
59 | + if (! $invoice_settings) { |
|
60 | + $this->add_error(__('Could not migrate EE4.4 invoice settings to EE4.5 because they didnt exist', 'event_espresso')); |
|
61 | + } else { |
|
62 | + $invoice_settings['template_payment_instructions'] = $invoice_settings['pdf_instructions']; |
|
63 | + $invoice_settings['template_invoice_payee_name'] = $invoice_settings['payable_to']; |
|
64 | + $invoice_settings['template_invoice_address'] = $invoice_settings['payment_address']; |
|
65 | + $invoice_settings['template_invoice_email'] = ''; |
|
66 | + $invoice_settings['template_invoice_tax_number'] = ''; |
|
67 | + unset($invoice_settings['pdf_instructions']); |
|
68 | + unset($invoice_settings['payable_to']); |
|
69 | + unset($invoice_settings['payment_address']); |
|
70 | + EE_Config::instance()->gateway->payment_settings['Invoice'] = $invoice_settings; |
|
71 | + EE_Config::instance()->update_espresso_config(false, false); |
|
72 | 72 | |
73 | - // @todo: check 'invoice_css' too because we can't easily affect that so we might need to set a persistent notice |
|
74 | - // (why is it tough to change? because we want to update the receipt and invoice message template, but |
|
75 | - // message templates are only initialized AFTER migrations and those two are new in 4.5. So if we wanted to |
|
76 | - // update them from a DMS, we'd need to have the DMS create the message templates which is quite a lot of code; |
|
77 | - // also we don't want to build a dependency on the messages code because it is likely to change soon |
|
78 | - if (isset($invoice_settings['invoice_css']) |
|
79 | - && ! in_array($invoice_settings['invoice_css'], ['', 'simple.css'])) { |
|
80 | - new PersistentAdminNotice( |
|
81 | - 'invoice_css_not_updated', |
|
82 | - sprintf( |
|
83 | - esc_html__( |
|
84 | - 'You had previously set your Invoice Payment Method\'s stylesheet to be %1$s, but that setting has moved. PDF and HTML Invoices and Receipts are now Messages, which means you can easily modify them from your Wordpress Dashboard instead of using filters or uploading template files. Please visit Messages -> Receipt and Messages -> Invoice to change their stylesheets.', |
|
85 | - 'event_espresso' |
|
86 | - ), |
|
87 | - $invoice_settings['invoice_css'] |
|
88 | - ) |
|
89 | - ); |
|
90 | - } |
|
91 | - $templates_relative_path = 'modules/gateways/Invoice/lib/templates/'; |
|
92 | - $overridden_invoice_body = EEH_Template::locate_template($templates_relative_path . 'invoice_body.template.php', null, false, false, true); |
|
93 | - $overridden_receipt_body= EEH_Template::locate_template($templates_relative_path . 'receipt_body.template.php', null, false, false, true); |
|
94 | - if ($overridden_invoice_body || $overridden_receipt_body) { |
|
95 | - new PersistentAdminNotice( |
|
96 | - 'invoice_overriding_templates', |
|
97 | - esc_html__( |
|
98 | - 'Note: in this version of Event Espresso, PDF and HTML Invoices and Receipts are now Messages and can be changed just like any other messages; however we noticed you had previously overridden the old default Invoice/Receipt templates. Because of this, your old Invoice/Receipt templates will continue to be used INSTEAD of the new Invoice/Receipt message equivalents. We recommend deleting your old Invoice/Receipt templates and modifying the new Invoice and Receipt messages\'s content in Messages -> Invoice and Messages -> Receipt.', |
|
99 | - 'event_espresso' |
|
100 | - ), |
|
101 | - true |
|
102 | - ); |
|
103 | - } |
|
104 | - } |
|
105 | - // regardless of whether it worked or not, we ought to continue the migration |
|
106 | - $this->set_completed(); |
|
107 | - return 1; |
|
108 | - } |
|
73 | + // @todo: check 'invoice_css' too because we can't easily affect that so we might need to set a persistent notice |
|
74 | + // (why is it tough to change? because we want to update the receipt and invoice message template, but |
|
75 | + // message templates are only initialized AFTER migrations and those two are new in 4.5. So if we wanted to |
|
76 | + // update them from a DMS, we'd need to have the DMS create the message templates which is quite a lot of code; |
|
77 | + // also we don't want to build a dependency on the messages code because it is likely to change soon |
|
78 | + if (isset($invoice_settings['invoice_css']) |
|
79 | + && ! in_array($invoice_settings['invoice_css'], ['', 'simple.css'])) { |
|
80 | + new PersistentAdminNotice( |
|
81 | + 'invoice_css_not_updated', |
|
82 | + sprintf( |
|
83 | + esc_html__( |
|
84 | + 'You had previously set your Invoice Payment Method\'s stylesheet to be %1$s, but that setting has moved. PDF and HTML Invoices and Receipts are now Messages, which means you can easily modify them from your Wordpress Dashboard instead of using filters or uploading template files. Please visit Messages -> Receipt and Messages -> Invoice to change their stylesheets.', |
|
85 | + 'event_espresso' |
|
86 | + ), |
|
87 | + $invoice_settings['invoice_css'] |
|
88 | + ) |
|
89 | + ); |
|
90 | + } |
|
91 | + $templates_relative_path = 'modules/gateways/Invoice/lib/templates/'; |
|
92 | + $overridden_invoice_body = EEH_Template::locate_template($templates_relative_path . 'invoice_body.template.php', null, false, false, true); |
|
93 | + $overridden_receipt_body= EEH_Template::locate_template($templates_relative_path . 'receipt_body.template.php', null, false, false, true); |
|
94 | + if ($overridden_invoice_body || $overridden_receipt_body) { |
|
95 | + new PersistentAdminNotice( |
|
96 | + 'invoice_overriding_templates', |
|
97 | + esc_html__( |
|
98 | + 'Note: in this version of Event Espresso, PDF and HTML Invoices and Receipts are now Messages and can be changed just like any other messages; however we noticed you had previously overridden the old default Invoice/Receipt templates. Because of this, your old Invoice/Receipt templates will continue to be used INSTEAD of the new Invoice/Receipt message equivalents. We recommend deleting your old Invoice/Receipt templates and modifying the new Invoice and Receipt messages\'s content in Messages -> Invoice and Messages -> Receipt.', |
|
99 | + 'event_espresso' |
|
100 | + ), |
|
101 | + true |
|
102 | + ); |
|
103 | + } |
|
104 | + } |
|
105 | + // regardless of whether it worked or not, we ought to continue the migration |
|
106 | + $this->set_completed(); |
|
107 | + return 1; |
|
108 | + } |
|
109 | 109 | } |