PluginProbe
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent / 3.5.4
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent v3.5.4
3.5.4 3.5.3 3.5.2 3.5.1 3.4.9 3.5.0 3.4.8 3.4.7 trunk 2.3.1 3.3.6 3.3.7 3.3.8 3.3.9 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.6
supportcandy / upgrade / class-wpsc-upgrade-db-v2.php

class-wpsc-upgrade-db-v2.php in SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent 3.5.4, at upgrade/class-wpsc-upgrade-db-v2.php

5,578 lines 186.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit; // Exit if accessed directly!
4 }
5
6 if ( ! class_exists( 'WPSC_Upgrade_DB_V2' ) ) :
7
8 final class WPSC_Upgrade_DB_V2 {
9
10 /**
11 * Initialize this class
12 *
13 * @return void
14 */
15 public static function init() {
16
17 add_action( 'init', 'wpsc_upgrade_send_admin_email' );
18 add_action( 'admin_menu', array( __CLASS__, 'load_admin_menus' ), 11 );
19 add_action( 'admin_enqueue_scripts', 'wpsc_upgrade_enqueue_scripts' );
20
21 // register custom post typs for upgrade.
22 add_action( 'init', 'wpsc_upgrade_register_post_type' );
23
24 // check compatibility.
25 add_action( 'wp_ajax_wpsc_authorize_v2_upgrade', array( __CLASS__, 'authorize' ) );
26 add_action( 'wp_ajax_wpsc_upgrade_v2_check_compatibility', array( __CLASS__, 'check_compatibility' ) );
27
28 // cron manager.
29 add_action( 'init', array( __CLASS__, 'cron_manager' ) );
30 add_action( 'wp_ajax_wpsc_v2_upgrade_status', array( __CLASS__, 'get_v2_upgrade_cron_status' ) );
31 add_action( 'wpsc_upgrade_v2', array( __CLASS__, 'upgrade' ) );
32 }
33
34 /**
35 * Load upgrade screen for admin menu
36 *
37 * @return void
38 */
39 public static function load_admin_menus() {
40
41 add_menu_page(
42 esc_attr__( 'Support', 'supportcandy' ),
43 esc_attr__( 'Support', 'supportcandy' ),
44 'manage_options',
45 'wpsc-tickets',
46 array( __CLASS__, 'upgrade_layout' ),
47 'dashicons-sos',
48 25
49 );
50 }
51
52 /**
53 * Upgrade layout caller
54 *
55 * @return void
56 */
57 public static function upgrade_layout() {
58
59 $upgrade_permission = get_option( 'wpsc_upgrade_permission_v2', 0 );
60 ?>
61 <div class="wrap">
62 <hr class="wp-header-end">
63 <h1>SupportCandy v3.0</h1>
64 <div class="wpsc-upgrade-container">
65 <?php
66 if ( ! $upgrade_permission ) {
67 ?>
68 <p>SupportCandy v3.0 is a major release. This version has significant changes that may break your current workflow. Please review the below changes that may be responsible for breaking your current workflow if it is dependent on them. <strong>We strongly recommend you check this on your test or staging site before the live site.</strong></p>
69 <ol>
70 <li>You must update all premium add-ons (if any).</li>
71 <li>If you took any paid customizations from us, it will not work. Please contact us on <a href="mailto:[email protected]">support@supportcandy.net</a> to know when you will get your customization delivered. Until then you must revert to the previous version.</li>
72 <li>All hooks and filters are changed.</li>
73 <li>Translations are subject to availability. <a href="https://wordpress.org/plugins/supportcandy/">Click here</a> to see list of translations available.</li>
74 <li>We discontinued the REST APIs for some time. However, it will be back soon with a new version.</li>
75 <li>User interface design is changed. Previous appearance settings will not work on the new interface.</li>
76 </ol>
77 <p>It will migrate your tickets to custom database tables to improve performance and efficiency. This process may take a while and will make <strong>irreversible</strong> changes to the database. Please create a <strong>complete backup of your website</strong> before proceeding.</p>
78 <p><input type="checkbox" class="wpsc-confirm-backup"> I have secured a backup of my website data.</p>
79 <p><input type="checkbox" class="wpsc-confirm-read"> I have read and understood all the points above.</p>
80 <p>
81 <button disabled class="button action proceed">Proceed to upgrade</button>
82 <script>
83 jQuery('.wpsc-confirm-backup, .wpsc-confirm-read').change(function(){
84 let cb1 = jQuery('.wpsc-confirm-backup');
85 let cb2 = jQuery('.wpsc-confirm-read');
86 if ( cb1.is(":checked") && cb2.is(":checked") ) {
87 jQuery('button.proceed').attr( 'disabled', false );
88 } else {
89 jQuery('button.proceed').attr( 'disabled', true );
90 }
91 });
92 </script>
93 </p>
94 <h3 style="margin-top: 50px;">How do I revert this to the previous version?</h3>
95 <p>If you are not ready to upgrade yet, you can revert to the previous version of SupportCandy and its add-ons with the help of the below steps:</p>
96 <h4 style="margin-top: 30px;">Revert core plugin</h4>
97 <p>
98 <ol>
99 <li><a href="https://downloads.wordpress.org/plugin/supportcandy.2.3.1.zip">Click here</a> to download the previous version, v2.3.1</li>
100 <li>Go to the Plugins page in your WordPress dashboard.</li>
101 <li>Deactivate and delete SupportCandy.</li>
102 <li>Click Add New plugin.</li>
103 <li>Click Upload Plugin.</li>
104 <li>Upload the downloaded zip file in step 1.</li>
105 <li>Activate</li>
106 </ol>
107 </p>
108 <h4 style="margin-top: 30px;">Revert add-ons (if any)</h4>
109 <p>
110 If you have premium add-ons installed for SupportCandy, you can follow the below steps to revert them:
111 <ol>
112 <li><a href="https://supportcandy.net/account/" target="_blank">Click here</a> to go to the My Account page on our website.</li>
113 <li>Login to your account.</li>
114 <li>Click on View Details and Downloads for your recent order.</li>
115 <li>Download previous versions for each add-on ( less than 3.0.0 ).</li>
116 <li>Go to the Plugins page in your WordPress dashboard.</li>
117 <li>Deactivate and delete each SupportCandy add-on.</li>
118 <li>Click Add New and then install each add-on by uploading it.</li>
119 <li>Activate each add-on.</li>
120 </ol>
121 </p>
122 <?php
123 }
124 ?>
125 </div>
126 </div>
127 <script>
128 <?php
129 if ( $upgrade_permission ) {
130 ?>
131 jQuery(document).ready(function(){
132 wpsc_upgrade_v2_load_compatibilty();
133 });
134 <?php
135 } else {
136 ?>
137 jQuery('button.proceed').click(function(){
138 jQuery('div.wpsc-upgrade-container').html(supportcandy.loader_html);
139 var data = {
140 action: 'wpsc_authorize_v2_upgrade',
141 _ajax_nonce: '<?php echo esc_attr( wp_create_nonce( 'wpsc_authorize_v2_upgrade' ) ); ?>'
142 };
143 jQuery.post(supportcandy.ajax_url, data, function (response) {
144 if ( response.success ) {
145 wpsc_upgrade_v2_load_compatibilty();
146 }
147 });
148 });
149 <?php
150 }
151 ?>
152 /**
153 * Load compatibility section
154 *
155 * @return void
156 */
157 function wpsc_upgrade_v2_load_compatibilty() {
158 jQuery('div.wpsc-upgrade-container').html(supportcandy.loader_html);
159 var data = {
160 action: 'wpsc_upgrade_v2_check_compatibility',
161 _ajax_nonce: '<?php echo esc_attr( wp_create_nonce( 'wpsc_upgrade_v2_check_compatibility' ) ); ?>'
162 };
163 jQuery.post(supportcandy.ajax_url, data, function (response) {
164 jQuery('div.wpsc-upgrade-container').html(response);
165 });
166 }
167 </script>
168 <style>
169 body {
170 background-color: #fff;
171 }
172 p, ol {
173 font-size: 15px;
174 }
175 </style>
176 <?php
177 }
178
179 /**
180 * Authorize upgrade by an administrator
181 *
182 * @return void
183 */
184 public static function authorize() {
185
186 if ( ! wpsc_upgrade_is_site_admin() ) {
187 wp_send_json_error( 'Unauthorized request!', 401 );
188 }
189
190 if ( check_ajax_referer( 'wpsc_authorize_v2_upgrade', '_ajax_nonce', false ) != 1 ) {
191 wp_send_json_error( 'Unauthorized request!', 401 );
192 }
193
194 update_option( 'wpsc_upgrade_permission_v2', 1 );
195 wp_send_json( array( 'success' => true ) );
196 }
197
198 /**
199 * Check v3 compatiblity of current installation
200 *
201 * @return void
202 */
203 public static function check_compatibility() {
204
205 global $wpdb, $current_user;
206
207 $upgrade_permission = get_option( 'wpsc_upgrade_permission_v2', 0 );
208
209 if ( ! wpsc_upgrade_is_site_admin() || ! $upgrade_permission ) {
210 wp_send_json_error( 'Unauthorized request!', 401 );
211 }
212
213 if ( check_ajax_referer( 'wpsc_upgrade_v2_check_compatibility', '_ajax_nonce', false ) != 1 ) {
214 wp_send_json_error( 'Unauthorized request!', 401 );
215 }
216
217 $errors = array();
218
219 // check php version.
220 if ( version_compare( PHP_VERSION, '7.4.0', '<' ) ) {
221 $errors[] = 'PHP version must be 7.4 and above, current version is ' . PHP_VERSION;
222 }
223
224 // check WordPress version.
225 $wp_version = get_bloginfo( 'version' );
226 if ( $wp_version < '5.6' ) {
227 $errors[] = 'WordPress version must be 5.2 and above, current version is ' . $wp_version;
228 }
229
230 // check add-on versions.
231 $installed_addons = wpsc_upgrade_get_installed_plugin_info();
232 update_option( 'wpsc_upgrade_installed_addons', $installed_addons );
233
234 $plugins_url = admin_url( 'plugins.php' );
235 foreach ( $installed_addons as $addon ) {
236 if ( $addon['is_installed'] && $addon['version'] < '3.0.0' ) {
237
238 $errors[] = '<strong>' . $addon['name'] . '</strong> must be v3.0 and above. <a href="' . $plugins_url . '">Click here</a> to see updates.';
239
240 } elseif ( $addon['is_installed'] && $addon['version'] >= '3.0.0' && ! $addon['is_active'] ) {
241
242 $errors[] = '<strong>' . $addon['name'] . '</strong> must be active in order to upgrade data related to it.';
243 }
244 }
245
246 // check for customizations.
247 if ( class_exists( 'WPSC_CUST' ) ) {
248 $errors[] = 'Customization detected! Please contact us on <a href="mailto:[email protected]">[email protected]</a> from your registered email address in order to plan re-development of your customization. Until then, you need to use previous version of SupportCandy.';
249 }
250
251 if ( $errors ) {
252
253 delete_option( 'wpsc_upgrade_permission_v2' );
254
255 ?>
256 <p>Please fix below problems:</p>
257 <ol>
258 <?php
259 foreach ( $errors as $error ) {
260 echo '<li>' . wp_kses_post( $error ) . '</li>';
261 }
262 ?>
263 </ol>
264 <?php
265
266 } else {
267
268 $cron_status = get_option( 'wpsc_v2_upgrade_cron_status' );
269 $percentage = 100;
270 if ( $cron_status['total_pages'] ) {
271 $percentage = round( ( $cron_status['page'] / $cron_status['total_pages'] ) * 100, 2 );
272 }
273 ?>
274 <p>This process can take several hours to complete depending your database size.</p>
275 <p>Please keep this tab open for faster upgrade. If you close this tab, you need server scheduled cron job for the site.</p>
276 <i class="wpsc-progressbar-title"><?php echo esc_html( $cron_status['title'] ); ?></i>
277 <div id="wpsc-progressbar"><div class="progress-label"><?php echo esc_html( $percentage ) . '%'; ?></div></div>
278
279 <!-- Server cron setup instructions -->
280 <h3 style="margin-top: 50px;">Why server scheduled cron job?</h3>
281 <p>WordPress has the default WP-Cron enabled for you, which only gets executed when the website has a visitor. Therefore, it is not suitable for time-critical events like sending an email, pulling emails for email piping, scheduled backups, scheduled upgrade (like this) etc. Also, visitors may experience slowness in page loading because WP-Cron has to finish its job before it renders output for the visitor.</p>
282 <h3 style="margin-top: 50px;">How to setup server scheduled cron job?</h3>
283 <h4>Step 1: Disable WP-Cron</h4>
284 <p>You can disable WP-Cron by adding the below line to your wp-config.php file.</p>
285 <code>define('DISABLE_WP_CRON', true);</code>
286 <h4>Step 2: Schedule cron on your server</h4>
287 <p>To schedule cron on your server, you must log in to cPanel (or your hosting interface). Then, add a new cron job with the below command, which will execute cron every minute.</p>
288 <code>*/1 * * * * wget -qO- <?php echo esc_url( site_url( '/wp-cron.php' ) ); ?> &> /dev/null</code>
289 <p>The reasonable time interval is 5-15 minutes. That is */5 * * * * or */15 * * * * for Cron interval setting. The longer the cron execution time, the longer it will take to complete this upgrade. You can change the interval from every minute to 5 or 15 minutes later.</p>
290
291
292 <style>
293 .ui-progressbar {
294 position: relative;
295 }
296 .progress-label {
297 position: absolute;
298 left: 50%;
299 top: 4px;
300 font-weight: bold;
301 text-shadow: 1px 1px 0 #fff;
302 }
303 </style>
304 <script>
305 var progressbar = jQuery( "#wpsc-progressbar" );
306 var progressLabel = jQuery( ".progress-label" );
307 var progressbarTitle = jQuery( ".wpsc-progressbar-title" );
308 progressbar.progressbar({ value: <?php echo intval( $percentage ); ?> });
309 wpsc_v2_upgrade_status();
310
311 /**
312 * Get cron status
313 *
314 * @return void
315 */
316 function wpsc_v2_upgrade_status() {
317 var data = { action: 'wpsc_v2_upgrade_status' };
318 jQuery.post(supportcandy.ajax_url, data, function (response) {
319 if ( response.success && response.status == 'running' ) {
320 let percentage = 100;
321 if ( response.total_pages ) {
322 percentage = ( ( response.page/response.total_pages ) * 100 ).toFixed(2);
323 }
324 progressbar.progressbar({ value: parseInt( percentage ) });
325 progressLabel.text( percentage + '%' );
326 progressbarTitle.text( response.title );
327 wpsc_v2_upgrade_status();
328 } else if ( response.success && response.status == 'complete' ) {
329 window.location.reload();
330 }
331 }).fail( function( xhr, status, error ) {
332 window.location.reload();
333 });
334 }
335 </script>
336 <?php
337 }
338
339 wp_die();
340 }
341
342 /**
343 * Cron manager for upgrade
344 *
345 * @return void
346 */
347 public static function cron_manager() {
348
349 $cron_status = get_option( 'wpsc_v2_upgrade_cron_status', array() );
350 if ( ! $cron_status ) {
351 $cron_status = array(
352 'status' => 'running',
353 'title' => 'Installing database tables',
354 'resource' => 'db_tables',
355 'page' => 0,
356 'total_pages' => 1,
357 );
358 update_option( 'wpsc_v2_upgrade_cron_status', $cron_status );
359 }
360
361 // Do not proceed for the first iteration via cron.
362 if ( $cron_status['resource'] == 'db_tables' ) {
363 return;
364 }
365
366 // Do not allow parallel process to run.
367 if ( 'yes' === get_transient( 'wpsc_ui_upgrading' ) ) {
368 return;
369 }
370
371 $upgrade_permission = get_option( 'wpsc_upgrade_permission_v2', 0 );
372 if ( $upgrade_permission && $cron_status['status'] == 'running' && ! wp_next_scheduled( 'wpsc_upgrade_v2' ) ) {
373 wp_schedule_single_event( time(), 'wpsc_upgrade_v2' );
374 }
375 }
376
377 /**
378 * Return cron status for v2 upgrade
379 *
380 * @return void
381 */
382 public static function get_v2_upgrade_cron_status() {
383
384 if ( ! wpsc_upgrade_is_site_admin() ) {
385 wp_send_json_error( 'Unauthorized request!', 401 );
386 }
387
388 // Set transient.
389 set_transient( 'wpsc_ui_upgrading', 'yes', MINUTE_IN_SECONDS * 2 );
390
391 do_action( 'wpsc_upgrade_v2' );
392
393 $cron_status = get_option( 'wpsc_v2_upgrade_cron_status' );
394 $cron_status['success'] = true;
395 wp_send_json( $cron_status );
396 }
397
398 /**
399 * Upgrade the resource
400 *
401 * @return void
402 */
403 public static function upgrade() {
404
405 global $wpdb;
406
407 // Do not allow parallel process to run.
408 if ( 'yes' === get_transient( 'wpsc_upgrading' ) ) {
409 return;
410 }
411
412 // Set transient.
413 set_transient( 'wpsc_upgrading', 'yes', MINUTE_IN_SECONDS * 2 );
414
415 $cron_status = get_option( 'wpsc_v2_upgrade_cron_status' );
416 switch ( $cron_status['resource'] ) {
417
418 case 'db_tables':
419 if ( $cron_status['page'] == $cron_status['total_pages'] ) {
420
421 $total_fields = count(
422 get_terms(
423 array(
424 'taxonomy' => 'wpsc_ticket_custom_fields',
425 'hide_empty' => false,
426 )
427 )
428 );
429
430 $total_pages = $total_fields ? ceil( $total_fields / 10 ) : 0;
431 $cron_status = array(
432 'status' => 'running',
433 'title' => 'Importing custom fields',
434 'resource' => 'custom_fields',
435 'page' => 0,
436 'total_pages' => $total_pages,
437 );
438 }
439 break;
440
441 case 'custom_fields':
442 if ( $cron_status['page'] == $cron_status['total_pages'] ) {
443 $cron_status = array(
444 'status' => 'running',
445 'title' => 'Importing settings',
446 'resource' => 'settings',
447 'page' => 0,
448 'total_pages' => 8,
449 );
450 }
451 break;
452
453 case 'settings':
454 if ( $cron_status['page'] == $cron_status['total_pages'] ) {
455 $total_tickets = $wpdb->get_var( 'SELECT COUNT(id) FROM ' . $wpdb->prefix . 'wpsc_ticket' );
456 $total_pages = $total_tickets ? ceil( $total_tickets / 5 ) : 0;
457 $cron_status = array(
458 'status' => 'running',
459 'title' => 'Importing tickets',
460 'resource' => 'tickets',
461 'page' => 0,
462 'total_pages' => $total_pages,
463 );
464 }
465 break;
466
467 case 'tickets':
468 if ( $cron_status['page'] == $cron_status['total_pages'] ) {
469 $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}wpsc_ticket, {$wpdb->prefix}wpsc_ticketmeta, {$wpdb->prefix}wpsc_email_notification, {$wpdb->prefix}wpsc_reports, {$wpdb->prefix}wpsc_sla_reports, {$wpdb->prefix}wpsc_timer" );
470 $total_customers = $wpdb->get_var( 'SELECT COUNT(id) FROM ' . $wpdb->prefix . 'psmsc_customers' );
471 $total_pages = $total_customers ? ceil( $total_customers / 40 ) : 0;
472 $cron_status = array(
473 'status' => 'running',
474 'title' => 'Importing customers',
475 'resource' => 'customers',
476 'page' => 0,
477 'total_pages' => $total_pages,
478 );
479 }
480 break;
481
482 case 'customers':
483 if ( $cron_status['page'] == $cron_status['total_pages'] ) {
484 $total_agents = $wpdb->get_var( 'SELECT COUNT(id) FROM ' . $wpdb->prefix . 'psmsc_agents' );
485 $total_pages = $total_agents ? ceil( $total_agents / 20 ) : 0;
486 $cron_status = array(
487 'status' => 'running',
488 'title' => 'Importing agents',
489 'resource' => 'agents',
490 'page' => 0,
491 'total_pages' => $total_pages,
492 );
493 }
494 break;
495
496 case 'agents':
497 if ( $cron_status['page'] == $cron_status['total_pages'] ) {
498 $total_pages = 3;
499 $cron_status = array(
500 'status' => 'running',
501 'title' => 'Importing ticket conditions',
502 'resource' => 'ticket_conditions',
503 'page' => 0,
504 'total_pages' => $total_pages,
505 );
506 }
507 break;
508
509 case 'ticket_conditions':
510 if ( $cron_status['page'] == $cron_status['total_pages'] ) {
511 WPSC_Installation::set_upgrade_complete();
512 update_option(
513 'wpsc_upgrade_cleanup',
514 array(
515 'version' => 2,
516 'status' => 'texonomy',
517 )
518 );
519 $cron_status = array(
520 'status' => 'complete',
521 );
522 update_option( 'wpsc_v2_upgrade_cron_status', $cron_status );
523 }
524 break;
525 }
526
527 if ( $cron_status['status'] == 'complete' ) {
528 return;
529 }
530
531 if ( $cron_status['total_pages'] == 0 ) {
532 update_option( 'wpsc_v2_upgrade_cron_status', $cron_status );
533 delete_transient( 'wpsc_upgrading' );
534 return;
535 }
536
537 // execute the cron.
538 $page = intval( $cron_status['page'] ) + 1;
539
540 switch ( $cron_status['resource'] ) {
541
542 case 'db_tables':
543 WPSC_Installation::create_db_tables();
544 WPSC_Installation::initial_setup();
545 do_action( 'wpsc_upgrade_install_addons' );
546 break;
547
548 case 'custom_fields':
549 self::import_custom_fields( $page );
550 break;
551
552 case 'settings':
553 self::upgrade_settings( $page );
554 break;
555
556 case 'tickets':
557 self::upgrade_tickets( $page );
558 break;
559
560 case 'customers':
561 self::customer_ticket_count( $page );
562 break;
563
564 case 'agents':
565 self::agent_ticket_count( $page );
566 break;
567
568 case 'ticket_conditions':
569 self::ticket_conditions( $page );
570 break;
571 }
572
573 $cron_status['page'] = $page;
574 update_option( 'wpsc_v2_upgrade_cron_status', $cron_status );
575
576 // Delete transient.
577 delete_transient( 'wpsc_upgrading' );
578 }
579
580 /**
581 * Upgrade settings
582 *
583 * @param integer $page - page number.
584 * @return void
585 */
586 public static function upgrade_settings( $page ) {
587
588 switch ( $page ) {
589
590 case 1:
591 self::import_statuses();
592 self::import_categories();
593 self::import_priorities();
594 self::import_agents();
595 break;
596
597 case 2:
598 self::import_ticket_form_fields();
599 self::import_ticket_list_items();
600 self::import_tl_more_settings();
601 self::import_en_general();
602 self::import_en_ticket_notifications();
603 break;
604
605 case 3:
606 self::reorder_widgets();
607 self::import_general_settings();
608 self::import_thankyou_settings();
609 self::import_terms_and_conditions();
610 self::import_advanced_settings();
611 break;
612
613 case 4:
614 self::import_captcha();
615 self::import_assign_agent_rules();
616 self::import_automatic_close_tickets();
617 self::import_canned_reply();
618 self::import_report_settings();
619 break;
620
621 case 5:
622 self::import_satisfaction_survey();
623 self::import_email_piping();
624 self::import_faq_integration();
625 self::import_knowledgebase_integration();
626 self::import_export_addon();
627 break;
628
629 case 6:
630 self::import_woocommerce_addon();
631 self::import_shedule_tickets();
632 self::import_sla_settings();
633 self::import_usergroup_settings();
634 self::import_edd_settings();
635 break;
636
637 case 7:
638 self::import_gravity_settings();
639 self::import_timer_settings();
640 self::import_print_settings();
641 self::import_tinymce_settings();
642 self::import_attachment_settings();
643 break;
644
645 case 8:
646 self::import_pc_settings();
647 self::import_licences();
648 break;
649 }
650 }
651
652 /**
653 * Upgrade tickets
654 *
655 * @param int $page - page number.
656 * @return void
657 */
658 public static function upgrade_tickets( $page ) {
659
660 global $wpdb;
661 $offset = ( $page - 1 ) * 5;
662 $sql = "SELECT * FROM {$wpdb->prefix}wpsc_ticket ORDER BY id ASC LIMIT 5 OFFSET " . $offset;
663 $tickets = $wpdb->get_results( $sql );
664 foreach ( $tickets as $ticket ) {
665 self::import_individual_ticket( $ticket );
666 }
667 }
668
669 /**
670 * Customer ticket count
671 *
672 * @param int $page - page number.
673 * @return void
674 */
675 public static function customer_ticket_count( $page ) {
676
677 global $wpdb;
678 $installed_addons = get_option( 'wpsc_upgrade_installed_addons' );
679 $offset = ( $page - 1 ) * 40;
680 $sql = "SELECT * FROM {$wpdb->prefix}psmsc_customers ORDER BY id ASC LIMIT 40 OFFSET " . $offset;
681 $customers = $wpdb->get_results( $sql );
682 foreach ( $customers as $customer ) {
683 wpsc_update_customer_ticket_count( $customer );
684 if ( $installed_addons[7]['is_installed'] ) {
685 wpsc_update_customer_usergroups( $customer );
686 }
687 self::import_saved_filters( $customer );
688 }
689 }
690
691 /**
692 * Agent ticket count
693 *
694 * @param int $page - page number.
695 * @return void
696 */
697 public static function agent_ticket_count( $page ) {
698
699 global $wpdb;
700 $offset = ( $page - 1 ) * 20;
701 $sql = "SELECT * FROM {$wpdb->prefix}psmsc_agents WHERE is_agentgroup = 0 ORDER BY id ASC LIMIT 20 OFFSET " . $offset;
702 $agents = $wpdb->get_results( $sql );
703 foreach ( $agents as $agent ) {
704 wpsc_agent_reset_unresolved_count( $agent );
705 wpsc_agent_reset_workload( $agent );
706 self::import_saved_filters( wpsc_get_customer_by( 'id', $agent->customer ) );
707 self::import_agent_settings( $agent );
708 }
709 }
710
711 /**
712 * Upgrade ticket conditions
713 *
714 * @param int $page - page number.
715 * @return void
716 */
717 public static function ticket_conditions( $page ) {
718
719 switch ( $page ) {
720
721 case 1:
722 self::import_en_conditions();
723 break;
724
725 case 2:
726 self::import_aar_conditions();
727 break;
728
729 case 3:
730 self::import_sla_conditions();
731 break;
732 }
733 }
734
735 /**
736 * Import saved ticket filters
737 *
738 * @param stdClass $customer - customer db object.
739 * @return void
740 */
741 public static function import_saved_filters( $customer ) {
742
743 global $wpdb;
744
745 // return if customer is guest.
746 if ( ! $customer->user ) {
747 return;
748 }
749
750 $cf_slug_map = get_option( 'wpsc_upgrade_cf_slug_map' );
751 $options_map = get_option( 'wpsc_upgrade_cf_options_map' );
752 $status_map = get_option( 'wpsc_upgrade_status_map' );
753 $category_map = get_option( 'wpsc_upgrade_category_map' );
754 $priority_map = get_option( 'wpsc_upgrade_priority_map' );
755 $rating_map = get_option( 'wpsc_upgrade_sf_rating_map' );
756 $agent_map = get_option( 'wpsc_upgrade_agent_map' );
757 $usergroup_map = get_option( 'wpsc_upgrade_ug_term_id_map' );
758 $old_date_format = get_option( 'wpsc_calender_date_format' );
759 $parent_filter_map = array(
760 'all' => 'all',
761 'unresolved_agent' => 'unresolved',
762 'unresolved_customer' => 'unresolved',
763 'unassigned' => 'unassigned',
764 'mine' => 'mine',
765 'closed' => 'closed',
766 'deleted' => 'deleted',
767 );
768
769 $date_formats = array(
770 'dd-mm-yy' => 'd-m-Y',
771 'dd-yy-mm' => 'd-Y-m',
772 'mm-dd-yy' => 'm-d-Y',
773 'mm-yy-dd' => 'm-Y-d',
774 'yy-mm-dd' => 'Y-m-d',
775 'yy-dd-mm' => 'Y-d-m',
776 );
777
778 // previous filters.
779 $prev_filters = get_user_meta( $customer->user, get_current_blog_id() . '_wpsc_filter', true );
780 if ( $prev_filters ) {
781
782 // new filters.
783 $index = 1;
784 $new_filters = array();
785
786 // import filters.
787 foreach ( $prev_filters as $key => $prev ) {
788
789 $new = array(
790 'label' => $prev['save_label'],
791 'parent-filter' => $parent_filter_map[ $prev['label'] ],
792 'sort-by' => $cf_slug_map[ $prev['orderby'] ],
793 'sort-order' => $prev['order'],
794 );
795
796 $filters = array();
797 foreach ( $prev['custom_filter'] as $slug => $filter ) {
798
799 if ( $slug == 's' ) {
800 continue;
801 }
802
803 if ( $slug == 'id' ) {
804 $slug = 'ticket_id';
805 }
806
807 $cf = wpsc_get_cf_by( 'slug', $cf_slug_map[ $slug ] );
808 if ( ! $cf ) {
809 continue;
810 }
811
812 switch ( $cf->type ) {
813
814 case 'df_category':
815 $filters[ $cf->slug ] = array(
816 'operator' => 'IN',
817 'operand_val_1' => array_map(
818 function ( $prev_category ) use ( $category_map ) {
819 return $category_map[ $prev_category ];
820 },
821 $filter
822 ),
823 );
824 break;
825
826 case 'df_status':
827 $filters[ $cf->slug ] = array(
828 'operator' => 'IN',
829 'operand_val_1' => array_map(
830 function ( $prev_status ) use ( $status_map ) {
831 return $status_map[ $prev_status ];
832 },
833 $filter
834 ),
835 );
836 break;
837
838 case 'df_priority':
839 $filters[ $cf->slug ] = array(
840 'operator' => 'IN',
841 'operand_val_1' => array_map(
842 function ( $prev_priority ) use ( $priority_map ) {
843 return $priority_map[ $prev_priority ];
844 },
845 $filter
846 ),
847 );
848 break;
849
850 case 'df_customer_name':
851 case 'df_customer_email':
852 $slug = $cf->type == 'df_customer_name' ? 'name' : 'email';
853 $sql = "SELECT * FROM {$wpdb->prefix}psmsc_customers WHERE " . $slug . " IN( '" . implode( "', '", $filter ) . "' )";
854 $customers = $wpdb->get_results( $sql );
855 if ( ! $customers ) {
856 break;
857 }
858 if ( isset( $filters['customer'] ) ) {
859
860 $filters['customer']['operand_val_1'] = array_unique(
861 array_merge(
862 $filters['customer']['operand_val_1'],
863 array_map(
864 function ( $cust ) {
865 return $cust->id;
866 },
867 $customers
868 )
869 )
870 );
871
872 } else {
873
874 $filters['customer'] = array(
875 'operator' => 'IN',
876 'operand_val_1' => array_map(
877 function ( $cust ) {
878 return $cust->id;
879 },
880 $customers
881 ),
882 );
883 }
884 break;
885
886 case 'df_assigned_agent':
887 case 'df_agent_created':
888 $filters[ $cf->slug ] = array(
889 'operator' => 'IN',
890 'operand_val_1' => array_map(
891 function ( $prev_agent ) use ( $agent_map ) {
892 return $agent_map[ $prev_agent ];
893 },
894 $filter
895 ),
896 );
897 break;
898
899 case 'df_date_created':
900 case 'cf_date':
901 case 'df_date_closed':
902 case 'df_last_reply_on':
903 if ( ! ( $filter['from'] && $filter['to'] ) ) {
904 break;
905 }
906 $from = DateTime::createFromFormat( $date_formats[ $old_date_format ], $filter['from'] );
907 $to = DateTime::createFromFormat( $date_formats[ $old_date_format ], $filter['to'] );
908 if ( ! ( $from && $to ) ) {
909 break;
910 }
911 $filters[ $cf->slug ] = array(
912 'operator' => 'BETWEEN',
913 'operand_val_1' => $from->format( 'Y-m-d' ),
914 'operand_val_2' => $to->format( 'Y-m-d' ),
915 );
916 break;
917
918 case 'cf_datetime':
919 if ( ! ( $filter['from'] && $filter['to'] ) ) {
920 break;
921 }
922 $from = DateTime::createFromFormat( $date_formats[ $old_date_format ] . ' H:i:s', $filter['from'] );
923 $to = DateTime::createFromFormat( $date_formats[ $old_date_format ] . ' H:i:s', $filter['to'] );
924 if ( ! ( $from && $to ) ) {
925 break;
926 }
927 $filters[ $cf->slug ] = array(
928 'operator' => 'BETWEEN',
929 'operand_val_1' => $from->format( 'Y-m-d H:i' ),
930 'operand_val_2' => $to->format( 'Y-m-d H:i' ),
931 );
932 break;
933
934 case 'cf_time':
935 if ( ! ( $filter['from'] && $filter['to'] ) ) {
936 break;
937 }
938 $from = ( new DateTime( $filter['from'] ) )->format( 'H:i' );
939 $to = ( new DateTime( $filter['to'] ) )->format( 'H:i' );
940 $filters[ $cf->slug ] = array(
941 'operator' => 'BETWEEN',
942 'operand_val_1' => $from,
943 'operand_val_2' => $to,
944 );
945 break;
946
947 case 'df_sf_rating':
948 $filters[ $cf->slug ] = array(
949 'operator' => 'IN',
950 'operand_val_1' => array_map(
951 function ( $prev_rating ) use ( $rating_map ) {
952 return $rating_map[ $prev_rating ];
953 },
954 $filter
955 ),
956 );
957 break;
958
959 case 'df_id':
960 case 'cf_textfield':
961 case 'cf_email':
962 case 'cf_number':
963 case 'cf_url':
964 $filters[ $cf->slug ] = array(
965 'operator' => 'IN',
966 'operand_val_1' => implode( '^^', $filter ),
967 );
968 break;
969
970 case 'cf_checkbox':
971 case 'cf_multi_select':
972 case 'cf_radio_button':
973 case 'cf_single_select':
974 $filters[ $cf->slug ] = array(
975 'operator' => 'IN',
976 'operand_val_1' => array_map(
977 function ( $prev_option ) use ( $options_map, $cf ) {
978 return $options_map[ $cf->id ][ $prev_option ];
979 },
980 $filter
981 ),
982 );
983 break;
984
985 case 'df_last_reply_by':
986 $sql = "SELECT * FROM {$wpdb->prefix}psmsc_customers WHERE name IN( '" . implode( "', '", $filter ) . "' )";
987 $customers = $wpdb->get_results( $sql );
988 if ( ! $customers ) {
989 break;
990 }
991 if ( isset( $filters[ $cf->slug ] ) ) {
992
993 $filters[ $cf->slug ]['operand_val_1'] = array_unique(
994 array_merge(
995 $filters['customer']['operand_val_1'],
996 array_map(
997 function ( $cust ) {
998 return $cust->id;
999 },
1000 $customers
1001 )
1002 )
1003 );
1004
1005 } else {
1006
1007 $filters[ $cf->slug ] = array(
1008 'operator' => 'IN',
1009 'operand_val_1' => array_map(
1010 function ( $cust ) {
1011 return $cust->id;
1012 },
1013 $customers
1014 ),
1015 );
1016 }
1017 break;
1018
1019 case 'df_user_type':
1020 $filters[ $cf->slug ] = array(
1021 'operator' => '=',
1022 'operand_val_1' => $filter[0] == 'user' ? 'registered' : 'guest',
1023 );
1024 break;
1025
1026 case 'df_sla':
1027 $filters[ $cf->slug ] = array(
1028 'operator' => '=',
1029 'operand_val_1' => $filter[0] == 'sla_out' ? 'overdue' : 'within-sla',
1030 );
1031 break;
1032
1033 case 'df_usergroups':
1034 $filters[ $cf->slug ] = array(
1035 'operator' => 'IN',
1036 'operand_val_1' => array_map(
1037 function ( $prev_option ) use ( $usergroup_map ) {
1038 return $usergroup_map[ $prev_option ];
1039 },
1040 $filter
1041 ),
1042 );
1043 break;
1044
1045 case 'cf_woo_product':
1046 case 'cf_woo_order':
1047 $filters[ $cf->slug ] = array(
1048 'operator' => 'IN',
1049 'operand_val_1' => $filter,
1050 );
1051 break;
1052 }
1053 }
1054
1055 $new['filters'] = wp_json_encode( $filters );
1056 $parent_filter_map[ $key ] = $index;
1057 $new_filters[ $index++ ] = $new;
1058 }
1059
1060 // import Visibility conditions.
1061 foreach ( $new_filters as $slug => $properties ) {
1062 if ( ! $properties['filters'] ) {
1063 continue;
1064 }
1065 $new_filters[ $slug ]['filters'] = WPSC_SC_Upgrade::upgrade_condition( $properties['filters'], 'AND' );
1066 }
1067 update_user_meta( $customer->user, get_current_blog_id() . '-wpsc-tl-saved-filters', $new_filters );
1068 update_user_meta( $customer->user, get_current_blog_id() . '-wpsc-tl-cf-auto-increament', ++$index );
1069 }
1070
1071 update_option( 'wpsc_upgrade_saved_filters_map', $parent_filter_map );
1072 }
1073
1074 /**
1075 * Import agent settings
1076 *
1077 * @param stdClass $agent - agent db object.
1078 * @return void
1079 */
1080 public static function import_agent_settings( $agent ) {
1081
1082 $signature = get_user_meta( $agent->user, 'wpsc_agent_signature', true );
1083 if ( $signature ) {
1084 update_user_meta( $agent->user, get_current_blog_id() . '_wpsc_email_signature', $signature );
1085 }
1086
1087 $sf_map = get_option( 'wpsc_upgrade_saved_filters_map' );
1088 $old_filter = get_user_meta( $agent->user, get_current_blog_id() . '_wpsc_user_default_filter', true );
1089 if ( is_numeric( $old_filter ) ) {
1090 $new_filter = 'saved-' . $sf_map[ $old_filter ];
1091 } elseif ( $old_filter ) {
1092 $new_filter = $sf_map[ $old_filter ];
1093 } else {
1094 $new_filter = 'all';
1095 }
1096 update_user_meta( $agent->user, get_current_blog_id() . '_wpsc_tl_default_filter', $new_filter );
1097 }
1098
1099 /**
1100 * Import statuses
1101 *
1102 * @return void
1103 */
1104 public static function import_statuses() {
1105
1106 global $wpdb;
1107 $wpdb->query( 'DELETE FROM ' . $wpdb->prefix . 'psmsc_statuses' );
1108 $wpdb->query( 'ALTER TABLE ' . $wpdb->prefix . 'psmsc_statuses AUTO_INCREMENT = 1' );
1109
1110 $statuses = get_terms(
1111 array(
1112 'taxonomy' => 'wpsc_statuses',
1113 'hide_empty' => false,
1114 'orderby' => 'meta_value_num',
1115 'order' => 'ASC',
1116 'meta_query' => array( 'order_clause' => array( 'key' => 'wpsc_status_load_order' ) ),
1117 )
1118 );
1119
1120 $string_translations = get_option( 'wpsc-string-translation' );
1121 $map = array();
1122 $load_order = 1;
1123 foreach ( $statuses as $prev ) {
1124
1125 $wpdb->insert(
1126 $wpdb->prefix . 'psmsc_statuses',
1127 array(
1128 'name' => $prev->name,
1129 'color' => get_term_meta( $prev->term_id, 'wpsc_status_color', true ),
1130 'bg_color' => get_term_meta( $prev->term_id, 'wpsc_status_background_color', true ),
1131 'load_order' => $load_order++,
1132 )
1133 );
1134 $string_translations[ 'wpsc-status-' . $wpdb->insert_id ] = $prev->name;
1135 $map[ $prev->term_id ] = $wpdb->insert_id;
1136 }
1137
1138 update_option( 'wpsc-string-translation', $string_translations );
1139 update_option( 'wpsc_upgrade_status_map', $map );
1140 }
1141
1142 /**
1143 * Import categories
1144 *
1145 * @return void
1146 */
1147 public static function import_categories() {
1148
1149 global $wpdb;
1150 $wpdb->query( 'DELETE FROM ' . $wpdb->prefix . 'psmsc_categories' );
1151 $wpdb->query( 'ALTER TABLE ' . $wpdb->prefix . 'psmsc_categories AUTO_INCREMENT = 1' );
1152
1153 $categories = get_terms(
1154 array(
1155 'taxonomy' => 'wpsc_categories',
1156 'hide_empty' => false,
1157 'orderby' => 'meta_value_num',
1158 'order' => 'ASC',
1159 'meta_query' => array( 'order_clause' => array( 'key' => 'wpsc_category_load_order' ) ),
1160 )
1161 );
1162
1163 $string_translations = get_option( 'wpsc-string-translation' );
1164 $map = array();
1165 $load_order = 1;
1166 foreach ( $categories as $prev ) {
1167
1168 $wpdb->insert(
1169 $wpdb->prefix . 'psmsc_categories',
1170 array(
1171 'name' => $prev->name,
1172 'load_order' => $load_order++,
1173 )
1174 );
1175
1176 $string_translations[ 'wpsc-category-' . $wpdb->insert_id ] = $prev->name;
1177 $map[ $prev->term_id ] = $wpdb->insert_id;
1178 }
1179
1180 update_option( 'wpsc-string-translation', $string_translations );
1181 update_option( 'wpsc_upgrade_category_map', $map );
1182 }
1183
1184 /**
1185 * Import priorities
1186 *
1187 * @return void
1188 */
1189 public static function import_priorities() {
1190
1191 global $wpdb;
1192 $wpdb->query( 'DELETE FROM ' . $wpdb->prefix . 'psmsc_priorities' );
1193 $wpdb->query( 'ALTER TABLE ' . $wpdb->prefix . 'psmsc_priorities AUTO_INCREMENT = 1' );
1194
1195 $priorities = get_terms(
1196 array(
1197 'taxonomy' => 'wpsc_priorities',
1198 'hide_empty' => false,
1199 'orderby' => 'meta_value_num',
1200 'order' => 'ASC',
1201 'meta_query' => array( 'order_clause' => array( 'key' => 'wpsc_priority_load_order' ) ),
1202 )
1203 );
1204
1205 $string_translations = get_option( 'wpsc-string-translation' );
1206 $map = array();
1207 $load_order = 1;
1208 foreach ( $priorities as $prev ) {
1209
1210 $wpdb->insert(
1211 $wpdb->prefix . 'psmsc_priorities',
1212 array(
1213 'name' => $prev->name,
1214 'color' => get_term_meta( $prev->term_id, 'wpsc_priority_color', true ),
1215 'bg_color' => get_term_meta( $prev->term_id, 'wpsc_priority_background_color', true ),
1216 'load_order' => $load_order++,
1217 )
1218 );
1219 $string_translations[ 'wpsc-priority-' . $wpdb->insert_id ] = $prev->name;
1220 $map[ $prev->term_id ] = $wpdb->insert_id;
1221 }
1222
1223 update_option( 'wpsc-string-translation', $string_translations );
1224 update_option( 'wpsc_upgrade_priority_map', $map );
1225 }
1226
1227 /**
1228 * Import custom fields
1229 *
1230 * @param int $page - current page number.
1231 * @return void
1232 */
1233 public static function import_custom_fields( $page ) {
1234
1235 global $wpdb;
1236
1237 // Disable InnoDB strict mode if enabled to avoid limit of number of columns in tables.
1238 $strict_mode = $wpdb->get_var( "SHOW VARIABLES LIKE 'innodb_strict_mode'", 1 );
1239 if ( $strict_mode == 'ON' ) {
1240 $wpdb->query( "SET innodb_strict_mode = 'OFF'" );
1241 }
1242
1243 // Change load order of all existing custom fields to higher number.
1244 if ( $page == 1 ) {
1245 $wpdb->query( "UPDATE {$wpdb->prefix}psmsc_custom_fields SET load_order=1000 WHERE slug NOT IN('id','customer','status')" );
1246 }
1247
1248 $offset = ( $page - 1 ) * 10;
1249 $args = array(
1250 'taxonomy' => 'wpsc_ticket_custom_fields',
1251 'hide_empty' => false,
1252 'number' => 10,
1253 'offset' => $offset,
1254 'orderby' => 'term_id',
1255 'order' => 'ASC',
1256 );
1257
1258 $fields = get_terms( $args );
1259 $string_translations = get_option( 'wpsc-string-translation' );
1260 $installed_addons = get_option( 'wpsc_upgrade_installed_addons' );
1261 $custom_fields = $wpdb->get_results( 'SELECT * FROM ' . $wpdb->prefix . 'psmsc_custom_fields', ARRAY_A );
1262 $term_id_map = get_option( 'wpsc_upgrade_cf_term_id_map', array() );
1263 $slug_map = get_option( 'wpsc_upgrade_cf_slug_map', array() );
1264 $load_order = get_option( 'wpsc_upgrade_cf_load_order', 8 );
1265 foreach ( $fields as $prev ) {
1266
1267 $label = get_term_meta( $prev->term_id, 'wpsc_tf_label', true );
1268 $extra_info = get_term_meta( $prev->term_id, 'wpsc_tf_extra_info', true );
1269 $type = get_term_meta( $prev->term_id, 'wpsc_tf_type', true );
1270 $char_limit = get_term_meta( $prev->term_id, 'wpsc_tf_limit', true );
1271 $placeholder = get_term_meta( $prev->term_id, 'wpsc_tf_placeholder_text', true );
1272
1273 if ( intval( $type ) === 0 ) {
1274
1275 switch ( $prev->slug ) {
1276
1277 case 'ticket_id':
1278 $filtered_fields = array_filter( $custom_fields, fn( $field ) => $field['slug'] == 'id' );
1279 $cf = reset( $filtered_fields );
1280 $term_id_map[ $prev->term_id ] = $cf['id'];
1281 $slug_map[ $prev->slug ] = 'id';
1282 break;
1283
1284 case 'ticket_status':
1285 $filtered_fields = array_filter( $custom_fields, fn( $field ) => $field['slug'] == 'status' );
1286 $cf = reset( $filtered_fields );
1287 $term_id_map[ $prev->term_id ] = $cf['id'];
1288 $slug_map[ $prev->slug ] = 'status';
1289 break;
1290
1291 case 'customer_name':
1292 $filtered_fields = array_filter( $custom_fields, fn( $field ) => $field['slug'] == 'name' );
1293 $cf = reset( $filtered_fields );
1294 $wpdb->update(
1295 $wpdb->prefix . 'psmsc_custom_fields',
1296 array(
1297 'name' => $label,
1298 'extra_info' => $extra_info,
1299 'load_order' => $load_order++,
1300 ),
1301 array( 'id' => $cf['id'] )
1302 );
1303 $term_id_map[ $prev->term_id ] = $cf['id'];
1304 $slug_map[ $prev->slug ] = 'name';
1305 $string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $label;
1306 break;
1307
1308 case 'customer_email':
1309 $filtered_fields = array_filter( $custom_fields, fn( $field ) => $field['slug'] == 'email' );
1310 $cf = reset( $filtered_fields );
1311 $wpdb->update(
1312 $wpdb->prefix . 'psmsc_custom_fields',
1313 array(
1314 'name' => $label,
1315 'extra_info' => $extra_info,
1316 'load_order' => $load_order++,
1317 ),
1318 array( 'id' => $cf['id'] )
1319 );
1320 $term_id_map[ $prev->term_id ] = $cf['id'];
1321 $slug_map[ $prev->slug ] = 'email';
1322 $string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $label;
1323 break;
1324
1325 case 'ticket_subject':
1326 $filtered_fields = array_filter( $custom_fields, fn( $field ) => $field['slug'] == 'subject' );
1327 $cf = reset( $filtered_fields );
1328 $default_value = get_term_meta( $prev->term_id, 'wpsc_tf_default_subject', true );
1329 $default_value = $default_value ? $default_value : 'Not Applicable';
1330 $wpdb->update(
1331 $wpdb->prefix . 'psmsc_custom_fields',
1332 array(
1333 'name' => $label,
1334 'extra_info' => $extra_info,
1335 'char_limit' => $char_limit,
1336 'placeholder_text' => $placeholder,
1337 'default_value' => $default_value,
1338 'load_order' => $load_order++,
1339 ),
1340 array( 'id' => $cf['id'] )
1341 );
1342 $term_id_map[ $prev->term_id ] = $cf['id'];
1343 $slug_map[ $prev->slug ] = 'subject';
1344 $string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $label;
1345 $string_translations[ 'wpsc-cf-exi-' . $wpdb->insert_id ] = $extra_info;
1346 $string_translations[ 'wpsc-cf-pl-txt-' . $wpdb->insert_id ] = $placeholder;
1347 break;
1348
1349 case 'ticket_description':
1350 $filtered_fields = array_filter( $custom_fields, fn( $field ) => $field['slug'] == 'description' );
1351 $cf = reset( $filtered_fields );
1352 $default_value = get_term_meta( $prev->term_id, 'wpsc_tf_default_description', true );
1353 $default_value = $default_value ? $default_value : 'Not Applicable';
1354 $wpdb->update(
1355 $wpdb->prefix . 'psmsc_custom_fields',
1356 array(
1357 'name' => $label,
1358 'extra_info' => $extra_info,
1359 'default_value' => $default_value,
1360 'load_order' => $load_order++,
1361 ),
1362 array( 'id' => $cf['id'] )
1363 );
1364 $term_id_map[ $prev->term_id ] = $cf['id'];
1365 $slug_map[ $prev->slug ] = 'description';
1366 $string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $label;
1367 $string_translations[ 'wpsc-cf-exi-' . $wpdb->insert_id ] = $extra_info;
1368 break;
1369
1370 case 'ticket_priority':
1371 $filtered_fields = array_filter( $custom_fields, fn( $field ) => $field['slug'] == 'priority' );
1372 $cf = reset( $filtered_fields );
1373 $wpdb->update(
1374 $wpdb->prefix . 'psmsc_custom_fields',
1375 array(
1376 'name' => $label,
1377 'extra_info' => $extra_info,
1378 'load_order' => $load_order++,
1379 ),
1380 array( 'id' => $cf['id'] )
1381 );
1382 $term_id_map[ $prev->term_id ] = $cf['id'];
1383 $slug_map[ $prev->slug ] = 'priority';
1384 $string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $label;
1385 $string_translations[ 'wpsc-cf-exi-' . $wpdb->insert_id ] = $extra_info;
1386 break;
1387
1388 case 'ticket_category':
1389 $filtered_fields = array_filter( $custom_fields, fn( $field ) => $field['slug'] == 'category' );
1390 $cf = reset( $filtered_fields );
1391 $wpdb->update(
1392 $wpdb->prefix . 'psmsc_custom_fields',
1393 array(
1394 'name' => $label,
1395 'extra_info' => $extra_info,
1396 'load_order' => $load_order++,
1397 ),
1398 array( 'id' => $cf['id'] )
1399 );
1400 $term_id_map[ $prev->term_id ] = $cf['id'];
1401 $slug_map[ $prev->slug ] = 'category';
1402 $string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $label;
1403 $string_translations[ 'wpsc-cf-exi-' . $wpdb->insert_id ] = $extra_info;
1404 break;
1405
1406 case 'assigned_agent':
1407 $filtered_fields = array_filter( $custom_fields, fn( $field ) => $field['slug'] == 'assigned_agent' );
1408 $cf = reset( $filtered_fields );
1409 $wpdb->update(
1410 $wpdb->prefix . 'psmsc_custom_fields',
1411 array(
1412 'name' => $label,
1413 'load_order' => $load_order++,
1414 ),
1415 array( 'id' => $cf['id'] )
1416 );
1417 $term_id_map[ $prev->term_id ] = $cf['id'];
1418 $slug_map[ $prev->slug ] = 'assigned_agent';
1419 $string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $label;
1420 break;
1421
1422 case 'date_created':
1423 $filtered_fields = array_filter( $custom_fields, fn( $field ) => $field['slug'] == 'date_created' );
1424 $cf = reset( $filtered_fields );
1425 $wpdb->update(
1426 $wpdb->prefix . 'psmsc_custom_fields',
1427 array(
1428 'name' => $label,
1429 'load_order' => $load_order++,
1430 ),
1431 array( 'id' => $cf['id'] )
1432 );
1433 $term_id_map[ $prev->term_id ] = $cf['id'];
1434 $slug_map[ $prev->slug ] = 'date_created';
1435 $string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $label;
1436 break;
1437
1438 case 'date_updated':
1439 $filtered_fields = array_filter( $custom_fields, fn( $field ) => $field['slug'] == 'date_updated' );
1440 $cf = reset( $filtered_fields );
1441 $wpdb->update(
1442 $wpdb->prefix . 'psmsc_custom_fields',
1443 array(
1444 'name' => $label,
1445 'load_order' => $load_order++,
1446 ),
1447 array( 'id' => $cf['id'] )
1448 );
1449 $term_id_map[ $prev->term_id ] = $cf['id'];
1450 $slug_map[ $prev->slug ] = 'date_updated';
1451 $string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $label;
1452 break;
1453
1454 case 'agent_created':
1455 $filtered_fields = array_filter( $custom_fields, fn( $field ) => $field['slug'] == 'agent_created' );
1456 $cf = reset( $filtered_fields );
1457 $wpdb->update(
1458 $wpdb->prefix . 'psmsc_custom_fields',
1459 array(
1460 'name' => $label,
1461 'load_order' => $load_order++,
1462 ),
1463 array( 'id' => $cf['id'] )
1464 );
1465 $term_id_map[ $prev->term_id ] = $cf['id'];
1466 $slug_map[ $prev->slug ] = 'agent_created';
1467 $string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $label;
1468 break;
1469
1470 case 'date_closed':
1471 $filtered_fields = array_filter( $custom_fields, fn( $field ) => $field['slug'] == 'date_closed' );
1472 $cf = reset( $filtered_fields );
1473 $wpdb->update(
1474 $wpdb->prefix . 'psmsc_custom_fields',
1475 array(
1476 'name' => $label,
1477 'load_order' => $load_order++,
1478 ),
1479 array( 'id' => $cf['id'] )
1480 );
1481 $term_id_map[ $prev->term_id ] = $cf['id'];
1482 $slug_map[ $prev->slug ] = 'date_closed';
1483 $string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $label;
1484 break;
1485
1486 case 'user_type':
1487 $filtered_fields = array_filter( $custom_fields, fn( $field ) => $field['slug'] == 'user_type' );
1488 $cf = reset( $filtered_fields );
1489 $wpdb->update(
1490 $wpdb->prefix . 'psmsc_custom_fields',
1491 array(
1492 'name' => $label,
1493 'load_order' => $load_order++,
1494 ),
1495 array( 'id' => $cf['id'] )
1496 );
1497 $term_id_map[ $prev->term_id ] = $cf['id'];
1498 $slug_map[ $prev->slug ] = 'user_type';
1499 $string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $label;
1500 break;
1501
1502 case 'last_reply_on':
1503 $filtered_fields = array_filter( $custom_fields, fn( $field ) => $field['slug'] == 'last_reply_on' );
1504 $cf = reset( $filtered_fields );
1505 $wpdb->update(
1506 $wpdb->prefix . 'psmsc_custom_fields',
1507 array(
1508 'name' => $label,
1509 'load_order' => $load_order++,
1510 ),
1511 array( 'id' => $cf['id'] )
1512 );
1513 $term_id_map[ $prev->term_id ] = $cf['id'];
1514 $slug_map[ $prev->slug ] = 'last_reply_on';
1515 $string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $label;
1516 break;
1517
1518 case 'last_reply_by':
1519 $filtered_fields = array_filter( $custom_fields, fn( $field ) => $field['slug'] == 'last_reply_by' );
1520 $cf = reset( $filtered_fields );
1521 $wpdb->update(
1522 $wpdb->prefix . 'psmsc_custom_fields',
1523 array(
1524 'name' => $label,
1525 'load_order' => $load_order++,
1526 ),
1527 array( 'id' => $cf['id'] )
1528 );
1529 $term_id_map[ $prev->term_id ] = $cf['id'];
1530 $slug_map[ $prev->slug ] = 'last_reply_by';
1531 $string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $label;
1532 break;
1533
1534 case 'sf_rating':
1535 $filtered_fields = array_filter( $custom_fields, fn( $field ) => $field['slug'] == 'rating' );
1536 $cf = reset( $filtered_fields );
1537 if ( ! empty( $cf ) ) {
1538 $wpdb->update(
1539 $wpdb->prefix . 'psmsc_custom_fields',
1540 array(
1541 'name' => $label,
1542 'load_order' => $load_order++,
1543 ),
1544 array( 'id' => $cf[0]['id'] )
1545 );
1546 $term_id_map[ $prev->term_id ] = $cf[0]['id'];
1547 $slug_map[ $prev->slug ] = 'rating';
1548 $string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $label;
1549 }
1550 break;
1551
1552 case 'sla':
1553 $filtered_fields = array_filter( $custom_fields, fn( $field ) => $field['slug'] == 'sla' );
1554 $cf = reset( $filtered_fields );
1555 if ( ! empty( $cf ) ) {
1556 $wpdb->update(
1557 $wpdb->prefix . 'psmsc_custom_fields',
1558 array(
1559 'name' => $label,
1560 'load_order' => $load_order++,
1561 ),
1562 array( 'id' => $cf[0]['id'] )
1563 );
1564 $term_id_map[ $prev->term_id ] = $cf[0]['id'];
1565 $slug_map[ $prev->slug ] = 'sla';
1566 $string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $label;
1567 }
1568 break;
1569
1570 case 'usergroup':
1571 $filtered_fields = array_filter( $custom_fields, fn( $field ) => $field['slug'] == 'usergroups' );
1572 $cf = reset( $filtered_fields );
1573 if ( ! empty( $cf ) ) {
1574 $wpdb->update(
1575 $wpdb->prefix . 'psmsc_custom_fields',
1576 array(
1577 'name' => $label,
1578 'load_order' => $load_order++,
1579 ),
1580 array( 'id' => $cf[0]['id'] )
1581 );
1582 $term_id_map[ $prev->term_id ] = $cf[0]['id'];
1583 $slug_map[ $prev->slug ] = 'usergroups';
1584 $string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $label;
1585 }
1586 break;
1587
1588 case 'timer':
1589 $filtered_fields = array_filter( $custom_fields, fn( $field ) => $field['slug'] == 'time_spent' );
1590 $cf = reset( $filtered_fields );
1591 if ( ! empty( $cf ) ) {
1592 $wpdb->update(
1593 $wpdb->prefix . 'psmsc_custom_fields',
1594 array(
1595 'name' => $label,
1596 'load_order' => $load_order++,
1597 ),
1598 array( 'id' => $cf[0]['id'] )
1599 );
1600 $term_id_map[ $prev->term_id ] = $cf[0]['id'];
1601 $slug_map[ $prev->slug ] = 'time_spent';
1602 $string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $label;
1603 }
1604 break;
1605 }
1606 } else {
1607
1608 $personal_info = get_term_meta( $prev->term_id, 'wpsc_tf_personal_info', true );
1609 $field = get_term_meta( $prev->term_id, 'agentonly', true ) == 1 ? 'agentonly' : 'ticket';
1610
1611 switch ( intval( $type ) ) {
1612
1613 case 1:
1614 $response = wpsc_upgrade_insert_custom_field(
1615 array(
1616 'name' => $label,
1617 'extra_info' => $extra_info,
1618 'field' => $field,
1619 'type' => 'cf_textfield',
1620 'placeholder_text' => $placeholder,
1621 'char_limit' => $char_limit,
1622 'is_personal_info' => $personal_info,
1623 'load_order' => $load_order++,
1624 )
1625 );
1626 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_tickets ADD " . $response['slug'] . ' TINYTEXT NULL' );
1627 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_archived_tickets ADD " . $response['slug'] . ' TINYTEXT NULL' );
1628 $term_id_map[ $prev->term_id ] = $response['id'];
1629 $slug_map[ $prev->slug ] = $response['slug'];
1630 $string_translations[ 'wpsc-cf-name-' . $response['id'] ] = $label;
1631 $string_translations[ 'wpsc-cf-exi-' . $response['id'] ] = $extra_info;
1632 $string_translations[ 'wpsc-cf-pl-txt-' . $response['id'] ] = $placeholder;
1633 break;
1634
1635 case 2:
1636 $response = wpsc_upgrade_insert_custom_field(
1637 array(
1638 'name' => $label,
1639 'extra_info' => $extra_info,
1640 'field' => $field,
1641 'type' => 'cf_single_select',
1642 'is_personal_info' => $personal_info,
1643 'load_order' => $load_order++,
1644 )
1645 );
1646 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_tickets ADD " . $response['slug'] . ' TINYTEXT NULL' );
1647 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_archived_tickets ADD " . $response['slug'] . ' TINYTEXT NULL' );
1648 $option_strings = self::import_options( $prev, $response['id'] );
1649 $string_translations = array_merge( $string_translations, $option_strings );
1650 $term_id_map[ $prev->term_id ] = $response['id'];
1651 $slug_map[ $prev->slug ] = $response['slug'];
1652 $string_translations[ 'wpsc-cf-name-' . $response['id'] ] = $label;
1653 $string_translations[ 'wpsc-cf-exi-' . $response['id'] ] = $extra_info;
1654 break;
1655
1656 case 3:
1657 $response = wpsc_upgrade_insert_custom_field(
1658 array(
1659 'name' => $label,
1660 'extra_info' => $extra_info,
1661 'field' => $field,
1662 'type' => 'cf_checkbox',
1663 'is_personal_info' => $personal_info,
1664 'load_order' => $load_order++,
1665 )
1666 );
1667 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_tickets ADD " . $response['slug'] . ' TINYTEXT NULL' );
1668 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_archived_tickets ADD " . $response['slug'] . ' TINYTEXT NULL' );
1669 $option_strings = self::import_options( $prev, $response['id'] );
1670 $string_translations = array_merge( $string_translations, $option_strings );
1671 $term_id_map[ $prev->term_id ] = $response['id'];
1672 $slug_map[ $prev->slug ] = $response['slug'];
1673 $string_translations[ 'wpsc-cf-name-' . $response['id'] ] = $label;
1674 $string_translations[ 'wpsc-cf-exi-' . $response['id'] ] = $extra_info;
1675 break;
1676
1677 case 4:
1678 $response = wpsc_upgrade_insert_custom_field(
1679 array(
1680 'name' => $label,
1681 'extra_info' => $extra_info,
1682 'field' => $field,
1683 'type' => 'cf_radio_button',
1684 'is_personal_info' => $personal_info,
1685 'load_order' => $load_order++,
1686 )
1687 );
1688 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_tickets ADD " . $response['slug'] . ' TINYTEXT NULL' );
1689 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_archived_tickets ADD " . $response['slug'] . ' TINYTEXT NULL' );
1690 $option_strings = self::import_options( $prev, $response['id'] );
1691 $string_translations = array_merge( $string_translations, $option_strings );
1692 $term_id_map[ $prev->term_id ] = $response['id'];
1693 $slug_map[ $prev->slug ] = $response['slug'];
1694 $string_translations[ 'wpsc-cf-name-' . $response['id'] ] = $label;
1695 $string_translations[ 'wpsc-cf-exi-' . $response['id'] ] = $extra_info;
1696 break;
1697
1698 case 5:
1699 $response = wpsc_upgrade_insert_custom_field(
1700 array(
1701 'name' => $label,
1702 'extra_info' => $extra_info,
1703 'field' => $field,
1704 'type' => 'cf_textarea',
1705 'placeholder_text' => $placeholder,
1706 'char_limit' => $char_limit,
1707 'is_personal_info' => $personal_info,
1708 'load_order' => $load_order++,
1709 )
1710 );
1711 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_tickets ADD " . $response['slug'] . ' LONGTEXT NULL DEFAULT NULL' );
1712 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_archived_tickets ADD " . $response['slug'] . ' LONGTEXT NULL DEFAULT NULL' );
1713 $term_id_map[ $prev->term_id ] = $response['id'];
1714 $slug_map[ $prev->slug ] = $response['slug'];
1715 $string_translations[ 'wpsc-cf-name-' . $response['id'] ] = $label;
1716 $string_translations[ 'wpsc-cf-exi-' . $response['id'] ] = $extra_info;
1717 $string_translations[ 'wpsc-cf-pl-txt-' . $response['id'] ] = $placeholder;
1718 break;
1719
1720 case 6:
1721 $date_range = get_term_meta( $prev->term_id, 'wpsc_date_range', true );
1722 $start_range = get_term_meta( $prev->term_id, 'date_range_from', true );
1723 $end_range = get_term_meta( $prev->term_id, 'date_range_to', true );
1724 $response = wpsc_upgrade_insert_custom_field(
1725 array(
1726 'name' => $label,
1727 'extra_info' => $extra_info,
1728 'field' => $field,
1729 'type' => 'cf_date',
1730 'placeholder_text' => $placeholder,
1731 'date_range' => $date_range,
1732 'start_range' => $start_range,
1733 'end_range' => $end_range,
1734 'is_personal_info' => $personal_info,
1735 'load_order' => $load_order++,
1736 )
1737 );
1738 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_tickets ADD " . $response['slug'] . ' DATETIME NULL DEFAULT NULL' );
1739 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_archived_tickets ADD " . $response['slug'] . ' DATETIME NULL DEFAULT NULL' );
1740 $term_id_map[ $prev->term_id ] = $response['id'];
1741 $slug_map[ $prev->slug ] = $response['slug'];
1742 $string_translations[ 'wpsc-cf-name-' . $response['id'] ] = $label;
1743 $string_translations[ 'wpsc-cf-exi-' . $response['id'] ] = $extra_info;
1744 $string_translations[ 'wpsc-cf-pl-txt-' . $response['id'] ] = $placeholder;
1745 break;
1746
1747 case 7:
1748 $response = wpsc_upgrade_insert_custom_field(
1749 array(
1750 'name' => $label,
1751 'extra_info' => $extra_info,
1752 'field' => $field,
1753 'type' => 'cf_url',
1754 'placeholder_text' => $placeholder,
1755 'is_personal_info' => $personal_info,
1756 'load_order' => $load_order++,
1757 )
1758 );
1759 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_tickets ADD " . $response['slug'] . ' TINYTEXT NULL' );
1760 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_archived_tickets ADD " . $response['slug'] . ' TINYTEXT NULL' );
1761 $term_id_map[ $prev->term_id ] = $response['id'];
1762 $slug_map[ $prev->slug ] = $response['slug'];
1763 $string_translations[ 'wpsc-cf-name-' . $response['id'] ] = $label;
1764 $string_translations[ 'wpsc-cf-exi-' . $response['id'] ] = $extra_info;
1765 $string_translations[ 'wpsc-cf-pl-txt-' . $response['id'] ] = $placeholder;
1766 break;
1767
1768 case 8:
1769 $response = wpsc_upgrade_insert_custom_field(
1770 array(
1771 'name' => $label,
1772 'extra_info' => $extra_info,
1773 'field' => $field,
1774 'type' => 'cf_email',
1775 'placeholder_text' => $placeholder,
1776 'is_personal_info' => $personal_info,
1777 'load_order' => $load_order++,
1778 )
1779 );
1780 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_tickets ADD " . $response['slug'] . ' TINYTEXT NULL' );
1781 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_archived_tickets ADD " . $response['slug'] . ' TINYTEXT NULL' );
1782 $term_id_map[ $prev->term_id ] = $response['id'];
1783 $slug_map[ $prev->slug ] = $response['slug'];
1784 $string_translations[ 'wpsc-cf-name-' . $response['id'] ] = $label;
1785 $string_translations[ 'wpsc-cf-exi-' . $response['id'] ] = $extra_info;
1786 $string_translations[ 'wpsc-cf-pl-txt-' . $response['id'] ] = $placeholder;
1787 break;
1788
1789 case 9:
1790 $response = wpsc_upgrade_insert_custom_field(
1791 array(
1792 'name' => $label,
1793 'extra_info' => $extra_info,
1794 'field' => $field,
1795 'type' => 'cf_number',
1796 'placeholder_text' => $placeholder,
1797 'char_limit' => $char_limit,
1798 'is_personal_info' => $personal_info,
1799 'load_order' => $load_order++,
1800 )
1801 );
1802 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_tickets ADD " . $response['slug'] . ' TINYTEXT NULL' );
1803 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_archived_tickets ADD " . $response['slug'] . ' TINYTEXT NULL' );
1804 $term_id_map[ $prev->term_id ] = $response['id'];
1805 $slug_map[ $prev->slug ] = $response['slug'];
1806 $string_translations[ 'wpsc-cf-name-' . $response['id'] ] = $label;
1807 $string_translations[ 'wpsc-cf-exi-' . $response['id'] ] = $extra_info;
1808 $string_translations[ 'wpsc-cf-pl-txt-' . $response['id'] ] = $placeholder;
1809 break;
1810
1811 case 10:
1812 $response = wpsc_upgrade_insert_custom_field(
1813 array(
1814 'name' => $label,
1815 'extra_info' => $extra_info,
1816 'field' => $field,
1817 'type' => 'cf_file_attachment_multiple',
1818 'is_personal_info' => $personal_info,
1819 'load_order' => $load_order++,
1820 )
1821 );
1822 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_tickets ADD " . $response['slug'] . ' TINYTEXT NULL' );
1823 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_archived_tickets ADD " . $response['slug'] . ' TINYTEXT NULL' );
1824 $term_id_map[ $prev->term_id ] = $response['id'];
1825 $slug_map[ $prev->slug ] = $response['slug'];
1826 $string_translations[ 'wpsc-cf-name-' . $response['id'] ] = $label;
1827 $string_translations[ 'wpsc-cf-exi-' . $response['id'] ] = $extra_info;
1828 break;
1829
1830 case 11:
1831 if ( $installed_addons[5]['is_installed'] ) {
1832 $response = wpsc_upgrade_insert_custom_field(
1833 array(
1834 'name' => $label,
1835 'extra_info' => $extra_info,
1836 'field' => $field,
1837 'type' => 'cf_woo_product',
1838 'is_personal_info' => $personal_info,
1839 'load_order' => $load_order++,
1840 )
1841 );
1842 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_tickets ADD " . $response['slug'] . ' BIGINT NULL DEFAULT 0' );
1843 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_archived_tickets ADD " . $response['slug'] . ' BIGINT NULL DEFAULT 0' );
1844 $term_id_map[ $prev->term_id ] = $response['id'];
1845 $slug_map[ $prev->slug ] = $response['slug'];
1846 $string_translations[ 'wpsc-cf-name-' . $response['id'] ] = $label;
1847 $string_translations[ 'wpsc-cf-exi-' . $response['id'] ] = $extra_info;
1848 }
1849 break;
1850
1851 case 12:
1852 if ( $installed_addons[5]['is_installed'] ) {
1853 $response = wpsc_upgrade_insert_custom_field(
1854 array(
1855 'name' => $label,
1856 'extra_info' => $extra_info,
1857 'field' => $field,
1858 'type' => 'cf_woo_order',
1859 'is_personal_info' => $personal_info,
1860 'load_order' => $load_order++,
1861 )
1862 );
1863 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_tickets ADD " . $response['slug'] . ' BIGINT NULL DEFAULT 0' );
1864 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_archived_tickets ADD " . $response['slug'] . ' BIGINT NULL DEFAULT 0' );
1865 $term_id_map[ $prev->term_id ] = $response['id'];
1866 $slug_map[ $prev->slug ] = $response['slug'];
1867 $string_translations[ 'wpsc-cf-name-' . $response['id'] ] = $label;
1868 $string_translations[ 'wpsc-cf-exi-' . $response['id'] ] = $extra_info;
1869 }
1870 break;
1871
1872 case 13:
1873 if ( $installed_addons[8]['is_installed'] ) {
1874 $response = wpsc_upgrade_insert_custom_field(
1875 array(
1876 'name' => $label,
1877 'extra_info' => $extra_info,
1878 'field' => $field,
1879 'type' => 'cf_edd_product',
1880 'is_personal_info' => $personal_info,
1881 'load_order' => $load_order++,
1882 )
1883 );
1884 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_tickets ADD " . $response['slug'] . ' BIGINT NULL DEFAULT 0' );
1885 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_archived_tickets ADD " . $response['slug'] . ' BIGINT NULL DEFAULT 0' );
1886 $term_id_map[ $prev->term_id ] = $response['id'];
1887 $slug_map[ $prev->slug ] = $response['slug'];
1888 $string_translations[ 'wpsc-cf-name-' . $response['id'] ] = $label;
1889 $string_translations[ 'wpsc-cf-exi-' . $response['id'] ] = $extra_info;
1890 }
1891 break;
1892
1893 case 14:
1894 if ( $installed_addons[8]['is_installed'] ) {
1895 $response = wpsc_upgrade_insert_custom_field(
1896 array(
1897 'name' => $label,
1898 'extra_info' => $extra_info,
1899 'field' => $field,
1900 'type' => 'cf_edd_order',
1901 'is_personal_info' => $personal_info,
1902 'load_order' => $load_order++,
1903 )
1904 );
1905 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_tickets ADD " . $response['slug'] . ' BIGINT NULL DEFAULT 0' );
1906 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_archived_tickets ADD " . $response['slug'] . ' BIGINT NULL DEFAULT 0' );
1907 $term_id_map[ $prev->term_id ] = $response['id'];
1908 $slug_map[ $prev->slug ] = $response['slug'];
1909 $string_translations[ 'wpsc-cf-name-' . $response['id'] ] = $label;
1910 $string_translations[ 'wpsc-cf-exi-' . $response['id'] ] = $extra_info;
1911 }
1912 break;
1913
1914 case 18:
1915 $response = wpsc_upgrade_insert_custom_field(
1916 array(
1917 'name' => $label,
1918 'extra_info' => $extra_info,
1919 'field' => $field,
1920 'type' => 'cf_datetime',
1921 'placeholder_text' => $placeholder,
1922 'is_personal_info' => $personal_info,
1923 'load_order' => $load_order++,
1924 )
1925 );
1926 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_tickets ADD " . $response['slug'] . ' DATETIME NULL DEFAULT NULL' );
1927 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_archived_tickets ADD " . $response['slug'] . ' DATETIME NULL DEFAULT NULL' );
1928 $term_id_map[ $prev->term_id ] = $response['id'];
1929 $slug_map[ $prev->slug ] = $response['slug'];
1930 $string_translations[ 'wpsc-cf-name-' . $response['id'] ] = $label;
1931 $string_translations[ 'wpsc-cf-exi-' . $response['id'] ] = $extra_info;
1932 $string_translations[ 'wpsc-cf-pl-txt-' . $response['id'] ] = $placeholder;
1933 break;
1934
1935 case 21:
1936 $time_format = get_term_meta( $prev->term_id, 'wpsc_time_format', true );
1937 $response = wpsc_upgrade_insert_custom_field(
1938 array(
1939 'name' => $label,
1940 'extra_info' => $extra_info,
1941 'field' => $field,
1942 'type' => 'cf_time',
1943 'time_format' => $time_format,
1944 'placeholder_text' => $placeholder,
1945 'is_personal_info' => $personal_info,
1946 'load_order' => $load_order++,
1947 )
1948 );
1949 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_tickets ADD " . $response['slug'] . ' TINYTEXT NULL' );
1950 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_archived_tickets ADD " . $response['slug'] . ' TINYTEXT NULL' );
1951 $term_id_map[ $prev->term_id ] = $response['id'];
1952 $slug_map[ $prev->slug ] = $response['slug'];
1953 $string_translations[ 'wpsc-cf-name-' . $response['id'] ] = $label;
1954 $string_translations[ 'wpsc-cf-exi-' . $response['id'] ] = $extra_info;
1955 $string_translations[ 'wpsc-cf-pl-txt-' . $response['id'] ] = $placeholder;
1956 break;
1957
1958 case 22:
1959 $html = get_term_meta( $prev->term_id, 'wpsc_html_content', true );
1960 $response = wpsc_upgrade_insert_custom_field(
1961 array(
1962 'name' => $label,
1963 'extra_info' => $extra_info,
1964 'field' => $field,
1965 'type' => 'cf_html',
1966 'default_value' => $html,
1967 'load_order' => $load_order++,
1968 )
1969 );
1970 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_tickets ADD " . $response['slug'] . ' TEXT NULL DEFAULT NULL' );
1971 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_archived_tickets ADD " . $response['slug'] . ' TEXT NULL DEFAULT NULL' );
1972 $term_id_map[ $prev->term_id ] = $response['id'];
1973 $slug_map[ $prev->slug ] = $response['slug'];
1974 $string_translations[ 'wpsc-cf-name-' . $response['id'] ] = $label;
1975 $string_translations[ 'wpsc-cf-exi-' . $response['id'] ] = $extra_info;
1976 break;
1977 }
1978 }
1979 }
1980 update_option( 'wpsc-string-translation', $string_translations );
1981 update_option( 'wpsc_upgrade_cf_term_id_map', $term_id_map );
1982 update_option( 'wpsc_upgrade_cf_slug_map', $slug_map );
1983 update_option( 'wpsc_upgrade_cf_load_order', $load_order );
1984 }
1985
1986 /**
1987 * Import options for custom field
1988 *
1989 * @param mixed $prev - previous custom field object.
1990 * @param int $id - new custom field id.
1991 * @return array
1992 */
1993 public static function import_options( $prev, $id ) {
1994
1995 global $wpdb;
1996 $string_translations = array();
1997 $options = get_term_meta( $prev->term_id, 'wpsc_tf_options', true );
1998 $load_order = 1;
1999 $options_map = get_option( 'wpsc_upgrade_cf_options_map', array() );
2000 foreach ( $options as $name ) {
2001 $wpdb->insert(
2002 $wpdb->prefix . 'psmsc_options',
2003 array(
2004 'name' => $name,
2005 'date_created' => ( new DateTime( 'now' ) )->format( 'Y-m-d H:m:s' ),
2006 'custom_field' => $id,
2007 'load_order' => $load_order++,
2008 )
2009 );
2010 $string_translations[ 'wpsc-option-' . $wpdb->insert_id ] = $name;
2011 $options_map[ $id ][ $name ] = $wpdb->insert_id;
2012 }
2013
2014 update_option( 'wpsc_upgrade_cf_options_map', $options_map );
2015 return $string_translations;
2016 }
2017
2018 /**
2019 * Import agent and agentgroups
2020 *
2021 * @return void
2022 */
2023 public static function import_agents() {
2024
2025 global $wpdb;
2026
2027 // removing agent role cap.
2028 $agents = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}psmsc_agents" );
2029 foreach ( $agents as $agent ) {
2030 $user = get_user_by( 'id', $agent->user );
2031 if ( $user ) {
2032 $user->remove_cap( 'wpsc_agent' );
2033 }
2034 }
2035
2036 $wpdb->query( 'DELETE FROM ' . $wpdb->prefix . 'psmsc_agents' );
2037 $wpdb->query( 'ALTER TABLE ' . $wpdb->prefix . 'psmsc_agents AUTO_INCREMENT = 1' );
2038 $wpdb->query( 'DELETE FROM ' . $wpdb->prefix . 'psmsc_customers' );
2039 $wpdb->query( 'ALTER TABLE ' . $wpdb->prefix . 'psmsc_customers AUTO_INCREMENT = 1' );
2040
2041 // import agent roles.
2042 $new = array();
2043 $prev = get_option( 'wpsc_agent_role' );
2044 foreach ( $prev as $key => $role ) {
2045 $new[ $key ] = array(
2046 'label' => $role['label'],
2047 'caps' => array(
2048 'view-unassigned' => $role['view_unassigned'] == 1 ? true : false, // View ticket.
2049 'view-assigned-me' => $role['view_assigned_me'] == 1 ? true : false,
2050 'view-assigned-others' => $role['view_assigned_others'] == 1 ? true : false,
2051 'reply-unassigned' => $role['reply_unassigned'] == 1 ? true : false, // Reply ticket.
2052 'reply-assigned-me' => $role['reply_assigned_me'] == 1 ? true : false,
2053 'reply-assigned-others' => $role['reply_assigned_others'] == 1 ? true : false,
2054 'pn-unassigned' => true, // Private notes.
2055 'pn-assigned-me' => true,
2056 'pn-assigned-others' => true,
2057 'aa-unassigned' => $role['assign_unassigned'] == 1 ? true : false, // Assignee.
2058 'aa-assigned-me' => $role['assign_assigned_me'] == 1 ? true : false,
2059 'aa-assigned-others' => $role['assign_assigned_others'] == 1 ? true : false,
2060 'cs-unassigned' => $role['cng_tkt_sts_unassigned'] == 1 ? true : false, // Change status.
2061 'cs-assigned-me' => $role['cng_tkt_sts_assigned_me'] == 1 ? true : false,
2062 'cs-assigned-others' => $role['cng_tkt_sts_assigned_others'] == 1 ? true : false,
2063 'ctf-unassigned' => $role['cng_tkt_field_unassigned'] == 1 ? true : false, // Change ticket fields.
2064 'ctf-assigned-me' => $role['cng_tkt_field_assigned_me'] == 1 ? true : false,
2065 'ctf-assigned-others' => $role['cng_tkt_field_assigned_others'] == 1 ? true : false,
2066 'caof-unassigned' => $role['cng_tkt_ao_unassigned'] == 1 ? true : false, // Change agent only fields.
2067 'caof-assigned-me' => $role['cng_tkt_ao_assigned_me'] == 1 ? true : false,
2068 'caof-assigned-others' => $role['cng_tkt_ao_assigned_others'] == 1 ? true : false,
2069 'crb-unassigned' => $role['cng_tkt_rb_unassigned'] == 1 ? true : false, // Change raised by.
2070 'crb-assigned-me' => $role['cng_tkt_rb_assigned_me'] == 1 ? true : false,
2071 'crb-assigned-others' => $role['cng_tkt_rb_assigned_others'] == 1 ? true : false,
2072 'eth-unassigned' => $role['delete_unassigned'] == 1 ? true : false, // Edit thread.
2073 'eth-assigned-me' => $role['delete_assigned_me'] == 1 ? true : false,
2074 'eth-assigned-others' => $role['delete_assigned_others'] == 1 ? true : false,
2075 'dth-unassigned' => $role['delete_unassigned'] == 1 ? true : false, // Delete thread.
2076 'dth-assigned-me' => $role['delete_assigned_me'] == 1 ? true : false,
2077 'dth-assigned-others' => $role['delete_assigned_others'] == 1 ? true : false,
2078 'vl-unassigned' => true, // View logs.
2079 'vl-assigned-me' => true,
2080 'vl-assigned-others' => true,
2081 'dtt-unassigned' => $role['delete_unassigned'] == 1 ? true : false, // Delete ticket.
2082 'dtt-assigned-me' => $role['delete_assigned_me'] == 1 ? true : false,
2083 'dtt-assigned-others' => $role['delete_assigned_others'] == 1 ? true : false,
2084 'ar-unassigned' => true, // Additional recipients.
2085 'ar-assigned-me' => true,
2086 'ar-assigned-others' => true,
2087 'dt-unassigned' => true, // Duplicate ticket.
2088 'dt-assigned-me' => true,
2089 'dt-assigned-others' => true,
2090 'backend-access' => true, // Dashboard support menu access.
2091 'create-as' => true, // Create ticket on others behalf.
2092 'eci-access' => true, // Edit customer info.
2093 'dash-access' => true, // Dashboard access.
2094 ),
2095 );
2096 }
2097 update_option( 'wpsc-agent-roles', $new );
2098
2099 $map = array();
2100 $agents = get_terms(
2101 array(
2102 'taxonomy' => 'wpsc_agents',
2103 'hide_empty' => false,
2104 )
2105 );
2106
2107 // import agents.
2108 foreach ( $agents as $prev ) {
2109
2110 $is_agentgroup = get_term_meta( $prev->term_id, 'agentgroup', true );
2111 if ( $is_agentgroup ) {
2112 continue;
2113 }
2114
2115 $user_id = get_term_meta( $prev->term_id, 'user_id', true );
2116 $user = get_user_by( 'id', $user_id );
2117 if ( ! $user->ID ) {
2118 continue;
2119 }
2120
2121 // create customer record.
2122 $wpdb->insert(
2123 $wpdb->prefix . 'psmsc_customers',
2124 array(
2125 'user' => $user_id,
2126 'name' => $user->display_name,
2127 'email' => $user->user_email,
2128 )
2129 );
2130
2131 // insert agent record.
2132 $wpdb->insert(
2133 $wpdb->prefix . 'psmsc_agents',
2134 array(
2135 'user' => $user_id,
2136 'customer' => $wpdb->insert_id,
2137 'role' => get_term_meta( $prev->term_id, 'role', true ),
2138 'name' => $user->display_name,
2139 'is_active' => 1,
2140 )
2141 );
2142
2143 // adding agent role cap.
2144 $user->add_cap( 'wpsc_agent' );
2145
2146 // agent working hrs.
2147 $agent_id = $wpdb->insert_id;
2148 for ( $i = 1; $i <= 7; $i++ ) {
2149 $wpdb->insert(
2150 $wpdb->prefix . 'psmsc_working_hrs',
2151 array(
2152 'agent' => $agent_id,
2153 'day' => $i,
2154 'start_time' => '00:00:00',
2155 'end_time' => '23:59:59',
2156 )
2157 );
2158 }
2159
2160 $map[ $prev->term_id ] = $agent_id;
2161 }
2162
2163 // import agentgroups.
2164 $installed_addons = get_option( 'wpsc_upgrade_installed_addons' );
2165 if ( $installed_addons[16]['is_installed'] ) {
2166
2167 $table = $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}psmsc_agentgroups'" );
2168 if ( $table ) {
2169 $wpdb->query( 'DELETE FROM ' . $wpdb->prefix . 'psmsc_agentgroups' );
2170 $wpdb->query( 'ALTER TABLE ' . $wpdb->prefix . 'psmsc_agentgroups AUTO_INCREMENT = 1' );
2171 }
2172 foreach ( $agents as $prev ) {
2173
2174 $is_agentgroup = get_term_meta( $prev->term_id, 'agentgroup', true );
2175 if ( ! $is_agentgroup ) {
2176 continue;
2177 }
2178
2179 // insert agent record for the group.
2180 $wpdb->insert(
2181 $wpdb->prefix . 'psmsc_agents',
2182 array(
2183 'name' => $prev->name,
2184 'is_agentgroup' => 1,
2185 'is_active' => 1,
2186 )
2187 );
2188 $map[ $prev->term_id ] = $wpdb->insert_id;
2189
2190 // get members of the group.
2191 $group_user_ids = get_term_meta( $prev->term_id, 'agentgroup_user_id', false );
2192 $member_ids = array();
2193 foreach ( $group_user_ids as $user_id ) {
2194 $member_ids[] = $map[ $user_id ];
2195 }
2196
2197 // create agentgroup record.
2198 $wpdb->insert(
2199 $wpdb->prefix . 'psmsc_agentgroups',
2200 array(
2201 'agent_id' => $wpdb->insert_id,
2202 'name' => $prev->name,
2203 'agents' => implode( '|', $member_ids ),
2204 'supervisors' => implode( '|', $member_ids ),
2205 )
2206 );
2207 }
2208 }
2209
2210 update_option( 'wpsc_upgrade_agent_map', $map );
2211 }
2212
2213 /**
2214 * Import ticket form field settings
2215 *
2216 * @return void
2217 */
2218 public static function import_ticket_form_fields() {
2219
2220 $form_fields = array();
2221 $cf_map = get_option( 'wpsc_upgrade_cf_term_id_map' );
2222 $options_map = get_option( 'wpsc_upgrade_cf_options_map' );
2223 $category_map = get_option( 'wpsc_upgrade_category_map' );
2224 $priority_map = get_option( 'wpsc_upgrade_priority_map' );
2225 $fields = get_terms(
2226 array(
2227 'taxonomy' => 'wpsc_ticket_custom_fields',
2228 'hide_empty' => false,
2229 'orderby' => 'meta_value_num',
2230 'meta_key' => 'wpsc_tf_load_order',
2231 'order' => 'ASC',
2232 'meta_query' => array(
2233 array(
2234 'key' => 'agentonly',
2235 'value' => '0',
2236 'compare' => '=',
2237 ),
2238 ),
2239 )
2240 );
2241
2242 foreach ( $fields as $field ) {
2243
2244 $status = get_term_meta( $field->term_id, 'wpsc_tf_status', true );
2245 if ( $status == 0 ) {
2246 continue;
2247 }
2248
2249 $is_required = get_term_meta( $field->term_id, 'wpsc_tf_required', true );
2250
2251 $width = get_term_meta( $field->term_id, 'wpsc_tf_width', true );
2252 switch ( $width ) {
2253
2254 case '1/2':
2255 $width = 'half';
2256 break;
2257
2258 case '1':
2259 $width = 'full';
2260 }
2261
2262 $visibility = array();
2263 $prev_visibility = get_term_meta( $field->term_id, 'wpsc_tf_visibility', true );
2264 if ( $prev_visibility ) {
2265 foreach ( $prev_visibility as $condition ) {
2266 $condition = explode( '--', $condition );
2267 $cf = wpsc_get_cf_by( 'id', $cf_map[ $condition[0] ] );
2268 switch ( $cf->slug ) {
2269
2270 case 'category':
2271 if ( isset( $visibility[ $cf->slug ] ) ) {
2272 $visibility[ $cf->slug ]['operand_val_1'][] = $category_map[ $condition[1] ];
2273 } else {
2274 $visibility[ $cf->slug ] = array(
2275 'operator' => 'IN',
2276 'operand_val_1' => array(
2277 $category_map[ $condition[1] ],
2278 ),
2279 );
2280 }
2281 break;
2282
2283 case 'priority':
2284 if ( isset( $visibility[ $cf->slug ] ) ) {
2285 $visibility[ $cf->slug ]['operand_val_1'][] = $priority_map[ $condition[1] ];
2286 } else {
2287 $visibility[ $cf->slug ] = array(
2288 'operator' => 'IN',
2289 'operand_val_1' => array(
2290 $priority_map[ $condition[1] ],
2291 ),
2292 );
2293 }
2294 break;
2295
2296 default:
2297 if ( isset( $visibility[ $cf->slug ] ) ) {
2298 $visibility[ $cf->slug ]['operand_val_1'][] = $options_map[ $cf->id ][ $condition[1] ];
2299 } else {
2300 $visibility[ $cf->slug ] = array(
2301 'operator' => 'IN',
2302 'operand_val_1' => array(
2303 $options_map[ $cf->id ][ $condition[1] ],
2304 ),
2305 );
2306 }
2307 }
2308 }
2309 }
2310
2311 $cf = wpsc_get_cf_by( 'id', $cf_map[ $field->term_id ] );
2312 $form_fields[ $cf->slug ] = array(
2313 'is-required' => $is_required,
2314 'width' => $width,
2315 'relation' => 'OR',
2316 'visibility' => $visibility ? wp_json_encode( $visibility ) : '{}',
2317 );
2318 }
2319
2320 // import tff conditions.
2321 foreach ( $form_fields as $slug => $properties ) {
2322 if ( ! $properties['visibility'] ) {
2323 continue;
2324 }
2325 $form_fields[ $slug ]['visibility'] = WPSC_SC_Upgrade::upgrade_condition( $properties['visibility'], $properties['relation'] );
2326 }
2327 update_option( 'wpsc-tff', $form_fields );
2328 }
2329
2330 /**
2331 * Import agent and customer ticket list and filter items
2332 *
2333 * @return void
2334 */
2335 public static function import_ticket_list_items() {
2336
2337 $map = get_option( 'wpsc_upgrade_cf_term_id_map' );
2338
2339 // import agent ticket list.
2340 $fields = get_terms(
2341 array(
2342 'taxonomy' => 'wpsc_ticket_custom_fields',
2343 'hide_empty' => false,
2344 'orderby' => 'meta_value_num',
2345 'meta_key' => 'wpsc_tl_agent_load_order',
2346 'order' => 'ASC',
2347 'meta_query' => array(
2348 'relation' => 'AND',
2349 array(
2350 'key' => 'wpsc_allow_ticket_list',
2351 'value' => '1',
2352 'compare' => '=',
2353 ),
2354 array(
2355 'key' => 'wpsc_agent_ticket_list_status',
2356 'value' => '1',
2357 'compare' => '=',
2358 ),
2359 ),
2360 )
2361 );
2362
2363 $items = array();
2364 foreach ( $fields as $field ) {
2365 $cf = wpsc_get_cf_by( 'id', $map[ $field->term_id ] );
2366 $items[] = $cf->slug;
2367 }
2368 update_option( 'wpsc-atl-list-items', $items );
2369
2370 // import agent filter items.
2371 $fields = get_terms(
2372 array(
2373 'taxonomy' => 'wpsc_ticket_custom_fields',
2374 'hide_empty' => false,
2375 'orderby' => 'meta_value_num',
2376 'meta_key' => 'wpsc_filter_agent_load_order',
2377 'order' => 'ASC',
2378 'meta_query' => array(
2379 'relation' => 'AND',
2380 array(
2381 'key' => 'wpsc_allow_ticket_filter',
2382 'value' => '1',
2383 'compare' => '=',
2384 ),
2385 array(
2386 'key' => 'wpsc_agent_ticket_filter_status',
2387 'value' => '1',
2388 'compare' => '=',
2389 ),
2390 ),
2391 )
2392 );
2393
2394 $items = array();
2395 foreach ( $fields as $field ) {
2396 $cf = wpsc_get_cf_by( 'id', $map[ $field->term_id ] );
2397 if ( $cf->slug == 'name' ) {
2398 $items[] = 'customer';
2399 } else {
2400 $items[] = $cf->slug;
2401 }
2402 }
2403 update_option( 'wpsc-atl-filter-items', $items );
2404
2405 // import customer list items.
2406 $fields = get_terms(
2407 array(
2408 'taxonomy' => 'wpsc_ticket_custom_fields',
2409 'hide_empty' => false,
2410 'orderby' => 'meta_value_num',
2411 'meta_key' => 'wpsc_tl_customer_load_order',
2412 'order' => 'ASC',
2413 'meta_query' => array(
2414 'relation' => 'AND',
2415 array(
2416 'key' => 'wpsc_allow_ticket_list',
2417 'value' => '1',
2418 'compare' => '=',
2419 ),
2420 array(
2421 'key' => 'wpsc_customer_ticket_list_status',
2422 'value' => '1',
2423 'compare' => '=',
2424 ),
2425 ),
2426 )
2427 );
2428
2429 $items = array();
2430 foreach ( $fields as $field ) {
2431 $cf = wpsc_get_cf_by( 'id', $map[ $field->term_id ] );
2432 $items[] = $cf->slug;
2433 }
2434 update_option( 'wpsc-ctl-list-items', $items );
2435
2436 // import customer filter items.
2437 $fields = get_terms(
2438 array(
2439 'taxonomy' => 'wpsc_ticket_custom_fields',
2440 'hide_empty' => false,
2441 'orderby' => 'meta_value_num',
2442 'meta_key' => 'wpsc_filter_customer_load_order',
2443 'order' => 'ASC',
2444 'meta_query' => array(
2445 'relation' => 'AND',
2446 array(
2447 'key' => 'wpsc_allow_ticket_filter',
2448 'value' => '1',
2449 'compare' => '=',
2450 ),
2451 array(
2452 'key' => 'wpsc_customer_ticket_filter_status',
2453 'value' => '1',
2454 'compare' => '=',
2455 ),
2456 ),
2457 )
2458 );
2459
2460 $items = array();
2461 foreach ( $fields as $field ) {
2462 $cf = wpsc_get_cf_by( 'id', $map[ $field->term_id ] );
2463 if ( $cf->slug == 'name' ) {
2464 $items[] = 'customer';
2465 } else {
2466 $items[] = $cf->slug;
2467 }
2468 }
2469 update_option( 'wpsc-ctl-filter-items', $items );
2470 }
2471
2472 /**
2473 * Import ticket list more settings
2474 *
2475 * @return void
2476 */
2477 public static function import_tl_more_settings() {
2478
2479 $cf_map = get_option( 'wpsc_upgrade_cf_term_id_map' );
2480 $status_map = get_option( 'wpsc_upgrade_status_map' );
2481 // agent view.
2482 $aview = get_option( 'wpsc-tl-ms-agent-view' );
2483 $orderby = get_option( 'wpsc_tl_agent_orderby' );
2484 $orderby = get_term_by( 'slug', $orderby, 'wpsc_ticket_custom_fields' );
2485 $orderby = wpsc_get_cf_by( 'id', $cf_map[ $orderby->term_id ] );
2486 $aview['default-sort-by'] = $orderby->slug;
2487 $aview['default-sort-order'] = get_option( 'wpsc_tl_agent_orderby_order' );
2488 $aview['number-of-tickets'] = get_option( 'wpsc_tl_agent_no_of_tickets' );
2489 $unresolved_statuses = get_option( 'wpsc_tl_agent_unresolve_statuses', array() );
2490 $aview['unresolved-ticket-statuses'] = array_filter(
2491 array_unique(
2492 array_map(
2493 function ( $status_id ) use ( $status_map ) {
2494 return isset( $status_map[ $status_id ] ) ? $status_map[ $status_id ] : null;
2495 },
2496 $unresolved_statuses
2497 )
2498 )
2499 );
2500 update_option( 'wpsc-tl-ms-agent-view', $aview );
2501 // customer view.
2502 $cview = get_option( 'wpsc-tl-ms-customer-view' );
2503 $orderby = get_option( 'wpsc_tl_customer_orderby' );
2504 $orderby = get_term_by( 'slug', $orderby, 'wpsc_ticket_custom_fields' );
2505 $orderby = wpsc_get_cf_by( 'id', $cf_map[ $orderby->term_id ] );
2506 $cview['default-sort-by'] = $orderby->slug;
2507 $cview['default-sort-order'] = get_option( 'wpsc_tl_customer_orderby_order' );
2508 $cview['number-of-tickets'] = get_option( 'wpsc_tl_customer_no_of_tickets' );
2509 $unresolved_statuses = get_option( 'wpsc_tl_customer_unresolve_statuses', array() );
2510 $cview['unresolved-ticket-statuses'] = array_filter(
2511 array_unique(
2512 array_map(
2513 function ( $status_id ) use ( $status_map ) {
2514 return isset( $status_map[ $status_id ] ) ? $status_map[ $status_id ] : null;
2515 },
2516 $unresolved_statuses
2517 )
2518 )
2519 );
2520 update_option( 'wpsc-tl-ms-customer-view', $cview );
2521 // Importing TL more setting -> advance setting.
2522 $setting = get_option( 'wpsc-tl-ms-advanced' );
2523 $setting['closed-ticket-statuses'] = array_unique(
2524 array_map(
2525 function ( $status_id ) use ( $status_map ) {
2526 return isset( $status_map[ $status_id ] ) ? $status_map[ $status_id ] : null;
2527 },
2528 get_option( 'wpsc_close_ticket_group', array() )
2529 )
2530 );
2531 update_option( 'wpsc-tl-ms-advanced', $setting );
2532 }
2533
2534 /**
2535 * Import email notifications general settings
2536 *
2537 * @return void
2538 */
2539 public static function import_en_general() {
2540
2541 $settings = get_option( 'wpsc-en-general', array() );
2542 $settings['from-name'] = get_option( 'wpsc_en_from_name' );
2543 $settings['from-email'] = get_option( 'wpsc_en_from_email' );
2544 $settings['reply-to'] = get_option( 'wpsc_en_reply_to' );
2545 $settings['blocked-emails'] = get_option( 'wpsc_en_ignore_emails', array() );
2546 $settings['cron-email-count'] = intval( get_option( 'wpsc_en_send_mail_count', 5 ) );
2547 update_option( 'wpsc-en-general', $settings );
2548 }
2549
2550 /**
2551 * Import ticket notifications
2552 *
2553 * @return void
2554 */
2555 public static function import_en_ticket_notifications() {
2556
2557 $en_template_map = array();
2558 $new_templates = array();
2559 $event_map = wpsc_get_en_event_map();
2560 $email_templates = get_terms(
2561 array(
2562 'taxonomy' => 'wpsc_en',
2563 'hide_empty' => false,
2564 'orderby' => 'ID',
2565 'order' => 'ASC',
2566 )
2567 );
2568
2569 $string_translations = get_option( 'wpsc-string-translation' );
2570 foreach ( $email_templates as $template ) {
2571
2572 $type = get_term_meta( $template->term_id, 'type', true );
2573 $subject = get_term_meta( $template->term_id, 'subject', true );
2574 $body = get_term_meta( $template->term_id, 'body', true );
2575
2576 $subject = wpsc_upgrade_macros( $subject );
2577 $body = wpsc_upgrade_macros( $body );
2578 $et = array(
2579 'title' => $template->name,
2580 'event' => $event_map[ $type ],
2581 'is_enable' => 1,
2582 'subject' => $subject,
2583 'body' => array(
2584 'text' => $body,
2585 'editor' => 'html',
2586 ),
2587 'to' => array(
2588 'general-recipients' => array(),
2589 'agent-roles' => array(),
2590 'custom' => array(),
2591 ),
2592 'cc' => array(
2593 'general-recipients' => array(),
2594 'agent-roles' => array(),
2595 'custom' => array(),
2596 ),
2597 'bcc' => wpsc_en_extract_bcc( $template ),
2598 'relation' => 'AND',
2599 'conditions' => '',
2600 );
2601
2602 if ( count( $new_templates ) == 0 ) {
2603 $new_templates[1] = $et;
2604 } else {
2605 $new_templates[] = $et;
2606 }
2607 $template_id = array_key_last( $new_templates );
2608 $en_template_map[ $template->term_id ] = $template_id;
2609 $string_translations[ 'wpsc-en-tn-subject-' . $template_id ] = $subject;
2610 $string_translations[ 'wpsc-en-tn-body-' . $template_id ] = $body;
2611 }
2612
2613 update_option( 'wpsc-string-translation', $string_translations );
2614 update_option( 'wpsc-email-templates', $new_templates );
2615 update_option( 'wpsc_upgrade_en_term_id_map', $en_template_map );
2616 }
2617
2618 /**
2619 * Import general settings
2620 *
2621 * @return void
2622 */
2623 public static function import_general_settings() {
2624
2625 global $wpdb;
2626 $gs = get_option( 'wpsc-gs-general' );
2627 $page_settings = get_option( 'wpsc-gs-page-settings' );
2628 $advanced = get_option( 'wpsc-ms-advanced-settings', array() );
2629 $roles = get_option( 'wpsc-agent-roles' );
2630 $status_map = get_option( 'wpsc_upgrade_status_map' );
2631 $category_map = get_option( 'wpsc_upgrade_category_map' );
2632 $priority_map = get_option( 'wpsc_upgrade_priority_map' );
2633 // support page.
2634 $page_settings['support-page'] = get_option( 'wpsc_support_page_id' );
2635 // default ticket status.
2636 $default_value = get_option( 'wpsc_default_ticket_status' );
2637 $default_value = $default_value ? $status_map[ $default_value ] : '1';
2638 $wpdb->update(
2639 $wpdb->prefix . 'psmsc_custom_fields',
2640 array( 'default_value' => $default_value ),
2641 array( 'id' => 7 )
2642 );
2643 // default ticket category.
2644 $default_value = get_option( 'wpsc_default_ticket_category' );
2645 $default_value = $default_value ? $category_map[ $default_value ] : '';
2646 $wpdb->update(
2647 $wpdb->prefix . 'psmsc_custom_fields',
2648 array( 'default_value' => $default_value ),
2649 array( 'id' => 9 )
2650 );
2651 // default ticket priority.
2652 $default_value = get_option( 'wpsc_default_ticket_priority' );
2653 $default_value = $default_value ? $priority_map[ $default_value ] : '';
2654 $wpdb->update(
2655 $wpdb->prefix . 'psmsc_custom_fields',
2656 array( 'default_value' => $default_value ),
2657 array( 'id' => 8 )
2658 );
2659 // ticket status after customer reply.
2660 $status = get_option( 'wpsc_ticket_status_after_customer_reply' );
2661 $gs['ticket-status-after-customer-reply'] = $status ? $status_map[ $status ] : '';
2662 // ticket status after agent reply.
2663 $status = get_option( 'wpsc_ticket_status_after_agent_reply' );
2664 $gs['ticket-status-after-agent-reply'] = $status ? $status_map[ $status ] : '';
2665 // close ticket status.
2666 $status = get_option( 'wpsc_close_ticket_status' );
2667 $gs['close-ticket-status'] = $status ? $status_map[ $status ] : '';
2668 // allow customer to close ticket.
2669 $customer = get_option( 'wpsc_allow_customer_close_ticket', 1 );
2670 $allow_close_ticket = $customer ? array( 'customer' ) : array();
2671 foreach ( $roles as $key => $role ) {
2672 $allow_close_ticket[] = $key;
2673 }
2674 $gs['allow-close-ticket'] = $allow_close_ticket;
2675 // reply form position.
2676 $position = get_option( 'wpsc_reply_form_position' );
2677 $gs['reply-form-position'] = $position == 1 ? 'top' : 'bottom';
2678 // ticket alice.
2679 $gs['ticket-alice'] = get_option( 'wpsc_ticket_alice' );
2680 // allow to create new tickets.
2681 $allow_ct = get_option( 'wpsc_allow_to_create_ticket' );
2682 $allow_create_ticket = array();
2683 if ( $allow_ct ) {
2684 if ( in_array( 'customer', $allow_ct ) ) {
2685 $allow_create_ticket[] = 'registered-user';
2686 }
2687 if ( in_array( 'guest', $allow_ct ) ) {
2688 $allow_create_ticket[] = 'guest';
2689 }
2690 foreach ( $roles as $key => $role ) {
2691 if ( in_array( $key, $allow_ct ) ) {
2692 $allow_create_ticket[] = $key;
2693 }
2694 }
2695 } else {
2696 $allow_create_ticket = array( 'registered-user' );
2697 if ( get_option( 'wpsc_allow_guest_ticket' ) == 1 ) {
2698 $allow_create_ticket[] = 'guest';
2699 }
2700 foreach ( $roles as $key => $role ) {
2701 $allow_create_ticket[] = $key;
2702 }
2703 }
2704 $gs['allow-create-ticket'] = $allow_create_ticket;
2705 // enable otp login if guest tickets are allowed.
2706 if ( in_array( 'guest', $gs['allow-create-ticket'] ) ) {
2707 $page_settings['otp-login'] = 1;
2708 }
2709 // allow reply to closed ticket.
2710 $allow_close = array();
2711 $reply_to_close_ticket = get_option( 'wpsc_allow_reply_to_close_ticket', array() );
2712 if ( in_array( 'customer', $reply_to_close_ticket ) ) {
2713 $allow_close[] = 'customer';
2714 }
2715 if ( in_array( 'agents', $reply_to_close_ticket ) ) {
2716 $allow_close[] = 'agent';
2717 }
2718 $advanced['allow-reply-to-close-ticket'] = $allow_close;
2719 // default login.
2720 $default_login = get_option( 'wpsc_default_login_setting', 1 );
2721 switch ( intval( $default_login ) ) {
2722 case 1:
2723 $page_settings['user-login'] = 'default';
2724 break;
2725 case 2:
2726 $page_settings['user-login'] = 'wp-default';
2727 break;
2728 case 3:
2729 $page_settings['user-login'] = 'custom';
2730 $page_settings['custom-login-url'] = get_option( 'wpsc_custom_login_url' );
2731 break;
2732 }
2733 // user registration.
2734 $user_registration = get_option( 'wpsc_user_registration', 0 );
2735 if ( $user_registration == 0 ) {
2736 $page_settings['user-registration'] = 'disable';
2737 } else {
2738 $registration_method = get_option( 'wpsc_user_registration_method', 1 );
2739 switch ( intval( $registration_method ) ) {
2740 case 1:
2741 $page_settings['user-registration'] = 'default';
2742 break;
2743 case 2:
2744 $page_settings['user-registration'] = 'wp-default';
2745 break;
2746 case 3:
2747 $page_settings['user-registration'] = 'custom';
2748 $page_settings['custom-registration-url'] = get_option( 'wpsc_custom_registration_url' );
2749 break;
2750 }
2751 }
2752 // update options.
2753 update_option( 'wpsc-gs-general', $gs );
2754 update_option( 'wpsc-gs-page-settings', $page_settings );
2755 update_option( 'wpsc-ms-advanced-settings', $advanced );
2756 }
2757
2758 /**
2759 * Re-order widgets as per old records
2760 *
2761 * @return void
2762 */
2763 public static function reorder_widgets() {
2764
2765 $installed_addons = get_option( 'wpsc_upgrade_installed_addons' );
2766 $new = get_option( 'wpsc-ticket-widget', array() );
2767 $prev = get_terms(
2768 array(
2769 'taxonomy' => 'wpsc_ticket_widget',
2770 'hide_empty' => false,
2771 'orderby' => 'meta_value_num',
2772 'order' => 'ASC',
2773 'meta_query' => array( 'order_clause' => array( 'key' => 'wpsc_ticket_widget_load_order' ) ),
2774 )
2775 );
2776 $widget_map = array(
2777 'status' => 'change-status',
2778 'raised-by' => 'raised-by',
2779 'assign-agent' => 'assignee',
2780 'ticket-fields' => 'ticket-fields',
2781 'agent-only-fields' => 'agentonly-fields',
2782 'additional-recepients' => 'additional-recipients',
2783 'biographical-info' => 'biographical-info',
2784 'rating' => 'rating',
2785 'woo-order' => 'woo-order',
2786 'woo-subscriptions' => 'woo-sub',
2787 'timer' => 'timer',
2788 'edd-order' => 'edd',
2789 'usergroup' => 'usergroups',
2790 );
2791
2792 $string_translations = get_option( 'wpsc-string-translation' );
2793 $reordered = array();
2794 foreach ( $prev as $widget ) {
2795
2796 $flag = true;
2797 switch ( $widget->slug ) {
2798 case 'rating':
2799 if ( ! $installed_addons[15]['is_installed'] ) {
2800 $flag = false;
2801 }
2802 break;
2803 case 'timer':
2804 if ( ! $installed_addons[13]['is_installed'] ) {
2805 $flag = false;
2806 }
2807 break;
2808 case 'woo-order':
2809 case 'woo-subscriptions':
2810 if ( ! $installed_addons[5]['is_installed'] ) {
2811 $flag = false;
2812 }
2813 break;
2814 case 'edd-order':
2815 if ( ! $installed_addons[8]['is_installed'] ) {
2816 $flag = false;
2817 }
2818 break;
2819 }
2820
2821 if ( $flag && isset( $new[ $widget_map[ $widget->slug ] ] ) ) {
2822
2823 $reordered[ $widget_map[ $widget->slug ] ] = $new[ $widget_map[ $widget->slug ] ];
2824 unset( $new[ $widget_map[ $widget->slug ] ] );
2825
2826 $reordered[ $widget_map[ $widget->slug ] ]['title'] = get_term_meta( $widget->term_id, 'wpsc_label', true );
2827 $reordered[ $widget_map[ $widget->slug ] ]['is_enable'] = get_term_meta( $widget->term_id, 'wpsc_ticket_widget_type', true );
2828 $agent_roles = get_term_meta( $widget->term_id, 'wpsc_ticket_widget_role', true );
2829 $reordered[ $widget_map[ $widget->slug ] ]['allowed-agent-roles'] = $agent_roles;
2830 if ( in_array( 'customer', $agent_roles ) ) {
2831 $reordered[ $widget_map[ $widget->slug ] ]['allow-customer'] = 1;
2832 }
2833 }
2834 }
2835
2836 foreach ( $reordered as $key => $widget ) {
2837 $string_translations[ 'wpsc-twt-' . $key ] = $widget['title'];
2838 }
2839
2840 foreach ( $new as $key => $widget ) {
2841 $reordered[ $key ] = $widget;
2842 }
2843
2844 update_option( 'wpsc-string-translation', $string_translations );
2845 update_option( 'wpsc-ticket-widget', $reordered );
2846 }
2847
2848 /**
2849 * Thank you page import
2850 *
2851 * @return void
2852 */
2853 public static function import_thankyou_settings() {
2854
2855 $string_translations = get_option( 'wpsc-string-translation' );
2856
2857 $thankyou_html = wpsc_upgrade_macros( get_option( 'wpsc_thankyou_html' ) );
2858 $thankyou_url = get_option( 'wpsc_thankyou_url' );
2859 if ( $thankyou_url ) {
2860 $action = 'url';
2861 } else {
2862 $action = 'text';
2863 }
2864
2865 update_option(
2866 'wpsc-gs-thankyou-page-settings',
2867 array(
2868 'action-agent' => $action,
2869 'action-customer' => $action,
2870 'html-agent' => $thankyou_html,
2871 'html-customer' => $thankyou_html,
2872 'page-url-agent' => $thankyou_url,
2873 'page-url-customer' => $thankyou_url,
2874 'editor-agent' => 'html',
2875 'editor-customer' => 'html',
2876 )
2877 );
2878
2879 $string_translations['wpsc-thankyou-html'] = $thankyou_html;
2880 $string_translations['wpsc-thankyou-html-agent'] = $thankyou_html;
2881
2882 update_option( 'wpsc-string-translation', $string_translations );
2883 }
2884
2885 /**
2886 * Import terms and conditions
2887 *
2888 * @return void
2889 */
2890 public static function import_terms_and_conditions() {
2891
2892 $tc = get_option( 'wpsc-term-and-conditions' );
2893 $string_translations = get_option( 'wpsc-string-translation' );
2894 $tandc_text = get_option( 'wpsc_terms_and_conditions_html', $tc['tandc-text'] );
2895 $tc['allow-term-and-conditions'] = intval( get_option( 'wpsc_terms_and_conditions', $tc['allow-term-and-conditions'] ) );
2896 $tc['tandc-text'] = $tandc_text;
2897 $string_translations['wpsc-term-and-conditions'] = $tandc_text;
2898 update_option( 'wpsc-term-and-conditions', $tc );
2899
2900 $gdpr = get_option( 'wpsc-gdpr-settings' );
2901 $gdpr_text = get_option( 'wpsc_gdpr_html', $gdpr['gdpr-text'] );
2902 $gdpr['allow-gdpr'] = intval( get_option( 'wpsc_set_in_gdpr', $gdpr['allow-gdpr'] ) );
2903 $gdpr['gdpr-text'] = $gdpr_text;
2904 $gdpr['personal-data-retention-time'] = intval( get_option( 'wpsc_personal_data_retention_period_time', $gdpr['personal-data-retention-time'] ) );
2905 $unit_map = array(
2906 'days' => 'days',
2907 'months' => 'month',
2908 'years' => 'year',
2909 );
2910 $unit = get_option( 'wpsc_personal_data_retention_period_unit' );
2911 $gdpr['personal-data-retention-unit'] = isset( $unit_map[ $unit ] ) ? $unit_map[ $unit ] : 'days';
2912 $string_translations['wpsc-gdpr'] = $gdpr_text;
2913
2914 update_option( 'wpsc-string-translation', $string_translations );
2915 update_option( 'wpsc-gdpr-settings', $gdpr );
2916 }
2917
2918 /**
2919 * Import advanced settings
2920 *
2921 * @return void
2922 */
2923 public static function import_advanced_settings() {
2924
2925 $advanced = get_option( 'wpsc-ms-advanced-settings' );
2926
2927 // Ticket url permissions.
2928 $ticket_url_permission = intval( get_option( 'wpsc_ticket_url_permission', 1 ) ) ? 0 : 1;
2929 $advanced['ticket-url-auth'] = $ticket_url_permission;
2930 // public mode.
2931 $advanced['public-mode'] = intval( get_option( 'wpsc_ticket_public_mode', $advanced['public-mode'] ) );
2932 $advanced['public-mode-reply'] = intval( get_option( 'wpsc_allow_reply_to_public_tickets', $advanced['public-mode-reply'] ) );
2933 // Allow Reply Confirmation.
2934 $advanced['reply-confirmation'] = intval( get_option( 'wpsc_allow_reply_confirmation', $advanced['reply-confirmation'] ) );
2935 // Thread Date Format.
2936 $display_as = get_option( 'wpsc_thread_date_format' );
2937 $advanced['thread-date-display-as'] = $display_as == 'string' ? 'diff' : 'date';
2938 $advanced['thread-date-format'] = get_option( 'wpsc_thread_date_time_format', $advanced['thread-date-format'] );
2939 // Do not notify owner.
2940 $advanced['do-not-notify-owner'] = get_option( 'wpsc_do_not_notify_setting', $advanced['do-not-notify-owner'] );
2941 $advanced['do-not-notify-owner-status'] = get_option( 'wpsc_default_do_not_notify_option', $advanced['do-not-notify-owner-status'] );
2942 // Priority visibility for customers in open ticket.
2943 $ticket_widgets = get_option( 'wpsc-ticket-widget' );
2944 $ticket_widgets['change-status']['show-priority-to-customer'] = intval( get_option( 'wpsc_hide_show_priority' ) );
2945 update_option( 'wpsc-ticket-widget', $ticket_widgets );
2946 // Ticket thread view more.
2947 $advanced['view-more'] = intval( get_option( 'wpsc_view_more', $advanced['view-more'] ) );
2948 // Auto refresh default status.
2949 $advanced_settings = get_option( 'wpsc-tl-ms-advanced' );
2950 $advanced_settings['auto-refresh-list-status'] = intval( get_option( 'wpsc_on_and_off_auto_refresh', $advanced_settings['auto-refresh-list-status'] ) );
2951 update_option( 'wpsc-tl-ms-advanced', $advanced_settings );
2952 // Ticket id setting.
2953 $advanced['ticket-id-format'] = get_option( 'wpsc_ticket_id_type' ) == '1' ? 'sequential' : 'random';
2954 $advanced['starting-ticket-id'] = intval( get_option( 'wpsc_custom_ticket_count', $advanced['starting-ticket-id'] ) );
2955 $advanced['random-id-length'] = intval( get_option( 'wpsc_rt_id_length', $advanced['random-id-length'] ) );
2956 // Ticket history limit.
2957 $advanced['ticket-history-macro-threads'] = intval( get_option( 'wpsc_thread_limit', $advanced['ticket-history-macro-threads'] ) );
2958 // Ticket reply redirect.
2959 $av_settings = get_option( 'wpsc-tl-ms-agent-view' );
2960 $av_settings['ticket-reply-redirect'] = get_option( 'wpsc_redirect_to_ticket_list' ) == '1' ? 'ticket-list' : 'no-redirect';
2961 update_option( 'wpsc-tl-ms-agent-view', $av_settings );
2962 $cv_settings = get_option( 'wpsc-tl-ms-customer-view' );
2963 $cv_settings['ticket-reply-redirect'] = get_option( 'wpsc_redirect_to_ticket_list' ) == '1' ? 'ticket-list' : 'no-redirect';
2964 update_option( 'wpsc-tl-ms-customer-view', $cv_settings );
2965 // Register user on creating ticket.
2966 $advanced['register-user-if-not-exist'] = intval( get_option( 'wpsc_reg_guest_user_after_create_ticket', $advanced['register-user-if-not-exist'] ) );
2967 // Auto delete closed tickets.
2968 $wpsc_auto_delete_ticket = get_option( 'wpsc_auto_delete_ticket', 0 );
2969 if ( $wpsc_auto_delete_ticket ) {
2970 $advanced['auto-archive-tickets-time'] = intval( get_option( 'wpsc_auto_delete_ticket_time', $advanced['auto-archive-tickets-time'] ) );
2971 } else {
2972 $advanced['auto-archive-tickets-time'] = 0;
2973 }
2974 $unit_map = array(
2975 'days' => 'days',
2976 'months' => 'month',
2977 'years' => 'year',
2978 );
2979 $unit = get_option( 'wpsc_auto_delete_ticket_time_period_unit' );
2980 $advanced['auto-archive-tickets-unit'] = isset( $unit_map[ $unit ] ) ? $unit_map[ $unit ] : 'days';
2981 // BCC in reply form.
2982 $advanced['allow-bcc'] = intval( get_option( 'wpsc_reply_bcc_visibility', $advanced['allow-bcc'] ) );
2983 // New ticket button url.
2984 $btn_url = get_option( 'wpsc_new_ticket_btn_url' );
2985 if ( $btn_url ) {
2986 $settings = get_option( 'wpsc-gs-page-settings' );
2987 $settings['new-ticket-page'] = 'custom';
2988 $settings['new-ticket-url'] = $btn_url;
2989 update_option( 'wpsc-gs-page-settings', $settings );
2990 }
2991 // Raised by user setting.
2992 $advanced['raised-by-user'] = get_option( 'wpsc_report_raised_by_user', 'customer' ) == 'customer' ? 'customer' : 'agent';
2993
2994 // update options.
2995 update_option( 'wpsc-ms-advanced-settings', $advanced );
2996 }
2997
2998 /**
2999 * Import captcha
3000 *
3001 * @return void
3002 */
3003 public static function import_captcha() {
3004
3005 if (
3006 ( get_option( 'wpsc_captcha' ) == 1 || get_option( 'wpsc_registration_captcha' ) == 1 || get_option( 'wpsc_login_captcha' ) == 1 ) &&
3007 get_option( 'wpsc_recaptcha_type', 1 ) == 0
3008 ) {
3009 $recaptcha = get_option( 'wpsc-recaptcha-settings' );
3010 $recaptcha['allow-recaptcha'] = 1;
3011 $recaptcha['recaptcha-version'] = 2;
3012 $recaptcha['recaptcha-site-key'] = get_option( 'wpsc_get_site_key', '' );
3013 $recaptcha['recaptcha-secret-key'] = get_option( 'wpsc_get_secret_key', '' );
3014 update_option( 'wpsc-recaptcha-settings', $recaptcha );
3015 }
3016 }
3017
3018 /**
3019 * Import assign agent rules.
3020 *
3021 * @return void
3022 */
3023 public static function import_assign_agent_rules() {
3024
3025 global $wpdb;
3026 $installed_addons = get_option( 'wpsc_upgrade_installed_addons' );
3027 if ( ! $installed_addons[10]['is_installed'] ) {
3028 return;
3029 }
3030
3031 // import settings.
3032 $general = get_option( 'wpsc-aar-general-settings' );
3033 $general['auto-assign-agent'] = get_option( 'wpsc_assign_auto_responder', $general['auto-assign-agent'] );
3034 update_option( 'wpsc-aar-general-settings', $general );
3035
3036 // import rules.
3037 $agent_map = get_option( 'wpsc_upgrade_agent_map' );
3038 $new_rules = array();
3039 $rules_map = array();
3040 $prev_rules = get_terms(
3041 array(
3042 'taxonomy' => 'wpsc_caa',
3043 'hide_empty' => false,
3044 )
3045 );
3046
3047 foreach ( $prev_rules as $prev ) {
3048
3049 $prev_agents = get_term_meta( $prev->term_id, 'agent_ids', true );
3050 $new_agents = array_map(
3051 function ( $old_id ) use ( $wpdb, $agent_map ) {
3052 return $wpdb->get_row( "SELECT * from {$wpdb->prefix}psmsc_agents WHERE id = " . $agent_map[ $old_id ] );
3053 },
3054 $prev_agents
3055 );
3056 $agents = array();
3057 $agentgroups = array();
3058 foreach ( $new_agents as $agent ) {
3059 if ( $agent->is_agentgroup ) {
3060 $agentgroups[] = $agent->id;
3061 } else {
3062 $agents[] = $agent->id;
3063 }
3064 }
3065
3066 $conditions = array();
3067
3068 $rule = array(
3069 'title' => $prev->name,
3070 'agents' => implode( '|', $agents ),
3071 'assign_method' => 'assign_all',
3072 'agentgroups' => implode( '|', $agentgroups ),
3073 'assign_group_method' => 'assign_all_groups',
3074 'relation' => 'AND',
3075 'conditions' => $conditions ? wp_json_encode( $conditions ) : '{}',
3076 );
3077
3078 if ( $new_rules ) {
3079 $new_rules[] = $rule;
3080 } else {
3081 $new_rules[1] = $rule;
3082 }
3083 $rules_map[ $prev->term_id ] = array_key_last( $new_rules );
3084 }
3085 update_option( 'wpsc-aar-rules', $new_rules );
3086 update_option( 'wpsc_upgrade_aar_map', $rules_map );
3087 }
3088
3089 /**
3090 * Import automatic close tickets add-on
3091 *
3092 * @return void
3093 */
3094 public static function import_automatic_close_tickets() {
3095
3096 $installed_addons = get_option( 'wpsc_upgrade_installed_addons' );
3097 if ( ! $installed_addons[0]['is_installed'] ) {
3098 return;
3099 }
3100
3101 // import settings.
3102 $string_translations = get_option( 'wpsc-string-translation' );
3103 $gs = get_option( 'wpsc-gs-general' );
3104 $status_map = get_option( 'wpsc_upgrade_status_map' );
3105 $settings = get_option( 'wpsc-atc-settings' );
3106 $settings['statuses-enabled'] = array_map(
3107 function ( $status_id ) use ( $status_map ) {
3108 return $status_map[ $status_id ];
3109 },
3110 get_option( 'wpsc_tl_statuses', array() )
3111 );
3112 $settings['age'] = get_option( 'wpsc_atc_age', '0' );
3113 $settings['close-status'] = get_option( 'wpsc_atc_status', $gs['close-ticket-status'] );
3114 update_option( 'wpsc-atc-settings', $settings );
3115
3116 // import warning email.
3117 $subject = wpsc_upgrade_macros( get_option( 'wpsc_atc_subject', '' ) );
3118 $body = wpsc_upgrade_macros( get_option( 'wpsc_atc_email_body', '' ) );
3119 $templates = array(
3120 array(
3121 'title' => 'Default template',
3122 'days-before' => get_option( 'wpsc_atc_waring_email_age', 3 ),
3123 'subject' => $subject,
3124 'body' => $body,
3125 'editor' => 'html',
3126 ),
3127 );
3128 $string_translations['wpsc-act-subject-0'] = $subject;
3129 $string_translations['wpsc-act-body-0'] = $body;
3130 update_option( 'wpsc-string-translation', $string_translations );
3131 update_option( 'wpsc-atc-et', $templates );
3132 }
3133
3134 /**
3135 * Import canned reply addon
3136 *
3137 * @return void
3138 */
3139 public static function import_canned_reply() {
3140
3141 global $wpdb;
3142
3143 $installed_addons = get_option( 'wpsc_upgrade_installed_addons' );
3144 if ( ! $installed_addons[1]['is_installed'] ) {
3145 return;
3146 }
3147
3148 // reset data.
3149 $wpdb->query( 'DELETE FROM ' . $wpdb->prefix . 'psmsc_cr_categories' );
3150 $wpdb->query( 'ALTER TABLE ' . $wpdb->prefix . 'psmsc_cr_categories AUTO_INCREMENT = 1' );
3151 $wpdb->query( 'DELETE FROM ' . $wpdb->prefix . 'psmsc_canned_reply' );
3152 $wpdb->query( 'ALTER TABLE ' . $wpdb->prefix . 'psmsc_canned_reply AUTO_INCREMENT = 1' );
3153
3154 // import canned reply categories.
3155 $wpdb->insert(
3156 $wpdb->prefix . 'psmsc_cr_categories',
3157 array(
3158 'name' => 'Uncategorized',
3159 )
3160 );
3161 $categories = get_terms(
3162 array(
3163 'taxonomy' => 'wpsc_canned_reply_categories',
3164 'hide_empty' => false,
3165 )
3166 );
3167
3168 $string_translations = get_option( 'wpsc-string-translation' );
3169 $map = array();
3170 foreach ( $categories as $prev ) {
3171 $wpdb->insert(
3172 $wpdb->prefix . 'psmsc_cr_categories',
3173 array(
3174 'name' => $prev->name,
3175 )
3176 );
3177 $string_translations[ 'wpsc-cr-category-' . $wpdb->insert_id ] = $prev->name;
3178 $map[ $prev->term_id ] = $wpdb->insert_id;
3179 }
3180
3181 // import canned reply.
3182 $response = get_posts(
3183 array(
3184 'post_type' => 'wpsc_canned_reply',
3185 'post_status' => 'publish',
3186 'orderby' => 'date',
3187 'order' => 'ASC',
3188 'posts_per_page' => -1,
3189 )
3190 );
3191 foreach ( $response as $prev ) {
3192 $prev_categories = get_the_terms( $prev->ID, 'wpsc_canned_reply_categories' );
3193 $categories = '1';
3194 if ( is_array( $prev_categories ) ) {
3195 $categories = implode(
3196 '|',
3197 array_map(
3198 function ( $category ) use ( $map ) {
3199 return $map[ $category->term_id ];
3200 },
3201 $prev_categories
3202 ),
3203 );
3204 }
3205 $author = wpsc_get_customer_by( 'user_id', $prev->post_author );
3206 $visibility = get_post_meta( $prev->ID, 'wpsc_agent_visibility', true );
3207 $wpdb->insert(
3208 $wpdb->prefix . 'psmsc_canned_reply',
3209 array(
3210 'title' => $prev->post_title,
3211 'author' => $author->id,
3212 'body' => wpautop( wpsc_upgrade_macros( $prev->post_content ) ),
3213 'categories' => $categories,
3214 'visibility' => $visibility ? 'public' : 'private',
3215 'date_created' => $prev->post_date,
3216 )
3217 );
3218 }
3219 update_option( 'wpsc-string-translation', $string_translations );
3220 }
3221
3222 /**
3223 * Import report settings
3224 *
3225 * @return void
3226 */
3227 public static function import_report_settings() {
3228
3229 $installed_addons = get_option( 'wpsc_upgrade_installed_addons' );
3230 if ( ! $installed_addons[6]['is_installed'] ) {
3231 return;
3232 }
3233
3234 $agent_roles = get_option( 'wpsc-agent-roles' );
3235 foreach ( $agent_roles as $index => $role ) {
3236 $role['caps']['view-reports'] = $index == 1 ? true : false;
3237 $agent_roles[ $index ] = $role;
3238 }
3239 update_option( 'wpsc-agent-roles', $agent_roles );
3240 }
3241
3242 /**
3243 * Import satisfaction survey
3244 *
3245 * @return void
3246 */
3247 public static function import_satisfaction_survey() {
3248
3249 global $wpdb;
3250
3251 $installed_addons = get_option( 'wpsc_upgrade_installed_addons' );
3252 if ( ! $installed_addons[15]['is_installed'] ) {
3253 return;
3254 }
3255
3256 // reset data.
3257 $wpdb->query( 'DELETE FROM ' . $wpdb->prefix . 'psmsc_sf_ratings' );
3258 $wpdb->query( 'ALTER TABLE ' . $wpdb->prefix . 'psmsc_sf_ratings AUTO_INCREMENT = 1' );
3259
3260 // import ratings.
3261 $ratings = get_terms(
3262 array(
3263 'taxonomy' => 'wpsc_sf_rating',
3264 'hide_empty' => false,
3265 'orderby' => 'meta_value_num',
3266 'order' => 'ASC',
3267 'meta_query' => array( 'order_clause' => array( 'key' => 'load_order' ) ),
3268 )
3269 );
3270
3271 $string_translations = get_option( 'wpsc-string-translation' );
3272 $map = array();
3273 $load_order = 1;
3274 $confirmation_text = get_option( 'wpsc_sf_thankyou_text', '' );
3275 foreach ( $ratings as $prev ) {
3276 $bg_color = get_term_meta( $prev->term_id, 'color', true );
3277 $wpdb->insert(
3278 $wpdb->prefix . 'psmsc_sf_ratings',
3279 array(
3280 'name' => $prev->name,
3281 'color' => '#FFFFFF',
3282 'bg_color' => $bg_color,
3283 'confirmation_text' => $confirmation_text,
3284 'load_order' => $load_order++,
3285 )
3286 );
3287
3288 $string_translations[ 'wpsc-rating-name-' . $wpdb->insert_id ] = $prev->name;
3289 $string_translations[ 'wpsc-rating-ct-' . $wpdb->insert_id ] = $confirmation_text;
3290 $map[ $prev->term_id ] = $wpdb->insert_id;
3291 }
3292
3293 update_option( 'wpsc_upgrade_sf_rating_map', $map );
3294
3295 // import settings.
3296 $gs = get_option( 'wpsc-gs-general' );
3297 $settings = get_option( 'wpsc-sf-general-setting' );
3298 $settings['survey-page'] = get_option( 'wpsc_sf_page', 0 );
3299 $settings['customer-trigger'] = get_option( 'wpsc_allow_survey_after_ticket_close', 0 );
3300 $settings['statuses-enabled'] = array( $gs['close-ticket-status'] );
3301 update_option( 'wpsc-sf-general-setting', $settings );
3302
3303 // import email template.
3304 $days_after = get_option( 'wpsc_sf_age', '0' );
3305 if ( get_option( 'wpsc_sf_age_unit', 'd' ) == 'h' ) {
3306 $days_after = 1;
3307 }
3308
3309 $subject = wpsc_upgrade_macros( get_option( 'wpsc_sf_subject', '' ) );
3310 $body = wpsc_upgrade_macros( get_option( 'wpsc_sf_email_body', '' ) );
3311 $new = array(
3312 array(
3313 'title' => 'Default template',
3314 'days-after' => $days_after,
3315 'subject' => $subject,
3316 'body' => $body,
3317 'editor' => 'html',
3318 ),
3319 );
3320 $string_translations['wpsc-sf-et-subject-0'] = $subject;
3321 $string_translations['wpsc-sf-et-body-0'] = $body;
3322 update_option( 'wpsc-string-translation', $string_translations );
3323 update_option( 'wpsc-sf-et', $new );
3324 }
3325
3326 /**
3327 * Import email piping add-on settings
3328 *
3329 * @return void
3330 */
3331 public static function import_email_piping() {
3332
3333 $installed_addons = get_option( 'wpsc_upgrade_installed_addons' );
3334 if ( ! $installed_addons[3]['is_installed'] ) {
3335 return;
3336 }
3337
3338 $string_translations = get_option( 'wpsc-string-translation' );
3339 // import settings.
3340 $general = get_option( 'wpsc-ep-general-settings' );
3341 $general['connection'] = get_option( 'wpsc_ep_piping_type', 'imap' );
3342
3343 $block_emails = array();
3344 if ( $general['block-emails'] ) {
3345 $block_emails = array_merge( $general['block-emails'], get_option( 'wpsc_ep_block_emails', array() ) );
3346 }
3347 $general['block-emails'] = array_filter( array_map( 'trim', $block_emails ) );
3348
3349 $block_subject = array();
3350 if ( $general['block-subject'] ) {
3351 $block_subject = array_merge( $general['block-subject'], explode( PHP_EOL, get_option( 'wpsc_ep_block_subject', '' ) ) );
3352 }
3353 $general['block-subject'] = array_filter( array_map( 'trim', $block_subject ) );
3354
3355 $general['allowed-emails'] = get_option( 'wpsc_ep_accept_emails', 'all' );
3356 $allowed_users = get_option( 'wpsc_ep_allowed_user', 0 );
3357 $general['allowed-users'] = $allowed_users ? 'anyone' : 'registered';
3358 $general['import-cc'] = get_option( 'wpsc_add_additional_recepients', 0 );
3359 $general['time-frequency'] = get_option( 'wpsc_ep_cron_execution_time', 5 );
3360 $general['body-reference'] = get_option( 'wpsc_ep_email_type', 'text' );
3361
3362 $forwarding_addresses = get_option( 'wpsc_ep_emails_forwarded', array() );
3363 $general['forwarding-addresses'] = array_filter( array_map( 'trim', $forwarding_addresses ) );
3364
3365 $general['forwarding-as-from-email'] = get_option( 'wpsc_ep_from_email', 0 );
3366 update_option( 'wpsc-ep-general-settings', $general );
3367
3368 // import connection settings.
3369 if ( $general['connection'] == 'imap' ) {
3370
3371 $imap = array(
3372 'email-address' => get_option( 'wpsc_ep_imap_email_address', '' ),
3373 'password' => get_option( 'wpsc_ep_imap_email_password', '' ),
3374 'encryption' => get_option( 'wpsc_ep_imap_encryption', 'ssl' ),
3375 'incoming-mail-server' => get_option( 'wpsc_ep_imap_incoming_mail_server', '' ),
3376 'port' => get_option( 'wpsc_ep_imap_port', '' ),
3377 'is_active' => 0,
3378 'last-error' => '',
3379 );
3380
3381 // check connection.
3382 $encryption_text = '';
3383 if ( $imap['encryption'] == 'none' ) {
3384 $encryption_text = 'novalidate-cert';
3385 } elseif ( $imap['encryption'] == 'ssl' ) {
3386 $encryption_text = 'imap/ssl/novalidate-cert';
3387 }
3388
3389 // Check if IMAP extension is enable or not.
3390 if ( extension_loaded( 'imap' ) ) {
3391 $conn = @imap_open( '{' . $imap['incoming-mail-server'] . ':' . $imap['port'] . '/' . $encryption_text . '}INBOX', $imap['email-address'], $imap['password'] ); // phpcs:ignore
3392 if ( $conn ) {
3393 $imap['is_active'] = 1;
3394 } else {
3395 $imap['last-error'] = imap_last_error();
3396 }
3397 }
3398
3399 update_option( 'wpsc-ep-imap-settings', $imap );
3400
3401 } else { // gmail.
3402
3403 $gmail = array(
3404 'email-address' => get_option( 'wpsc_ep_email_address', '' ),
3405 'client-id' => get_option( 'wpsc_ep_client_id', '' ),
3406 'client-secret' => get_option( 'wpsc_ep_client_secret', '' ),
3407 'is-active' => 0,
3408 'last-error' => '',
3409 'refresh-token' => get_option( 'wpsc_ep_refresh_token', '' ),
3410 'history-id' => get_option( 'wpsc_ep_historyId', '' ),
3411 );
3412 if (
3413 $gmail['email-address'] &&
3414 $gmail['client-id'] &&
3415 $gmail['client-secret'] &&
3416 $gmail['refresh-token'] &&
3417 $gmail['history-id']
3418 ) {
3419 $gmail['is-active'] = 1;
3420 }
3421 update_option( 'wpsc-ep-gmail-settings', $gmail );
3422 }
3423
3424 // import email piping rules.
3425 $cf_map = get_option( 'wpsc_upgrade_cf_term_id_map' );
3426 $status_map = get_option( 'wpsc_upgrade_status_map' );
3427 $category_map = get_option( 'wpsc_upgrade_category_map' );
3428 $priority_map = get_option( 'wpsc_upgrade_priority_map' );
3429 $new_rules = array();
3430
3431 $fields = get_terms(
3432 array(
3433 'taxonomy' => 'wpsc_ticket_custom_fields',
3434 'hide_empty' => false,
3435 'meta_query' => array(
3436 'relation' => 'AND',
3437 array(
3438 'key' => 'agentonly',
3439 'value' => array( 0, 1 ),
3440 'compare' => 'IN',
3441 ),
3442 array(
3443 'key' => 'wpsc_tf_type',
3444 'value' => '0',
3445 'compare' => '>',
3446 ),
3447 ),
3448 )
3449 );
3450
3451 $email_piping_rules = get_terms(
3452 array(
3453 'taxonomy' => 'wpsc_ep_rules',
3454 'hide_empty' => false,
3455 'orderby' => 'meta_value_num',
3456 'order' => 'ASC',
3457 'meta_query' => array( 'order_clause' => array( 'key' => 'wpsc_en_rule_load_order' ) ),
3458 )
3459 );
3460
3461 $date_formats = array(
3462 'dd-mm-yy' => 'd-m-Y',
3463 'dd-yy-mm' => 'd-Y-m',
3464 'mm-dd-yy' => 'm-d-Y',
3465 'mm-yy-dd' => 'm-Y-d',
3466 'yy-mm-dd' => 'Y-m-d',
3467 'yy-dd-mm' => 'Y-d-m',
3468 );
3469
3470 foreach ( $email_piping_rules as $prev ) {
3471
3472 $rule = array(
3473 'title' => $prev->name,
3474 );
3475
3476 // condition.
3477 $forwarding_address = get_term_meta( $prev->term_id, 'wpsc_ep_to_address', true );
3478 $forwarding_address = $forwarding_address ? $forwarding_address : array();
3479 $rule['forwarding-address'] = array_filter( array_map( 'trim', $forwarding_address ) );
3480
3481 $from_address = get_term_meta( $prev->term_id, 'wpsc_ep_from_address', true );
3482 $from_address = $from_address ? $from_address : array();
3483 $rule['from-address'] = array_filter( array_map( 'trim', $from_address ) );
3484
3485 $has_words = get_term_meta( $prev->term_id, 'wpsc_ep_has_words', true );
3486 $has_words = $has_words ? $has_words : array();
3487 $rule['has-words'] = array_filter( array_map( 'trim', $has_words ) );
3488
3489 // category and priority.
3490 $status = get_term_meta( $prev->term_id, 'ticket_status', true );
3491 if ( $status ) {
3492 $rule['status'] = $status_map[ $status ];
3493 }
3494 $category = get_term_meta( $prev->term_id, 'ticket_category', true );
3495 if ( $category ) {
3496 $rule['category'] = $category_map[ $category ];
3497 }
3498 $priority = get_term_meta( $prev->term_id, 'ticket_priority', true );
3499 if ( $priority ) {
3500 $rule['priority'] = $priority_map[ $priority ];
3501 }
3502
3503 // custom fields.
3504 foreach ( $fields as $field ) {
3505
3506 $type = get_term_meta( $field->term_id, 'wpsc_tf_type', true );
3507 $cf = wpsc_get_cf_by( 'id', $cf_map[ $field->term_id ] );
3508
3509 switch ( $type ) {
3510
3511 case 1:
3512 case 5:
3513 case 7:
3514 case 8:
3515 case 9:
3516 case 11:
3517 $val = get_term_meta( $prev->term_id, $field->slug, true );
3518 if ( $val ) {
3519 $rule[ $cf->slug ] = $val ? $val : '';
3520 }
3521 break;
3522
3523 case 2:
3524 case 4:
3525 $options_map = get_option( 'wpsc_upgrade_cf_options_map' );
3526 $val = get_term_meta( $prev->term_id, $field->slug, true );
3527 if ( $val ) {
3528 $rule[ $cf->slug ] = $options_map[ $cf->id ][ $val ];
3529 }
3530 break;
3531
3532 case 3:
3533 $options_map = get_option( 'wpsc_upgrade_cf_options_map' );
3534 $val = get_term_meta( $prev->term_id, $field->slug, false );
3535 if ( $val ) {
3536 $rule[ $cf->slug ] = implode(
3537 '|',
3538 array_filter(
3539 array_map(
3540 function ( $name ) use ( $cf, $options_map ) {
3541 return $name ? $options_map[ $cf->id ][ $name ] : false;
3542 },
3543 $val
3544 )
3545 )
3546 );
3547 }
3548 break;
3549
3550 case 6:
3551 $val = get_term_meta( $prev->term_id, $field->slug, true );
3552 if ( $val ) {
3553 $old_date_format = get_option( 'wpsc_calender_date_format' );
3554 $val = DateTime::createFromFormat( $date_formats[ $old_date_format ] . ' H:i:s', $val );
3555 if ( $val ) {
3556 $rule[ $cf->slug ] = $val->format( 'Y-m-d' );
3557 }
3558 }
3559 break;
3560
3561 case 18:
3562 $val = get_term_meta( $prev->term_id, $field->slug, true );
3563 if ( $val ) {
3564 $old_date_format = get_option( 'wpsc_calender_date_format' );
3565 $val = DateTime::createFromFormat( $date_formats[ $old_date_format ] . ' H:i:s', $val );
3566 if ( $val ) {
3567 $rule[ $cf->slug ] = $val->format( 'Y-m-d H:i:s' );
3568 }
3569 }
3570 break;
3571
3572 case 21:
3573 $val = get_term_meta( $prev->term_id, $field->slug, true );
3574 if ( $val ) {
3575 $val = new DateTime( $val );
3576 $rule[ $cf->slug ] = $val->format( 'H:i' );
3577 }
3578 break;
3579 }
3580 }
3581
3582 $additional_users = get_term_meta( $prev->term_id, 'wpsc_ticket_et_user', true );
3583 $additional_users = $additional_users ? $additional_users : array();
3584 $additional_users = array_unique( array_filter( array_map( 'trim', $additional_users ) ) );
3585 $rule['add_recipients'] = $additional_users ? implode( '|', $additional_users ) : '';
3586
3587 if ( $new_rules ) {
3588 $new_rules[] = $rule;
3589 } else {
3590 $new_rules[1] = $rule;
3591 }
3592 }
3593
3594 update_option( 'wpsc-ep-pipe-rules', $new_rules );
3595
3596 // Import email piping notification.
3597 // Allowed usertype warning.
3598 $ep_notification_allowed = get_option( 'wpsc-ep-usertype-warning-email' );
3599 $close_email_body = get_option( 'wpsc_close_user_warn_email_body', $ep_notification_allowed['email-warning-message'] );
3600 $ep_notification_allowed['enable'] = intval( get_option( 'wpsc_close_user_warn_email_status', $ep_notification_allowed['enable'] ) );
3601 $ep_notification_allowed['email-warning-message'] = $close_email_body;
3602 $string_translations['wpsc-ep-usertype-warning-message'] = $close_email_body;
3603 update_option( 'wpsc-ep-usertype-warning-email', $ep_notification_allowed );
3604
3605 // Allowed closed ticket warning.
3606 $ep_notification_closed = get_option( 'wpsc-close-ticket-page-settings' );
3607 $warn_email_body = wpsc_upgrade_macros( get_option( 'wpsc_ct_warn_email_body', $ep_notification_closed['close-ticket-html'] ) );
3608 $ep_notification_closed['enable'] = intval( get_option( 'wpsc_ct_warn_email_status', $ep_notification_closed['enable'] ) );
3609 $ep_notification_closed['close-ticket-html'] = $warn_email_body;
3610 $string_translations['wpsc-close-ticket-html'] = $warn_email_body;
3611 update_option( 'wpsc-close-ticket-page-settings', $ep_notification_closed );
3612 update_option( 'wpsc-string-translation', $string_translations );
3613 }
3614
3615 /**
3616 * Import FAQ integration add-on settings
3617 *
3618 * @return void
3619 */
3620 public static function import_faq_integration() {
3621
3622 $installed_addons = get_option( 'wpsc_upgrade_installed_addons' );
3623 if ( ! $installed_addons[11]['is_installed'] ) {
3624 return;
3625 }
3626
3627 $map = array(
3628 'WPSC_Ultimate_FAQ' => 'ultimate_faq',
3629 'WPSC_Acronix_FAQ' => 'acronix_faq',
3630 );
3631 $prev = get_option( 'wpsc_select_faq_set', '' );
3632 if ( $prev ) {
3633 update_option(
3634 'wpsc-faq-settings',
3635 array(
3636 'faq' => $map[ $prev ],
3637 )
3638 );
3639 }
3640 }
3641
3642 /**
3643 * Import knowledgebase integration
3644 *
3645 * @return void
3646 */
3647 public static function import_knowledgebase_integration() {
3648
3649 $installed_addons = get_option( 'wpsc_upgrade_installed_addons' );
3650 if ( ! $installed_addons[12]['is_installed'] ) {
3651 return;
3652 }
3653
3654 $map = array(
3655 'WPSC_PrassApp_Knowledgbase' => 'pressapp_kb',
3656 'WPSC_WP_Knowledgbase' => 'wp_kb',
3657 'WPSC_HelpGuru_Knowledgbase' => 'ht_kb',
3658 'WPSC_BasePress_Knowledgbase' => 'basepress_kb',
3659 'WPSC_BWL_Knowledgbase' => 'bwl_kb',
3660 'WPSC_Echo_Knowledgbase' => 'echo_kb',
3661 'WPSC_Knowledgebase_Helpdesk' => 'helpdesk_kb',
3662 'WPSC_BetterDocs' => 'betterdocs_kb',
3663 );
3664 $prev = get_option( 'wpsc_select_knowledgbase_set', '' );
3665 if ( $prev ) {
3666 update_option(
3667 'wpsc-kb-settings',
3668 array(
3669 'knowledgebase' => $map[ $prev ],
3670 )
3671 );
3672 }
3673 }
3674
3675 /**
3676 * Import export add-on settings
3677 *
3678 * @return void
3679 */
3680 public static function import_export_addon() {
3681
3682 $installed_addons = get_option( 'wpsc_upgrade_installed_addons' );
3683 if ( ! $installed_addons[2]['is_installed'] ) {
3684 return;
3685 }
3686
3687 // visibility.
3688 $new_visibility = array();
3689 $prev_visibility = get_option( 'wpsc_selected_user_roll_data', array() );
3690 foreach ( $prev_visibility as $visibility ) {
3691 if ( $visibility == 'customer' ) {
3692 $new_visibility[] = 'registered-user';
3693 $new_visibility[] = 'guest';
3694 continue;
3695 }
3696 $new_visibility[] = $visibility;
3697 }
3698
3699 update_option(
3700 'wpsc-export-roles',
3701 array(
3702 'allow-export-ticket' => $new_visibility,
3703 )
3704 );
3705
3706 // agent export fields.
3707 $cf_slug_map = get_option( 'wpsc_upgrade_cf_slug_map' );
3708 $prev_items = get_option( 'wpsc_export_ticket_list', array() );
3709 $new_items = array();
3710 foreach ( $prev_items as $slug ) {
3711 $new_items[] = $cf_slug_map[ $slug ];
3712 }
3713 update_option( 'wpsc-agent-export-settings', $new_items );
3714
3715 // customer export fields.
3716 $prev_items = get_option( 'wpsc_customer_export_ticket_list', array() );
3717 $new_items = array();
3718 foreach ( $prev_items as $slug ) {
3719 $new_items[] = $cf_slug_map[ $slug ];
3720 }
3721 update_option( 'wpsc-register-export-settings', $new_items );
3722 }
3723
3724 /**
3725 * Import woocommerce settings
3726 *
3727 * @return void
3728 */
3729 public static function import_woocommerce_addon() {
3730
3731 $installed_addons = get_option( 'wpsc_upgrade_installed_addons' );
3732 if ( ! $installed_addons[5]['is_installed'] ) {
3733 return;
3734 }
3735
3736 $string_translations = get_option( 'wpsc-string-translation' );
3737 // settings.
3738 $tab_lable = get_option( 'wpsc_dashboard_support_tab_label', '' );
3739 $help_lable = get_option( 'wpsc_order_help_button_label', '' );
3740 $settings = get_option( 'wpsc-woo-settings' );
3741 $settings['dashboard-support-tab'] = intval( get_option( 'wpsc_dashboard_support_tab', 1 ) );
3742 $settings['dashboard-support-tab-label'] = $tab_lable;
3743 $settings['order-help-button'] = intval( get_option( 'wpsc_order_help_button', 0 ) );
3744 $settings['order-help-button-label'] = $help_lable;
3745 $settings['dashboard-as-ticket-url'] = get_option( 'wpsc_woo_ticket_url', '' );
3746 update_option( 'wpsc-woo-settings', $settings );
3747
3748 $string_translations['wpsc-woo-dashboard-tab-label'] = $tab_lable;
3749 $string_translations['wpsc-woo-order-help-button-label'] = $help_lable;
3750 update_option( 'wpsc-string-translation', $string_translations );
3751 }
3752
3753 /**
3754 * Import schedule tickets
3755 *
3756 * @return void
3757 */
3758 public static function import_shedule_tickets() {
3759
3760 global $wpdb;
3761 $installed_addons = get_option( 'wpsc_upgrade_installed_addons' );
3762 if ( ! $installed_addons[14]['is_installed'] ) {
3763 return;
3764 }
3765
3766 $cf_map = get_option( 'wpsc_upgrade_cf_term_id_map' );
3767 $category_map = get_option( 'wpsc_upgrade_category_map' );
3768 $priority_map = get_option( 'wpsc_upgrade_priority_map' );
3769 $new_rules = array();
3770 $date_formats = array(
3771 'dd-mm-yy' => 'd-m-Y',
3772 'dd-yy-mm' => 'd-Y-m',
3773 'mm-dd-yy' => 'm-d-Y',
3774 'mm-yy-dd' => 'm-Y-d',
3775 'yy-mm-dd' => 'Y-m-d',
3776 'yy-dd-mm' => 'Y-d-m',
3777 );
3778
3779 $fields = get_terms(
3780 array(
3781 'taxonomy' => 'wpsc_ticket_custom_fields',
3782 'hide_empty' => false,
3783 'meta_query' => array(
3784 'relation' => 'AND',
3785 array(
3786 'key' => 'agentonly',
3787 'value' => array( 0, 1 ),
3788 'compare' => 'IN',
3789 ),
3790 array(
3791 'key' => 'wpsc_tf_type',
3792 'value' => '0',
3793 'compare' => '>',
3794 ),
3795 ),
3796 )
3797 );
3798
3799 $scheule_tickets = get_terms(
3800 array(
3801 'taxonomy' => 'wpsc_schedule_tickets',
3802 'hide_empty' => false,
3803 )
3804 );
3805
3806 foreach ( $scheule_tickets as $prev ) {
3807
3808 $time_unit = get_term_meta( $prev->term_id, 'repeat_every_time_unit', true );
3809 $recurrence = get_term_meta( $prev->term_id, 'no_of_recurrence', true );
3810 $start_date = new DateTime( get_term_meta( $prev->term_id, 'start_date', true ) . ' 00:00:00' );
3811
3812 $rule = array(
3813 'title' => $prev->name,
3814 'recurrence-period' => 'daily',
3815 'daily-recurrence-type' => 'daily-every-day',
3816 'daily-x-days' => 1,
3817 'daily-x-work-days' => 1,
3818 'weekly-x-weeks' => 1,
3819 'weekly-days' => array( 1, 2, 3, 4, 5 ),
3820 'monthly-recurrence-type' => 'monthly-day-number',
3821 'monthly-day-number-x-months' => 1,
3822 'monthly-day-number-day' => 1,
3823 'monthly-week-number-x-months' => 1,
3824 'monthly-week-number-occurrence' => 1,
3825 'monthly-week-number-day' => 1,
3826 'yearly-recurrence-type' => 'yearly-day-number',
3827 'yearly-day-number-x-years' => 1,
3828 'yearly-day-number-day' => 1,
3829 'yearly-day-number-month' => 1,
3830 'yearly-week-number-x-years' => 1,
3831 'yearly-week-number-occurrence' => 1,
3832 'yearly-week-number-day' => 1,
3833 'yearly-week-number-month' => 1,
3834 'starts-on' => ( new DateTime() )->format( 'Y-m-d' ),
3835 'ends-on' => 'no-end-date',
3836 'ends-after-times' => 10,
3837 'end-date' => '',
3838 'ticket-count' => 0,
3839 );
3840
3841 if ( $time_unit == 'days' ) {
3842
3843 $rule['recurrence-period'] = 'daily';
3844 $rule['daily-recurrence-type'] = 'daily-every-day';
3845 $rule['daily-x-days'] = intval( $recurrence );
3846
3847 } else {
3848
3849 $rule['recurrence-period'] = 'monthly';
3850 $rule['monthly-recurrence-type'] = 'monthly-day-number';
3851 $rule['monthly-day-number-x-months'] = intval( $recurrence );
3852 $rule['monthly-day-number-day'] = $start_date->format( 'd' );
3853 }
3854
3855 $rule['starts-on'] = $start_date->format( 'Y-m-d' );
3856 $rule['ends-on'] = 'no-end-date';
3857
3858 // customer.
3859 $customer_name = get_term_meta( $prev->term_id, 'customer_name', true );
3860 $customer_email = get_term_meta( $prev->term_id, 'customer_email', true );
3861 $customer_id = $wpdb->get_var( "SELECT * FROM {$wpdb->prefix}psmsc_customers WHERE email = '" . $customer_email . "'" );
3862 if ( ! $customer_id ) {
3863 $user = get_user_by( 'email', $customer_email );
3864 if ( $user ) {
3865 $wpdb->insert(
3866 $wpdb->prefix . 'psmsc_customers',
3867 array(
3868 'user' => $user->ID,
3869 'name' => $user->display_name,
3870 'email' => $user->user_email,
3871 )
3872 );
3873 } else {
3874 $wpdb->insert(
3875 $wpdb->prefix . 'psmsc_customers',
3876 array(
3877 'user' => 0,
3878 'name' => $customer_name,
3879 'email' => $customer_email,
3880 )
3881 );
3882 }
3883 $customer_id = $wpdb->insert_id;
3884 }
3885 $rule['customer'] = $customer_id;
3886
3887 // subject, description, category & priority.
3888 $rule['subject'] = get_term_meta( $prev->term_id, 'ticket_subject', true );
3889 $rule['description'] = get_term_meta( $prev->term_id, 'ticket_description', true );
3890 $category = get_term_meta( $prev->term_id, 'ticket_category', true );
3891 if ( $category ) {
3892 $rule['category'] = $category_map[ $category ];
3893 }
3894 $priority = get_term_meta( $prev->term_id, 'ticket_priority', true );
3895 if ( $priority ) {
3896 $rule['priority'] = $priority_map[ $priority ];
3897 }
3898
3899 // custom fields.
3900 foreach ( $fields as $field ) {
3901
3902 $type = get_term_meta( $field->term_id, 'wpsc_tf_type', true );
3903 $cf = wpsc_get_cf_by( 'id', $cf_map[ $field->term_id ] );
3904
3905 switch ( $type ) {
3906
3907 case 1:
3908 case 5:
3909 case 7:
3910 case 8:
3911 case 9:
3912 case 11:
3913 $val = get_term_meta( $prev->term_id, $field->slug, true );
3914 if ( $val ) {
3915 $rule[ $cf->slug ] = $val ? $val : '';
3916 }
3917 break;
3918
3919 case 2:
3920 case 4:
3921 $options_map = get_option( 'wpsc_upgrade_cf_options_map' );
3922 $val = get_term_meta( $prev->term_id, $field->slug, true );
3923 if ( $val ) {
3924 $rule[ $cf->slug ] = $options_map[ $cf->id ][ $val ];
3925 }
3926 break;
3927
3928 case 3:
3929 $options_map = get_option( 'wpsc_upgrade_cf_options_map' );
3930 $val = get_term_meta( $prev->term_id, $field->slug, false );
3931 if ( $val ) {
3932 $rule[ $cf->slug ] = implode(
3933 '|',
3934 array_filter(
3935 array_map(
3936 function ( $name ) use ( $options_map, $cf ) {
3937 return $name ? $options_map[ $cf->id ][ $name ] : false;
3938 },
3939 $val
3940 )
3941 )
3942 );
3943 }
3944 break;
3945
3946 case 6:
3947 $val = get_term_meta( $prev->term_id, $field->slug, true );
3948 if ( $val ) {
3949 $old_date_format = get_option( 'wpsc_calender_date_format' );
3950 $val = DateTime::createFromFormat( $date_formats[ $old_date_format ] . ' H:i:s', $val );
3951 if ( $val ) {
3952 $rule[ $cf->slug ] = $val->format( 'Y-m-d' );
3953 }
3954 }
3955 break;
3956
3957 case 18:
3958 $val = get_term_meta( $prev->term_id, $field->slug, true );
3959 if ( $val ) {
3960 $old_date_format = get_option( 'wpsc_calender_date_format' );
3961 $val = DateTime::createFromFormat( $date_formats[ $old_date_format ] . ' H:i:s', $val );
3962 if ( $val ) {
3963 $rule[ $cf->slug ] = $val->format( 'Y-m-d H:i:s' );
3964 }
3965 }
3966 break;
3967
3968 case 21:
3969 $val = get_term_meta( $prev->term_id, $field->slug, true );
3970 if ( $val ) {
3971 $val = new DateTime( $val );
3972 $rule[ $cf->slug ] = $val->format( 'H:i' );
3973 }
3974 break;
3975 }
3976 }
3977
3978 if ( ! $new_rules ) {
3979 $new_rules[1] = $rule;
3980 } else {
3981 $new_rules[] = $rule;
3982 }
3983 }
3984
3985 update_option( 'wpsc-st-rules', $new_rules );
3986
3987 // Shehdule existing ticket.
3988 $general = get_option( 'wpsc-st-general-settings' );
3989 $general['schedule-existing'] = get_option( 'wpsc_schedule_ticket_btn', $general['schedule-existing'] );
3990 update_option( 'wpsc-st-general-settings', $general );
3991
3992 // Add Modify scheduled ticket permissions to all agent roles.
3993 $agent_role = get_option( 'wpsc-agent-roles' );
3994 foreach ( $agent_role as $key => $agent ) {
3995
3996 $agent['caps']['modify-schedule-ticket'] = true;
3997 $agent_role[ $key ] = $agent;
3998 }
3999 update_option( 'wpsc-agent-roles', $agent_role );
4000 }
4001
4002 /**
4003 * Import SLA settings
4004 *
4005 * @return void
4006 */
4007 public static function import_sla_settings() {
4008
4009 $installed_addons = get_option( 'wpsc_upgrade_installed_addons' );
4010 if ( ! $installed_addons[4]['is_installed'] ) {
4011 return;
4012 }
4013
4014 $cf_map = get_option( 'wpsc_upgrade_cf_term_id_map' );
4015 $options_map = get_option( 'wpsc_upgrade_cf_options_map' );
4016 $category_map = get_option( 'wpsc_upgrade_category_map' );
4017 $priority_map = get_option( 'wpsc_upgrade_priority_map' );
4018 $status_map = get_option( 'wpsc_upgrade_status_map' );
4019
4020 // settings.
4021 $settings = get_option( 'wpsc-sla-general-settings' );
4022 $settings['out-sla-bg-color'] = get_option( 'wpsc_out_sla_color', $settings['out-sla-bg-color'] );
4023 $settings['out-sla-text-color'] = '#ffffff';
4024 $settings['in-sla-bg-color'] = get_option( 'wpsc_in_sla_color', $settings['in-sla-bg-color'] );
4025 $settings['in-sla-text-color'] = '#ffffff';
4026 update_option( 'wpsc-sla-general-settings', $settings );
4027
4028 // sla policies.
4029 $policies = get_terms(
4030 array(
4031 'taxonomy' => 'wpsc_sla',
4032 'hide_empty' => false,
4033 'orderby' => 'meta_value_num',
4034 'order' => 'ASC',
4035 'meta_query' => array( 'order_clause' => array( 'key' => 'load_order' ) ),
4036 )
4037 );
4038
4039 $new_policies = array();
4040 $count = 0;
4041 $map = array();
4042
4043 foreach ( $policies as $prev ) {
4044
4045 $time_unit_map = array(
4046 'minutes' => 'minute',
4047 'hours' => 'hour',
4048 'days' => 'day',
4049 'months' => 'month',
4050 'years' => 'year',
4051 );
4052 $time = get_term_meta( $prev->term_id, 'time', true );
4053 $time_unit = get_term_meta( $prev->term_id, 'time_unit', true );
4054
4055 $conditions = array();
4056 $policy = array(
4057 'title' => $prev->name,
4058 'time' => $time,
4059 'time-unit' => $time_unit_map[ $time_unit ],
4060 'calculate-from' => 'date_updated',
4061 'relation' => 'AND',
4062 'conditions' => $conditions ? wp_json_encode( $conditions ) : '{}',
4063 );
4064
4065 $new_policies[ ++$count ] = $policy;
4066 $map[ $prev->term_id ] = $count;
4067 }
4068
4069 update_option( 'wpsc-sla-policies', $new_policies );
4070 update_option( 'wpsc_upgrade_sla_policy_map', $map );
4071 }
4072
4073 /**
4074 * Import usergroup settings
4075 *
4076 * @return void
4077 */
4078 public static function import_usergroup_settings() {
4079
4080 global $wpdb;
4081 $installed_addons = get_option( 'wpsc_upgrade_installed_addons' );
4082 if ( ! $installed_addons[7]['is_installed'] ) {
4083 return;
4084 }
4085
4086 // Importing Other Settings into General setting.
4087 $string_translations = get_option( 'wpsc-string-translation' );
4088 $user_group_term = get_term_by( 'slug', 'usergroup', 'wpsc_ticket_custom_fields' );
4089 if ( $user_group_term ) {
4090 $ug_label = get_term_meta( $user_group_term->term_id, 'wpsc_tf_label', true );
4091 $ticket_widgets = get_option( 'wpsc-ticket-widget' );
4092 $ticket_widgets['usergroups']['title'] = $ug_label;
4093 update_option( 'wpsc-ticket-widget', $ticket_widgets );
4094 }
4095
4096 $ug_general = get_option( 'wpsc-ug-general-settings' );
4097 $ug_general['allow-change-category'] = get_option( 'wpsc_usergroup_change_category', $ug_general['allow-change-category'] );
4098 $ug_general['allow-sup-close-ticket'] = get_option( 'wpsc_allow_ug_sup_close_ticket', $ug_general['allow-sup-close-ticket'] );
4099 update_option( 'wpsc-ug-general-settings', $ug_general );
4100
4101 // Importing UG custom fields.
4102 $cf_map = get_option( 'wpsc_upgrade_cf_term_id_map' );
4103 $cf_slug_map = get_option( 'wpsc_upgrade_cf_slug_map' );
4104
4105 $fields = get_terms(
4106 array(
4107 'taxonomy' => 'wpsc_usergroup_custom_field',
4108 'hide_empty' => false,
4109 'orderby' => 'meta_value_num',
4110 'order' => 'ASC',
4111 'meta_query' => array(
4112 array(
4113 'key' => 'agentonly',
4114 'value' => '3',
4115 'compare' => '=',
4116 ),
4117 ),
4118 )
4119 );
4120
4121 foreach ( $fields as $prev ) {
4122
4123 $label = get_term_meta( $prev->term_id, 'wpsc_tf_label', true );
4124 $extra_info = get_term_meta( $prev->term_id, 'wpsc_tf_extra_info', true );
4125 $type = get_term_meta( $prev->term_id, 'wpsc_tf_type', true );
4126 $personal_info = get_term_meta( $prev->term_id, 'wpsc_tf_personal_info', true );
4127
4128 switch ( intval( $type ) ) {
4129
4130 case 1:
4131 $response = wpsc_upgrade_insert_custom_field(
4132 array(
4133 'name' => $label,
4134 'extra_info' => $extra_info,
4135 'field' => 'usergroup',
4136 'type' => 'cf_textfield',
4137 )
4138 );
4139 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_usergroups ADD " . $response['slug'] . ' TINYTEXT NULL' );
4140 $cf_map[ $prev->term_id ] = $response['id'];
4141 $cf_slug_map[ $prev->slug ] = $response['slug'];
4142 $string_translations[ 'wpsc-cf-name-' . $response['id'] ] = $label;
4143 $string_translations[ 'wpsc-cf-exi-' . $response['id'] ] = $extra_info;
4144 break;
4145
4146 case 2:
4147 $response = wpsc_upgrade_insert_custom_field(
4148 array(
4149 'name' => $label,
4150 'extra_info' => $extra_info,
4151 'field' => 'usergroup',
4152 'type' => 'cf_single_select',
4153 )
4154 );
4155 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_usergroups ADD " . $response['slug'] . ' TINYTEXT NULL' );
4156 $option_strings = self::import_options( $prev, $response['id'] );
4157 $string_translations = array_merge( $string_translations, $option_strings );
4158 $string_translations[ 'wpsc-cf-name-' . $response['id'] ] = $label;
4159 $string_translations[ 'wpsc-cf-exi-' . $response['id'] ] = $extra_info;
4160 $cf_map[ $prev->term_id ] = $response['id'];
4161 $cf_slug_map[ $prev->slug ] = $response['slug'];
4162 break;
4163
4164 case 5:
4165 $response = wpsc_upgrade_insert_custom_field(
4166 array(
4167 'name' => $label,
4168 'extra_info' => $extra_info,
4169 'field' => 'usergroup',
4170 'type' => 'cf_textarea',
4171 )
4172 );
4173 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_usergroups ADD " . $response['slug'] . ' LONGTEXT NULL DEFAULT NULL' );
4174 $cf_map[ $prev->term_id ] = $response['id'];
4175 $cf_slug_map[ $prev->slug ] = $response['slug'];
4176 $string_translations[ 'wpsc-cf-name-' . $response['id'] ] = $label;
4177 $string_translations[ 'wpsc-cf-exi-' . $response['id'] ] = $extra_info;
4178 break;
4179 }
4180 }
4181 update_option( 'wpsc_upgrade_cf_term_id_map', $cf_map );
4182 update_option( 'wpsc_upgrade_cf_slug_map', $cf_slug_map );
4183
4184 $option_map = get_option( 'wpsc_upgrade_cf_options_map' );
4185
4186 // Importing usergroups.
4187 $category_map = get_option( 'wpsc_upgrade_category_map' );
4188 $usergroups = get_terms(
4189 array(
4190 'taxonomy' => 'wpsc_usergroup_data',
4191 'hide_empty' => false,
4192 )
4193 );
4194
4195 $usergroup_map = array();
4196 foreach ( $usergroups as $prev ) {
4197
4198 $members = array();
4199 $prev_members = get_term_meta( $prev->term_id, 'wpsc_usergroup_userid', false );
4200 foreach ( $prev_members as $user_id ) {
4201 $customer_id = $wpdb->get_var( "SELECT id FROM {$wpdb->prefix}psmsc_customers WHERE user = " . $user_id );
4202 if ( ! $customer_id ) {
4203 $user = get_user_by( 'id', $user_id );
4204 $wpdb->insert(
4205 $wpdb->prefix . 'psmsc_customers',
4206 array(
4207 'user' => $user_id,
4208 'name' => $user->display_name,
4209 'email' => $user->user_email,
4210 )
4211 );
4212 $customer_id = $wpdb->insert_id;
4213 }
4214 $members[] = $customer_id;
4215 }
4216
4217 $supervisors = array();
4218 $prev_supervisors = get_term_meta( $prev->term_id, 'wpsc_usergroup_supervisor_id', false );
4219 foreach ( $prev_supervisors as $user_id ) {
4220 $supervisors[] = $wpdb->get_var( "SELECT id FROM {$wpdb->prefix}psmsc_customers WHERE user = " . $user_id );
4221 }
4222
4223 $category = get_term_meta( $prev->term_id, 'wpsc_usergroup_category', true );
4224
4225 $data = array(
4226 'name' => $prev->name,
4227 'members' => implode( '|', $members ),
4228 'supervisors' => implode( '|', $supervisors ),
4229 'category' => $category ? $category_map[ $category ] : '',
4230 );
4231
4232 foreach ( $fields as $field ) {
4233
4234 $cf = wpsc_get_cf_by( 'id', $cf_map[ $field->term_id ] );
4235 if ( $cf->type == 'cf_single_select' ) {
4236 $option = get_term_meta( $prev->term_id, $field->slug, true );
4237 if ( $option ) {
4238 $data[ $cf->slug ] = $option_map[ $cf->id ][ $option ];
4239 }
4240 } else {
4241 $data[ $cf->slug ] = get_term_meta( $prev->term_id, $field->slug, true );
4242 }
4243 }
4244
4245 $wpdb->insert( $wpdb->prefix . 'psmsc_usergroups', $data );
4246 $usergroup_map[ $prev->term_id ] = $wpdb->insert_id;
4247 }
4248 update_option( 'wpsc-string-translation', $string_translations );
4249 update_option( 'wpsc_upgrade_ug_term_id_map', $usergroup_map );
4250 }
4251
4252 /**
4253 * Import EDD settings
4254 *
4255 * @return void
4256 */
4257 public static function import_edd_settings() {}
4258
4259 /**
4260 * Import gravity settings
4261 *
4262 * @return void
4263 */
4264 public static function import_gravity_settings() {
4265
4266 global $wpdb;
4267 $installed_addons = get_option( 'wpsc_upgrade_installed_addons' );
4268 if ( ! $installed_addons[9]['is_installed'] || ! class_exists( 'GFForms' ) ) {
4269 return;
4270 }
4271
4272 $allowed_mapping_types = array(
4273 'cf_textfield' => array( 'name', 'text', 'email', 'number', 'hidden', 'date', 'time', 'phone', 'website' ),
4274 'cf_multi_select' => array( 'multiselect', 'select' ),
4275 'cf_single_select' => array( 'select', 'hidden' ),
4276 'cf_radio_button' => array( 'radio', 'hidden' ),
4277 'cf_checkbox' => array( 'checkbox', 'hidden' ),
4278 'cf_textarea' => array( 'textarea', 'name', 'text', 'email', 'number', 'hidden', 'date', 'time', 'phone', 'website', 'address' ),
4279 'cf_date' => array( 'date', 'hidden' ),
4280 'cf_datetime' => array( 'date', 'hidden' ),
4281 'cf_number' => array( 'number', 'hidden' ),
4282 'cf_email' => array( 'email', 'hidden' ),
4283 'cf_url' => array( 'website', 'hidden' ),
4284 'cf_time' => array( 'time', 'hidden' ),
4285 'cf_file_attachment_multiple' => array( 'fileupload' ),
4286 'cf_file_attachment_single' => array( 'fileupload' ),
4287 'df_customer_name' => array( 'name', 'text' ),
4288 'df_customer_email' => array( 'email' ),
4289 'df_subject' => array( 'name', 'text', 'email', 'number', 'hidden', 'date', 'time', 'phone', 'website' ),
4290 'df_description' => array( 'textarea', 'name', 'text', 'email', 'number', 'hidden', 'date', 'time', 'phone', 'website', 'address' ),
4291 'df_status' => array( 'select', 'radio', 'hidden' ),
4292 'df_priority' => array( 'select', 'radio', 'hidden' ),
4293 'df_category' => array( 'select', 'radio', 'hidden' ),
4294 'df_add_recipients' => array( 'email' ),
4295 );
4296
4297 $gravity_forms = get_terms(
4298 array(
4299 'taxonomy' => 'wpsc_gf',
4300 'hide_empty' => false,
4301 )
4302 );
4303
4304 $cf_map = get_option( 'wpsc_upgrade_cf_term_id_map' );
4305 $options_map = get_option( 'wpsc_upgrade_cf_options_map' );
4306 $category_map = get_option( 'wpsc_upgrade_category_map' );
4307 $priority_map = get_option( 'wpsc_upgrade_priority_map' );
4308
4309 $index = 1;
4310 $gf_integrations = array();
4311 foreach ( $gravity_forms as $form ) {
4312
4313 $gform_id = get_term_meta( $form->term_id, 'wpsc_gravity_form_id', true );
4314 $gform = GFAPI::get_form( $gform_id );
4315 if ( ! $gform ) {
4316 continue;
4317 }
4318 $mapping = array();
4319 $option_mapping = array();
4320 $mapping_values = get_term_meta( $form->term_id, 'wpsc_gf_mapping_values', true );
4321 foreach ( $mapping_values as $key => $field ) {
4322
4323 if ( ! $field ) {
4324 continue;
4325 }
4326
4327 $cf = wpsc_get_cf_by( 'id', $cf_map[ $key ] );
4328 if ( ! $cf ) {
4329 continue;
4330 }
4331
4332 $gfield = GFFormsModel::get_field( $gform, $field );
4333 if ( ! ( $gfield && isset( $allowed_mapping_types[ $cf->type ] ) && in_array( $gfield->type, $allowed_mapping_types[ $cf->type ] ) ) ) {
4334 continue;
4335 }
4336
4337 $mapping[ $cf->slug ] = $field;
4338
4339 // option mapping.
4340 if ( in_array( $cf->type, array( 'cf_checkbox', 'cf_radio_button', 'cf_single_select' ) ) ) {
4341
4342 if ( $gfield->type != 'hidden' ) {
4343
4344 $opts = array();
4345 foreach ( $options_map[ $cf->id ] as $key => $option ) {
4346 foreach ( $gfield->choices as $goption ) {
4347 if ( $goption['value'] == $key ) {
4348 $opts[ $option ] = $goption['value'];
4349 }
4350 }
4351 }
4352 $option_mapping[ $cf->slug ] = $opts;
4353 } else {
4354
4355 $gf = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}gf_form_meta WHERE form_id = $gform_id", ARRAY_A );
4356 $form_fields = json_decode( $gf['display_meta'], true );
4357 $key = array_search( $field, array_column( $form_fields['fields'], 'id' ) );
4358 $hf_val = $form_fields['fields'][ $key ]['defaultValue'];
4359 $form_fields['fields'][ $key ]['defaultValue'] = $options_map[ $cf->id ][ $hf_val ];
4360 $display_meta = wp_json_encode( $form_fields );
4361
4362 $success = $wpdb->update(
4363 $wpdb->prefix . 'gf_form_meta',
4364 array( 'display_meta' => $display_meta ),
4365 array( 'form_id' => $gform_id )
4366 );
4367 }
4368 } elseif ( $cf->slug == 'category' ) {
4369
4370 if ( $gfield->type != 'hidden' ) {
4371
4372 $opts = array();
4373 foreach ( $category_map as $key => $category ) {
4374 foreach ( $gfield->choices as $goption ) {
4375 if ( $goption['value'] == $key ) {
4376 $opts[ $category ] = $goption['value'];
4377 }
4378 }
4379 }
4380 $option_mapping[ $cf->slug ] = $opts;
4381 } else {
4382
4383 $gf = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}gf_form_meta WHERE form_id = $gform_id", ARRAY_A );
4384 $form_fields = json_decode( $gf['display_meta'], true );
4385 $key = array_search( $field, array_column( $form_fields['fields'], 'id' ) );
4386 $hf_val = $form_fields['fields'][ $key ]['defaultValue'];
4387 $form_fields['fields'][ $key ]['defaultValue'] = $category_map[ $hf_val ];
4388 $display_meta = wp_json_encode( $form_fields );
4389
4390 $success = $wpdb->update(
4391 $wpdb->prefix . 'gf_form_meta',
4392 array( 'display_meta' => $display_meta ),
4393 array( 'form_id' => $gform_id )
4394 );
4395 }
4396 } elseif ( $cf->slug == 'priority' ) {
4397
4398 if ( $gfield->type != 'hidden' ) {
4399
4400 $opts = array();
4401 foreach ( $priority_map as $key => $priority ) {
4402 foreach ( $gfield->choices as $goption ) {
4403 if ( $goption['value'] == $key ) {
4404 $opts[ $priority ] = $goption['value'];
4405 }
4406 }
4407 }
4408 $option_mapping[ $cf->slug ] = $opts;
4409 } else {
4410
4411 $gf = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}gf_form_meta WHERE form_id = $gform_id", ARRAY_A );
4412 $form_fields = json_decode( $gf['display_meta'], true );
4413 $key = array_search( $field, array_column( $form_fields['fields'], 'id' ) );
4414 $hf_val = $form_fields['fields'][ $key ]['defaultValue'];
4415 $form_fields['fields'][ $key ]['defaultValue'] = $priority_map[ $hf_val ];
4416 $display_meta = wp_json_encode( $form_fields );
4417
4418 $success = $wpdb->update(
4419 $wpdb->prefix . 'gf_form_meta',
4420 array( 'display_meta' => $display_meta ),
4421 array( 'form_id' => $gform_id )
4422 );
4423 }
4424 }
4425 }
4426
4427 $mappings = array(
4428 'title' => $gform['title'],
4429 'form' => $gform_id,
4430 'is_enable' => 1,
4431 'mappings' => $mapping,
4432 'options' => $option_mapping,
4433 );
4434 $gf_integrations[ $index ] = $mappings;
4435 ++$index;
4436 }
4437
4438 update_option( 'wpsc-gf-integrations', $gf_integrations );
4439 }
4440
4441 /**
4442 * Import timer settings
4443 *
4444 * @return void
4445 */
4446 public static function import_timer_settings() {
4447
4448 $installed_addons = get_option( 'wpsc_upgrade_installed_addons' );
4449 if ( ! $installed_addons[13]['is_installed'] ) {
4450 return;
4451 }
4452
4453 // Import timer setting.
4454 $setting = get_option( 'wpsc-timer-settings' );
4455 $setting['auto-start'] = get_option( 'wpsc_timer_enable', $setting['auto-start'] );
4456 $setting['auto-stop'] = get_option( 'wpsc_timer_stop', $setting['auto-stop'] );
4457 update_option( 'wpsc-timer-settings', $setting );
4458
4459 $tw_setting = get_option( 'wpsc-ticket-widget' );
4460 $tw_setting['timer']['allow-customer'] = intval( get_option( 'wpsc_timer_visibility_for_customer' ) );
4461 update_option( 'wpsc-ticket-widget', $tw_setting );
4462
4463 $agent_roles = get_option( 'wpsc-agent-roles' );
4464 foreach ( $agent_roles as $index => $role ) {
4465 $role['caps']['modify-timer-log'] = $index == 1 ? true : false;
4466 $agent_roles[ $index ] = $role;
4467 }
4468 update_option( 'wpsc-agent-roles', $agent_roles );
4469 }
4470
4471 /**
4472 * Import private credentials settings
4473 *
4474 * @return void
4475 */
4476 public static function import_pc_settings() {
4477
4478 $installed_addons = get_option( 'wpsc_upgrade_installed_addons' );
4479 if ( ! $installed_addons[17]['is_installed'] ) {
4480 return;
4481 }
4482
4483 // Add PC role permissions.
4484 $agent_role = get_option( 'wpsc-agent-roles' );
4485 $role = get_option( 'wpsc_pc_role_permissions' );
4486
4487 foreach ( $agent_role as $key => $agent ) {
4488
4489 $checked_view = isset( $role[ $key ]['role_view'] ) ? true : false;
4490 $checked_edit = isset( $role[ $key ]['role_modify'] ) ? true : false;
4491 $checked_delete = isset( $role[ $key ]['role_delete'] ) ? true : false;
4492 $match = isset( $role[ $key ] ) ? $role[ $key ]['role_matching_criteria'] : 0;
4493
4494 $agent['caps']['view-pc-unassigned'] = $match == 1 ? $checked_view : false;
4495 $agent['caps']['view-pc-assigned-me'] = $checked_view;
4496 $agent['caps']['view-pc-assigned-others'] = $match == 1 ? $checked_view : false;
4497
4498 $agent['caps']['modify-pc-unassigned'] = $match == 1 ? $checked_edit : false;
4499 $agent['caps']['modify-pc-assigned-me'] = $checked_edit;
4500 $agent['caps']['modify-pc-assigned-others'] = $match == 1 ? $checked_edit : false;
4501
4502 $agent['caps']['delete-pc-unassigned'] = $match == 1 ? $checked_delete : false;
4503 $agent['caps']['delete-pc-assigned-me'] = $checked_delete;
4504 $agent['caps']['delete-pc-assigned-others'] = $match == 1 ? $checked_delete : false;
4505
4506 $agent_role[ $key ] = $agent;
4507 }
4508 update_option( 'wpsc-agent-roles', $agent_role );
4509 }
4510
4511 /**
4512 * Import print ticket settings
4513 *
4514 * @return void
4515 */
4516 public static function import_print_settings() {
4517
4518 $installed_addons = get_option( 'wpsc_upgrade_installed_addons' );
4519 if ( ! $installed_addons[18]['is_installed'] ) {
4520 return;
4521 }
4522
4523 $string_translations = get_option( 'wpsc-string-translation' );
4524 // Importing Print ticket gneneral setting.
4525 $settings = get_option( 'wpsc-pt-general-settings' );
4526 $settings['thankyou-page-button'] = get_option( 'wpsc_print_th_btn_setting', $settings['thankyou-page-button'] );
4527 $settings['button-label'] = get_option( 'wpsc_print_btn_lbl', $settings['button-label'] );
4528 $settings['allow-print-to-customer'] = get_option( 'wpsc_print_cust_btn_setting', $settings['allow-print-to-customer'] );
4529 update_option( 'wpsc-pt-general-settings', $settings );
4530
4531 // Importing Print ticket templete setting.
4532 $temp_settings = get_option( 'wpsc-pt-template-settings' );
4533 $header = wpsc_upgrade_macros( get_option( 'wpsc_print_ticket_header', $temp_settings['header']['text'] ) );
4534 $body = wpsc_upgrade_macros( get_option( 'wpsc_print_ticket_body', $temp_settings['body']['text'] ) );
4535 $footer = wpsc_upgrade_macros( get_option( 'wpsc_print_ticket_footer', $temp_settings['footer']['text'] ) );
4536 $temp_settings['header-height'] = get_option( 'wpsc_print_page_header_height', $temp_settings['header-height'] );
4537 $temp_settings['footer-height'] = get_option( 'wpsc_print_page_footer_height', $temp_settings['footer-height'] );
4538 $temp_settings['header']['text'] = $header;
4539 $temp_settings['body']['text'] = $body;
4540 $temp_settings['footer']['text'] = $footer;
4541 update_option( 'wpsc-pt-template-settings', $temp_settings );
4542
4543 $string_translations['wpsc-pt-header'] = $header;
4544 $string_translations['wpsc-pt-body'] = $body;
4545 $string_translations['wpsc-pt-footer'] = $footer;
4546 update_option( 'wpsc-string-translation', $string_translations );
4547 }
4548
4549 /**
4550 * Import TinyMCE settings
4551 *
4552 * @return void
4553 */
4554 public static function import_tinymce_settings() {
4555
4556 $agent_user = get_option( 'wpsc-te-agent' );
4557 $reg_user = get_option( 'wpsc-te-registered-user' );
4558 $guest_user = get_option( 'wpsc-te-guest-user' );
4559
4560 // Importing toolbar setting.
4561 $toolbar = get_option( 'wpsc_tinymce_toolbar' );
4562 if ( $toolbar !== false ) {
4563 $old = get_option( 'wpsc_tinymce_toolbar_active' );
4564 $new = array();
4565 foreach ( $old as $key ) {
4566 $new[] = $toolbar[ $key ]['value'] == 'image' ? 'wpsc_insert_editor_img' : $toolbar[ $key ]['value'];
4567 }
4568 $agent_user['toolbar'] = $new;
4569 $reg_user['toolbar'] = $new;
4570 $guest_user['toolbar'] = $new;
4571 }
4572
4573 // Agent user.
4574 update_option( 'wpsc-te-agent', $agent_user );
4575
4576 // Registered user.
4577 $allow_rich_text_editor = array( 'register_user', 'guest_user' );
4578 $reg_user['enable'] = in_array( 'register_user', get_option( 'wpsc_allow_rich_text_editor', $allow_rich_text_editor ) ) ? 1 : 0;
4579 update_option( 'wpsc-te-registered-user', $reg_user );
4580
4581 // Guest user.
4582 $guest_user['enable'] = in_array( 'guest_user', get_option( 'wpsc_allow_rich_text_editor', $allow_rich_text_editor ) ) ? 1 : 0;
4583 update_option( 'wpsc-te-guest-user', $guest_user );
4584
4585 // HTML pasting.
4586 $html_pasting = get_option( 'wpsc-te-advanced' );
4587 $html_pasting['html-pasting'] = get_option( 'wpsc_allow_html_pasting', $html_pasting['html-pasting'] );
4588 update_option( 'wpsc-te-advanced', $html_pasting );
4589 }
4590
4591 /**
4592 * Import attachment settings
4593 *
4594 * @return void
4595 */
4596 public static function import_attachment_settings() {
4597
4598 // Import file attachment setting.
4599 $file_settings = get_option( 'wpsc-gs-file-attachments' );
4600 $file_settings['attachments-max-filesize'] = get_option( 'wpsc_attachment_max_filesize', $file_settings['attachments-max-filesize'] );
4601 $file_settings['allowed-file-extensions'] = get_option( 'wpsc_allow_attachment_type', $file_settings['allowed-file-extensions'] );
4602 $download_method = intval( get_option( 'wpsc_image_download_method' ) );
4603 $file_settings['image-download-behaviour'] = $download_method == 1 ? 'open-browser' : 'download';
4604 update_option( 'wpsc-gs-file-attachments', $file_settings );
4605
4606 // Import file attachment setting for agent.
4607 $allow_attach_create_ticket = array( 'agents', 'customers', 'guests' );
4608 $allow_attach_reply_form = array( 'agents', 'customers', 'guests' );
4609 $agent_user = get_option( 'wpsc-te-agent' );
4610 $agent_user['allow-attachments'] = ( in_array( 'agents', get_option( 'wpsc_allow_attach_create_ticket', $allow_attach_create_ticket ) ) || in_array( 'agents', get_option( 'wpsc_allow_attach_reply_form', $allow_attach_reply_form ) ) ) ? 1 : 0;
4611 $agent_user['file-attachment-notice'] = get_option( 'wpsc_show_attachment_notice', $agent_user['file-attachment-notice'] );
4612 $agent_user['file-attachment-notice-text'] = get_option( 'wpsc_attachment_notice', $agent_user['file-attachment-notice-text'] );
4613 update_option( 'wpsc-te-agent', $agent_user );
4614
4615 // Import file attachment setting for registered user.
4616 $reg_user = get_option( 'wpsc-te-registered-user' );
4617 $reg_user['allow-attachments'] = ( in_array( 'customers', get_option( 'wpsc_allow_attach_create_ticket', $allow_attach_create_ticket ) ) || in_array( 'customers', get_option( 'wpsc_allow_attach_reply_form', $allow_attach_reply_form ) ) ) ? 1 : 0;
4618 $reg_user['file-attachment-notice'] = get_option( 'wpsc_show_attachment_notice', $reg_user['file-attachment-notice'] );
4619 $reg_user['file-attachment-notice-text'] = get_option( 'wpsc_attachment_notice', $reg_user['file-attachment-notice-text'] );
4620 update_option( 'wpsc-te-registered-user', $reg_user );
4621
4622 // Import file attachment setting for guest user.
4623 $guest_user = get_option( 'wpsc-te-guest-user' );
4624 $guest_user['allow-attachments'] = ( in_array( 'guests', get_option( 'wpsc_allow_attach_create_ticket', $allow_attach_create_ticket ) ) || in_array( 'guests', get_option( 'wpsc_allow_attach_reply_form', $allow_attach_reply_form ) ) ) ? 1 : 0;
4625 $guest_user['file-attachment-notice'] = get_option( 'wpsc_show_attachment_notice', $guest_user['file-attachment-notice'] );
4626 $guest_user['file-attachment-notice-text'] = get_option( 'wpsc_attachment_notice', $guest_user['file-attachment-notice-text'] );
4627 update_option( 'wpsc-te-guest-user', $guest_user );
4628 }
4629
4630 /**
4631 * Import single ticket
4632 *
4633 * @param stdClass $ticket - ticket collection.
4634 * @return void
4635 */
4636 public static function import_individual_ticket( $ticket ) {
4637
4638 global $wpdb;
4639
4640 // destroy existing ticket if already imported.
4641 $ticket_id = $wpdb->get_var( "SELECT id FROM {$wpdb->prefix}psmsc_tickets WHERE id = " . $ticket->id );
4642 if ( $ticket_id ) {
4643 wpsc_destroy_existing_ticket( $ticket_id );
4644 }
4645
4646 $fields = get_terms(
4647 array(
4648 'taxonomy' => 'wpsc_ticket_custom_fields',
4649 'hide_empty' => false,
4650 'orderby' => 'term_id',
4651 'order' => 'ASC',
4652 )
4653 );
4654
4655 $cf_map = get_option( 'wpsc_upgrade_cf_term_id_map' );
4656 $data = array();
4657
4658 foreach ( $fields as $prev ) {
4659
4660 $type = get_term_meta( $prev->term_id, 'wpsc_tf_type', true );
4661
4662 if ( ! isset( $cf_map[ $prev->term_id ] ) || $prev->slug == 'ticket_description' ) {
4663 continue;
4664 }
4665
4666 $cf = wpsc_get_cf_by( 'id', $cf_map[ $prev->term_id ] );
4667
4668 if ( intval( $type ) === 0 ) {
4669
4670 switch ( $prev->slug ) {
4671
4672 case 'ticket_id':
4673 $data[ $cf->slug ] = $ticket->id;
4674 break;
4675
4676 case 'customer_name':
4677 case 'customer_email':
4678 case 'ticket_subject':
4679 case 'date_created':
4680 case 'date_updated':
4681 $data[ $cf->slug ] = $ticket->{$prev->slug};
4682 break;
4683
4684 case 'ticket_status':
4685 $map = get_option( 'wpsc_upgrade_status_map' );
4686 $data[ $cf->slug ] = $map[ $ticket->ticket_status ];
4687 break;
4688
4689 case 'ticket_category':
4690 $map = get_option( 'wpsc_upgrade_category_map' );
4691 $data[ $cf->slug ] = $map[ $ticket->ticket_category ];
4692 break;
4693
4694 case 'ticket_priority':
4695 $map = get_option( 'wpsc_upgrade_priority_map' );
4696 $data[ $cf->slug ] = $map[ $ticket->ticket_priority ];
4697 break;
4698
4699 case 'agent_created':
4700 $map = get_option( 'wpsc_upgrade_agent_map' );
4701 $data[ $cf->slug ] = $ticket->agent_created ? $map[ $ticket->agent_created ] : 0;
4702 break;
4703
4704 case 'assigned_agent':
4705 $map = get_option( 'wpsc_upgrade_agent_map' );
4706 $val = array_filter(
4707 array_map(
4708 function ( $agent_id ) use ( $map ) {
4709 return $agent_id && array_key_exists( $agent_id, $map ) ? $map[ $agent_id ] : '';
4710 },
4711 get_ticket_meta( $ticket->id, $prev->slug )
4712 )
4713 );
4714 $data[ $cf->slug ] = implode( '|', $val );
4715 break;
4716
4717 case 'sf_rating':
4718 $map = get_option( 'wpsc_upgrade_sf_rating_map' );
4719 $val = get_ticket_meta( $ticket->id, $prev->slug, true );
4720 if ( is_numeric( $val ) ) {
4721 $data[ $cf->slug ] = $map[ $val ];
4722 }
4723 break;
4724
4725 case 'sla':
4726 $val = get_ticket_meta( $ticket->id, $prev->slug, true );
4727 if ( $val && $val != '3099-01-01 00:00:00' ) {
4728 $policy_map = get_option( 'wpsc_upgrade_sla_policy_map' );
4729 $data[ $cf->slug ] = $val;
4730
4731 $policy_id = get_ticket_meta( $ticket->id, 'sla_term', true );
4732 if ( $policy_id ) {
4733 $data['sla_policy'] = $policy_map[ get_ticket_meta( $ticket->id, 'sla_term', true ) ];
4734 }
4735
4736 $od_email = get_ticket_meta( $ticket->id, 'wpsp_out_of_sla_email_send', true );
4737 if ( $policy_id ) {
4738 $data['od_email'] = get_ticket_meta( $ticket->id, 'wpsp_out_of_sla_email_send', true );
4739 }
4740 }
4741 break;
4742 }
4743 } else {
4744
4745 switch ( intval( $type ) ) {
4746
4747 case 1:
4748 case 5:
4749 case 6:
4750 case 7:
4751 case 8:
4752 case 9:
4753 case 11:
4754 case 12:
4755 case 13:
4756 case 14:
4757 case 18:
4758 $data[ $cf->slug ] = get_ticket_meta( $ticket->id, $prev->slug, true );
4759 break;
4760
4761 case 2:
4762 case 4:
4763 $options = wpsc_get_cf_options( $cf->id );
4764 $val = get_ticket_meta( $ticket->id, $prev->slug, true );
4765 foreach ( $options as $option ) {
4766 if ( $option->name == $val ) {
4767 $data[ $cf->slug ] = $option->id;
4768 break;
4769 }
4770 }
4771 break;
4772
4773 case 3:
4774 $options = wpsc_get_cf_options( $cf->id );
4775 $prev_val = get_ticket_meta( $ticket->id, $prev->slug );
4776 $new_val = array();
4777 foreach ( $options as $option ) {
4778 if ( in_array( $option->name, $prev_val ) ) {
4779 $new_val[] = $option->id;
4780 }
4781 }
4782 $data[ $cf->slug ] = implode( '|', $new_val );
4783 break;
4784
4785 case 10:
4786 $prev_val = array_filter( get_ticket_meta( $ticket->id, $prev->slug ) );
4787 $new_val = array();
4788 $upload_dir = wp_upload_dir();
4789 foreach ( $prev_val as $item ) {
4790 $term_meta = get_term_meta( $item );
4791 if ( ! $term_meta ) {
4792 continue;
4793 }
4794 $filepath = '/wpsc/' . $term_meta['save_file_name'][0];
4795 if ( isset( $term_meta['is_restructured'] ) && $term_meta['is_restructured'][0] ) {
4796 $updated_time = $term_meta['time_uploaded'][0];
4797 $time = strtotime( $updated_time );
4798 $month = date( 'm', $time ); // phpcs:ignore
4799 $year = date( 'Y', $time ); // phpcs:ignore
4800 $filepath = '/wpsc/' . $year . '/' . $month . '/' . $term_meta['save_file_name'][0];
4801 }
4802 $wpdb->insert(
4803 $wpdb->prefix . 'psmsc_attachments',
4804 array(
4805 'name' => $term_meta['filename'][0],
4806 'file_path' => $filepath,
4807 'is_image' => $term_meta['is_image'][0],
4808 'is_active' => 1,
4809 'date_created' => $term_meta['time_uploaded'][0],
4810 'source' => 'cf',
4811 'source_id' => $cf->id,
4812 'ticket_id' => $data['id'],
4813 )
4814 );
4815 $new_val[] = $wpdb->insert_id;
4816 }
4817 $data[ $cf->slug ] = implode( '|', $new_val );
4818 break;
4819
4820 case 21:
4821 $val = get_ticket_meta( $ticket->id, $prev->slug, true );
4822 if ( $val ) {
4823 $val = new DateTime( $val );
4824 $data[ $cf->slug ] = $val->format( 'H:i' );
4825 }
4826 break;
4827 }
4828 }
4829 }
4830
4831 // customer record if not exists.
4832 $customer = wpsc_import_customer( $data['name'], $data['email'] );
4833 $data['customer'] = $customer->id;
4834 unset( $data['name'] );
4835 unset( $data['email'] );
4836
4837 // user type.
4838 $data['user_type'] = $customer->user ? 'registered' : 'guest';
4839
4840 // deleted.
4841 $data['is_active'] = $ticket->active;
4842
4843 // IP address.
4844 $data['ip_address'] = $ticket->ip_address;
4845
4846 // Additional recipients.
4847 $ad_recep = get_ticket_meta( $ticket->id, 'extra_ticket_users' );
4848 $data['add_recipients'] = implode( '|', $ad_recep );
4849
4850 // Auth code.
4851 $data['auth_code'] = $ticket->ticket_auth_code;
4852
4853 // create ticket record.
4854 $wpdb->insert(
4855 $wpdb->prefix . 'psmsc_tickets',
4856 $data
4857 );
4858
4859 $ticket = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}psmsc_tickets WHERE id = " . $wpdb->insert_id );
4860
4861 // import ticket threads.
4862 self::import_ticket_threads( $ticket );
4863 }
4864
4865 /**
4866 * Import ticket threads
4867 *
4868 * @param stdClass $ticket - ticket object.
4869 * @return void
4870 */
4871 public static function import_ticket_threads( $ticket ) {
4872
4873 global $wpdb;
4874 $gs = get_option( 'wpsc-gs-general' );
4875 $tl_advanced = get_option( 'wpsc-tl-ms-advanced' );
4876 $installed_addons = get_option( 'wpsc_upgrade_installed_addons' );
4877
4878 $threads = get_posts(
4879 array(
4880 'post_type' => 'wpsc_ticket_thread',
4881 'post_status' => 'publish',
4882 'orderby' => 'date',
4883 'order' => 'ASC',
4884 'posts_per_page' => -1,
4885 'meta_query' => array(
4886 'relation' => 'AND',
4887 array(
4888 'key' => 'ticket_id',
4889 'value' => $ticket->id,
4890 'compare' => '=',
4891 ),
4892 ),
4893 )
4894 );
4895
4896 // ticket update data.
4897 $ticket_data = array();
4898
4899 // last reply thread.
4900 $last_thread = null;
4901
4902 // first response delay.
4903 $frd = 0;
4904
4905 // average response delay.
4906 $ard = 0;
4907
4908 // communication gap.
4909 $cg = 1;
4910
4911 // report temp variables.
4912 $count = 0;
4913 $last_reply_by = 'customer';
4914 $last_reply_time = new DateTime( $ticket->date_created );
4915 $delay = 0;
4916
4917 foreach ( $threads as $thread ) {
4918
4919 $thread_type = get_post_meta( $thread->ID, 'thread_type', true );
4920
4921 $ip_address = get_post_meta( $thread->ID, 'ip_address', true );
4922 $source = get_post_meta( $thread->ID, 'reply_source', true );
4923 $os = get_post_meta( $thread->ID, 'os', true );
4924 $browser = get_post_meta( $thread->ID, 'browser', true );
4925
4926 if ( in_array( $thread_type, array( 'report', 'reply', 'note' ) ) ) {
4927
4928 // thread_customer import.
4929 $customer_name = get_post_meta( $thread->ID, 'customer_name', true );
4930 $customer_email = get_post_meta( $thread->ID, 'customer_email', true );
4931 $customer = wpsc_import_customer( $customer_name, $customer_email );
4932
4933 // create thread record.
4934 $wpdb->insert(
4935 $wpdb->prefix . 'psmsc_threads',
4936 array(
4937 'ticket' => $ticket->id,
4938 'customer' => $customer->id,
4939 'type' => $thread_type,
4940 'body' => $thread->post_content,
4941 'date_created' => $thread->post_date,
4942 'date_updated' => $thread->post_date,
4943 'ip_address' => $ip_address,
4944 'source' => $source,
4945 'os' => $os,
4946 'browser' => $browser,
4947 )
4948 );
4949 $new_thread = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}psmsc_threads WHERE id = " . $wpdb->insert_id );
4950
4951 // Source, OS, browser.
4952 if ( $new_thread->type == 'report' ) {
4953 $ticket_data['source'] = $new_thread->source;
4954 $ticket_data['os'] = $new_thread->os;
4955 $ticket_data['browser'] = $new_thread->browser;
4956 $last_thread = $new_thread;
4957 }
4958
4959 // Calculate response delays.
4960 if ( $new_thread->type == 'reply' ) {
4961 ++$cg;
4962 $current_reply_by = 'customer';
4963 if ( $ticket->customer != $new_thread->customer && wpsc_is_agent( $new_thread->customer ) ) {
4964 $current_reply_by = 'agent';
4965 }
4966 if ( $last_reply_by == 'customer' && $current_reply_by == 'agent' ) {
4967 ++$count;
4968 $diff = ceil( abs( $last_reply_time->getTimestamp() - ( new DateTime( $new_thread->date_created ) )->getTimestamp() ) / 60 );
4969 if ( $count == 1 ) {
4970 $frd = $diff;
4971 }
4972 $delay += $diff;
4973 }
4974 if ( $last_reply_by == 'agent' && $current_reply_by == 'customer' ) {
4975 $last_reply_time = new DateTime( $new_thread->date_created );
4976 }
4977 $last_reply_by = $current_reply_by;
4978 }
4979
4980 if ( $new_thread->type == 'report' || $new_thread->type == 'reply' ) {
4981 $last_thread = $new_thread;
4982 }
4983
4984 // Handle attachments.
4985 $prev = get_post_meta( $thread->ID, 'attachments', true );
4986 $new = array();
4987 $upload_dir = wp_upload_dir();
4988 foreach ( $prev as $item ) {
4989
4990 $term_meta = get_term_meta( $item );
4991 if ( ! $term_meta ) {
4992 continue;
4993 }
4994
4995 $filepath = '/wpsc/' . $term_meta['save_file_name'][0];
4996 if ( isset( $term_meta['is_restructured'] ) && $term_meta['is_restructured'][0] ) {
4997 $updated_time = $term_meta['time_uploaded'][0];
4998 $time = strtotime( $updated_time );
4999 $month = date( 'm', $time ); // phpcs:ignore
5000 $year = date( 'Y', $time ); // phpcs:ignore
5001 $filepath = '/wpsc/' . $year . '/' . $month . '/' . $term_meta['save_file_name'][0];
5002 }
5003
5004 $wpdb->insert(
5005 $wpdb->prefix . 'psmsc_attachments',
5006 array(
5007 'name' => $term_meta['filename'][0],
5008 'file_path' => $filepath,
5009 'is_image' => $term_meta['is_image'][0],
5010 'is_active' => 1,
5011 'date_created' => $term_meta['time_uploaded'][0],
5012 'source' => $thread_type,
5013 'source_id' => $new_thread->id,
5014 'ticket_id' => $ticket->id,
5015 )
5016 );
5017 $new[] = $wpdb->insert_id;
5018 }
5019
5020 // update attachments to db.
5021 $wpdb->update(
5022 $wpdb->prefix . 'psmsc_threads',
5023 array(
5024 'attachments' => implode( '|', $new ),
5025 'body' => self::import_uploaded_thread_images( $new_thread->body, $new_thread, $ticket ),
5026 ),
5027 array( 'id' => $new_thread->id )
5028 );
5029
5030 } elseif ( $thread_type == 'log' ) {
5031
5032 $wpdb->insert(
5033 $wpdb->prefix . 'psmsc_threads',
5034 array(
5035 'ticket' => $ticket->id,
5036 'customer' => 0,
5037 'type' => 'log',
5038 'body' => $thread->post_content,
5039 'date_created' => $thread->post_date,
5040 'date_updated' => $thread->post_date,
5041 'ip_address' => $ip_address,
5042 'source' => $source,
5043 'os' => $os,
5044 'browser' => $browser,
5045 )
5046 );
5047
5048 } elseif ( $installed_addons[15]['is_installed'] && $thread_type == 'feedback' ) {
5049 // Add ticket feedback (satisfaction survey).
5050 $ticket_data['sf_feedback'] = $thread->post_content;
5051 $ticket_data['sf_date'] = $thread->post_date;
5052 }
5053 }
5054
5055 // date_closed was not available in v1 so date_updated is considered as date closed for closed tickets.
5056 if ( ! isset( $ticket->date_closed ) && ( $ticket->status == $gs['close-ticket-status'] || in_array( $ticket->status, $tl_advanced['closed-ticket-statuses'] ) ) ) {
5057 $ticket_data['date_closed'] = $ticket->date_updated;
5058 }
5059
5060 // last reply by and last reply on.
5061 if ( $last_thread ) {
5062 $ticket_data['last_reply_by'] = $last_thread->customer;
5063 $ticket_data['last_reply_on'] = $last_thread->date_created;
5064 }
5065
5066 // report add-on.
5067 if ( $installed_addons[6]['is_installed'] ) {
5068 $ticket_data['frd'] = $frd;
5069 if ( $count ) {
5070 $ticket_data['ard'] = ceil( $delay / $count );
5071 }
5072 $ticket_data['cg'] = $cg;
5073 if ( $ticket->status == $gs['close-ticket-status'] || in_array( $ticket->status, $tl_advanced['closed-ticket-statuses'] ) ) {
5074 $ticket_data['cd'] = ceil( abs( ( new DateTime( $ticket->date_created ) )->getTimestamp() - ( new DateTime( $ticket->date_closed ) )->getTimestamp() ) / 60 );
5075 }
5076 }
5077
5078 // import addtional recepients usergroup.
5079 if ( $installed_addons[7]['is_installed'] ) {
5080 $ug_map = get_option( 'wpsc_upgrade_ug_term_id_map' );
5081 $u_groups = array_filter(
5082 array_map(
5083 function ( $ug_id ) use ( $ug_map ) {
5084 return $ug_id ? $ug_map[ $ug_id ] : '';
5085 },
5086 get_ticket_meta( $ticket->id, 'usergroups' )
5087 )
5088 );
5089 $ticket_data['ar_usergroups'] = implode( '|', $u_groups );
5090 }
5091
5092 // import en_from email piping.
5093 if ( $installed_addons[3]['is_installed'] ) {
5094 $ticket_data['en_from'] = get_ticket_meta( $ticket->id, 'to_email', true );
5095 }
5096
5097 // import Private credentials.
5098 if ( $installed_addons[17]['is_installed'] ) {
5099
5100 $new_pc = array();
5101 $pc = get_ticket_meta( $ticket->id, 'private_credentials' );
5102 if ( $pc ) {
5103
5104 $new_pc['secure_key'] = get_ticket_meta( $ticket->id, 'secure_key', true );
5105 $new_pc['secure_iv'] = get_ticket_meta( $ticket->id, 'secure_iv', true );
5106 $data = array();
5107 $index = 1;
5108 foreach ( $pc as $crd ) {
5109
5110 $old_pc = json_decode( $crd, JSON_OBJECT_AS_ARRAY );
5111 $temp = array_map(
5112 function ( $tag ) {
5113 return array(
5114 'label' => $tag['label'],
5115 'value' => $tag['name'],
5116 'type' => $tag['type'] == 1 ? 'text' : 'textarea',
5117 );
5118 },
5119 $old_pc['data']
5120 );
5121 $old_pc['data'] = $temp;
5122 $data[ $index++ ] = $old_pc;
5123 }
5124 $new_pc['data'] = $data;
5125 $ticket_data['pc_data'] = wp_json_encode( $new_pc );
5126 }
5127 }
5128
5129 // import timer data.
5130 if ( $installed_addons[13]['is_installed'] ) {
5131
5132 if ( ! isset( $installed_addons[13]['has_db_table'] ) ) {
5133 $table = $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}wpsc_timer'" );
5134 $installed_addons[13]['has_db_table'] = $table ? 1 : 0;
5135 update_option( 'wpsc_upgrade_installed_addons', $installed_addons );
5136 }
5137
5138 $sql = "SELECT * FROM {$wpdb->prefix}wpsc_timer WHERE post_id = " . $ticket->id;
5139 $logs = $installed_addons[13]['has_db_table'] ? $wpdb->get_results( $sql ) : false;
5140 if ( $logs ) {
5141
5142 $temp_ts = array();
5143 foreach ( $logs as $log ) {
5144
5145 $auther = wpsc_get_agent_by( 'user_id', $log->started_by );
5146 if ( ! $auther ) {
5147 $timer_setting = get_option( 'wpsc-timer-settings' );
5148 $auther = wpsc_get_agent_by( 'id', $timer_setting['agent_id'] );
5149 }
5150
5151 $time_spent = 'PT0M';
5152 $status = 'running';
5153 if ( ! $log->timer_status ) {
5154 $time_spent = convert_sec_to_date_interval_string( $log->time_spend );
5155 if ( $time_spent != 'PT0M' ) {
5156 $temp_ts[] = new DateInterval( $time_spent );
5157 }
5158 $status = 'stopped';
5159 }
5160 $temp_start = $log->start_time;
5161
5162 $wpdb->insert(
5163 $wpdb->prefix . 'psmsc_timer_logs',
5164 array(
5165 'ticket' => $ticket->id,
5166 'author' => $auther->id,
5167 'date_started' => $log->start_time,
5168 'time_spent' => $time_spent,
5169 'temp_start' => $temp_start,
5170 'description' => $log->note,
5171 'status' => $status,
5172 )
5173 );
5174 }
5175 $total_time = $temp_ts ? wpsc_date_interval_to_string( wpsc_date_interval_sum( $temp_ts ) ) : 'PT0M';
5176 $ticket_data['time_spent'] = $total_time;
5177 }
5178 }
5179
5180 // insert sf_date if only rating is available.
5181 if ( isset( $ticket->rating ) && $ticket->rating && ! isset( $ticket_data['sf_date'] ) ) {
5182 $date_closed = isset( $ticket->date_closed ) ? $ticket->date_closed : '';
5183 $date_closed = ! $date_closed && isset( $ticket_data['date_closed'] ) ? $ticket_data['date_closed'] : $date_closed;
5184 if ( $date_closed ) {
5185 $ticket_data['sf_date'] = $date_closed;
5186 }
5187 }
5188
5189 // update ticket data.
5190 $wpdb->update(
5191 $wpdb->prefix . 'psmsc_tickets',
5192 $ticket_data,
5193 array( 'id' => $ticket->id )
5194 );
5195 }
5196
5197 /**
5198 * Import uploaded thread images
5199 *
5200 * @param string $thread_content - thread html.
5201 * @param stdClass $thread - thread db object.
5202 * @param stdClass $ticket - ticket db object.
5203 * @return string
5204 */
5205 public static function import_uploaded_thread_images( $thread_content, $thread, $ticket ) {
5206
5207 if ( empty( $thread_content ) || empty( $thread ) || empty( $ticket ) ) {
5208 return $thread_content;
5209 }
5210
5211 if ( strpos( $thread_content, 'wpsc_img_attachment=' ) === false ) {
5212 return $thread_content;
5213 }
5214
5215 global $wpdb;
5216 $upload_dir = wp_upload_dir();
5217 $regex = '/src="([^"]*\?wpsc_img_attachment=([0-9]+))"/';
5218 if ( ! preg_match_all( $regex, $thread_content, $matches, PREG_SET_ORDER ) ) {
5219 return $thread_content;
5220 }
5221
5222 foreach ( $matches as $match ) {
5223
5224 $full_url = $match[1];
5225 $attachment_id = (int) $match[2];
5226 if ( ! $attachment_id ) {
5227 continue;
5228 }
5229
5230 $file_path = get_term_meta( $attachment_id, 'file_path', true );
5231 if ( empty( $file_path ) || ! file_exists( $file_path ) ) {
5232 continue;
5233 }
5234
5235 $relative_path = str_replace( $upload_dir['basedir'], '', $file_path );
5236 $file_name = basename( $relative_path );
5237 $inserted = $wpdb->insert(
5238 $wpdb->prefix . 'psmsc_attachments',
5239 array(
5240 'name' => $file_name,
5241 'file_path' => $relative_path,
5242 'is_image' => 1,
5243 'is_active' => 1,
5244 'date_created' => current_time( 'mysql' ),
5245 'source' => 'img_editor',
5246 'source_id' => (int) $thread->id,
5247 'ticket_id' => (int) $ticket->id,
5248 ),
5249 array(
5250 '%s',
5251 '%s',
5252 '%d',
5253 '%d',
5254 '%s',
5255 '%s',
5256 '%d',
5257 '%d',
5258 )
5259 );
5260
5261 // If insert failed, skip replacement.
5262 if ( false === $inserted ) {
5263 continue;
5264 }
5265
5266 // Replace exact matched URL .
5267 $new_url = home_url( '/' ) . '?wpsc_attachment=' . $wpdb->insert_id;
5268 $thread_content = str_replace( $full_url, $new_url, $thread_content );
5269 }
5270 return $thread_content;
5271 }
5272
5273 /**
5274 * Import email notification conditions
5275 *
5276 * @return void
5277 */
5278 public static function import_en_conditions() {
5279
5280 $en_template_map = get_option( 'wpsc_upgrade_en_term_id_map' );
5281 $new_templates = get_option( 'wpsc-email-templates' );
5282 $email_templates = get_terms(
5283 array(
5284 'taxonomy' => 'wpsc_en',
5285 'hide_empty' => false,
5286 'orderby' => 'ID',
5287 'order' => 'ASC',
5288 )
5289 );
5290
5291 foreach ( $email_templates as $template ) {
5292
5293 $prev_conditions = get_term_meta( $template->term_id, 'conditions', true );
5294 $new_template = $new_templates[ $en_template_map[ $template->term_id ] ];
5295 $new_template['conditions'] = upgrade_conditions( $prev_conditions );
5296 $new_templates[ $en_template_map[ $template->term_id ] ] = $new_template;
5297 }
5298
5299 // Email notifications.
5300 foreach ( $new_templates as $index => $properties ) {
5301 if ( ! $properties['conditions'] ) {
5302 continue;
5303 }
5304 $new_templates[ $index ]['conditions'] = WPSC_SC_Upgrade::upgrade_condition( $properties['conditions'], $properties['relation'] );
5305 }
5306 update_option( 'wpsc-email-templates', $new_templates );
5307 }
5308
5309 /**
5310 * Import assign agent rules conditions
5311 *
5312 * @return void
5313 */
5314 public static function import_aar_conditions() {
5315
5316 $rules_map = get_option( 'wpsc_upgrade_aar_map' );
5317 if ( empty( $rules_map ) ) {
5318 return;
5319 }
5320
5321 $new_rules = get_option( 'wpsc-aar-rules' );
5322 $prev_rules = get_terms(
5323 array(
5324 'taxonomy' => 'wpsc_caa',
5325 'hide_empty' => false,
5326 )
5327 );
5328
5329 foreach ( $prev_rules as $prev ) {
5330
5331 $prev_conditions = get_term_meta( $prev->term_id, 'conditions', true );
5332
5333 $new_rule = $new_rules[ $rules_map[ $prev->term_id ] ];
5334 $new_rule['conditions'] = upgrade_conditions( $prev_conditions );
5335 $new_rules[ $rules_map[ $prev->term_id ] ] = $new_rule;
5336 }
5337
5338 // Assigned agent rules filters.
5339 foreach ( $new_rules as $index => $properties ) {
5340 if ( ! $properties['conditions'] ) {
5341 continue;
5342 }
5343 $new_rules[ $index ]['conditions'] = WPSC_SC_Upgrade::upgrade_condition( $properties['conditions'], $properties['relation'] );
5344 }
5345 update_option( 'wpsc-aar-rules', $new_rules );
5346 }
5347
5348 /**
5349 * Import sla conditions
5350 *
5351 * @return void
5352 */
5353 public static function import_sla_conditions() {
5354
5355 $new_policies = get_option( 'wpsc-sla-policies' );
5356 $map = get_option( 'wpsc_upgrade_sla_policy_map' );
5357 if ( empty( $map ) ) {
5358 return;
5359 }
5360
5361 $policies = get_terms(
5362 array(
5363 'taxonomy' => 'wpsc_sla',
5364 'hide_empty' => false,
5365 'orderby' => 'meta_value_num',
5366 'order' => 'ASC',
5367 'meta_query' => array( 'order_clause' => array( 'key' => 'load_order' ) ),
5368 )
5369 );
5370
5371 foreach ( $policies as $prev ) {
5372 $prev_conditions = get_term_meta( $prev->term_id, 'conditions', true );
5373
5374 $new_policy = $new_policies[ $map[ $prev->term_id ] ];
5375 $new_policy['conditions'] = upgrade_conditions( $prev_conditions );
5376 $new_policies[ $map[ $prev->term_id ] ] = $new_policy;
5377 }
5378
5379 // SLA policy filters.
5380 foreach ( $new_policies as $index => $properties ) {
5381 if ( ! $properties['conditions'] ) {
5382 continue;
5383 }
5384 $new_policies[ $index ]['conditions'] = WPSC_SC_Upgrade::upgrade_condition( $properties['conditions'], $properties['relation'] );
5385 }
5386 update_option( 'wpsc-sla-policies', $new_policies );
5387 }
5388
5389 /**
5390 * Import add-on licences
5391 *
5392 * @return void
5393 */
5394 public static function import_licences() {
5395
5396 $licenses = array();
5397 $installed_addons = get_option( 'wpsc_upgrade_installed_addons' );
5398
5399 if ( $installed_addons[0]['is_installed'] ) {
5400 $key = get_option( 'wpsc_atc_license_key', '' );
5401 $expiry = get_option( 'wpsc_atc_license_expiry', '' );
5402 $licenses['atc'] = array(
5403 'key' => $key,
5404 'expiry' => $expiry,
5405 );
5406 }
5407
5408 if ( $installed_addons[1]['is_installed'] ) {
5409 $key = get_option( 'wpsc_canned_reply_license_key', '' );
5410 $expiry = get_option( 'wpsc_canned_reply_license_expiry', '' );
5411 $licenses['canned-reply'] = array(
5412 'key' => $key,
5413 'expiry' => $expiry,
5414 );
5415 }
5416
5417 if ( $installed_addons[2]['is_installed'] ) {
5418 $key = get_option( 'wpsc_export_ticket_license_key', '' );
5419 $expiry = get_option( 'wpsc_export_ticket_license_expiry', '' );
5420 $licenses['export'] = array(
5421 'key' => $key,
5422 'expiry' => $expiry,
5423 );
5424 }
5425
5426 if ( $installed_addons[3]['is_installed'] ) {
5427 $key = get_option( 'wpsc_ep_license_key', '' );
5428 $expiry = get_option( 'wpsc_ep_license_expiry', '' );
5429 $licenses['email-piping'] = array(
5430 'key' => $key,
5431 'expiry' => $expiry,
5432 );
5433 }
5434
5435 if ( $installed_addons[4]['is_installed'] ) {
5436 $key = get_option( 'wpsc_sla_license_key', '' );
5437 $expiry = get_option( 'wpsc_sla_license_expiry', '' );
5438 $licenses['sla'] = array(
5439 'key' => $key,
5440 'expiry' => $expiry,
5441 );
5442 }
5443
5444 if ( $installed_addons[5]['is_installed'] ) {
5445 $key = get_option( 'wpsc_woo_license_key', '' );
5446 $expiry = get_option( 'wpsc_woo_license_expiry', '' );
5447 $licenses['woo'] = array(
5448 'key' => $key,
5449 'expiry' => $expiry,
5450 );
5451 }
5452
5453 if ( $installed_addons[6]['is_installed'] ) {
5454 $key = get_option( 'wpsc_rp_license_key', '' );
5455 $expiry = get_option( 'wpsc_rp_license_expiry', '' );
5456 $licenses['reports'] = array(
5457 'key' => $key,
5458 'expiry' => $expiry,
5459 );
5460 }
5461
5462 if ( $installed_addons[7]['is_installed'] ) {
5463 $key = get_option( 'wpsc_usergroup_license_key', '' );
5464 $expiry = get_option( 'wpsc_usergroup_license_expiry', '' );
5465 $licenses['usergroup'] = array(
5466 'key' => $key,
5467 'expiry' => $expiry,
5468 );
5469 }
5470
5471 if ( $installed_addons[8]['is_installed'] ) {
5472 $key = get_option( 'wpsc_edd_license_key', '' );
5473 $expiry = get_option( 'wpsc_edd_license_expiry', '' );
5474 $licenses['edd'] = array(
5475 'key' => $key,
5476 'expiry' => $expiry,
5477 );
5478 }
5479
5480 if ( $installed_addons[9]['is_installed'] ) {
5481 $key = get_option( 'wpsc_gf_license_key', '' );
5482 $expiry = get_option( 'wpsc_gf_license_expiry', '' );
5483 $licenses['gf'] = array(
5484 'key' => $key,
5485 'expiry' => $expiry,
5486 );
5487 }
5488
5489 if ( $installed_addons[10]['is_installed'] ) {
5490 $key = get_option( 'wpsc_caa_license_key', '' );
5491 $expiry = get_option( 'wpsc_caa_license_expiry', '' );
5492 $licenses['aar'] = array(
5493 'key' => $key,
5494 'expiry' => $expiry,
5495 );
5496 }
5497
5498 if ( $installed_addons[11]['is_installed'] ) {
5499 $key = get_option( 'wpsc_ultfaq_license_key', '' );
5500 $expiry = get_option( 'wpsc_ultfaq_license_expiry', '' );
5501 $licenses['faq'] = array(
5502 'key' => $key,
5503 'expiry' => $expiry,
5504 );
5505 }
5506
5507 if ( $installed_addons[12]['is_installed'] ) {
5508 $key = get_option( 'wpsc_prass_kb_license_key', '' );
5509 $expiry = get_option( 'wpsc_prass_kb_license_expiry', '' );
5510 $licenses['kb'] = array(
5511 'key' => $key,
5512 'expiry' => $expiry,
5513 );
5514 }
5515
5516 if ( $installed_addons[13]['is_installed'] ) {
5517 $key = get_option( 'wpsc_timer_license_key', '' );
5518 $expiry = get_option( 'wpsc_timer_license_expiry', '' );
5519 $licenses['timer'] = array(
5520 'key' => $key,
5521 'expiry' => $expiry,
5522 );
5523 }
5524
5525 if ( $installed_addons[14]['is_installed'] ) {
5526 $key = get_option( 'wpsc_st_license_key', '' );
5527 $expiry = get_option( 'wpsc_st_license_expiry', '' );
5528 $licenses['schedule-tickets'] = array(
5529 'key' => $key,
5530 'expiry' => $expiry,
5531 );
5532 }
5533
5534 if ( $installed_addons[15]['is_installed'] ) {
5535 $key = get_option( 'wpsc_sf_license_key', '' );
5536 $expiry = get_option( 'wpsc_sf_license_expiry', '' );
5537 $licenses['sf'] = array(
5538 'key' => $key,
5539 'expiry' => $expiry,
5540 );
5541 }
5542
5543 if ( $installed_addons[16]['is_installed'] ) {
5544 $key = get_option( 'wpsc_agentgroup_license_key', '' );
5545 $expiry = get_option( 'wpsc_agentgroup_license_expiry', '' );
5546 $licenses['agentgroups'] = array(
5547 'key' => $key,
5548 'expiry' => $expiry,
5549 );
5550 }
5551
5552 if ( $installed_addons[17]['is_installed'] ) {
5553 $key = get_option( 'wpsc_pc_license_key', '' );
5554 $expiry = get_option( 'wpsc_pc_license_expiry', '' );
5555 $licenses['pc'] = array(
5556 'key' => $key,
5557 'expiry' => $expiry,
5558 );
5559 }
5560
5561 if ( $installed_addons[18]['is_installed'] ) {
5562 $key = get_option( 'wpsc_pt_license_key', '' );
5563 $expiry = get_option( 'wpsc_pt_license_expiry', '' );
5564 $licenses['print'] = array(
5565 'key' => $key,
5566 'expiry' => $expiry,
5567 );
5568 }
5569 update_option( 'wpsc-licenses', $licenses );
5570 }
5571 }
5572
5573 endif;
5574
5575 WPSC_Upgrade_DB_V2::init();
5576
5577 require_once __DIR__ . '/functions.php';
5578