PluginProbe
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent / 3.3.7
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent v3.3.7
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.3.7, at upgrade/class-wpsc-upgrade-db-v2.php

5,490 lines 180.5 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( 'Unauthorised request!', 401 );
188 }
189
190 if ( check_ajax_referer( 'wpsc_authorize_v2_upgrade', '_ajax_nonce', false ) != 1 ) {
191 wp_send_json_error( 'Unauthorised 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( 'Unauthorised request!', 401 );
211 }
212
213 if ( check_ajax_referer( 'wpsc_upgrade_v2_check_compatibility', '_ajax_nonce', false ) != 1 ) {
214 wp_send_json_error( 'Unauthorised 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( 'Unauthorised 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 id NOT IN(1,2,7)' );
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 $term_id_map = get_option( 'wpsc_upgrade_cf_term_id_map', array() );
1262 $slug_map = get_option( 'wpsc_upgrade_cf_slug_map', array() );
1263 $load_order = get_option( 'wpsc_upgrade_cf_load_order', 8 );
1264 foreach ( $fields as $prev ) {
1265
1266 $label = get_term_meta( $prev->term_id, 'wpsc_tf_label', true );
1267 $extra_info = get_term_meta( $prev->term_id, 'wpsc_tf_extra_info', true );
1268 $type = get_term_meta( $prev->term_id, 'wpsc_tf_type', true );
1269 $char_limit = get_term_meta( $prev->term_id, 'wpsc_tf_limit', true );
1270 $placeholder = get_term_meta( $prev->term_id, 'wpsc_tf_placeholder_text', true );
1271
1272 if ( intval( $type ) === 0 ) {
1273
1274 switch ( $prev->slug ) {
1275
1276 case 'ticket_id':
1277 $term_id_map[ $prev->term_id ] = 1;
1278 $slug_map[ $prev->slug ] = 'id';
1279 break;
1280
1281 case 'ticket_status':
1282 $term_id_map[ $prev->term_id ] = 7;
1283 $slug_map[ $prev->slug ] = 'status';
1284 break;
1285
1286 case 'customer_name':
1287 $wpdb->update(
1288 $wpdb->prefix . 'psmsc_custom_fields',
1289 array(
1290 'name' => $label,
1291 'extra_info' => $extra_info,
1292 'load_order' => $load_order++,
1293 ),
1294 array( 'id' => 3 )
1295 );
1296 $term_id_map[ $prev->term_id ] = 3;
1297 $slug_map[ $prev->slug ] = 'name';
1298 $string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $label;
1299 break;
1300
1301 case 'customer_email':
1302 $wpdb->update(
1303 $wpdb->prefix . 'psmsc_custom_fields',
1304 array(
1305 'name' => $label,
1306 'extra_info' => $extra_info,
1307 'load_order' => $load_order++,
1308 ),
1309 array( 'id' => 4 )
1310 );
1311 $term_id_map[ $prev->term_id ] = 4;
1312 $slug_map[ $prev->slug ] = 'email';
1313 $string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $label;
1314 break;
1315
1316 case 'ticket_subject':
1317 $default_value = get_term_meta( $prev->term_id, 'wpsc_tf_default_subject', true );
1318 $default_value = $default_value ? $default_value : 'Not Applicable';
1319 $wpdb->update(
1320 $wpdb->prefix . 'psmsc_custom_fields',
1321 array(
1322 'name' => $label,
1323 'extra_info' => $extra_info,
1324 'char_limit' => $char_limit,
1325 'placeholder_text' => $placeholder,
1326 'default_value' => $default_value,
1327 'load_order' => $load_order++,
1328 ),
1329 array( 'id' => 5 )
1330 );
1331 $term_id_map[ $prev->term_id ] = 5;
1332 $slug_map[ $prev->slug ] = 'subject';
1333 $string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $label;
1334 $string_translations[ 'wpsc-cf-exi-' . $wpdb->insert_id ] = $extra_info;
1335 $string_translations[ 'wpsc-cf-pl-txt-' . $wpdb->insert_id ] = $placeholder;
1336 break;
1337
1338 case 'ticket_description':
1339 $default_value = get_term_meta( $prev->term_id, 'wpsc_tf_default_description', true );
1340 $default_value = $default_value ? $default_value : 'Not Applicable';
1341 $wpdb->update(
1342 $wpdb->prefix . 'psmsc_custom_fields',
1343 array(
1344 'name' => $label,
1345 'extra_info' => $extra_info,
1346 'default_value' => $default_value,
1347 'load_order' => $load_order++,
1348 ),
1349 array( 'id' => 6 )
1350 );
1351 $term_id_map[ $prev->term_id ] = 6;
1352 $slug_map[ $prev->slug ] = 'description';
1353 $string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $label;
1354 $string_translations[ 'wpsc-cf-exi-' . $wpdb->insert_id ] = $extra_info;
1355 break;
1356
1357 case 'ticket_priority':
1358 $wpdb->update(
1359 $wpdb->prefix . 'psmsc_custom_fields',
1360 array(
1361 'name' => $label,
1362 'extra_info' => $extra_info,
1363 'load_order' => $load_order++,
1364 ),
1365 array( 'id' => 8 )
1366 );
1367 $term_id_map[ $prev->term_id ] = 8;
1368 $slug_map[ $prev->slug ] = 'priority';
1369 $string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $label;
1370 $string_translations[ 'wpsc-cf-exi-' . $wpdb->insert_id ] = $extra_info;
1371 break;
1372
1373 case 'ticket_category':
1374 $wpdb->update(
1375 $wpdb->prefix . 'psmsc_custom_fields',
1376 array(
1377 'name' => $label,
1378 'extra_info' => $extra_info,
1379 'load_order' => $load_order++,
1380 ),
1381 array( 'id' => 9 )
1382 );
1383 $term_id_map[ $prev->term_id ] = 9;
1384 $slug_map[ $prev->slug ] = 'category';
1385 $string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $label;
1386 $string_translations[ 'wpsc-cf-exi-' . $wpdb->insert_id ] = $extra_info;
1387 break;
1388
1389 case 'assigned_agent':
1390 $wpdb->update(
1391 $wpdb->prefix . 'psmsc_custom_fields',
1392 array(
1393 'name' => $label,
1394 'load_order' => $load_order++,
1395 ),
1396 array( 'id' => 10 )
1397 );
1398 $term_id_map[ $prev->term_id ] = 10;
1399 $slug_map[ $prev->slug ] = 'assigned_agent';
1400 $string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $label;
1401 break;
1402
1403 case 'date_created':
1404 $wpdb->update(
1405 $wpdb->prefix . 'psmsc_custom_fields',
1406 array(
1407 'name' => $label,
1408 'load_order' => $load_order++,
1409 ),
1410 array( 'id' => 11 )
1411 );
1412 $term_id_map[ $prev->term_id ] = 11;
1413 $slug_map[ $prev->slug ] = 'date_created';
1414 $string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $label;
1415 break;
1416
1417 case 'date_updated':
1418 $wpdb->update(
1419 $wpdb->prefix . 'psmsc_custom_fields',
1420 array(
1421 'name' => $label,
1422 'load_order' => $load_order++,
1423 ),
1424 array( 'id' => 12 )
1425 );
1426 $term_id_map[ $prev->term_id ] = 12;
1427 $slug_map[ $prev->slug ] = 'date_updated';
1428 $string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $label;
1429 break;
1430
1431 case 'agent_created':
1432 $wpdb->update(
1433 $wpdb->prefix . 'psmsc_custom_fields',
1434 array(
1435 'name' => $label,
1436 'load_order' => $load_order++,
1437 ),
1438 array( 'id' => 13 )
1439 );
1440 $term_id_map[ $prev->term_id ] = 13;
1441 $slug_map[ $prev->slug ] = 'agent_created';
1442 $string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $label;
1443 break;
1444
1445 case 'date_closed':
1446 $wpdb->update(
1447 $wpdb->prefix . 'psmsc_custom_fields',
1448 array(
1449 'name' => $label,
1450 'load_order' => $load_order++,
1451 ),
1452 array( 'id' => 20 )
1453 );
1454 $term_id_map[ $prev->term_id ] = 20;
1455 $slug_map[ $prev->slug ] = 'date_closed';
1456 $string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $label;
1457 break;
1458
1459 case 'user_type':
1460 $wpdb->update(
1461 $wpdb->prefix . 'psmsc_custom_fields',
1462 array(
1463 'name' => $label,
1464 'load_order' => $load_order++,
1465 ),
1466 array( 'id' => 21 )
1467 );
1468 $term_id_map[ $prev->term_id ] = 21;
1469 $slug_map[ $prev->slug ] = 'user_type';
1470 $string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $label;
1471 break;
1472
1473 case 'last_reply_on':
1474 $wpdb->update(
1475 $wpdb->prefix . 'psmsc_custom_fields',
1476 array(
1477 'name' => $label,
1478 'load_order' => $load_order++,
1479 ),
1480 array( 'id' => 22 )
1481 );
1482 $term_id_map[ $prev->term_id ] = 22;
1483 $slug_map[ $prev->slug ] = 'last_reply_on';
1484 $string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $label;
1485 break;
1486
1487 case 'last_reply_by':
1488 $wpdb->update(
1489 $wpdb->prefix . 'psmsc_custom_fields',
1490 array(
1491 'name' => $label,
1492 'load_order' => $load_order++,
1493 ),
1494 array( 'id' => 23 )
1495 );
1496 $term_id_map[ $prev->term_id ] = 23;
1497 $slug_map[ $prev->slug ] = 'last_reply_by';
1498 $string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $label;
1499 break;
1500
1501 case 'sf_rating':
1502 $id = $wpdb->get_var( "SELECT id from {$wpdb->prefix}psmsc_custom_fields WHERE slug = 'rating'" );
1503 if ( $id ) {
1504 $wpdb->update(
1505 $wpdb->prefix . 'psmsc_custom_fields',
1506 array(
1507 'name' => $label,
1508 'load_order' => $load_order++,
1509 ),
1510 array( 'id' => $id )
1511 );
1512 $term_id_map[ $prev->term_id ] = $id;
1513 $slug_map[ $prev->slug ] = 'rating';
1514 $string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $label;
1515 }
1516 break;
1517
1518 case 'sla':
1519 $id = $wpdb->get_var( "SELECT id from {$wpdb->prefix}psmsc_custom_fields WHERE slug = 'sla'" );
1520 if ( $id ) {
1521 $wpdb->update(
1522 $wpdb->prefix . 'psmsc_custom_fields',
1523 array(
1524 'name' => $label,
1525 'load_order' => $load_order++,
1526 ),
1527 array( 'id' => $id )
1528 );
1529 $term_id_map[ $prev->term_id ] = $id;
1530 $slug_map[ $prev->slug ] = 'sla';
1531 $string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $label;
1532 }
1533 break;
1534
1535 case 'usergroup':
1536 $id = $wpdb->get_var( "SELECT id from {$wpdb->prefix}psmsc_custom_fields WHERE slug = 'usergroups'" );
1537 if ( $id ) {
1538 $wpdb->update(
1539 $wpdb->prefix . 'psmsc_custom_fields',
1540 array(
1541 'name' => $label,
1542 'load_order' => $load_order++,
1543 ),
1544 array( 'id' => $id )
1545 );
1546 $term_id_map[ $prev->term_id ] = $id;
1547 $slug_map[ $prev->slug ] = 'usergroups';
1548 $string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $label;
1549 }
1550 break;
1551
1552 case 'timer':
1553 $id = $wpdb->get_var( "SELECT id from {$wpdb->prefix}psmsc_custom_fields WHERE slug = 'time_spent'" );
1554 if ( $id ) {
1555 $wpdb->update(
1556 $wpdb->prefix . 'psmsc_custom_fields',
1557 array(
1558 'name' => $label,
1559 'load_order' => $load_order++,
1560 ),
1561 array( 'id' => $id )
1562 );
1563 $term_id_map[ $prev->term_id ] = $id;
1564 $slug_map[ $prev->slug ] = 'time_spent';
1565 $string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $label;
1566 }
1567 break;
1568 }
1569 } else {
1570
1571 $personal_info = get_term_meta( $prev->term_id, 'wpsc_tf_personal_info', true );
1572 $field = get_term_meta( $prev->term_id, 'agentonly', true ) == 1 ? 'agentonly' : 'ticket';
1573
1574 switch ( intval( $type ) ) {
1575
1576 case 1:
1577 $response = wpsc_upgrade_insert_custom_field(
1578 array(
1579 'name' => $label,
1580 'extra_info' => $extra_info,
1581 'field' => $field,
1582 'type' => 'cf_textfield',
1583 'placeholder_text' => $placeholder,
1584 'char_limit' => $char_limit,
1585 'is_personal_info' => $personal_info,
1586 'load_order' => $load_order++,
1587 )
1588 );
1589 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_tickets ADD " . $response['slug'] . ' TINYTEXT NULL' );
1590 $term_id_map[ $prev->term_id ] = $response['id'];
1591 $slug_map[ $prev->slug ] = $response['slug'];
1592 $string_translations[ 'wpsc-cf-name-' . $response['id'] ] = $label;
1593 $string_translations[ 'wpsc-cf-exi-' . $response['id'] ] = $extra_info;
1594 $string_translations[ 'wpsc-cf-pl-txt-' . $response['id'] ] = $placeholder;
1595 break;
1596
1597 case 2:
1598 $response = wpsc_upgrade_insert_custom_field(
1599 array(
1600 'name' => $label,
1601 'extra_info' => $extra_info,
1602 'field' => $field,
1603 'type' => 'cf_single_select',
1604 'is_personal_info' => $personal_info,
1605 'load_order' => $load_order++,
1606 )
1607 );
1608 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_tickets ADD " . $response['slug'] . ' TINYTEXT NULL' );
1609 $option_strings = self::import_options( $prev, $response['id'] );
1610 $string_translations = array_merge( $string_translations, $option_strings );
1611 $term_id_map[ $prev->term_id ] = $response['id'];
1612 $slug_map[ $prev->slug ] = $response['slug'];
1613 $string_translations[ 'wpsc-cf-name-' . $response['id'] ] = $label;
1614 $string_translations[ 'wpsc-cf-exi-' . $response['id'] ] = $extra_info;
1615 break;
1616
1617 case 3:
1618 $response = wpsc_upgrade_insert_custom_field(
1619 array(
1620 'name' => $label,
1621 'extra_info' => $extra_info,
1622 'field' => $field,
1623 'type' => 'cf_checkbox',
1624 'is_personal_info' => $personal_info,
1625 'load_order' => $load_order++,
1626 )
1627 );
1628 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_tickets ADD " . $response['slug'] . ' TINYTEXT NULL' );
1629 $option_strings = self::import_options( $prev, $response['id'] );
1630 $string_translations = array_merge( $string_translations, $option_strings );
1631 $term_id_map[ $prev->term_id ] = $response['id'];
1632 $slug_map[ $prev->slug ] = $response['slug'];
1633 $string_translations[ 'wpsc-cf-name-' . $response['id'] ] = $label;
1634 $string_translations[ 'wpsc-cf-exi-' . $response['id'] ] = $extra_info;
1635 break;
1636
1637 case 4:
1638 $response = wpsc_upgrade_insert_custom_field(
1639 array(
1640 'name' => $label,
1641 'extra_info' => $extra_info,
1642 'field' => $field,
1643 'type' => 'cf_radio_button',
1644 'is_personal_info' => $personal_info,
1645 'load_order' => $load_order++,
1646 )
1647 );
1648 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_tickets ADD " . $response['slug'] . ' TINYTEXT NULL' );
1649 $option_strings = self::import_options( $prev, $response['id'] );
1650 $string_translations = array_merge( $string_translations, $option_strings );
1651 $term_id_map[ $prev->term_id ] = $response['id'];
1652 $slug_map[ $prev->slug ] = $response['slug'];
1653 $string_translations[ 'wpsc-cf-name-' . $response['id'] ] = $label;
1654 $string_translations[ 'wpsc-cf-exi-' . $response['id'] ] = $extra_info;
1655 break;
1656
1657 case 5:
1658 $response = wpsc_upgrade_insert_custom_field(
1659 array(
1660 'name' => $label,
1661 'extra_info' => $extra_info,
1662 'field' => $field,
1663 'type' => 'cf_textarea',
1664 'placeholder_text' => $placeholder,
1665 'char_limit' => $char_limit,
1666 'is_personal_info' => $personal_info,
1667 'load_order' => $load_order++,
1668 )
1669 );
1670 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_tickets ADD " . $response['slug'] . ' LONGTEXT NULL DEFAULT NULL' );
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 $string_translations[ 'wpsc-cf-pl-txt-' . $response['id'] ] = $placeholder;
1676 break;
1677
1678 case 6:
1679 $date_range = get_term_meta( $prev->term_id, 'wpsc_date_range', true );
1680 $start_range = get_term_meta( $prev->term_id, 'date_range_from', true );
1681 $end_range = get_term_meta( $prev->term_id, 'date_range_to', true );
1682 $response = wpsc_upgrade_insert_custom_field(
1683 array(
1684 'name' => $label,
1685 'extra_info' => $extra_info,
1686 'field' => $field,
1687 'type' => 'cf_date',
1688 'placeholder_text' => $placeholder,
1689 'date_range' => $date_range,
1690 'start_range' => $start_range,
1691 'end_range' => $end_range,
1692 'is_personal_info' => $personal_info,
1693 'load_order' => $load_order++,
1694 )
1695 );
1696 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_tickets ADD " . $response['slug'] . ' DATETIME NULL DEFAULT NULL' );
1697 $term_id_map[ $prev->term_id ] = $response['id'];
1698 $slug_map[ $prev->slug ] = $response['slug'];
1699 $string_translations[ 'wpsc-cf-name-' . $response['id'] ] = $label;
1700 $string_translations[ 'wpsc-cf-exi-' . $response['id'] ] = $extra_info;
1701 $string_translations[ 'wpsc-cf-pl-txt-' . $response['id'] ] = $placeholder;
1702 break;
1703
1704 case 7:
1705 $response = wpsc_upgrade_insert_custom_field(
1706 array(
1707 'name' => $label,
1708 'extra_info' => $extra_info,
1709 'field' => $field,
1710 'type' => 'cf_url',
1711 'placeholder_text' => $placeholder,
1712 'is_personal_info' => $personal_info,
1713 'load_order' => $load_order++,
1714 )
1715 );
1716 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_tickets ADD " . $response['slug'] . ' TINYTEXT NULL' );
1717 $term_id_map[ $prev->term_id ] = $response['id'];
1718 $slug_map[ $prev->slug ] = $response['slug'];
1719 $string_translations[ 'wpsc-cf-name-' . $response['id'] ] = $label;
1720 $string_translations[ 'wpsc-cf-exi-' . $response['id'] ] = $extra_info;
1721 $string_translations[ 'wpsc-cf-pl-txt-' . $response['id'] ] = $placeholder;
1722 break;
1723
1724 case 8:
1725 $response = wpsc_upgrade_insert_custom_field(
1726 array(
1727 'name' => $label,
1728 'extra_info' => $extra_info,
1729 'field' => $field,
1730 'type' => 'cf_email',
1731 'placeholder_text' => $placeholder,
1732 'is_personal_info' => $personal_info,
1733 'load_order' => $load_order++,
1734 )
1735 );
1736 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_tickets ADD " . $response['slug'] . ' TINYTEXT NULL' );
1737 $term_id_map[ $prev->term_id ] = $response['id'];
1738 $slug_map[ $prev->slug ] = $response['slug'];
1739 $string_translations[ 'wpsc-cf-name-' . $response['id'] ] = $label;
1740 $string_translations[ 'wpsc-cf-exi-' . $response['id'] ] = $extra_info;
1741 $string_translations[ 'wpsc-cf-pl-txt-' . $response['id'] ] = $placeholder;
1742 break;
1743
1744 case 9:
1745 $response = wpsc_upgrade_insert_custom_field(
1746 array(
1747 'name' => $label,
1748 'extra_info' => $extra_info,
1749 'field' => $field,
1750 'type' => 'cf_number',
1751 'placeholder_text' => $placeholder,
1752 'char_limit' => $char_limit,
1753 'is_personal_info' => $personal_info,
1754 'load_order' => $load_order++,
1755 )
1756 );
1757 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_tickets ADD " . $response['slug'] . ' TINYTEXT NULL' );
1758 $term_id_map[ $prev->term_id ] = $response['id'];
1759 $slug_map[ $prev->slug ] = $response['slug'];
1760 $string_translations[ 'wpsc-cf-name-' . $response['id'] ] = $label;
1761 $string_translations[ 'wpsc-cf-exi-' . $response['id'] ] = $extra_info;
1762 $string_translations[ 'wpsc-cf-pl-txt-' . $response['id'] ] = $placeholder;
1763 break;
1764
1765 case 10:
1766 $response = wpsc_upgrade_insert_custom_field(
1767 array(
1768 'name' => $label,
1769 'extra_info' => $extra_info,
1770 'field' => $field,
1771 'type' => 'cf_file_attachment_multiple',
1772 'is_personal_info' => $personal_info,
1773 'load_order' => $load_order++,
1774 )
1775 );
1776 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_tickets ADD " . $response['slug'] . ' TINYTEXT NULL' );
1777 $term_id_map[ $prev->term_id ] = $response['id'];
1778 $slug_map[ $prev->slug ] = $response['slug'];
1779 $string_translations[ 'wpsc-cf-name-' . $response['id'] ] = $label;
1780 $string_translations[ 'wpsc-cf-exi-' . $response['id'] ] = $extra_info;
1781 break;
1782
1783 case 11:
1784 if ( $installed_addons[5]['is_installed'] ) {
1785 $response = wpsc_upgrade_insert_custom_field(
1786 array(
1787 'name' => $label,
1788 'extra_info' => $extra_info,
1789 'field' => $field,
1790 'type' => 'cf_woo_product',
1791 'is_personal_info' => $personal_info,
1792 'load_order' => $load_order++,
1793 )
1794 );
1795 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_tickets ADD " . $response['slug'] . ' BIGINT NULL DEFAULT 0' );
1796 $term_id_map[ $prev->term_id ] = $response['id'];
1797 $slug_map[ $prev->slug ] = $response['slug'];
1798 $string_translations[ 'wpsc-cf-name-' . $response['id'] ] = $label;
1799 $string_translations[ 'wpsc-cf-exi-' . $response['id'] ] = $extra_info;
1800 }
1801 break;
1802
1803 case 12:
1804 if ( $installed_addons[5]['is_installed'] ) {
1805 $response = wpsc_upgrade_insert_custom_field(
1806 array(
1807 'name' => $label,
1808 'extra_info' => $extra_info,
1809 'field' => $field,
1810 'type' => 'cf_woo_order',
1811 'is_personal_info' => $personal_info,
1812 'load_order' => $load_order++,
1813 )
1814 );
1815 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_tickets ADD " . $response['slug'] . ' BIGINT NULL DEFAULT 0' );
1816 $term_id_map[ $prev->term_id ] = $response['id'];
1817 $slug_map[ $prev->slug ] = $response['slug'];
1818 $string_translations[ 'wpsc-cf-name-' . $response['id'] ] = $label;
1819 $string_translations[ 'wpsc-cf-exi-' . $response['id'] ] = $extra_info;
1820 }
1821 break;
1822
1823 case 13:
1824 if ( $installed_addons[8]['is_installed'] ) {
1825 $response = wpsc_upgrade_insert_custom_field(
1826 array(
1827 'name' => $label,
1828 'extra_info' => $extra_info,
1829 'field' => $field,
1830 'type' => 'cf_edd_product',
1831 'is_personal_info' => $personal_info,
1832 'load_order' => $load_order++,
1833 )
1834 );
1835 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_tickets ADD " . $response['slug'] . ' BIGINT NULL DEFAULT 0' );
1836 $term_id_map[ $prev->term_id ] = $response['id'];
1837 $slug_map[ $prev->slug ] = $response['slug'];
1838 $string_translations[ 'wpsc-cf-name-' . $response['id'] ] = $label;
1839 $string_translations[ 'wpsc-cf-exi-' . $response['id'] ] = $extra_info;
1840 }
1841 break;
1842
1843 case 14:
1844 if ( $installed_addons[8]['is_installed'] ) {
1845 $response = wpsc_upgrade_insert_custom_field(
1846 array(
1847 'name' => $label,
1848 'extra_info' => $extra_info,
1849 'field' => $field,
1850 'type' => 'cf_edd_order',
1851 'is_personal_info' => $personal_info,
1852 'load_order' => $load_order++,
1853 )
1854 );
1855 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_tickets ADD " . $response['slug'] . ' BIGINT NULL DEFAULT 0' );
1856 $term_id_map[ $prev->term_id ] = $response['id'];
1857 $slug_map[ $prev->slug ] = $response['slug'];
1858 $string_translations[ 'wpsc-cf-name-' . $response['id'] ] = $label;
1859 $string_translations[ 'wpsc-cf-exi-' . $response['id'] ] = $extra_info;
1860 }
1861 break;
1862
1863 case 18:
1864 $response = wpsc_upgrade_insert_custom_field(
1865 array(
1866 'name' => $label,
1867 'extra_info' => $extra_info,
1868 'field' => $field,
1869 'type' => 'cf_datetime',
1870 'placeholder_text' => $placeholder,
1871 'is_personal_info' => $personal_info,
1872 'load_order' => $load_order++,
1873 )
1874 );
1875 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_tickets ADD " . $response['slug'] . ' DATETIME NULL DEFAULT NULL' );
1876 $term_id_map[ $prev->term_id ] = $response['id'];
1877 $slug_map[ $prev->slug ] = $response['slug'];
1878 $string_translations[ 'wpsc-cf-name-' . $response['id'] ] = $label;
1879 $string_translations[ 'wpsc-cf-exi-' . $response['id'] ] = $extra_info;
1880 $string_translations[ 'wpsc-cf-pl-txt-' . $response['id'] ] = $placeholder;
1881 break;
1882
1883 case 21:
1884 $time_format = get_term_meta( $prev->term_id, 'wpsc_time_format', true );
1885 $response = wpsc_upgrade_insert_custom_field(
1886 array(
1887 'name' => $label,
1888 'extra_info' => $extra_info,
1889 'field' => $field,
1890 'type' => 'cf_time',
1891 'time_format' => $time_format,
1892 'placeholder_text' => $placeholder,
1893 'is_personal_info' => $personal_info,
1894 'load_order' => $load_order++,
1895 )
1896 );
1897 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_tickets ADD " . $response['slug'] . ' TINYTEXT NULL' );
1898 $term_id_map[ $prev->term_id ] = $response['id'];
1899 $slug_map[ $prev->slug ] = $response['slug'];
1900 $string_translations[ 'wpsc-cf-name-' . $response['id'] ] = $label;
1901 $string_translations[ 'wpsc-cf-exi-' . $response['id'] ] = $extra_info;
1902 $string_translations[ 'wpsc-cf-pl-txt-' . $response['id'] ] = $placeholder;
1903 break;
1904
1905 case 22:
1906 $html = get_term_meta( $prev->term_id, 'wpsc_html_content', true );
1907 $response = wpsc_upgrade_insert_custom_field(
1908 array(
1909 'name' => $label,
1910 'extra_info' => $extra_info,
1911 'field' => $field,
1912 'type' => 'cf_html',
1913 'default_value' => $html,
1914 'load_order' => $load_order++,
1915 )
1916 );
1917 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_tickets ADD " . $response['slug'] . ' TEXT NULL DEFAULT NULL' );
1918 $term_id_map[ $prev->term_id ] = $response['id'];
1919 $slug_map[ $prev->slug ] = $response['slug'];
1920 $string_translations[ 'wpsc-cf-name-' . $response['id'] ] = $label;
1921 $string_translations[ 'wpsc-cf-exi-' . $response['id'] ] = $extra_info;
1922 break;
1923 }
1924 }
1925 }
1926 update_option( 'wpsc-string-translation', $string_translations );
1927 update_option( 'wpsc_upgrade_cf_term_id_map', $term_id_map );
1928 update_option( 'wpsc_upgrade_cf_slug_map', $slug_map );
1929 update_option( 'wpsc_upgrade_cf_load_order', $load_order );
1930 }
1931
1932 /**
1933 * Import options for custom field
1934 *
1935 * @param mixed $prev - previous custom field object.
1936 * @param int $id - new custom field id.
1937 * @return array
1938 */
1939 public static function import_options( $prev, $id ) {
1940
1941 global $wpdb;
1942 $string_translations = array();
1943 $options = get_term_meta( $prev->term_id, 'wpsc_tf_options', true );
1944 $load_order = 1;
1945 $options_map = get_option( 'wpsc_upgrade_cf_options_map', array() );
1946 foreach ( $options as $name ) {
1947 $wpdb->insert(
1948 $wpdb->prefix . 'psmsc_options',
1949 array(
1950 'name' => $name,
1951 'date_created' => ( new DateTime( 'now' ) )->format( 'Y-m-d H:m:s' ),
1952 'custom_field' => $id,
1953 'load_order' => $load_order++,
1954 )
1955 );
1956 $string_translations[ 'wpsc-option-' . $wpdb->insert_id ] = $name;
1957 $options_map[ $id ][ $name ] = $wpdb->insert_id;
1958 }
1959
1960 update_option( 'wpsc_upgrade_cf_options_map', $options_map );
1961 return $string_translations;
1962 }
1963
1964 /**
1965 * Import agent and agentgroups
1966 *
1967 * @return void
1968 */
1969 public static function import_agents() {
1970
1971 global $wpdb;
1972
1973 // removing agent role cap.
1974 $agents = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}psmsc_agents" );
1975 foreach ( $agents as $agent ) {
1976 $user = get_user_by( 'id', $agent->user );
1977 if ( $user ) {
1978 $user->remove_cap( 'wpsc_agent' );
1979 }
1980 }
1981
1982 $wpdb->query( 'DELETE FROM ' . $wpdb->prefix . 'psmsc_agents' );
1983 $wpdb->query( 'ALTER TABLE ' . $wpdb->prefix . 'psmsc_agents AUTO_INCREMENT = 1' );
1984 $wpdb->query( 'DELETE FROM ' . $wpdb->prefix . 'psmsc_customers' );
1985 $wpdb->query( 'ALTER TABLE ' . $wpdb->prefix . 'psmsc_customers AUTO_INCREMENT = 1' );
1986
1987 // import agent roles.
1988 $new = array();
1989 $prev = get_option( 'wpsc_agent_role' );
1990 foreach ( $prev as $key => $role ) {
1991 $new[ $key ] = array(
1992 'label' => $role['label'],
1993 'caps' => array(
1994 'view-unassigned' => $role['view_unassigned'] == 1 ? true : false, // View ticket.
1995 'view-assigned-me' => $role['view_assigned_me'] == 1 ? true : false,
1996 'view-assigned-others' => $role['view_assigned_others'] == 1 ? true : false,
1997 'reply-unassigned' => $role['reply_unassigned'] == 1 ? true : false, // Reply ticket.
1998 'reply-assigned-me' => $role['reply_assigned_me'] == 1 ? true : false,
1999 'reply-assigned-others' => $role['reply_assigned_others'] == 1 ? true : false,
2000 'pn-unassigned' => true, // Private notes.
2001 'pn-assigned-me' => true,
2002 'pn-assigned-others' => true,
2003 'aa-unassigned' => $role['assign_unassigned'] == 1 ? true : false, // Assignee.
2004 'aa-assigned-me' => $role['assign_assigned_me'] == 1 ? true : false,
2005 'aa-assigned-others' => $role['assign_assigned_others'] == 1 ? true : false,
2006 'cs-unassigned' => $role['cng_tkt_sts_unassigned'] == 1 ? true : false, // Change status.
2007 'cs-assigned-me' => $role['cng_tkt_sts_assigned_me'] == 1 ? true : false,
2008 'cs-assigned-others' => $role['cng_tkt_sts_assigned_others'] == 1 ? true : false,
2009 'ctf-unassigned' => $role['cng_tkt_field_unassigned'] == 1 ? true : false, // Change ticket fields.
2010 'ctf-assigned-me' => $role['cng_tkt_field_assigned_me'] == 1 ? true : false,
2011 'ctf-assigned-others' => $role['cng_tkt_field_assigned_others'] == 1 ? true : false,
2012 'caof-unassigned' => $role['cng_tkt_ao_unassigned'] == 1 ? true : false, // Change agent only fields.
2013 'caof-assigned-me' => $role['cng_tkt_ao_assigned_me'] == 1 ? true : false,
2014 'caof-assigned-others' => $role['cng_tkt_ao_assigned_others'] == 1 ? true : false,
2015 'crb-unassigned' => $role['cng_tkt_rb_unassigned'] == 1 ? true : false, // Change raised by.
2016 'crb-assigned-me' => $role['cng_tkt_rb_assigned_me'] == 1 ? true : false,
2017 'crb-assigned-others' => $role['cng_tkt_rb_assigned_others'] == 1 ? true : false,
2018 'eth-unassigned' => $role['delete_unassigned'] == 1 ? true : false, // Edit thread.
2019 'eth-assigned-me' => $role['delete_assigned_me'] == 1 ? true : false,
2020 'eth-assigned-others' => $role['delete_assigned_others'] == 1 ? true : false,
2021 'dth-unassigned' => $role['delete_unassigned'] == 1 ? true : false, // Delete thread.
2022 'dth-assigned-me' => $role['delete_assigned_me'] == 1 ? true : false,
2023 'dth-assigned-others' => $role['delete_assigned_others'] == 1 ? true : false,
2024 'vl-unassigned' => true, // View logs.
2025 'vl-assigned-me' => true,
2026 'vl-assigned-others' => true,
2027 'dtt-unassigned' => $role['delete_unassigned'] == 1 ? true : false, // Delete ticket.
2028 'dtt-assigned-me' => $role['delete_assigned_me'] == 1 ? true : false,
2029 'dtt-assigned-others' => $role['delete_assigned_others'] == 1 ? true : false,
2030 'ar-unassigned' => true, // Additional recipients.
2031 'ar-assigned-me' => true,
2032 'ar-assigned-others' => true,
2033 'dt-unassigned' => true, // Duplicate ticket.
2034 'dt-assigned-me' => true,
2035 'dt-assigned-others' => true,
2036 'backend-access' => true, // Dashboard support menu access.
2037 'create-as' => true, // Create ticket on others behalf.
2038 'dtt-access' => true, // Deleted ticket access.
2039 'eci-access' => true, // Edit customer info.
2040 'dash-access' => true, // Dashboard access.
2041 ),
2042 );
2043 }
2044 update_option( 'wpsc-agent-roles', $new );
2045
2046 $map = array();
2047 $agents = get_terms(
2048 array(
2049 'taxonomy' => 'wpsc_agents',
2050 'hide_empty' => false,
2051 )
2052 );
2053
2054 // import agents.
2055 foreach ( $agents as $prev ) {
2056
2057 $is_agentgroup = get_term_meta( $prev->term_id, 'agentgroup', true );
2058 if ( $is_agentgroup ) {
2059 continue;
2060 }
2061
2062 $user_id = get_term_meta( $prev->term_id, 'user_id', true );
2063 $user = get_user_by( 'id', $user_id );
2064 if ( ! $user->ID ) {
2065 continue;
2066 }
2067
2068 // create customer record.
2069 $wpdb->insert(
2070 $wpdb->prefix . 'psmsc_customers',
2071 array(
2072 'user' => $user_id,
2073 'name' => $user->display_name,
2074 'email' => $user->user_email,
2075 )
2076 );
2077
2078 // insert agent record.
2079 $wpdb->insert(
2080 $wpdb->prefix . 'psmsc_agents',
2081 array(
2082 'user' => $user_id,
2083 'customer' => $wpdb->insert_id,
2084 'role' => get_term_meta( $prev->term_id, 'role', true ),
2085 'name' => $user->display_name,
2086 'is_active' => 1,
2087 )
2088 );
2089
2090 // adding agent role cap.
2091 $user->add_cap( 'wpsc_agent' );
2092
2093 // agent working hrs.
2094 $agent_id = $wpdb->insert_id;
2095 for ( $i = 1; $i <= 7; $i++ ) {
2096 $wpdb->insert(
2097 $wpdb->prefix . 'psmsc_working_hrs',
2098 array(
2099 'agent' => $agent_id,
2100 'day' => $i,
2101 'start_time' => '00:00:00',
2102 'end_time' => '23:59:59',
2103 )
2104 );
2105 }
2106
2107 $map[ $prev->term_id ] = $agent_id;
2108 }
2109
2110 // import agentgroups.
2111 $installed_addons = get_option( 'wpsc_upgrade_installed_addons' );
2112 if ( $installed_addons[16]['is_installed'] ) {
2113
2114 $table = $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}psmsc_agentgroups'" );
2115 if ( $table ) {
2116 $wpdb->query( 'DELETE FROM ' . $wpdb->prefix . 'psmsc_agentgroups' );
2117 $wpdb->query( 'ALTER TABLE ' . $wpdb->prefix . 'psmsc_agentgroups AUTO_INCREMENT = 1' );
2118 }
2119 foreach ( $agents as $prev ) {
2120
2121 $is_agentgroup = get_term_meta( $prev->term_id, 'agentgroup', true );
2122 if ( ! $is_agentgroup ) {
2123 continue;
2124 }
2125
2126 // insert agent record for the group.
2127 $wpdb->insert(
2128 $wpdb->prefix . 'psmsc_agents',
2129 array(
2130 'name' => $prev->name,
2131 'is_agentgroup' => 1,
2132 'is_active' => 1,
2133 )
2134 );
2135 $map[ $prev->term_id ] = $wpdb->insert_id;
2136
2137 // get members of the group.
2138 $group_user_ids = get_term_meta( $prev->term_id, 'agentgroup_user_id' );
2139 $member_ids = array();
2140 foreach ( $group_user_ids as $user_id ) {
2141 $member_ids[] = $map[ $user_id ];
2142 }
2143
2144 // create agentgroup record.
2145 $wpdb->insert(
2146 $wpdb->prefix . 'psmsc_agentgroups',
2147 array(
2148 'agent_id' => $wpdb->insert_id,
2149 'name' => $prev->name,
2150 'agents' => implode( '|', $member_ids ),
2151 'supervisors' => implode( '|', $member_ids ),
2152 )
2153 );
2154 }
2155 }
2156
2157 update_option( 'wpsc_upgrade_agent_map', $map );
2158 }
2159
2160 /**
2161 * Import ticket form field settings
2162 *
2163 * @return void
2164 */
2165 public static function import_ticket_form_fields() {
2166
2167 $form_fields = array();
2168 $cf_map = get_option( 'wpsc_upgrade_cf_term_id_map' );
2169 $options_map = get_option( 'wpsc_upgrade_cf_options_map' );
2170 $category_map = get_option( 'wpsc_upgrade_category_map' );
2171 $priority_map = get_option( 'wpsc_upgrade_priority_map' );
2172 $fields = get_terms(
2173 array(
2174 'taxonomy' => 'wpsc_ticket_custom_fields',
2175 'hide_empty' => false,
2176 'orderby' => 'meta_value_num',
2177 'meta_key' => 'wpsc_tf_load_order',
2178 'order' => 'ASC',
2179 'meta_query' => array(
2180 array(
2181 'key' => 'agentonly',
2182 'value' => '0',
2183 'compare' => '=',
2184 ),
2185 ),
2186 )
2187 );
2188
2189 foreach ( $fields as $field ) {
2190
2191 $status = get_term_meta( $field->term_id, 'wpsc_tf_status', true );
2192 if ( $status == 0 ) {
2193 continue;
2194 }
2195
2196 $is_required = get_term_meta( $field->term_id, 'wpsc_tf_required', true );
2197
2198 $width = get_term_meta( $field->term_id, 'wpsc_tf_width', true );
2199 switch ( $width ) {
2200
2201 case '1/2':
2202 $width = 'half';
2203 break;
2204
2205 case '1':
2206 $width = 'full';
2207 }
2208
2209 $visibility = array();
2210 $prev_visibility = get_term_meta( $field->term_id, 'wpsc_tf_visibility', true );
2211 if ( $prev_visibility ) {
2212 foreach ( $prev_visibility as $condition ) {
2213 $condition = explode( '--', $condition );
2214 $cf = wpsc_get_cf_by( 'id', $cf_map[ $condition[0] ] );
2215 switch ( $cf->slug ) {
2216
2217 case 'category':
2218 if ( isset( $visibility[ $cf->slug ] ) ) {
2219 $visibility[ $cf->slug ]['operand_val_1'][] = $category_map[ $condition[1] ];
2220 } else {
2221 $visibility[ $cf->slug ] = array(
2222 'operator' => 'IN',
2223 'operand_val_1' => array(
2224 $category_map[ $condition[1] ],
2225 ),
2226 );
2227 }
2228 break;
2229
2230 case 'priority':
2231 if ( isset( $visibility[ $cf->slug ] ) ) {
2232 $visibility[ $cf->slug ]['operand_val_1'][] = $priority_map[ $condition[1] ];
2233 } else {
2234 $visibility[ $cf->slug ] = array(
2235 'operator' => 'IN',
2236 'operand_val_1' => array(
2237 $priority_map[ $condition[1] ],
2238 ),
2239 );
2240 }
2241 break;
2242
2243 default:
2244 if ( isset( $visibility[ $cf->slug ] ) ) {
2245 $visibility[ $cf->slug ]['operand_val_1'][] = $options_map[ $cf->id ][ $condition[1] ];
2246 } else {
2247 $visibility[ $cf->slug ] = array(
2248 'operator' => 'IN',
2249 'operand_val_1' => array(
2250 $options_map[ $cf->id ][ $condition[1] ],
2251 ),
2252 );
2253 }
2254 }
2255 }
2256 }
2257
2258 $cf = wpsc_get_cf_by( 'id', $cf_map[ $field->term_id ] );
2259 $form_fields[ $cf->slug ] = array(
2260 'is-required' => $is_required,
2261 'width' => $width,
2262 'relation' => 'OR',
2263 'visibility' => $visibility ? wp_json_encode( $visibility ) : '{}',
2264 );
2265 }
2266
2267 // import tff conditions.
2268 foreach ( $form_fields as $slug => $properties ) {
2269 if ( ! $properties['visibility'] ) {
2270 continue;
2271 }
2272 $form_fields[ $slug ]['visibility'] = WPSC_SC_Upgrade::upgrade_condition( $properties['visibility'], $properties['relation'] );
2273 }
2274 update_option( 'wpsc-tff', $form_fields );
2275 }
2276
2277 /**
2278 * Import agent and customer ticket list and filter items
2279 *
2280 * @return void
2281 */
2282 public static function import_ticket_list_items() {
2283
2284 $map = get_option( 'wpsc_upgrade_cf_term_id_map' );
2285
2286 // import agent ticket list.
2287 $fields = get_terms(
2288 array(
2289 'taxonomy' => 'wpsc_ticket_custom_fields',
2290 'hide_empty' => false,
2291 'orderby' => 'meta_value_num',
2292 'meta_key' => 'wpsc_tl_agent_load_order',
2293 'order' => 'ASC',
2294 'meta_query' => array(
2295 'relation' => 'AND',
2296 array(
2297 'key' => 'wpsc_allow_ticket_list',
2298 'value' => '1',
2299 'compare' => '=',
2300 ),
2301 array(
2302 'key' => 'wpsc_agent_ticket_list_status',
2303 'value' => '1',
2304 'compare' => '=',
2305 ),
2306 ),
2307 )
2308 );
2309
2310 $items = array();
2311 foreach ( $fields as $field ) {
2312 $cf = wpsc_get_cf_by( 'id', $map[ $field->term_id ] );
2313 $items[] = $cf->slug;
2314 }
2315 update_option( 'wpsc-atl-list-items', $items );
2316
2317 // import agent filter items.
2318 $fields = get_terms(
2319 array(
2320 'taxonomy' => 'wpsc_ticket_custom_fields',
2321 'hide_empty' => false,
2322 'orderby' => 'meta_value_num',
2323 'meta_key' => 'wpsc_filter_agent_load_order',
2324 'order' => 'ASC',
2325 'meta_query' => array(
2326 'relation' => 'AND',
2327 array(
2328 'key' => 'wpsc_allow_ticket_filter',
2329 'value' => '1',
2330 'compare' => '=',
2331 ),
2332 array(
2333 'key' => 'wpsc_agent_ticket_filter_status',
2334 'value' => '1',
2335 'compare' => '=',
2336 ),
2337 ),
2338 )
2339 );
2340
2341 $items = array();
2342 foreach ( $fields as $field ) {
2343 $cf = wpsc_get_cf_by( 'id', $map[ $field->term_id ] );
2344 if ( $cf->slug == 'name' ) {
2345 $items[] = 'customer';
2346 } else {
2347 $items[] = $cf->slug;
2348 }
2349 }
2350 update_option( 'wpsc-atl-filter-items', $items );
2351
2352 // import customer list items.
2353 $fields = get_terms(
2354 array(
2355 'taxonomy' => 'wpsc_ticket_custom_fields',
2356 'hide_empty' => false,
2357 'orderby' => 'meta_value_num',
2358 'meta_key' => 'wpsc_tl_customer_load_order',
2359 'order' => 'ASC',
2360 'meta_query' => array(
2361 'relation' => 'AND',
2362 array(
2363 'key' => 'wpsc_allow_ticket_list',
2364 'value' => '1',
2365 'compare' => '=',
2366 ),
2367 array(
2368 'key' => 'wpsc_customer_ticket_list_status',
2369 'value' => '1',
2370 'compare' => '=',
2371 ),
2372 ),
2373 )
2374 );
2375
2376 $items = array();
2377 foreach ( $fields as $field ) {
2378 $cf = wpsc_get_cf_by( 'id', $map[ $field->term_id ] );
2379 $items[] = $cf->slug;
2380 }
2381 update_option( 'wpsc-ctl-list-items', $items );
2382
2383 // import customer filter items.
2384 $fields = get_terms(
2385 array(
2386 'taxonomy' => 'wpsc_ticket_custom_fields',
2387 'hide_empty' => false,
2388 'orderby' => 'meta_value_num',
2389 'meta_key' => 'wpsc_filter_customer_load_order',
2390 'order' => 'ASC',
2391 'meta_query' => array(
2392 'relation' => 'AND',
2393 array(
2394 'key' => 'wpsc_allow_ticket_filter',
2395 'value' => '1',
2396 'compare' => '=',
2397 ),
2398 array(
2399 'key' => 'wpsc_customer_ticket_filter_status',
2400 'value' => '1',
2401 'compare' => '=',
2402 ),
2403 ),
2404 )
2405 );
2406
2407 $items = array();
2408 foreach ( $fields as $field ) {
2409 $cf = wpsc_get_cf_by( 'id', $map[ $field->term_id ] );
2410 if ( $cf->slug == 'name' ) {
2411 $items[] = 'customer';
2412 } else {
2413 $items[] = $cf->slug;
2414 }
2415 }
2416 update_option( 'wpsc-ctl-filter-items', $items );
2417 }
2418
2419 /**
2420 * Import ticket list more settings
2421 *
2422 * @return void
2423 */
2424 public static function import_tl_more_settings() {
2425
2426 $cf_map = get_option( 'wpsc_upgrade_cf_term_id_map' );
2427 $status_map = get_option( 'wpsc_upgrade_status_map' );
2428 // agent view.
2429 $aview = get_option( 'wpsc-tl-ms-agent-view' );
2430 $orderby = get_option( 'wpsc_tl_agent_orderby' );
2431 $orderby = get_term_by( 'slug', $orderby, 'wpsc_ticket_custom_fields' );
2432 $orderby = wpsc_get_cf_by( 'id', $cf_map[ $orderby->term_id ] );
2433 $aview['default-sort-by'] = $orderby->slug;
2434 $aview['default-sort-order'] = get_option( 'wpsc_tl_agent_orderby_order' );
2435 $aview['number-of-tickets'] = get_option( 'wpsc_tl_agent_no_of_tickets' );
2436 $aview['unresolved-ticket-statuses'] = array_filter(
2437 array_unique(
2438 array_map(
2439 function ( $status_id ) use ( $status_map ) {
2440 return $status_map[ $status_id ];
2441 },
2442 get_option( 'wpsc_tl_agent_unresolve_statuses', array() )
2443 )
2444 )
2445 );
2446 update_option( 'wpsc-tl-ms-agent-view', $aview );
2447 // customer view.
2448 $cview = get_option( 'wpsc-tl-ms-customer-view' );
2449 $orderby = get_option( 'wpsc_tl_customer_orderby' );
2450 $orderby = get_term_by( 'slug', $orderby, 'wpsc_ticket_custom_fields' );
2451 $orderby = wpsc_get_cf_by( 'id', $cf_map[ $orderby->term_id ] );
2452 $cview['default-sort-by'] = $orderby->slug;
2453 $cview['default-sort-order'] = get_option( 'wpsc_tl_customer_orderby_order' );
2454 $cview['number-of-tickets'] = get_option( 'wpsc_tl_customer_no_of_tickets' );
2455 $cview['unresolved-ticket-statuses'] = array_filter(
2456 array_unique(
2457 array_map(
2458 function ( $status_id ) use ( $status_map ) {
2459 return $status_map[ $status_id ];
2460 },
2461 get_option( 'wpsc_tl_customer_unresolve_statuses', array() )
2462 )
2463 )
2464 );
2465 update_option( 'wpsc-tl-ms-customer-view', $cview );
2466 // Importing TL more setting -> advance setting.
2467 $setting = get_option( 'wpsc-tl-ms-advanced' );
2468 $setting['closed-ticket-statuses'] = array_unique(
2469 array_map(
2470 function ( $status_id ) use ( $status_map ) {
2471 return $status_map[ $status_id ];
2472 },
2473 get_option( 'wpsc_close_ticket_group', array() )
2474 )
2475 );
2476 update_option( 'wpsc-tl-ms-advanced', $setting );
2477 }
2478
2479 /**
2480 * Import email notifications general settings
2481 *
2482 * @return void
2483 */
2484 public static function import_en_general() {
2485
2486 $settings = get_option( 'wpsc-en-general', array() );
2487 $settings['from-name'] = get_option( 'wpsc_en_from_name' );
2488 $settings['from-email'] = get_option( 'wpsc_en_from_email' );
2489 $settings['reply-to'] = get_option( 'wpsc_en_reply_to' );
2490 $settings['blocked-emails'] = get_option( 'wpsc_en_ignore_emails', array() );
2491 $settings['cron-email-count'] = intval( get_option( 'wpsc_en_send_mail_count', 5 ) );
2492 update_option( 'wpsc-en-general', $settings );
2493 }
2494
2495 /**
2496 * Import ticket notifications
2497 *
2498 * @return void
2499 */
2500 public static function import_en_ticket_notifications() {
2501
2502 $en_template_map = array();
2503 $new_templates = array();
2504 $event_map = wpsc_get_en_event_map();
2505 $email_templates = get_terms(
2506 array(
2507 'taxonomy' => 'wpsc_en',
2508 'hide_empty' => false,
2509 'orderby' => 'ID',
2510 'order' => 'ASC',
2511 )
2512 );
2513
2514 $string_translations = get_option( 'wpsc-string-translation' );
2515 foreach ( $email_templates as $template ) {
2516
2517 $type = get_term_meta( $template->term_id, 'type', true );
2518 $subject = get_term_meta( $template->term_id, 'subject', true );
2519 $body = get_term_meta( $template->term_id, 'body', true );
2520
2521 $subject = wpsc_upgrade_macros( $subject );
2522 $body = wpsc_upgrade_macros( $body );
2523 $et = array(
2524 'title' => $template->name,
2525 'event' => $event_map[ $type ],
2526 'is_enable' => 1,
2527 'subject' => $subject,
2528 'body' => array(
2529 'text' => $body,
2530 'editor' => 'html',
2531 ),
2532 'to' => array(
2533 'general-recipients' => array(),
2534 'agent-roles' => array(),
2535 'custom' => array(),
2536 ),
2537 'cc' => array(
2538 'general-recipients' => array(),
2539 'agent-roles' => array(),
2540 'custom' => array(),
2541 ),
2542 'bcc' => wpsc_en_extract_bcc( $template ),
2543 'relation' => 'AND',
2544 'conditions' => '',
2545 );
2546
2547 if ( count( $new_templates ) == 0 ) {
2548 $new_templates[1] = $et;
2549 } else {
2550 $new_templates[] = $et;
2551 }
2552 $template_id = array_key_last( $new_templates );
2553 $en_template_map[ $template->term_id ] = $template_id;
2554 $string_translations[ 'wpsc-en-tn-subject-' . $template_id ] = $subject;
2555 $string_translations[ 'wpsc-en-tn-body-' . $template_id ] = $body;
2556 }
2557
2558 update_option( 'wpsc-string-translation', $string_translations );
2559 update_option( 'wpsc-email-templates', $new_templates );
2560 update_option( 'wpsc_upgrade_en_term_id_map', $en_template_map );
2561 }
2562
2563 /**
2564 * Import general settings
2565 *
2566 * @return void
2567 */
2568 public static function import_general_settings() {
2569
2570 global $wpdb;
2571 $gs = get_option( 'wpsc-gs-general' );
2572 $page_settings = get_option( 'wpsc-gs-page-settings' );
2573 $advanced = get_option( 'wpsc-ms-advanced-settings', array() );
2574 $roles = get_option( 'wpsc-agent-roles' );
2575 $status_map = get_option( 'wpsc_upgrade_status_map' );
2576 $category_map = get_option( 'wpsc_upgrade_category_map' );
2577 $priority_map = get_option( 'wpsc_upgrade_priority_map' );
2578 // support page.
2579 $page_settings['support-page'] = get_option( 'wpsc_support_page_id' );
2580 // default ticket status.
2581 $default_value = get_option( 'wpsc_default_ticket_status' );
2582 $default_value = $default_value ? $status_map[ $default_value ] : '1';
2583 $wpdb->update(
2584 $wpdb->prefix . 'psmsc_custom_fields',
2585 array( 'default_value' => $default_value ),
2586 array( 'id' => 7 )
2587 );
2588 // default ticket category.
2589 $default_value = get_option( 'wpsc_default_ticket_category' );
2590 $default_value = $default_value ? $category_map[ $default_value ] : '';
2591 $wpdb->update(
2592 $wpdb->prefix . 'psmsc_custom_fields',
2593 array( 'default_value' => $default_value ),
2594 array( 'id' => 9 )
2595 );
2596 // default ticket priority.
2597 $default_value = get_option( 'wpsc_default_ticket_priority' );
2598 $default_value = $default_value ? $priority_map[ $default_value ] : '';
2599 $wpdb->update(
2600 $wpdb->prefix . 'psmsc_custom_fields',
2601 array( 'default_value' => $default_value ),
2602 array( 'id' => 8 )
2603 );
2604 // ticket status after customer reply.
2605 $status = get_option( 'wpsc_ticket_status_after_customer_reply' );
2606 $gs['ticket-status-after-customer-reply'] = $status ? $status_map[ $status ] : '';
2607 // ticket status after agent reply.
2608 $status = get_option( 'wpsc_ticket_status_after_agent_reply' );
2609 $gs['ticket-status-after-agent-reply'] = $status ? $status_map[ $status ] : '';
2610 // close ticket status.
2611 $status = get_option( 'wpsc_close_ticket_status' );
2612 $gs['close-ticket-status'] = $status ? $status_map[ $status ] : '';
2613 // allow customer to close ticket.
2614 $customer = get_option( 'wpsc_allow_customer_close_ticket', 1 );
2615 $allow_close_ticket = $customer ? array( 'customer' ) : array();
2616 foreach ( $roles as $key => $role ) {
2617 $allow_close_ticket[] = $key;
2618 }
2619 $gs['allow-close-ticket'] = $allow_close_ticket;
2620 // reply form position.
2621 $position = get_option( 'wpsc_reply_form_position' );
2622 $gs['reply-form-position'] = $position == 1 ? 'top' : 'bottom';
2623 // ticket alice.
2624 $gs['ticket-alice'] = get_option( 'wpsc_ticket_alice' );
2625 // allow to create new tickets.
2626 $allow_ct = get_option( 'wpsc_allow_to_create_ticket' );
2627 $allow_create_ticket = array();
2628 if ( $allow_ct ) {
2629 if ( in_array( 'customer', $allow_ct ) ) {
2630 $allow_create_ticket[] = 'registered-user';
2631 }
2632 if ( in_array( 'guest', $allow_ct ) ) {
2633 $allow_create_ticket[] = 'guest';
2634 }
2635 foreach ( $roles as $key => $role ) {
2636 if ( in_array( $key, $allow_ct ) ) {
2637 $allow_create_ticket[] = $key;
2638 }
2639 }
2640 } else {
2641 $allow_create_ticket = array( 'registered-user' );
2642 if ( get_option( 'wpsc_allow_guest_ticket' ) == 1 ) {
2643 $allow_create_ticket[] = 'guest';
2644 }
2645 foreach ( $roles as $key => $role ) {
2646 $allow_create_ticket[] = $key;
2647 }
2648 }
2649 $gs['allow-create-ticket'] = $allow_create_ticket;
2650 // enable otp login if guest tickets are allowed.
2651 if ( in_array( 'guest', $gs['allow-create-ticket'] ) ) {
2652 $page_settings['otp-login'] = 1;
2653 }
2654 // allow reply to closed ticket.
2655 $allow_close = array();
2656 $reply_to_close_ticket = get_option( 'wpsc_allow_reply_to_close_ticket', array() );
2657 if ( in_array( 'customer', $reply_to_close_ticket ) ) {
2658 $allow_close[] = 'customer';
2659 }
2660 if ( in_array( 'agents', $reply_to_close_ticket ) ) {
2661 $allow_close[] = 'agent';
2662 }
2663 $advanced['allow-reply-to-close-ticket'] = $allow_close;
2664 // default login.
2665 $default_login = get_option( 'wpsc_default_login_setting', 1 );
2666 switch ( intval( $default_login ) ) {
2667 case 1:
2668 $page_settings['user-login'] = 'default';
2669 break;
2670 case 2:
2671 $page_settings['user-login'] = 'wp-default';
2672 break;
2673 case 3:
2674 $page_settings['user-login'] = 'custom';
2675 $page_settings['custom-login-url'] = get_option( 'wpsc_custom_login_url' );
2676 break;
2677 }
2678 // user registration.
2679 $user_registration = get_option( 'wpsc_user_registration', 0 );
2680 if ( $user_registration == 0 ) {
2681 $page_settings['user-registration'] = 'disable';
2682 } else {
2683 $registration_method = get_option( 'wpsc_user_registration_method', 1 );
2684 switch ( intval( $registration_method ) ) {
2685 case 1:
2686 $page_settings['user-registration'] = 'default';
2687 break;
2688 case 2:
2689 $page_settings['user-registration'] = 'wp-default';
2690 break;
2691 case 3:
2692 $page_settings['user-registration'] = 'custom';
2693 $page_settings['custom-registration-url'] = get_option( 'wpsc_custom_registration_url' );
2694 break;
2695 }
2696 }
2697 // update options.
2698 update_option( 'wpsc-gs-general', $gs );
2699 update_option( 'wpsc-gs-page-settings', $page_settings );
2700 update_option( 'wpsc-ms-advanced-settings', $advanced );
2701 }
2702
2703 /**
2704 * Re-order widgets as per old records
2705 *
2706 * @return void
2707 */
2708 public static function reorder_widgets() {
2709
2710 $installed_addons = get_option( 'wpsc_upgrade_installed_addons' );
2711 $new = get_option( 'wpsc-ticket-widget', array() );
2712 $prev = get_terms(
2713 array(
2714 'taxonomy' => 'wpsc_ticket_widget',
2715 'hide_empty' => false,
2716 'orderby' => 'meta_value_num',
2717 'order' => 'ASC',
2718 'meta_query' => array( 'order_clause' => array( 'key' => 'wpsc_ticket_widget_load_order' ) ),
2719 )
2720 );
2721 $widget_map = array(
2722 'status' => 'change-status',
2723 'raised-by' => 'raised-by',
2724 'assign-agent' => 'assignee',
2725 'ticket-fields' => 'ticket-fields',
2726 'agent-only-fields' => 'agentonly-fields',
2727 'additional-recepients' => 'additional-recipients',
2728 'biographical-info' => 'biographical-info',
2729 'rating' => 'rating',
2730 'woo-order' => 'woo-order',
2731 'woo-subscriptions' => 'woo-sub',
2732 'timer' => 'timer',
2733 'edd-order' => 'edd',
2734 'usergroup' => 'usergroups',
2735 );
2736
2737 $string_translations = get_option( 'wpsc-string-translation' );
2738 $reordered = array();
2739 foreach ( $prev as $widget ) {
2740
2741 $flag = true;
2742 switch ( $widget->slug ) {
2743 case 'rating':
2744 if ( ! $installed_addons[15]['is_installed'] ) {
2745 $flag = false;
2746 }
2747 break;
2748 case 'timer':
2749 if ( ! $installed_addons[13]['is_installed'] ) {
2750 $flag = false;
2751 }
2752 break;
2753 case 'woo-order':
2754 case 'woo-subscriptions':
2755 if ( ! $installed_addons[5]['is_installed'] ) {
2756 $flag = false;
2757 }
2758 break;
2759 case 'edd-order':
2760 if ( ! $installed_addons[8]['is_installed'] ) {
2761 $flag = false;
2762 }
2763 break;
2764 }
2765
2766 if ( $flag && isset( $new[ $widget_map[ $widget->slug ] ] ) ) {
2767
2768 $reordered[ $widget_map[ $widget->slug ] ] = $new[ $widget_map[ $widget->slug ] ];
2769 unset( $new[ $widget_map[ $widget->slug ] ] );
2770
2771 $reordered[ $widget_map[ $widget->slug ] ]['title'] = get_term_meta( $widget->term_id, 'wpsc_label', true );
2772 $reordered[ $widget_map[ $widget->slug ] ]['is_enable'] = get_term_meta( $widget->term_id, 'wpsc_ticket_widget_type', true );
2773 $agent_roles = get_term_meta( $widget->term_id, 'wpsc_ticket_widget_role', true );
2774 $reordered[ $widget_map[ $widget->slug ] ]['allowed-agent-roles'] = $agent_roles;
2775 if ( in_array( 'customer', $agent_roles ) ) {
2776 $reordered[ $widget_map[ $widget->slug ] ]['allow-customer'] = 1;
2777 }
2778 }
2779 }
2780
2781 foreach ( $reordered as $key => $widget ) {
2782 $string_translations[ 'wpsc-twt-' . $key ] = $widget['title'];
2783 }
2784
2785 foreach ( $new as $key => $widget ) {
2786 $reordered[ $key ] = $widget;
2787 }
2788
2789 update_option( 'wpsc-string-translation', $string_translations );
2790 update_option( 'wpsc-ticket-widget', $reordered );
2791 }
2792
2793 /**
2794 * Thank you page import
2795 *
2796 * @return void
2797 */
2798 public static function import_thankyou_settings() {
2799
2800 $string_translations = get_option( 'wpsc-string-translation' );
2801
2802 $thankyou_html = wpsc_upgrade_macros( get_option( 'wpsc_thankyou_html' ) );
2803 $thankyou_url = get_option( 'wpsc_thankyou_url' );
2804 if ( $thankyou_url ) {
2805 $action = 'url';
2806 } else {
2807 $action = 'text';
2808 }
2809
2810 update_option(
2811 'wpsc-gs-thankyou-page-settings',
2812 array(
2813 'action-agent' => $action,
2814 'action-customer' => $action,
2815 'html-agent' => $thankyou_html,
2816 'html-customer' => $thankyou_html,
2817 'page-url-agent' => $thankyou_url,
2818 'page-url-customer' => $thankyou_url,
2819 'editor-agent' => 'html',
2820 'editor-customer' => 'html',
2821 )
2822 );
2823
2824 $string_translations['wpsc-thankyou-html'] = $thankyou_html;
2825 $string_translations['wpsc-thankyou-html-agent'] = $thankyou_html;
2826
2827 update_option( 'wpsc-string-translation', $string_translations );
2828 }
2829
2830 /**
2831 * Import terms and conditions
2832 *
2833 * @return void
2834 */
2835 public static function import_terms_and_conditions() {
2836
2837 $tc = get_option( 'wpsc-term-and-conditions' );
2838 $string_translations = get_option( 'wpsc-string-translation' );
2839 $tandc_text = get_option( 'wpsc_terms_and_conditions_html', $tc['tandc-text'] );
2840 $tc['allow-term-and-conditions'] = intval( get_option( 'wpsc_terms_and_conditions', $tc['allow-term-and-conditions'] ) );
2841 $tc['tandc-text'] = $tandc_text;
2842 $string_translations['wpsc-term-and-conditions'] = $tandc_text;
2843 update_option( 'wpsc-term-and-conditions', $tc );
2844
2845 $gdpr = get_option( 'wpsc-gdpr-settings' );
2846 $gdpr_text = get_option( 'wpsc_gdpr_html', $gdpr['gdpr-text'] );
2847 $gdpr['allow-gdpr'] = intval( get_option( 'wpsc_set_in_gdpr', $gdpr['allow-gdpr'] ) );
2848 $gdpr['gdpr-text'] = $gdpr_text;
2849 $gdpr['personal-data-retention-time'] = intval( get_option( 'wpsc_personal_data_retention_period_time', $gdpr['personal-data-retention-time'] ) );
2850 $unit_map = array(
2851 'days' => 'days',
2852 'months' => 'month',
2853 'years' => 'year',
2854 );
2855 $unit = get_option( 'wpsc_personal_data_retention_period_unit' );
2856 $gdpr['personal-data-retention-unit'] = isset( $unit_map[ $unit ] ) ? $unit_map[ $unit ] : 'days';
2857 $string_translations['wpsc-gdpr'] = $gdpr_text;
2858
2859 update_option( 'wpsc-string-translation', $string_translations );
2860 update_option( 'wpsc-gdpr-settings', $gdpr );
2861 }
2862
2863 /**
2864 * Import advanced settings
2865 *
2866 * @return void
2867 */
2868 public static function import_advanced_settings() {
2869
2870 $advanced = get_option( 'wpsc-ms-advanced-settings' );
2871
2872 // Ticket url permissions.
2873 $ticket_url_permission = intval( get_option( 'wpsc_ticket_url_permission', 1 ) ) ? 0 : 1;
2874 $advanced['ticket-url-auth'] = $ticket_url_permission;
2875 // public mode.
2876 $advanced['public-mode'] = intval( get_option( 'wpsc_ticket_public_mode', $advanced['public-mode'] ) );
2877 $advanced['public-mode-reply'] = intval( get_option( 'wpsc_allow_reply_to_public_tickets', $advanced['public-mode-reply'] ) );
2878 // Allow Reply Confirmation.
2879 $advanced['reply-confirmation'] = intval( get_option( 'wpsc_allow_reply_confirmation', $advanced['reply-confirmation'] ) );
2880 // Thread Date Format.
2881 $display_as = get_option( 'wpsc_thread_date_format' );
2882 $advanced['thread-date-display-as'] = $display_as == 'string' ? 'diff' : 'date';
2883 $advanced['thread-date-format'] = get_option( 'wpsc_thread_date_time_format', $advanced['thread-date-format'] );
2884 // Do not notify owner.
2885 $advanced['do-not-notify-owner'] = get_option( 'wpsc_do_not_notify_setting', $advanced['do-not-notify-owner'] );
2886 $advanced['do-not-notify-owner-status'] = get_option( 'wpsc_default_do_not_notify_option', $advanced['do-not-notify-owner-status'] );
2887 // Priority visibility for customers in open ticket.
2888 $ticket_widgets = get_option( 'wpsc-ticket-widget' );
2889 $ticket_widgets['change-status']['show-priority-to-customer'] = intval( get_option( 'wpsc_hide_show_priority' ) );
2890 update_option( 'wpsc-ticket-widget', $ticket_widgets );
2891 // Ticket thread view more.
2892 $advanced['view-more'] = intval( get_option( 'wpsc_view_more', $advanced['view-more'] ) );
2893 // Auto refresh default status.
2894 $advanced_settings = get_option( 'wpsc-tl-ms-advanced' );
2895 $advanced_settings['auto-refresh-list-status'] = intval( get_option( 'wpsc_on_and_off_auto_refresh', $advanced_settings['auto-refresh-list-status'] ) );
2896 update_option( 'wpsc-tl-ms-advanced', $advanced_settings );
2897 // Ticket id setting.
2898 $advanced['ticket-id-format'] = get_option( 'wpsc_ticket_id_type' ) == '1' ? 'sequential' : 'random';
2899 $advanced['starting-ticket-id'] = intval( get_option( 'wpsc_custom_ticket_count', $advanced['starting-ticket-id'] ) );
2900 $advanced['random-id-length'] = intval( get_option( 'wpsc_rt_id_length', $advanced['random-id-length'] ) );
2901 // Ticket history limit.
2902 $advanced['ticket-history-macro-threads'] = intval( get_option( 'wpsc_thread_limit', $advanced['ticket-history-macro-threads'] ) );
2903 // Ticket reply redirect.
2904 $av_settings = get_option( 'wpsc-tl-ms-agent-view' );
2905 $av_settings['ticket-reply-redirect'] = get_option( 'wpsc_redirect_to_ticket_list' ) == '1' ? 'ticket-list' : 'no-redirect';
2906 update_option( 'wpsc-tl-ms-agent-view', $av_settings );
2907 $cv_settings = get_option( 'wpsc-tl-ms-customer-view' );
2908 $cv_settings['ticket-reply-redirect'] = get_option( 'wpsc_redirect_to_ticket_list' ) == '1' ? 'ticket-list' : 'no-redirect';
2909 update_option( 'wpsc-tl-ms-customer-view', $cv_settings );
2910 // Register user on creating ticket.
2911 $advanced['register-user-if-not-exist'] = intval( get_option( 'wpsc_reg_guest_user_after_create_ticket', $advanced['register-user-if-not-exist'] ) );
2912 // Auto delete closed tickets.
2913 $wpsc_auto_delete_ticket = get_option( 'wpsc_auto_delete_ticket', 0 );
2914 if ( $wpsc_auto_delete_ticket ) {
2915 $advanced['auto-delete-tickets-time'] = intval( get_option( 'wpsc_auto_delete_ticket_time', $advanced['auto-delete-tickets-time'] ) );
2916 } else {
2917 $advanced['auto-delete-tickets-time'] = 0;
2918 }
2919 $unit_map = array(
2920 'days' => 'days',
2921 'months' => 'month',
2922 'years' => 'year',
2923 );
2924 $unit = get_option( 'wpsc_auto_delete_ticket_time_period_unit' );
2925 $advanced['auto-delete-tickets-unit'] = isset( $unit_map[ $unit ] ) ? $unit_map[ $unit ] : 'days';
2926 // BCC in reply form.
2927 $advanced['allow-bcc'] = intval( get_option( 'wpsc_reply_bcc_visibility', $advanced['allow-bcc'] ) );
2928 // New ticket button url.
2929 $btn_url = get_option( 'wpsc_new_ticket_btn_url' );
2930 if ( $btn_url ) {
2931 $settings = get_option( 'wpsc-gs-page-settings' );
2932 $settings['new-ticket-page'] = 'custom';
2933 $settings['new-ticket-url'] = $btn_url;
2934 update_option( 'wpsc-gs-page-settings', $settings );
2935 }
2936 // Raised by user setting.
2937 $advanced['raised-by-user'] = get_option( 'wpsc_report_raised_by_user', 'customer' ) == 'customer' ? 'customer' : 'agent';
2938
2939 // update options.
2940 update_option( 'wpsc-ms-advanced-settings', $advanced );
2941 }
2942
2943 /**
2944 * Import captcha
2945 *
2946 * @return void
2947 */
2948 public static function import_captcha() {
2949
2950 if (
2951 ( get_option( 'wpsc_captcha' ) == 1 || get_option( 'wpsc_registration_captcha' ) == 1 || get_option( 'wpsc_login_captcha' ) == 1 ) &&
2952 get_option( 'wpsc_recaptcha_type', 1 ) == 0
2953 ) {
2954 $recaptcha = get_option( 'wpsc-recaptcha-settings' );
2955 $recaptcha['allow-recaptcha'] = 1;
2956 $recaptcha['recaptcha-version'] = 2;
2957 $recaptcha['recaptcha-site-key'] = get_option( 'wpsc_get_site_key', '' );
2958 $recaptcha['recaptcha-secret-key'] = get_option( 'wpsc_get_secret_key', '' );
2959 update_option( 'wpsc-recaptcha-settings', $recaptcha );
2960 }
2961 }
2962
2963 /**
2964 * Import assign agent rules.
2965 *
2966 * @return void
2967 */
2968 public static function import_assign_agent_rules() {
2969
2970 global $wpdb;
2971 $installed_addons = get_option( 'wpsc_upgrade_installed_addons' );
2972 if ( ! $installed_addons[10]['is_installed'] ) {
2973 return;
2974 }
2975
2976 // import settings.
2977 $general = get_option( 'wpsc-aar-general-settings' );
2978 $general['auto-assign-agent'] = get_option( 'wpsc_assign_auto_responder', $general['auto-assign-agent'] );
2979 update_option( 'wpsc-aar-general-settings', $general );
2980
2981 // import rules.
2982 $agent_map = get_option( 'wpsc_upgrade_agent_map' );
2983 $new_rules = array();
2984 $rules_map = array();
2985 $prev_rules = get_terms(
2986 array(
2987 'taxonomy' => 'wpsc_caa',
2988 'hide_empty' => false,
2989 )
2990 );
2991
2992 foreach ( $prev_rules as $prev ) {
2993
2994 $prev_agents = get_term_meta( $prev->term_id, 'agent_ids', true );
2995 $new_agents = array_map(
2996 function ( $old_id ) use ( $wpdb, $agent_map ) {
2997 return $wpdb->get_row( "SELECT * from {$wpdb->prefix}psmsc_agents WHERE id = " . $agent_map[ $old_id ] );
2998 },
2999 $prev_agents
3000 );
3001 $agents = array();
3002 $agentgroups = array();
3003 foreach ( $new_agents as $agent ) {
3004 if ( $agent->is_agentgroup ) {
3005 $agentgroups[] = $agent->id;
3006 } else {
3007 $agents[] = $agent->id;
3008 }
3009 }
3010
3011 $conditions = array();
3012
3013 $rule = array(
3014 'title' => $prev->name,
3015 'agents' => implode( '|', $agents ),
3016 'assign_method' => 'assign_all',
3017 'agentgroups' => implode( '|', $agentgroups ),
3018 'assign_group_method' => 'assign_all_groups',
3019 'relation' => 'AND',
3020 'conditions' => $conditions ? wp_json_encode( $conditions ) : '{}',
3021 );
3022
3023 if ( $new_rules ) {
3024 $new_rules[] = $rule;
3025 } else {
3026 $new_rules[1] = $rule;
3027 }
3028 $rules_map[ $prev->term_id ] = array_key_last( $new_rules );
3029 }
3030 update_option( 'wpsc-aar-rules', $new_rules );
3031 update_option( 'wpsc_upgrade_aar_map', $rules_map );
3032 }
3033
3034 /**
3035 * Import automatic close tickets add-on
3036 *
3037 * @return void
3038 */
3039 public static function import_automatic_close_tickets() {
3040
3041 $installed_addons = get_option( 'wpsc_upgrade_installed_addons' );
3042 if ( ! $installed_addons[0]['is_installed'] ) {
3043 return;
3044 }
3045
3046 // import settings.
3047 $string_translations = get_option( 'wpsc-string-translation' );
3048 $gs = get_option( 'wpsc-gs-general' );
3049 $status_map = get_option( 'wpsc_upgrade_status_map' );
3050 $settings = get_option( 'wpsc-atc-settings' );
3051 $settings['statuses-enabled'] = array_map(
3052 function ( $status_id ) use ( $status_map ) {
3053 return $status_map[ $status_id ];
3054 },
3055 get_option( 'wpsc_tl_statuses', array() )
3056 );
3057 $settings['age'] = get_option( 'wpsc_atc_age', '0' );
3058 $settings['close-status'] = get_option( 'wpsc_atc_status', $gs['close-ticket-status'] );
3059 update_option( 'wpsc-atc-settings', $settings );
3060
3061 // import warning email.
3062 $subject = wpsc_upgrade_macros( get_option( 'wpsc_atc_subject', '' ) );
3063 $body = wpsc_upgrade_macros( get_option( 'wpsc_atc_email_body', '' ) );
3064 $templates = array(
3065 array(
3066 'title' => 'Default template',
3067 'days-before' => get_option( 'wpsc_atc_waring_email_age', 3 ),
3068 'subject' => $subject,
3069 'body' => $body,
3070 'editor' => 'html',
3071 ),
3072 );
3073 $string_translations['wpsc-act-subject-0'] = $subject;
3074 $string_translations['wpsc-act-body-0'] = $body;
3075 update_option( 'wpsc-string-translation', $string_translations );
3076 update_option( 'wpsc-atc-et', $templates );
3077 }
3078
3079 /**
3080 * Import canned reply addon
3081 *
3082 * @return void
3083 */
3084 public static function import_canned_reply() {
3085
3086 global $wpdb;
3087
3088 $installed_addons = get_option( 'wpsc_upgrade_installed_addons' );
3089 if ( ! $installed_addons[1]['is_installed'] ) {
3090 return;
3091 }
3092
3093 // reset data.
3094 $wpdb->query( 'DELETE FROM ' . $wpdb->prefix . 'psmsc_cr_categories' );
3095 $wpdb->query( 'ALTER TABLE ' . $wpdb->prefix . 'psmsc_cr_categories AUTO_INCREMENT = 1' );
3096 $wpdb->query( 'DELETE FROM ' . $wpdb->prefix . 'psmsc_canned_reply' );
3097 $wpdb->query( 'ALTER TABLE ' . $wpdb->prefix . 'psmsc_canned_reply AUTO_INCREMENT = 1' );
3098
3099 // import canned reply categories.
3100 $wpdb->insert(
3101 $wpdb->prefix . 'psmsc_cr_categories',
3102 array(
3103 'name' => 'Uncategorized',
3104 )
3105 );
3106 $categories = get_terms(
3107 array(
3108 'taxonomy' => 'wpsc_canned_reply_categories',
3109 'hide_empty' => false,
3110 )
3111 );
3112
3113 $string_translations = get_option( 'wpsc-string-translation' );
3114 $map = array();
3115 foreach ( $categories as $prev ) {
3116 $wpdb->insert(
3117 $wpdb->prefix . 'psmsc_cr_categories',
3118 array(
3119 'name' => $prev->name,
3120 )
3121 );
3122 $string_translations[ 'wpsc-cr-category-' . $wpdb->insert_id ] = $prev->name;
3123 $map[ $prev->term_id ] = $wpdb->insert_id;
3124 }
3125
3126 // import canned reply.
3127 $response = get_posts(
3128 array(
3129 'post_type' => 'wpsc_canned_reply',
3130 'post_status' => 'publish',
3131 'orderby' => 'date',
3132 'order' => 'ASC',
3133 'posts_per_page' => -1,
3134 )
3135 );
3136 foreach ( $response as $prev ) {
3137 $prev_categories = get_the_terms( $prev->ID, 'wpsc_canned_reply_categories' );
3138 $categories = '1';
3139 if ( is_array( $prev_categories ) ) {
3140 $categories = implode(
3141 '|',
3142 array_map(
3143 function ( $category ) use ( $map ) {
3144 return $map[ $category->term_id ];
3145 },
3146 $prev_categories
3147 ),
3148 );
3149 }
3150 $author = wpsc_get_customer_by( 'user_id', $prev->post_author );
3151 $visibility = get_post_meta( $prev->ID, 'wpsc_agent_visibility', true );
3152 $wpdb->insert(
3153 $wpdb->prefix . 'psmsc_canned_reply',
3154 array(
3155 'title' => $prev->post_title,
3156 'author' => $author->id,
3157 'body' => wpautop( wpsc_upgrade_macros( $prev->post_content ) ),
3158 'categories' => $categories,
3159 'visibility' => $visibility ? 'public' : 'private',
3160 'date_created' => $prev->post_date,
3161 )
3162 );
3163 }
3164 update_option( 'wpsc-string-translation', $string_translations );
3165 }
3166
3167 /**
3168 * Import report settings
3169 *
3170 * @return void
3171 */
3172 public static function import_report_settings() {
3173
3174 $installed_addons = get_option( 'wpsc_upgrade_installed_addons' );
3175 if ( ! $installed_addons[6]['is_installed'] ) {
3176 return;
3177 }
3178
3179 $agent_roles = get_option( 'wpsc-agent-roles' );
3180 foreach ( $agent_roles as $index => $role ) {
3181 $role['caps']['view-reports'] = $index == 1 ? true : false;
3182 $agent_roles[ $index ] = $role;
3183 }
3184 update_option( 'wpsc-agent-roles', $agent_roles );
3185 }
3186
3187 /**
3188 * Import satisfaction survey
3189 *
3190 * @return void
3191 */
3192 public static function import_satisfaction_survey() {
3193
3194 global $wpdb;
3195
3196 $installed_addons = get_option( 'wpsc_upgrade_installed_addons' );
3197 if ( ! $installed_addons[15]['is_installed'] ) {
3198 return;
3199 }
3200
3201 // reset data.
3202 $wpdb->query( 'DELETE FROM ' . $wpdb->prefix . 'psmsc_sf_ratings' );
3203 $wpdb->query( 'ALTER TABLE ' . $wpdb->prefix . 'psmsc_sf_ratings AUTO_INCREMENT = 1' );
3204
3205 // import ratings.
3206 $ratings = get_terms(
3207 array(
3208 'taxonomy' => 'wpsc_sf_rating',
3209 'hide_empty' => false,
3210 'orderby' => 'meta_value_num',
3211 'order' => 'ASC',
3212 'meta_query' => array( 'order_clause' => array( 'key' => 'load_order' ) ),
3213 )
3214 );
3215
3216 $string_translations = get_option( 'wpsc-string-translation' );
3217 $map = array();
3218 $load_order = 1;
3219 $confirmation_text = get_option( 'wpsc_sf_thankyou_text', '' );
3220 foreach ( $ratings as $prev ) {
3221 $bg_color = get_term_meta( $prev->term_id, 'color', true );
3222 $wpdb->insert(
3223 $wpdb->prefix . 'psmsc_sf_ratings',
3224 array(
3225 'name' => $prev->name,
3226 'color' => '#FFFFFF',
3227 'bg_color' => $bg_color,
3228 'confirmation_text' => $confirmation_text,
3229 'load_order' => $load_order++,
3230 )
3231 );
3232
3233 $string_translations[ 'wpsc-rating-name-' . $wpdb->insert_id ] = $prev->name;
3234 $string_translations[ 'wpsc-rating-ct-' . $wpdb->insert_id ] = $confirmation_text;
3235 $map[ $prev->term_id ] = $wpdb->insert_id;
3236 }
3237
3238 update_option( 'wpsc_upgrade_sf_rating_map', $map );
3239
3240 // import settings.
3241 $gs = get_option( 'wpsc-gs-general' );
3242 $settings = get_option( 'wpsc-sf-general-setting' );
3243 $settings['survey-page'] = get_option( 'wpsc_sf_page', 0 );
3244 $settings['customer-trigger'] = get_option( 'wpsc_allow_survey_after_ticket_close', 0 );
3245 $settings['statuses-enabled'] = array( $gs['close-ticket-status'] );
3246 update_option( 'wpsc-sf-general-setting', $settings );
3247
3248 // import email template.
3249 $days_after = get_option( 'wpsc_sf_age', '0' );
3250 if ( get_option( 'wpsc_sf_age_unit', 'd' ) == 'h' ) {
3251 $days_after = 1;
3252 }
3253
3254 $subject = wpsc_upgrade_macros( get_option( 'wpsc_sf_subject', '' ) );
3255 $body = wpsc_upgrade_macros( get_option( 'wpsc_sf_email_body', '' ) );
3256 $new = array(
3257 array(
3258 'title' => 'Default template',
3259 'days-after' => $days_after,
3260 'subject' => $subject,
3261 'body' => $body,
3262 'editor' => 'html',
3263 ),
3264 );
3265 $string_translations['wpsc-sf-et-subject-0'] = $subject;
3266 $string_translations['wpsc-sf-et-body-0'] = $body;
3267 update_option( 'wpsc-string-translation', $string_translations );
3268 update_option( 'wpsc-sf-et', $new );
3269 }
3270
3271 /**
3272 * Import email piping add-on settings
3273 *
3274 * @return void
3275 */
3276 public static function import_email_piping() {
3277
3278 $installed_addons = get_option( 'wpsc_upgrade_installed_addons' );
3279 if ( ! $installed_addons[3]['is_installed'] ) {
3280 return;
3281 }
3282
3283 $string_translations = get_option( 'wpsc-string-translation' );
3284 // import settings.
3285 $general = get_option( 'wpsc-ep-general-settings' );
3286 $general['connection'] = get_option( 'wpsc_ep_piping_type', 'imap' );
3287
3288 $block_emails = array();
3289 if ( $general['block-emails'] ) {
3290 $block_emails = array_merge( $general['block-emails'], get_option( 'wpsc_ep_block_emails', array() ) );
3291 }
3292 $general['block-emails'] = array_filter( array_map( 'trim', $block_emails ) );
3293
3294 $block_subject = array();
3295 if ( $general['block-subject'] ) {
3296 $block_subject = array_merge( $general['block-subject'], explode( PHP_EOL, get_option( 'wpsc_ep_block_subject', '' ) ) );
3297 }
3298 $general['block-subject'] = array_filter( array_map( 'trim', $block_subject ) );
3299
3300 $general['allowed-emails'] = get_option( 'wpsc_ep_accept_emails', 'all' );
3301 $allowed_users = get_option( 'wpsc_ep_allowed_user', 0 );
3302 $general['allowed-users'] = $allowed_users ? 'anyone' : 'registered';
3303 $general['import-cc'] = get_option( 'wpsc_add_additional_recepients', 0 );
3304 $general['time-frequency'] = get_option( 'wpsc_ep_cron_execution_time', 5 );
3305 $general['body-reference'] = get_option( 'wpsc_ep_email_type', 'text' );
3306
3307 $forwarding_addresses = get_option( 'wpsc_ep_emails_forwarded', array() );
3308 $general['forwarding-addresses'] = array_filter( array_map( 'trim', $forwarding_addresses ) );
3309
3310 $general['forwarding-as-from-email'] = get_option( 'wpsc_ep_from_email', 0 );
3311 update_option( 'wpsc-ep-general-settings', $general );
3312
3313 // import connection settings.
3314 if ( $general['connection'] == 'imap' ) {
3315
3316 $imap = array(
3317 'email-address' => get_option( 'wpsc_ep_imap_email_address', '' ),
3318 'password' => get_option( 'wpsc_ep_imap_email_password', '' ),
3319 'encryption' => get_option( 'wpsc_ep_imap_encryption', 'ssl' ),
3320 'incoming-mail-server' => get_option( 'wpsc_ep_imap_incoming_mail_server', '' ),
3321 'port' => get_option( 'wpsc_ep_imap_port', '' ),
3322 'is_active' => 0,
3323 'last-error' => '',
3324 );
3325
3326 // check connection.
3327 $encryption_text = '';
3328 if ( $imap['encryption'] == 'none' ) {
3329 $encryption_text = 'novalidate-cert';
3330 } elseif ( $imap['encryption'] == 'ssl' ) {
3331 $encryption_text = 'imap/ssl/novalidate-cert';
3332 }
3333
3334 // Check if IMAP extension is enable or not.
3335 if ( extension_loaded( 'imap' ) ) {
3336 $conn = @imap_open( '{' . $imap['incoming-mail-server'] . ':' . $imap['port'] . '/' . $encryption_text . '}INBOX', $imap['email-address'], $imap['password'] ); // phpcs:ignore
3337 if ( $conn ) {
3338 $imap['is_active'] = 1;
3339 } else {
3340 $imap['last-error'] = imap_last_error();
3341 }
3342 }
3343
3344 update_option( 'wpsc-ep-imap-settings', $imap );
3345
3346 } else { // gmail.
3347
3348 $gmail = array(
3349 'email-address' => get_option( 'wpsc_ep_email_address', '' ),
3350 'client-id' => get_option( 'wpsc_ep_client_id', '' ),
3351 'client-secret' => get_option( 'wpsc_ep_client_secret', '' ),
3352 'is-active' => 0,
3353 'last-error' => '',
3354 'refresh-token' => get_option( 'wpsc_ep_refresh_token', '' ),
3355 'history-id' => get_option( 'wpsc_ep_historyId', '' ),
3356 );
3357 if (
3358 $gmail['email-address'] &&
3359 $gmail['client-id'] &&
3360 $gmail['client-secret'] &&
3361 $gmail['refresh-token'] &&
3362 $gmail['history-id']
3363 ) {
3364 $gmail['is-active'] = 1;
3365 }
3366 update_option( 'wpsc-ep-gmail-settings', $gmail );
3367 }
3368
3369 // import email piping rules.
3370 $cf_map = get_option( 'wpsc_upgrade_cf_term_id_map' );
3371 $status_map = get_option( 'wpsc_upgrade_status_map' );
3372 $category_map = get_option( 'wpsc_upgrade_category_map' );
3373 $priority_map = get_option( 'wpsc_upgrade_priority_map' );
3374 $new_rules = array();
3375
3376 $fields = get_terms(
3377 array(
3378 'taxonomy' => 'wpsc_ticket_custom_fields',
3379 'hide_empty' => false,
3380 'meta_query' => array(
3381 'relation' => 'AND',
3382 array(
3383 'key' => 'agentonly',
3384 'value' => array( 0, 1 ),
3385 'compare' => 'IN',
3386 ),
3387 array(
3388 'key' => 'wpsc_tf_type',
3389 'value' => '0',
3390 'compare' => '>',
3391 ),
3392 ),
3393 )
3394 );
3395
3396 $email_piping_rules = get_terms(
3397 array(
3398 'taxonomy' => 'wpsc_ep_rules',
3399 'hide_empty' => false,
3400 'orderby' => 'meta_value_num',
3401 'order' => 'ASC',
3402 'meta_query' => array( 'order_clause' => array( 'key' => 'wpsc_en_rule_load_order' ) ),
3403 )
3404 );
3405
3406 $date_formats = array(
3407 'dd-mm-yy' => 'd-m-Y',
3408 'dd-yy-mm' => 'd-Y-m',
3409 'mm-dd-yy' => 'm-d-Y',
3410 'mm-yy-dd' => 'm-Y-d',
3411 'yy-mm-dd' => 'Y-m-d',
3412 'yy-dd-mm' => 'Y-d-m',
3413 );
3414
3415 foreach ( $email_piping_rules as $prev ) {
3416
3417 $rule = array(
3418 'title' => $prev->name,
3419 );
3420
3421 // condition.
3422 $forwarding_address = get_term_meta( $prev->term_id, 'wpsc_ep_to_address', true );
3423 $forwarding_address = $forwarding_address ? $forwarding_address : array();
3424 $rule['forwarding-address'] = array_filter( array_map( 'trim', $forwarding_address ) );
3425
3426 $from_address = get_term_meta( $prev->term_id, 'wpsc_ep_from_address', true );
3427 $from_address = $from_address ? $from_address : array();
3428 $rule['from-address'] = array_filter( array_map( 'trim', $from_address ) );
3429
3430 $has_words = get_term_meta( $prev->term_id, 'wpsc_ep_has_words', true );
3431 $has_words = $has_words ? $has_words : array();
3432 $rule['has-words'] = array_filter( array_map( 'trim', $has_words ) );
3433
3434 // category and priority.
3435 $status = get_term_meta( $prev->term_id, 'ticket_status', true );
3436 if ( $status ) {
3437 $rule['status'] = $status_map[ $status ];
3438 }
3439 $category = get_term_meta( $prev->term_id, 'ticket_category', true );
3440 if ( $category ) {
3441 $rule['category'] = $category_map[ $category ];
3442 }
3443 $priority = get_term_meta( $prev->term_id, 'ticket_priority', true );
3444 if ( $priority ) {
3445 $rule['priority'] = $priority_map[ $priority ];
3446 }
3447
3448 // custom fields.
3449 foreach ( $fields as $field ) {
3450
3451 $type = get_term_meta( $field->term_id, 'wpsc_tf_type', true );
3452 $cf = wpsc_get_cf_by( 'id', $cf_map[ $field->term_id ] );
3453
3454 switch ( $type ) {
3455
3456 case 1:
3457 case 5:
3458 case 7:
3459 case 8:
3460 case 9:
3461 case 11:
3462 $val = get_term_meta( $prev->term_id, $field->slug, true );
3463 if ( $val ) {
3464 $rule[ $cf->slug ] = $val ? $val : '';
3465 }
3466 break;
3467
3468 case 2:
3469 case 4:
3470 $options_map = get_option( 'wpsc_upgrade_cf_options_map' );
3471 $val = get_term_meta( $prev->term_id, $field->slug, true );
3472 if ( $val ) {
3473 $rule[ $cf->slug ] = $options_map[ $cf->id ][ $val ];
3474 }
3475 break;
3476
3477 case 3:
3478 $options_map = get_option( 'wpsc_upgrade_cf_options_map' );
3479 $val = get_term_meta( $prev->term_id, $field->slug );
3480 if ( $val ) {
3481 $rule[ $cf->slug ] = implode(
3482 '|',
3483 array_filter(
3484 array_map(
3485 function ( $name ) use ( $cf, $options_map ) {
3486 return $name ? $options_map[ $cf->id ][ $name ] : false;
3487 },
3488 $val
3489 )
3490 )
3491 );
3492 }
3493 break;
3494
3495 case 6:
3496 $val = get_term_meta( $prev->term_id, $field->slug, true );
3497 if ( $val ) {
3498 $old_date_format = get_option( 'wpsc_calender_date_format' );
3499 $val = DateTime::createFromFormat( $date_formats[ $old_date_format ] . ' H:i:s', $val );
3500 if ( $val ) {
3501 $rule[ $cf->slug ] = $val->format( 'Y-m-d' );
3502 }
3503 }
3504 break;
3505
3506 case 18:
3507 $val = get_term_meta( $prev->term_id, $field->slug, true );
3508 if ( $val ) {
3509 $old_date_format = get_option( 'wpsc_calender_date_format' );
3510 $val = DateTime::createFromFormat( $date_formats[ $old_date_format ] . ' H:i:s', $val );
3511 if ( $val ) {
3512 $rule[ $cf->slug ] = $val->format( 'Y-m-d H:i:s' );
3513 }
3514 }
3515 break;
3516
3517 case 21:
3518 $val = get_term_meta( $prev->term_id, $field->slug, true );
3519 if ( $val ) {
3520 $val = new DateTime( $val );
3521 $rule[ $cf->slug ] = $val->format( 'H:i' );
3522 }
3523 break;
3524 }
3525 }
3526
3527 $additional_users = get_term_meta( $prev->term_id, 'wpsc_ticket_et_user', true );
3528 $additional_users = $additional_users ? $additional_users : array();
3529 $additional_users = array_unique( array_filter( array_map( 'trim', $additional_users ) ) );
3530 $rule['add_recipients'] = $additional_users ? implode( '|', $additional_users ) : '';
3531
3532 if ( $new_rules ) {
3533 $new_rules[] = $rule;
3534 } else {
3535 $new_rules[1] = $rule;
3536 }
3537 }
3538
3539 update_option( 'wpsc-ep-pipe-rules', $new_rules );
3540
3541 // Import email piping notification.
3542 // Allowed usertype warning.
3543 $ep_notification_allowed = get_option( 'wpsc-ep-usertype-warning-email' );
3544 $close_email_body = get_option( 'wpsc_close_user_warn_email_body', $ep_notification_allowed['email-warning-message'] );
3545 $ep_notification_allowed['enable'] = intval( get_option( 'wpsc_close_user_warn_email_status', $ep_notification_allowed['enable'] ) );
3546 $ep_notification_allowed['email-warning-message'] = $close_email_body;
3547 $string_translations['wpsc-ep-usertype-warning-message'] = $close_email_body;
3548 update_option( 'wpsc-ep-usertype-warning-email', $ep_notification_allowed );
3549
3550 // Allowed closed ticket warning.
3551 $ep_notification_closed = get_option( 'wpsc-close-ticket-page-settings' );
3552 $warn_email_body = wpsc_upgrade_macros( get_option( 'wpsc_ct_warn_email_body', $ep_notification_closed['close-ticket-html'] ) );
3553 $ep_notification_closed['enable'] = intval( get_option( 'wpsc_ct_warn_email_status', $ep_notification_closed['enable'] ) );
3554 $ep_notification_closed['close-ticket-html'] = $warn_email_body;
3555 $string_translations['wpsc-close-ticket-html'] = $warn_email_body;
3556 update_option( 'wpsc-close-ticket-page-settings', $ep_notification_closed );
3557 update_option( 'wpsc-string-translation', $string_translations );
3558 }
3559
3560 /**
3561 * Import FAQ integration add-on settings
3562 *
3563 * @return void
3564 */
3565 public static function import_faq_integration() {
3566
3567 $installed_addons = get_option( 'wpsc_upgrade_installed_addons' );
3568 if ( ! $installed_addons[11]['is_installed'] ) {
3569 return;
3570 }
3571
3572 $map = array(
3573 'WPSC_Ultimate_FAQ' => 'ultimate_faq',
3574 'WPSC_Acronix_FAQ' => 'acronix_faq',
3575 );
3576 $prev = get_option( 'wpsc_select_faq_set', '' );
3577 if ( $prev ) {
3578 update_option(
3579 'wpsc-faq-settings',
3580 array(
3581 'faq' => $map[ $prev ],
3582 )
3583 );
3584 }
3585 }
3586
3587 /**
3588 * Import knowledgebase integration
3589 *
3590 * @return void
3591 */
3592 public static function import_knowledgebase_integration() {
3593
3594 $installed_addons = get_option( 'wpsc_upgrade_installed_addons' );
3595 if ( ! $installed_addons[12]['is_installed'] ) {
3596 return;
3597 }
3598
3599 $map = array(
3600 'WPSC_PrassApp_Knowledgbase' => 'pressapp_kb',
3601 'WPSC_WP_Knowledgbase' => 'wp_kb',
3602 'WPSC_HelpGuru_Knowledgbase' => 'ht_kb',
3603 'WPSC_BasePress_Knowledgbase' => 'basepress_kb',
3604 'WPSC_BWL_Knowledgbase' => 'bwl_kb',
3605 'WPSC_Echo_Knowledgbase' => 'echo_kb',
3606 'WPSC_Knowledgebase_Helpdesk' => 'helpdesk_kb',
3607 'WPSC_BetterDocs' => 'betterdocs_kb',
3608 );
3609 $prev = get_option( 'wpsc_select_knowledgbase_set', '' );
3610 if ( $prev ) {
3611 update_option(
3612 'wpsc-kb-settings',
3613 array(
3614 'knowledgebase' => $map[ $prev ],
3615 )
3616 );
3617 }
3618 }
3619
3620 /**
3621 * Import export add-on settings
3622 *
3623 * @return void
3624 */
3625 public static function import_export_addon() {
3626
3627 $installed_addons = get_option( 'wpsc_upgrade_installed_addons' );
3628 if ( ! $installed_addons[2]['is_installed'] ) {
3629 return;
3630 }
3631
3632 // visibility.
3633 $new_visibility = array();
3634 $prev_visibility = get_option( 'wpsc_selected_user_roll_data', array() );
3635 foreach ( $prev_visibility as $visibility ) {
3636 if ( $visibility == 'customer' ) {
3637 $new_visibility[] = 'registered-user';
3638 $new_visibility[] = 'guest';
3639 continue;
3640 }
3641 $new_visibility[] = $visibility;
3642 }
3643
3644 update_option(
3645 'wpsc-export-roles',
3646 array(
3647 'allow-export-ticket' => $new_visibility,
3648 )
3649 );
3650
3651 // agent export fields.
3652 $cf_slug_map = get_option( 'wpsc_upgrade_cf_slug_map' );
3653 $prev_items = get_option( 'wpsc_export_ticket_list', array() );
3654 $new_items = array();
3655 foreach ( $prev_items as $slug ) {
3656 $new_items[] = $cf_slug_map[ $slug ];
3657 }
3658 update_option( 'wpsc-agent-export-settings', $new_items );
3659
3660 // customer export fields.
3661 $prev_items = get_option( 'wpsc_customer_export_ticket_list', array() );
3662 $new_items = array();
3663 foreach ( $prev_items as $slug ) {
3664 $new_items[] = $cf_slug_map[ $slug ];
3665 }
3666 update_option( 'wpsc-register-export-settings', $new_items );
3667 }
3668
3669 /**
3670 * Import woocommerce settings
3671 *
3672 * @return void
3673 */
3674 public static function import_woocommerce_addon() {
3675
3676 $installed_addons = get_option( 'wpsc_upgrade_installed_addons' );
3677 if ( ! $installed_addons[5]['is_installed'] ) {
3678 return;
3679 }
3680
3681 $string_translations = get_option( 'wpsc-string-translation' );
3682 // settings.
3683 $tab_lable = get_option( 'wpsc_dashboard_support_tab_label', '' );
3684 $help_lable = get_option( 'wpsc_order_help_button_label', '' );
3685 $settings = get_option( 'wpsc-woo-settings' );
3686 $settings['dashboard-support-tab'] = intval( get_option( 'wpsc_dashboard_support_tab', 1 ) );
3687 $settings['dashboard-support-tab-label'] = $tab_lable;
3688 $settings['order-help-button'] = intval( get_option( 'wpsc_order_help_button', 0 ) );
3689 $settings['order-help-button-label'] = $help_lable;
3690 $settings['dashboard-as-ticket-url'] = get_option( 'wpsc_woo_ticket_url', '' );
3691 update_option( 'wpsc-woo-settings', $settings );
3692
3693 $string_translations['wpsc-woo-dashboard-tab-label'] = $tab_lable;
3694 $string_translations['wpsc-woo-order-help-button-label'] = $help_lable;
3695 update_option( 'wpsc-string-translation', $string_translations );
3696 }
3697
3698 /**
3699 * Import schedule tickets
3700 *
3701 * @return void
3702 */
3703 public static function import_shedule_tickets() {
3704
3705 global $wpdb;
3706 $installed_addons = get_option( 'wpsc_upgrade_installed_addons' );
3707 if ( ! $installed_addons[14]['is_installed'] ) {
3708 return;
3709 }
3710
3711 $cf_map = get_option( 'wpsc_upgrade_cf_term_id_map' );
3712 $category_map = get_option( 'wpsc_upgrade_category_map' );
3713 $priority_map = get_option( 'wpsc_upgrade_priority_map' );
3714 $new_rules = array();
3715 $date_formats = array(
3716 'dd-mm-yy' => 'd-m-Y',
3717 'dd-yy-mm' => 'd-Y-m',
3718 'mm-dd-yy' => 'm-d-Y',
3719 'mm-yy-dd' => 'm-Y-d',
3720 'yy-mm-dd' => 'Y-m-d',
3721 'yy-dd-mm' => 'Y-d-m',
3722 );
3723
3724 $fields = get_terms(
3725 array(
3726 'taxonomy' => 'wpsc_ticket_custom_fields',
3727 'hide_empty' => false,
3728 'meta_query' => array(
3729 'relation' => 'AND',
3730 array(
3731 'key' => 'agentonly',
3732 'value' => array( 0, 1 ),
3733 'compare' => 'IN',
3734 ),
3735 array(
3736 'key' => 'wpsc_tf_type',
3737 'value' => '0',
3738 'compare' => '>',
3739 ),
3740 ),
3741 )
3742 );
3743
3744 $scheule_tickets = get_terms(
3745 array(
3746 'taxonomy' => 'wpsc_schedule_tickets',
3747 'hide_empty' => false,
3748 )
3749 );
3750
3751 foreach ( $scheule_tickets as $prev ) {
3752
3753 $time_unit = get_term_meta( $prev->term_id, 'repeat_every_time_unit', true );
3754 $recurrence = get_term_meta( $prev->term_id, 'no_of_recurrence', true );
3755 $start_date = new DateTime( get_term_meta( $prev->term_id, 'start_date', true ) . ' 00:00:00' );
3756
3757 $rule = array(
3758 'title' => $prev->name,
3759 'recurrence-period' => 'daily',
3760 'daily-recurrence-type' => 'daily-every-day',
3761 'daily-x-days' => 1,
3762 'daily-x-work-days' => 1,
3763 'weekly-x-weeks' => 1,
3764 'weekly-days' => array( 1, 2, 3, 4, 5 ),
3765 'monthly-recurrence-type' => 'monthly-day-number',
3766 'monthly-day-number-x-months' => 1,
3767 'monthly-day-number-day' => 1,
3768 'monthly-week-number-x-months' => 1,
3769 'monthly-week-number-occurrence' => 1,
3770 'monthly-week-number-day' => 1,
3771 'yearly-recurrence-type' => 'yearly-day-number',
3772 'yearly-day-number-x-years' => 1,
3773 'yearly-day-number-day' => 1,
3774 'yearly-day-number-month' => 1,
3775 'yearly-week-number-x-years' => 1,
3776 'yearly-week-number-occurrence' => 1,
3777 'yearly-week-number-day' => 1,
3778 'yearly-week-number-month' => 1,
3779 'starts-on' => ( new DateTime() )->format( 'Y-m-d' ),
3780 'ends-on' => 'no-end-date',
3781 'ends-after-times' => 10,
3782 'end-date' => '',
3783 'ticket-count' => 0,
3784 );
3785
3786 if ( $time_unit == 'days' ) {
3787
3788 $rule['recurrence-period'] = 'daily';
3789 $rule['daily-recurrence-type'] = 'daily-every-day';
3790 $rule['daily-x-days'] = intval( $recurrence );
3791
3792 } else {
3793
3794 $rule['recurrence-period'] = 'monthly';
3795 $rule['monthly-recurrence-type'] = 'monthly-day-number';
3796 $rule['monthly-day-number-x-months'] = intval( $recurrence );
3797 $rule['monthly-day-number-day'] = $start_date->format( 'd' );
3798 }
3799
3800 $rule['starts-on'] = $start_date->format( 'Y-m-d' );
3801 $rule['ends-on'] = 'no-end-date';
3802
3803 // customer.
3804 $customer_name = get_term_meta( $prev->term_id, 'customer_name', true );
3805 $customer_email = get_term_meta( $prev->term_id, 'customer_email', true );
3806 $customer_id = $wpdb->get_var( "SELECT * FROM {$wpdb->prefix}psmsc_customers WHERE email = '" . $customer_email . "'" );
3807 if ( ! $customer_id ) {
3808 $user = get_user_by( 'email', $customer_email );
3809 if ( $user ) {
3810 $wpdb->insert(
3811 $wpdb->prefix . 'psmsc_customers',
3812 array(
3813 'user' => $user->ID,
3814 'name' => $user->display_name,
3815 'email' => $user->user_email,
3816 )
3817 );
3818 } else {
3819 $wpdb->insert(
3820 $wpdb->prefix . 'psmsc_customers',
3821 array(
3822 'user' => 0,
3823 'name' => $customer_name,
3824 'email' => $customer_email,
3825 )
3826 );
3827 }
3828 $customer_id = $wpdb->insert_id;
3829 }
3830 $rule['customer'] = $customer_id;
3831
3832 // subject, description, category & priority.
3833 $rule['subject'] = get_term_meta( $prev->term_id, 'ticket_subject', true );
3834 $rule['description'] = get_term_meta( $prev->term_id, 'ticket_description', true );
3835 $category = get_term_meta( $prev->term_id, 'ticket_category', true );
3836 if ( $category ) {
3837 $rule['category'] = $category_map[ $category ];
3838 }
3839 $priority = get_term_meta( $prev->term_id, 'ticket_priority', true );
3840 if ( $priority ) {
3841 $rule['priority'] = $priority_map[ $priority ];
3842 }
3843
3844 // custom fields.
3845 foreach ( $fields as $field ) {
3846
3847 $type = get_term_meta( $field->term_id, 'wpsc_tf_type', true );
3848 $cf = wpsc_get_cf_by( 'id', $cf_map[ $field->term_id ] );
3849
3850 switch ( $type ) {
3851
3852 case 1:
3853 case 5:
3854 case 7:
3855 case 8:
3856 case 9:
3857 case 11:
3858 $val = get_term_meta( $prev->term_id, $field->slug, true );
3859 if ( $val ) {
3860 $rule[ $cf->slug ] = $val ? $val : '';
3861 }
3862 break;
3863
3864 case 2:
3865 case 4:
3866 $options_map = get_option( 'wpsc_upgrade_cf_options_map' );
3867 $val = get_term_meta( $prev->term_id, $field->slug, true );
3868 if ( $val ) {
3869 $rule[ $cf->slug ] = $options_map[ $cf->id ][ $val ];
3870 }
3871 break;
3872
3873 case 3:
3874 $options_map = get_option( 'wpsc_upgrade_cf_options_map' );
3875 $val = get_term_meta( $prev->term_id, $field->slug );
3876 if ( $val ) {
3877 $rule[ $cf->slug ] = implode(
3878 '|',
3879 array_filter(
3880 array_map(
3881 function ( $name ) use ( $options_map, $cf ) {
3882 return $name ? $options_map[ $cf->id ][ $name ] : false;
3883 },
3884 $val
3885 )
3886 )
3887 );
3888 }
3889 break;
3890
3891 case 6:
3892 $val = get_term_meta( $prev->term_id, $field->slug, true );
3893 if ( $val ) {
3894 $old_date_format = get_option( 'wpsc_calender_date_format' );
3895 $val = DateTime::createFromFormat( $date_formats[ $old_date_format ] . ' H:i:s', $val );
3896 if ( $val ) {
3897 $rule[ $cf->slug ] = $val->format( 'Y-m-d' );
3898 }
3899 }
3900 break;
3901
3902 case 18:
3903 $val = get_term_meta( $prev->term_id, $field->slug, true );
3904 if ( $val ) {
3905 $old_date_format = get_option( 'wpsc_calender_date_format' );
3906 $val = DateTime::createFromFormat( $date_formats[ $old_date_format ] . ' H:i:s', $val );
3907 if ( $val ) {
3908 $rule[ $cf->slug ] = $val->format( 'Y-m-d H:i:s' );
3909 }
3910 }
3911 break;
3912
3913 case 21:
3914 $val = get_term_meta( $prev->term_id, $field->slug, true );
3915 if ( $val ) {
3916 $val = new DateTime( $val );
3917 $rule[ $cf->slug ] = $val->format( 'H:i' );
3918 }
3919 break;
3920 }
3921 }
3922
3923 if ( ! $new_rules ) {
3924 $new_rules[1] = $rule;
3925 } else {
3926 $new_rules[] = $rule;
3927 }
3928 }
3929
3930 update_option( 'wpsc-st-rules', $new_rules );
3931
3932 // Shehdule existing ticket.
3933 $general = get_option( 'wpsc-st-general-settings' );
3934 $general['schedule-existing'] = get_option( 'wpsc_schedule_ticket_btn', $general['schedule-existing'] );
3935 update_option( 'wpsc-st-general-settings', $general );
3936
3937 // Add Modify scheduled ticket permissions to all agent roles.
3938 $agent_role = get_option( 'wpsc-agent-roles' );
3939 foreach ( $agent_role as $key => $agent ) {
3940
3941 $agent['caps']['modify-schedule-ticket'] = true;
3942 $agent_role[ $key ] = $agent;
3943 }
3944 update_option( 'wpsc-agent-roles', $agent_role );
3945 }
3946
3947 /**
3948 * Import SLA settings
3949 *
3950 * @return void
3951 */
3952 public static function import_sla_settings() {
3953
3954 $installed_addons = get_option( 'wpsc_upgrade_installed_addons' );
3955 if ( ! $installed_addons[4]['is_installed'] ) {
3956 return;
3957 }
3958
3959 $cf_map = get_option( 'wpsc_upgrade_cf_term_id_map' );
3960 $options_map = get_option( 'wpsc_upgrade_cf_options_map' );
3961 $category_map = get_option( 'wpsc_upgrade_category_map' );
3962 $priority_map = get_option( 'wpsc_upgrade_priority_map' );
3963 $status_map = get_option( 'wpsc_upgrade_status_map' );
3964
3965 // settings.
3966 $settings = get_option( 'wpsc-sla-general-settings' );
3967 $settings['out-sla-bg-color'] = get_option( 'wpsc_out_sla_color', $settings['out-sla-bg-color'] );
3968 $settings['out-sla-text-color'] = '#ffffff';
3969 $settings['in-sla-bg-color'] = get_option( 'wpsc_in_sla_color', $settings['in-sla-bg-color'] );
3970 $settings['in-sla-text-color'] = '#ffffff';
3971 update_option( 'wpsc-sla-general-settings', $settings );
3972
3973 // sla policies.
3974 $policies = get_terms(
3975 array(
3976 'taxonomy' => 'wpsc_sla',
3977 'hide_empty' => false,
3978 'orderby' => 'meta_value_num',
3979 'order' => 'ASC',
3980 'meta_query' => array( 'order_clause' => array( 'key' => 'load_order' ) ),
3981 )
3982 );
3983
3984 $new_policies = array();
3985 $count = 0;
3986 $map = array();
3987
3988 foreach ( $policies as $prev ) {
3989
3990 $time_unit_map = array(
3991 'minutes' => 'minute',
3992 'hours' => 'hour',
3993 'days' => 'day',
3994 'months' => 'month',
3995 'years' => 'year',
3996 );
3997 $time = get_term_meta( $prev->term_id, 'time', true );
3998 $time_unit = get_term_meta( $prev->term_id, 'time_unit', true );
3999
4000 $conditions = array();
4001 $policy = array(
4002 'title' => $prev->name,
4003 'time' => $time,
4004 'time-unit' => $time_unit_map[ $time_unit ],
4005 'calculate-from' => 'date_updated',
4006 'relation' => 'AND',
4007 'conditions' => $conditions ? wp_json_encode( $conditions ) : '{}',
4008 );
4009
4010 $new_policies[ ++$count ] = $policy;
4011 $map[ $prev->term_id ] = $count;
4012 }
4013
4014 update_option( 'wpsc-sla-policies', $new_policies );
4015 update_option( 'wpsc_upgrade_sla_policy_map', $map );
4016 }
4017
4018 /**
4019 * Import usergroup settings
4020 *
4021 * @return void
4022 */
4023 public static function import_usergroup_settings() {
4024
4025 global $wpdb;
4026 $installed_addons = get_option( 'wpsc_upgrade_installed_addons' );
4027 if ( ! $installed_addons[7]['is_installed'] ) {
4028 return;
4029 }
4030
4031 // Importing Other Settings into General setting.
4032 $string_translations = get_option( 'wpsc-string-translation' );
4033 $user_group_term = get_term_by( 'slug', 'usergroup', 'wpsc_ticket_custom_fields' );
4034 if ( $user_group_term ) {
4035 $ug_label = get_term_meta( $user_group_term->term_id, 'wpsc_tf_label', true );
4036 $ticket_widgets = get_option( 'wpsc-ticket-widget' );
4037 $ticket_widgets['usergroups']['title'] = $ug_label;
4038 update_option( 'wpsc-ticket-widget', $ticket_widgets );
4039 }
4040
4041 $ug_general = get_option( 'wpsc-ug-general-settings' );
4042 $ug_general['allow-change-category'] = get_option( 'wpsc_usergroup_change_category', $ug_general['allow-change-category'] );
4043 $ug_general['allow-sup-close-ticket'] = get_option( 'wpsc_allow_ug_sup_close_ticket', $ug_general['allow-sup-close-ticket'] );
4044 update_option( 'wpsc-ug-general-settings', $ug_general );
4045
4046 // Importing UG custom fields.
4047 $cf_map = get_option( 'wpsc_upgrade_cf_term_id_map' );
4048 $cf_slug_map = get_option( 'wpsc_upgrade_cf_slug_map' );
4049
4050 $fields = get_terms(
4051 array(
4052 'taxonomy' => 'wpsc_usergroup_custom_field',
4053 'hide_empty' => false,
4054 'orderby' => 'meta_value_num',
4055 'order' => 'ASC',
4056 'meta_query' => array(
4057 array(
4058 'key' => 'agentonly',
4059 'value' => '3',
4060 'compare' => '=',
4061 ),
4062 ),
4063 )
4064 );
4065
4066 foreach ( $fields as $prev ) {
4067
4068 $label = get_term_meta( $prev->term_id, 'wpsc_tf_label', true );
4069 $extra_info = get_term_meta( $prev->term_id, 'wpsc_tf_extra_info', true );
4070 $type = get_term_meta( $prev->term_id, 'wpsc_tf_type', true );
4071 $personal_info = get_term_meta( $prev->term_id, 'wpsc_tf_personal_info', true );
4072
4073 switch ( intval( $type ) ) {
4074
4075 case 1:
4076 $response = wpsc_upgrade_insert_custom_field(
4077 array(
4078 'name' => $label,
4079 'extra_info' => $extra_info,
4080 'field' => 'usergroup',
4081 'type' => 'cf_textfield',
4082 )
4083 );
4084 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_usergroups ADD " . $response['slug'] . ' TINYTEXT NULL' );
4085 $cf_map[ $prev->term_id ] = $response['id'];
4086 $cf_slug_map[ $prev->slug ] = $response['slug'];
4087 $string_translations[ 'wpsc-cf-name-' . $response['id'] ] = $label;
4088 $string_translations[ 'wpsc-cf-exi-' . $response['id'] ] = $extra_info;
4089 break;
4090
4091 case 2:
4092 $response = wpsc_upgrade_insert_custom_field(
4093 array(
4094 'name' => $label,
4095 'extra_info' => $extra_info,
4096 'field' => 'usergroup',
4097 'type' => 'cf_single_select',
4098 )
4099 );
4100 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_usergroups ADD " . $response['slug'] . ' TINYTEXT NULL' );
4101 $option_strings = self::import_options( $prev, $response['id'] );
4102 $string_translations = array_merge( $string_translations, $option_strings );
4103 $string_translations[ 'wpsc-cf-name-' . $response['id'] ] = $label;
4104 $string_translations[ 'wpsc-cf-exi-' . $response['id'] ] = $extra_info;
4105 $cf_map[ $prev->term_id ] = $response['id'];
4106 $cf_slug_map[ $prev->slug ] = $response['slug'];
4107 break;
4108
4109 case 5:
4110 $response = wpsc_upgrade_insert_custom_field(
4111 array(
4112 'name' => $label,
4113 'extra_info' => $extra_info,
4114 'field' => 'usergroup',
4115 'type' => 'cf_textarea',
4116 )
4117 );
4118 $wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_usergroups ADD " . $response['slug'] . ' LONGTEXT NULL DEFAULT NULL' );
4119 $cf_map[ $prev->term_id ] = $response['id'];
4120 $cf_slug_map[ $prev->slug ] = $response['slug'];
4121 $string_translations[ 'wpsc-cf-name-' . $response['id'] ] = $label;
4122 $string_translations[ 'wpsc-cf-exi-' . $response['id'] ] = $extra_info;
4123 break;
4124 }
4125 }
4126 update_option( 'wpsc_upgrade_cf_term_id_map', $cf_map );
4127 update_option( 'wpsc_upgrade_cf_slug_map', $cf_slug_map );
4128
4129 $option_map = get_option( 'wpsc_upgrade_cf_options_map' );
4130
4131 // Importing usergroups.
4132 $category_map = get_option( 'wpsc_upgrade_category_map' );
4133 $usergroups = get_terms(
4134 array(
4135 'taxonomy' => 'wpsc_usergroup_data',
4136 'hide_empty' => false,
4137 )
4138 );
4139
4140 $usergroup_map = array();
4141 foreach ( $usergroups as $prev ) {
4142
4143 $members = array();
4144 $prev_members = get_term_meta( $prev->term_id, 'wpsc_usergroup_userid' );
4145 foreach ( $prev_members as $user_id ) {
4146 $customer_id = $wpdb->get_var( "SELECT id FROM {$wpdb->prefix}psmsc_customers WHERE user = " . $user_id );
4147 if ( ! $customer_id ) {
4148 $user = get_user_by( 'id', $user_id );
4149 $wpdb->insert(
4150 $wpdb->prefix . 'psmsc_customers',
4151 array(
4152 'user' => $user_id,
4153 'name' => $user->display_name,
4154 'email' => $user->user_email,
4155 )
4156 );
4157 $customer_id = $wpdb->insert_id;
4158 }
4159 $members[] = $customer_id;
4160 }
4161
4162 $supervisors = array();
4163 $prev_supervisors = get_term_meta( $prev->term_id, 'wpsc_usergroup_supervisor_id' );
4164 foreach ( $prev_supervisors as $user_id ) {
4165 $supervisors[] = $wpdb->get_var( "SELECT id FROM {$wpdb->prefix}psmsc_customers WHERE user = " . $user_id );
4166 }
4167
4168 $category = get_term_meta( $prev->term_id, 'wpsc_usergroup_category', true );
4169
4170 $data = array(
4171 'name' => $prev->name,
4172 'members' => implode( '|', $members ),
4173 'supervisors' => implode( '|', $supervisors ),
4174 'category' => $category ? $category_map[ $category ] : '',
4175 );
4176
4177 foreach ( $fields as $field ) {
4178
4179 $cf = wpsc_get_cf_by( 'id', $cf_map[ $field->term_id ] );
4180 if ( $cf->type == 'cf_single_select' ) {
4181 $option = get_term_meta( $prev->term_id, $field->slug, true );
4182 if ( $option ) {
4183 $data[ $cf->slug ] = $option_map[ $cf->id ][ $option ];
4184 }
4185 } else {
4186 $data[ $cf->slug ] = get_term_meta( $prev->term_id, $field->slug, true );
4187 }
4188 }
4189
4190 $wpdb->insert( $wpdb->prefix . 'psmsc_usergroups', $data );
4191 $usergroup_map[ $prev->term_id ] = $wpdb->insert_id;
4192 }
4193 update_option( 'wpsc-string-translation', $string_translations );
4194 update_option( 'wpsc_upgrade_ug_term_id_map', $usergroup_map );
4195 }
4196
4197 /**
4198 * Import EDD settings
4199 *
4200 * @return void
4201 */
4202 public static function import_edd_settings() {}
4203
4204 /**
4205 * Import gravity settings
4206 *
4207 * @return void
4208 */
4209 public static function import_gravity_settings() {
4210
4211 global $wpdb;
4212 $installed_addons = get_option( 'wpsc_upgrade_installed_addons' );
4213 if ( ! $installed_addons[9]['is_installed'] || ! class_exists( 'GFForms' ) ) {
4214 return;
4215 }
4216
4217 $allowed_mapping_types = array(
4218 'cf_textfield' => array( 'name', 'text', 'email', 'number', 'hidden', 'date', 'time', 'phone', 'website' ),
4219 'cf_multi_select' => array( 'multiselect', 'select' ),
4220 'cf_single_select' => array( 'select', 'hidden' ),
4221 'cf_radio_button' => array( 'radio', 'hidden' ),
4222 'cf_checkbox' => array( 'checkbox', 'hidden' ),
4223 'cf_textarea' => array( 'textarea', 'name', 'text', 'email', 'number', 'hidden', 'date', 'time', 'phone', 'website', 'address' ),
4224 'cf_date' => array( 'date', 'hidden' ),
4225 'cf_datetime' => array( 'date', 'hidden' ),
4226 'cf_number' => array( 'number', 'hidden' ),
4227 'cf_email' => array( 'email', 'hidden' ),
4228 'cf_url' => array( 'website', 'hidden' ),
4229 'cf_time' => array( 'time', 'hidden' ),
4230 'cf_file_attachment_multiple' => array( 'fileupload' ),
4231 'cf_file_attachment_single' => array( 'fileupload' ),
4232 'df_customer_name' => array( 'name', 'text' ),
4233 'df_customer_email' => array( 'email' ),
4234 'df_subject' => array( 'name', 'text', 'email', 'number', 'hidden', 'date', 'time', 'phone', 'website' ),
4235 'df_description' => array( 'textarea', 'name', 'text', 'email', 'number', 'hidden', 'date', 'time', 'phone', 'website', 'address' ),
4236 'df_status' => array( 'select', 'radio', 'hidden' ),
4237 'df_priority' => array( 'select', 'radio', 'hidden' ),
4238 'df_category' => array( 'select', 'radio', 'hidden' ),
4239 'df_add_recipients' => array( 'email' ),
4240 );
4241
4242 $gravity_forms = get_terms(
4243 array(
4244 'taxonomy' => 'wpsc_gf',
4245 'hide_empty' => false,
4246 )
4247 );
4248
4249 $cf_map = get_option( 'wpsc_upgrade_cf_term_id_map' );
4250 $options_map = get_option( 'wpsc_upgrade_cf_options_map' );
4251 $category_map = get_option( 'wpsc_upgrade_category_map' );
4252 $priority_map = get_option( 'wpsc_upgrade_priority_map' );
4253
4254 $index = 1;
4255 $gf_integrations = array();
4256 foreach ( $gravity_forms as $form ) {
4257
4258 $gform_id = get_term_meta( $form->term_id, 'wpsc_gravity_form_id', true );
4259 $gform = GFAPI::get_form( $gform_id );
4260 if ( ! $gform ) {
4261 continue;
4262 }
4263 $mapping = array();
4264 $option_mapping = array();
4265 $mapping_values = get_term_meta( $form->term_id, 'wpsc_gf_mapping_values', true );
4266 foreach ( $mapping_values as $key => $field ) {
4267
4268 if ( ! $field ) {
4269 continue;
4270 }
4271
4272 $cf = wpsc_get_cf_by( 'id', $cf_map[ $key ] );
4273 if ( ! $cf ) {
4274 continue;
4275 }
4276
4277 $gfield = GFFormsModel::get_field( $gform, $field );
4278 if ( ! ( $gfield && isset( $allowed_mapping_types[ $cf->type ] ) && in_array( $gfield->type, $allowed_mapping_types[ $cf->type ] ) ) ) {
4279 continue;
4280 }
4281
4282 $mapping[ $cf->slug ] = $field;
4283
4284 // option mapping.
4285 if ( in_array( $cf->type, array( 'cf_checkbox', 'cf_radio_button', 'cf_single_select' ) ) ) {
4286
4287 if ( $gfield->type != 'hidden' ) {
4288
4289 $opts = array();
4290 foreach ( $options_map[ $cf->id ] as $key => $option ) {
4291 foreach ( $gfield->choices as $goption ) {
4292 if ( $goption['value'] == $key ) {
4293 $opts[ $option ] = $goption['value'];
4294 }
4295 }
4296 }
4297 $option_mapping[ $cf->slug ] = $opts;
4298 } else {
4299
4300 $gf = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}gf_form_meta WHERE form_id = $gform_id", ARRAY_A );
4301 $form_fields = json_decode( $gf['display_meta'], true );
4302 $key = array_search( $field, array_column( $form_fields['fields'], 'id' ) );
4303 $hf_val = $form_fields['fields'][ $key ]['defaultValue'];
4304 $form_fields['fields'][ $key ]['defaultValue'] = $options_map[ $cf->id ][ $hf_val ];
4305 $display_meta = wp_json_encode( $form_fields );
4306
4307 $success = $wpdb->update(
4308 $wpdb->prefix . 'gf_form_meta',
4309 array( 'display_meta' => $display_meta ),
4310 array( 'form_id' => $gform_id )
4311 );
4312 }
4313 } elseif ( $cf->slug == 'category' ) {
4314
4315 if ( $gfield->type != 'hidden' ) {
4316
4317 $opts = array();
4318 foreach ( $category_map as $key => $category ) {
4319 foreach ( $gfield->choices as $goption ) {
4320 if ( $goption['value'] == $key ) {
4321 $opts[ $category ] = $goption['value'];
4322 }
4323 }
4324 }
4325 $option_mapping[ $cf->slug ] = $opts;
4326 } else {
4327
4328 $gf = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}gf_form_meta WHERE form_id = $gform_id", ARRAY_A );
4329 $form_fields = json_decode( $gf['display_meta'], true );
4330 $key = array_search( $field, array_column( $form_fields['fields'], 'id' ) );
4331 $hf_val = $form_fields['fields'][ $key ]['defaultValue'];
4332 $form_fields['fields'][ $key ]['defaultValue'] = $category_map[ $hf_val ];
4333 $display_meta = wp_json_encode( $form_fields );
4334
4335 $success = $wpdb->update(
4336 $wpdb->prefix . 'gf_form_meta',
4337 array( 'display_meta' => $display_meta ),
4338 array( 'form_id' => $gform_id )
4339 );
4340 }
4341 } elseif ( $cf->slug == 'priority' ) {
4342
4343 if ( $gfield->type != 'hidden' ) {
4344
4345 $opts = array();
4346 foreach ( $priority_map as $key => $priority ) {
4347 foreach ( $gfield->choices as $goption ) {
4348 if ( $goption['value'] == $key ) {
4349 $opts[ $priority ] = $goption['value'];
4350 }
4351 }
4352 }
4353 $option_mapping[ $cf->slug ] = $opts;
4354 } else {
4355
4356 $gf = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}gf_form_meta WHERE form_id = $gform_id", ARRAY_A );
4357 $form_fields = json_decode( $gf['display_meta'], true );
4358 $key = array_search( $field, array_column( $form_fields['fields'], 'id' ) );
4359 $hf_val = $form_fields['fields'][ $key ]['defaultValue'];
4360 $form_fields['fields'][ $key ]['defaultValue'] = $priority_map[ $hf_val ];
4361 $display_meta = wp_json_encode( $form_fields );
4362
4363 $success = $wpdb->update(
4364 $wpdb->prefix . 'gf_form_meta',
4365 array( 'display_meta' => $display_meta ),
4366 array( 'form_id' => $gform_id )
4367 );
4368 }
4369 }
4370 }
4371
4372 $mappings = array(
4373 'title' => $gform['title'],
4374 'form' => $gform_id,
4375 'is_enable' => 1,
4376 'mappings' => $mapping,
4377 'options' => $option_mapping,
4378 );
4379 $gf_integrations[ $index ] = $mappings;
4380 ++$index;
4381 }
4382
4383 update_option( 'wpsc-gf-integrations', $gf_integrations );
4384 }
4385
4386 /**
4387 * Import timer settings
4388 *
4389 * @return void
4390 */
4391 public static function import_timer_settings() {
4392
4393 $installed_addons = get_option( 'wpsc_upgrade_installed_addons' );
4394 if ( ! $installed_addons[13]['is_installed'] ) {
4395 return;
4396 }
4397
4398 // Import timer setting.
4399 $setting = get_option( 'wpsc-timer-settings' );
4400 $setting['auto-start'] = get_option( 'wpsc_timer_enable', $setting['auto-start'] );
4401 $setting['auto-stop'] = get_option( 'wpsc_timer_stop', $setting['auto-stop'] );
4402 update_option( 'wpsc-timer-settings', $setting );
4403
4404 $tw_setting = get_option( 'wpsc-ticket-widget' );
4405 $tw_setting['timer']['allow-customer'] = intval( get_option( 'wpsc_timer_visibility_for_customer' ) );
4406 update_option( 'wpsc-ticket-widget', $tw_setting );
4407
4408 $agent_roles = get_option( 'wpsc-agent-roles' );
4409 foreach ( $agent_roles as $index => $role ) {
4410 $role['caps']['modify-timer-log'] = $index == 1 ? true : false;
4411 $agent_roles[ $index ] = $role;
4412 }
4413 update_option( 'wpsc-agent-roles', $agent_roles );
4414 }
4415
4416 /**
4417 * Import private credentials settings
4418 *
4419 * @return void
4420 */
4421 public static function import_pc_settings() {
4422
4423 $installed_addons = get_option( 'wpsc_upgrade_installed_addons' );
4424 if ( ! $installed_addons[17]['is_installed'] ) {
4425 return;
4426 }
4427
4428 // Add PC role permissions.
4429 $agent_role = get_option( 'wpsc-agent-roles' );
4430 $role = get_option( 'wpsc_pc_role_permissions' );
4431
4432 foreach ( $agent_role as $key => $agent ) {
4433
4434 $checked_view = isset( $role[ $key ]['role_view'] ) ? true : false;
4435 $checked_edit = isset( $role[ $key ]['role_modify'] ) ? true : false;
4436 $checked_delete = isset( $role[ $key ]['role_delete'] ) ? true : false;
4437 $match = isset( $role[ $key ] ) ? $role[ $key ]['role_matching_criteria'] : 0;
4438
4439 $agent['caps']['view-pc-unassigned'] = $match == 1 ? $checked_view : false;
4440 $agent['caps']['view-pc-assigned-me'] = $checked_view;
4441 $agent['caps']['view-pc-assigned-others'] = $match == 1 ? $checked_view : false;
4442
4443 $agent['caps']['modify-pc-unassigned'] = $match == 1 ? $checked_edit : false;
4444 $agent['caps']['modify-pc-assigned-me'] = $checked_edit;
4445 $agent['caps']['modify-pc-assigned-others'] = $match == 1 ? $checked_edit : false;
4446
4447 $agent['caps']['delete-pc-unassigned'] = $match == 1 ? $checked_delete : false;
4448 $agent['caps']['delete-pc-assigned-me'] = $checked_delete;
4449 $agent['caps']['delete-pc-assigned-others'] = $match == 1 ? $checked_delete : false;
4450
4451 $agent_role[ $key ] = $agent;
4452 }
4453 update_option( 'wpsc-agent-roles', $agent_role );
4454 }
4455
4456 /**
4457 * Import print ticket settings
4458 *
4459 * @return void
4460 */
4461 public static function import_print_settings() {
4462
4463 $installed_addons = get_option( 'wpsc_upgrade_installed_addons' );
4464 if ( ! $installed_addons[18]['is_installed'] ) {
4465 return;
4466 }
4467
4468 $string_translations = get_option( 'wpsc-string-translation' );
4469 // Importing Print ticket gneneral setting.
4470 $settings = get_option( 'wpsc-pt-general-settings' );
4471 $settings['thankyou-page-button'] = get_option( 'wpsc_print_th_btn_setting', $settings['thankyou-page-button'] );
4472 $settings['button-label'] = get_option( 'wpsc_print_btn_lbl', $settings['button-label'] );
4473 $settings['allow-print-to-customer'] = get_option( 'wpsc_print_cust_btn_setting', $settings['allow-print-to-customer'] );
4474 update_option( 'wpsc-pt-general-settings', $settings );
4475
4476 // Importing Print ticket templete setting.
4477 $temp_settings = get_option( 'wpsc-pt-template-settings' );
4478 $header = wpsc_upgrade_macros( get_option( 'wpsc_print_ticket_header', $temp_settings['header']['text'] ) );
4479 $body = wpsc_upgrade_macros( get_option( 'wpsc_print_ticket_body', $temp_settings['body']['text'] ) );
4480 $footer = wpsc_upgrade_macros( get_option( 'wpsc_print_ticket_footer', $temp_settings['footer']['text'] ) );
4481 $temp_settings['header-height'] = get_option( 'wpsc_print_page_header_height', $temp_settings['header-height'] );
4482 $temp_settings['footer-height'] = get_option( 'wpsc_print_page_footer_height', $temp_settings['footer-height'] );
4483 $temp_settings['header']['text'] = $header;
4484 $temp_settings['body']['text'] = $body;
4485 $temp_settings['footer']['text'] = $footer;
4486 update_option( 'wpsc-pt-template-settings', $temp_settings );
4487
4488 $string_translations['wpsc-pt-header'] = $header;
4489 $string_translations['wpsc-pt-body'] = $body;
4490 $string_translations['wpsc-pt-footer'] = $footer;
4491 update_option( 'wpsc-string-translation', $string_translations );
4492 }
4493
4494 /**
4495 * Import TinyMCE settings
4496 *
4497 * @return void
4498 */
4499 public static function import_tinymce_settings() {
4500
4501 $agent_user = get_option( 'wpsc-te-agent' );
4502 $reg_user = get_option( 'wpsc-te-registered-user' );
4503 $guest_user = get_option( 'wpsc-te-guest-user' );
4504
4505 // Importing toolbar setting.
4506 $toolbar = get_option( 'wpsc_tinymce_toolbar' );
4507 if ( $toolbar !== false ) {
4508 $old = get_option( 'wpsc_tinymce_toolbar_active' );
4509 $new = array();
4510 foreach ( $old as $key ) {
4511 $new[] = $toolbar[ $key ]['value'] == 'image' ? 'wpsc_insert_editor_img' : $toolbar[ $key ]['value'];
4512 }
4513 $agent_user['toolbar'] = $new;
4514 $reg_user['toolbar'] = $new;
4515 $guest_user['toolbar'] = $new;
4516 }
4517
4518 // Agent user.
4519 update_option( 'wpsc-te-agent', $agent_user );
4520
4521 // Registered user.
4522 $allow_rich_text_editor = array( 'register_user', 'guest_user' );
4523 $reg_user['enable'] = in_array( 'register_user', get_option( 'wpsc_allow_rich_text_editor', $allow_rich_text_editor ) ) ? 1 : 0;
4524 update_option( 'wpsc-te-registered-user', $reg_user );
4525
4526 // Guest user.
4527 $guest_user['enable'] = in_array( 'guest_user', get_option( 'wpsc_allow_rich_text_editor', $allow_rich_text_editor ) ) ? 1 : 0;
4528 update_option( 'wpsc-te-guest-user', $guest_user );
4529
4530 // HTML pasting.
4531 $html_pasting = get_option( 'wpsc-te-advanced' );
4532 $html_pasting['html-pasting'] = get_option( 'wpsc_allow_html_pasting', $html_pasting['html-pasting'] );
4533 update_option( 'wpsc-te-advanced', $html_pasting );
4534 }
4535
4536 /**
4537 * Import attachment settings
4538 *
4539 * @return void
4540 */
4541 public static function import_attachment_settings() {
4542
4543 // Import file attachment setting.
4544 $file_settings = get_option( 'wpsc-gs-file-attachments' );
4545 $file_settings['attachments-max-filesize'] = get_option( 'wpsc_attachment_max_filesize', $file_settings['attachments-max-filesize'] );
4546 $file_settings['allowed-file-extensions'] = get_option( 'wpsc_allow_attachment_type', $file_settings['allowed-file-extensions'] );
4547 $download_method = intval( get_option( 'wpsc_image_download_method' ) );
4548 $file_settings['image-download-behaviour'] = $download_method == 1 ? 'open-browser' : 'download';
4549 update_option( 'wpsc-gs-file-attachments', $file_settings );
4550
4551 // Import file attachment setting for agent.
4552 $allow_attach_create_ticket = array( 'agents', 'customers', 'guests' );
4553 $allow_attach_reply_form = array( 'agents', 'customers', 'guests' );
4554 $agent_user = get_option( 'wpsc-te-agent' );
4555 $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;
4556 $agent_user['file-attachment-notice'] = get_option( 'wpsc_show_attachment_notice', $agent_user['file-attachment-notice'] );
4557 $agent_user['file-attachment-notice-text'] = get_option( 'wpsc_attachment_notice', $agent_user['file-attachment-notice-text'] );
4558 update_option( 'wpsc-te-agent', $agent_user );
4559
4560 // Import file attachment setting for registered user.
4561 $reg_user = get_option( 'wpsc-te-registered-user' );
4562 $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;
4563 $reg_user['file-attachment-notice'] = get_option( 'wpsc_show_attachment_notice', $reg_user['file-attachment-notice'] );
4564 $reg_user['file-attachment-notice-text'] = get_option( 'wpsc_attachment_notice', $reg_user['file-attachment-notice-text'] );
4565 update_option( 'wpsc-te-registered-user', $reg_user );
4566
4567 // Import file attachment setting for guest user.
4568 $guest_user = get_option( 'wpsc-te-guest-user' );
4569 $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;
4570 $guest_user['file-attachment-notice'] = get_option( 'wpsc_show_attachment_notice', $guest_user['file-attachment-notice'] );
4571 $guest_user['file-attachment-notice-text'] = get_option( 'wpsc_attachment_notice', $guest_user['file-attachment-notice-text'] );
4572 update_option( 'wpsc-te-guest-user', $guest_user );
4573 }
4574
4575 /**
4576 * Import single ticket
4577 *
4578 * @param stdClass $ticket - ticket collection.
4579 * @return void
4580 */
4581 public static function import_individual_ticket( $ticket ) {
4582
4583 global $wpdb;
4584
4585 // destroy existing ticket if already imported.
4586 $ticket_id = $wpdb->get_var( "SELECT id FROM {$wpdb->prefix}psmsc_tickets WHERE id = " . $ticket->id );
4587 if ( $ticket_id ) {
4588 wpsc_destroy_existing_ticket( $ticket_id );
4589 }
4590
4591 $fields = get_terms(
4592 array(
4593 'taxonomy' => 'wpsc_ticket_custom_fields',
4594 'hide_empty' => false,
4595 'orderby' => 'term_id',
4596 'order' => 'ASC',
4597 )
4598 );
4599
4600 $cf_map = get_option( 'wpsc_upgrade_cf_term_id_map' );
4601 $data = array();
4602
4603 foreach ( $fields as $prev ) {
4604
4605 $type = get_term_meta( $prev->term_id, 'wpsc_tf_type', true );
4606
4607 if ( ! isset( $cf_map[ $prev->term_id ] ) || $prev->slug == 'ticket_description' ) {
4608 continue;
4609 }
4610
4611 $cf = wpsc_get_cf_by( 'id', $cf_map[ $prev->term_id ] );
4612
4613 if ( intval( $type ) === 0 ) {
4614
4615 switch ( $prev->slug ) {
4616
4617 case 'ticket_id':
4618 $data[ $cf->slug ] = $ticket->id;
4619 break;
4620
4621 case 'customer_name':
4622 case 'customer_email':
4623 case 'ticket_subject':
4624 case 'date_created':
4625 case 'date_updated':
4626 $data[ $cf->slug ] = $ticket->{$prev->slug};
4627 break;
4628
4629 case 'ticket_status':
4630 $map = get_option( 'wpsc_upgrade_status_map' );
4631 $data[ $cf->slug ] = $map[ $ticket->ticket_status ];
4632 break;
4633
4634 case 'ticket_category':
4635 $map = get_option( 'wpsc_upgrade_category_map' );
4636 $data[ $cf->slug ] = $map[ $ticket->ticket_category ];
4637 break;
4638
4639 case 'ticket_priority':
4640 $map = get_option( 'wpsc_upgrade_priority_map' );
4641 $data[ $cf->slug ] = $map[ $ticket->ticket_priority ];
4642 break;
4643
4644 case 'agent_created':
4645 $map = get_option( 'wpsc_upgrade_agent_map' );
4646 $data[ $cf->slug ] = $ticket->agent_created ? $map[ $ticket->agent_created ] : 0;
4647 break;
4648
4649 case 'assigned_agent':
4650 $map = get_option( 'wpsc_upgrade_agent_map' );
4651 $val = array_filter(
4652 array_map(
4653 function ( $agent_id ) use ( $map ) {
4654 return $agent_id && array_key_exists( $agent_id, $map ) ? $map[ $agent_id ] : '';
4655 },
4656 get_ticket_meta( $ticket->id, $prev->slug )
4657 )
4658 );
4659 $data[ $cf->slug ] = implode( '|', $val );
4660 break;
4661
4662 case 'sf_rating':
4663 $map = get_option( 'wpsc_upgrade_sf_rating_map' );
4664 $val = get_ticket_meta( $ticket->id, $prev->slug, true );
4665 if ( is_numeric( $val ) ) {
4666 $data[ $cf->slug ] = $map[ $val ];
4667 }
4668 break;
4669
4670 case 'sla':
4671 $val = get_ticket_meta( $ticket->id, $prev->slug, true );
4672 if ( $val && $val != '3099-01-01 00:00:00' ) {
4673 $policy_map = get_option( 'wpsc_upgrade_sla_policy_map' );
4674 $data[ $cf->slug ] = $val;
4675
4676 $policy_id = get_ticket_meta( $ticket->id, 'sla_term', true );
4677 if ( $policy_id ) {
4678 $data['sla_policy'] = $policy_map[ get_ticket_meta( $ticket->id, 'sla_term', true ) ];
4679 }
4680
4681 $od_email = get_ticket_meta( $ticket->id, 'wpsp_out_of_sla_email_send', true );
4682 if ( $policy_id ) {
4683 $data['od_email'] = get_ticket_meta( $ticket->id, 'wpsp_out_of_sla_email_send', true );
4684 }
4685 }
4686 break;
4687 }
4688 } else {
4689
4690 switch ( intval( $type ) ) {
4691
4692 case 1:
4693 case 5:
4694 case 6:
4695 case 7:
4696 case 8:
4697 case 9:
4698 case 11:
4699 case 12:
4700 case 13:
4701 case 14:
4702 case 18:
4703 $data[ $cf->slug ] = get_ticket_meta( $ticket->id, $prev->slug, true );
4704 break;
4705
4706 case 2:
4707 case 4:
4708 $options = wpsc_get_cf_options( $cf->id );
4709 $val = get_ticket_meta( $ticket->id, $prev->slug, true );
4710 foreach ( $options as $option ) {
4711 if ( $option->name == $val ) {
4712 $data[ $cf->slug ] = $option->id;
4713 break;
4714 }
4715 }
4716 break;
4717
4718 case 3:
4719 $options = wpsc_get_cf_options( $cf->id );
4720 $prev_val = get_ticket_meta( $ticket->id, $prev->slug );
4721 $new_val = array();
4722 foreach ( $options as $option ) {
4723 if ( in_array( $option->name, $prev_val ) ) {
4724 $new_val[] = $option->id;
4725 }
4726 }
4727 $data[ $cf->slug ] = implode( '|', $new_val );
4728 break;
4729
4730 case 10:
4731 $prev_val = array_filter( get_ticket_meta( $ticket->id, $prev->slug ) );
4732 $new_val = array();
4733 $upload_dir = wp_upload_dir();
4734 foreach ( $prev_val as $item ) {
4735 $term_meta = get_term_meta( $item );
4736 if ( ! $term_meta ) {
4737 continue;
4738 }
4739 $filepath = '/wpsc/' . $term_meta['save_file_name'][0];
4740 if ( isset( $term_meta['is_restructured'] ) && $term_meta['is_restructured'][0] ) {
4741 $updated_time = $term_meta['time_uploaded'][0];
4742 $time = strtotime( $updated_time );
4743 $month = date( 'm', $time ); // phpcs:ignore
4744 $year = date( 'Y', $time ); // phpcs:ignore
4745 $filepath = '/wpsc/' . $year . '/' . $month . '/' . $term_meta['save_file_name'][0];
4746 }
4747 $wpdb->insert(
4748 $wpdb->prefix . 'psmsc_attachments',
4749 array(
4750 'name' => $term_meta['filename'][0],
4751 'file_path' => $filepath,
4752 'is_image' => $term_meta['is_image'][0],
4753 'is_active' => 1,
4754 'date_created' => $term_meta['time_uploaded'][0],
4755 'source' => 'cf',
4756 'source_id' => $cf->id,
4757 'ticket_id' => $data['id'],
4758 )
4759 );
4760 $new_val[] = $wpdb->insert_id;
4761 }
4762 $data[ $cf->slug ] = implode( '|', $new_val );
4763 break;
4764
4765 case 21:
4766 $val = get_ticket_meta( $ticket->id, $prev->slug, true );
4767 if ( $val ) {
4768 $val = new DateTime( $val );
4769 $data[ $cf->slug ] = $val->format( 'H:i' );
4770 }
4771 break;
4772 }
4773 }
4774 }
4775
4776 // customer record if not exists.
4777 $customer = wpsc_import_customer( $data['name'], $data['email'] );
4778 $data['customer'] = $customer->id;
4779 unset( $data['name'] );
4780 unset( $data['email'] );
4781
4782 // user type.
4783 $data['user_type'] = $customer->user ? 'registered' : 'guest';
4784
4785 // deleted.
4786 $data['is_active'] = $ticket->active;
4787
4788 // IP address.
4789 $data['ip_address'] = $ticket->ip_address;
4790
4791 // Additional recipients.
4792 $ad_recep = get_ticket_meta( $ticket->id, 'extra_ticket_users' );
4793 $data['add_recipients'] = implode( '|', $ad_recep );
4794
4795 // Auth code.
4796 $data['auth_code'] = $ticket->ticket_auth_code;
4797
4798 // create ticket record.
4799 $wpdb->insert(
4800 $wpdb->prefix . 'psmsc_tickets',
4801 $data
4802 );
4803
4804 $ticket = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}psmsc_tickets WHERE id = " . $wpdb->insert_id );
4805
4806 // import ticket threads.
4807 self::import_ticket_threads( $ticket );
4808 }
4809
4810 /**
4811 * Import ticket threads
4812 *
4813 * @param stdClass $ticket - ticket object.
4814 * @return void
4815 */
4816 public static function import_ticket_threads( $ticket ) {
4817
4818 global $wpdb;
4819 $gs = get_option( 'wpsc-gs-general' );
4820 $tl_advanced = get_option( 'wpsc-tl-ms-advanced' );
4821 $installed_addons = get_option( 'wpsc_upgrade_installed_addons' );
4822
4823 $threads = get_posts(
4824 array(
4825 'post_type' => 'wpsc_ticket_thread',
4826 'post_status' => 'publish',
4827 'orderby' => 'date',
4828 'order' => 'ASC',
4829 'posts_per_page' => -1,
4830 'meta_query' => array(
4831 'relation' => 'AND',
4832 array(
4833 'key' => 'ticket_id',
4834 'value' => $ticket->id,
4835 'compare' => '=',
4836 ),
4837 ),
4838 )
4839 );
4840
4841 // ticket update data.
4842 $ticket_data = array();
4843
4844 // last reply thread.
4845 $last_thread = null;
4846
4847 // first response delay.
4848 $frd = 0;
4849
4850 // average response delay.
4851 $ard = 0;
4852
4853 // communication gap.
4854 $cg = 1;
4855
4856 // report temp variables.
4857 $count = 0;
4858 $last_reply_by = 'customer';
4859 $last_reply_time = new DateTime( $ticket->date_created );
4860 $delay = 0;
4861
4862 foreach ( $threads as $thread ) {
4863
4864 $thread_type = get_post_meta( $thread->ID, 'thread_type', true );
4865
4866 $ip_address = get_post_meta( $thread->ID, 'ip_address', true );
4867 $source = get_post_meta( $thread->ID, 'reply_source', true );
4868 $os = get_post_meta( $thread->ID, 'os', true );
4869 $browser = get_post_meta( $thread->ID, 'browser', true );
4870
4871 if ( in_array( $thread_type, array( 'report', 'reply', 'note' ) ) ) {
4872
4873 // thread_customer import.
4874 $customer_name = get_post_meta( $thread->ID, 'customer_name', true );
4875 $customer_email = get_post_meta( $thread->ID, 'customer_email', true );
4876 $customer = wpsc_import_customer( $customer_name, $customer_email );
4877
4878 // create thread record.
4879 $wpdb->insert(
4880 $wpdb->prefix . 'psmsc_threads',
4881 array(
4882 'ticket' => $ticket->id,
4883 'customer' => $customer->id,
4884 'type' => $thread_type,
4885 'body' => $thread->post_content,
4886 'date_created' => $thread->post_date,
4887 'date_updated' => $thread->post_date,
4888 'ip_address' => $ip_address,
4889 'source' => $source,
4890 'os' => $os,
4891 'browser' => $browser,
4892 )
4893 );
4894 $new_thread = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}psmsc_threads WHERE id = " . $wpdb->insert_id );
4895
4896 // Source, OS, browser.
4897 if ( $new_thread->type == 'report' ) {
4898 $ticket_data['source'] = $new_thread->source;
4899 $ticket_data['os'] = $new_thread->os;
4900 $ticket_data['browser'] = $new_thread->browser;
4901 $last_thread = $new_thread;
4902 }
4903
4904 // Calculate response delays.
4905 if ( $new_thread->type == 'reply' ) {
4906 ++$cg;
4907 $current_reply_by = 'customer';
4908 if ( $ticket->customer != $new_thread->customer && wpsc_is_agent( $new_thread->customer ) ) {
4909 $current_reply_by = 'agent';
4910 }
4911 if ( $last_reply_by == 'customer' && $current_reply_by == 'agent' ) {
4912 ++$count;
4913 $diff = ceil( abs( $last_reply_time->getTimestamp() - ( new DateTime( $new_thread->date_created ) )->getTimestamp() ) / 60 );
4914 if ( $count == 1 ) {
4915 $frd = $diff;
4916 }
4917 $delay += $diff;
4918 }
4919 if ( $last_reply_by == 'agent' && $current_reply_by == 'customer' ) {
4920 $last_reply_time = new DateTime( $new_thread->date_created );
4921 }
4922 $last_reply_by = $current_reply_by;
4923 }
4924
4925 if ( $new_thread->type == 'report' || $new_thread->type == 'reply' ) {
4926 $last_thread = $new_thread;
4927 }
4928
4929 // Handle attachments.
4930 $prev = get_post_meta( $thread->ID, 'attachments', true );
4931 $new = array();
4932 $upload_dir = wp_upload_dir();
4933 foreach ( $prev as $item ) {
4934
4935 $term_meta = get_term_meta( $item );
4936 if ( ! $term_meta ) {
4937 continue;
4938 }
4939
4940 $filepath = '/wpsc/' . $term_meta['save_file_name'][0];
4941 if ( isset( $term_meta['is_restructured'] ) && $term_meta['is_restructured'][0] ) {
4942 $updated_time = $term_meta['time_uploaded'][0];
4943 $time = strtotime( $updated_time );
4944 $month = date( 'm', $time ); // phpcs:ignore
4945 $year = date( 'Y', $time ); // phpcs:ignore
4946 $filepath = '/wpsc/' . $year . '/' . $month . '/' . $term_meta['save_file_name'][0];
4947 }
4948
4949 $wpdb->insert(
4950 $wpdb->prefix . 'psmsc_attachments',
4951 array(
4952 'name' => $term_meta['filename'][0],
4953 'file_path' => $filepath,
4954 'is_image' => $term_meta['is_image'][0],
4955 'is_active' => 1,
4956 'date_created' => $term_meta['time_uploaded'][0],
4957 'source' => $thread_type,
4958 'source_id' => $new_thread->id,
4959 'ticket_id' => $ticket->id,
4960 )
4961 );
4962 $new[] = $wpdb->insert_id;
4963 }
4964
4965 // update attachments to db.
4966 $wpdb->update(
4967 $wpdb->prefix . 'psmsc_threads',
4968 array(
4969 'attachments' => implode( '|', $new ),
4970 'body' => self::import_uploaded_thread_images( $new_thread->body, $new_thread, $ticket ),
4971 ),
4972 array( 'id' => $new_thread->id )
4973 );
4974
4975 } elseif ( $thread_type == 'log' ) {
4976
4977 $wpdb->insert(
4978 $wpdb->prefix . 'psmsc_threads',
4979 array(
4980 'ticket' => $ticket->id,
4981 'customer' => 0,
4982 'type' => 'log',
4983 'body' => $thread->post_content,
4984 'date_created' => $thread->post_date,
4985 'date_updated' => $thread->post_date,
4986 'ip_address' => $ip_address,
4987 'source' => $source,
4988 'os' => $os,
4989 'browser' => $browser,
4990 )
4991 );
4992
4993 } elseif ( $installed_addons[15]['is_installed'] && $thread_type == 'feedback' ) {
4994 // Add ticket feedback (satisfaction survey).
4995 $ticket_data['sf_feedback'] = $thread->post_content;
4996 $ticket_data['sf_date'] = $thread->post_date;
4997 }
4998 }
4999
5000 // date_closed was not available in v1 so date_updated is considered as date closed for closed tickets.
5001 if ( ! isset( $ticket->date_closed ) && ( $ticket->status == $gs['close-ticket-status'] || in_array( $ticket->status, $tl_advanced['closed-ticket-statuses'] ) ) ) {
5002 $ticket_data['date_closed'] = $ticket->date_updated;
5003 }
5004
5005 // last reply by and last reply on.
5006 if ( $last_thread ) {
5007 $ticket_data['last_reply_by'] = $last_thread->customer;
5008 $ticket_data['last_reply_on'] = $last_thread->date_created;
5009 }
5010
5011 // report add-on.
5012 if ( $installed_addons[6]['is_installed'] ) {
5013 $ticket_data['frd'] = $frd;
5014 if ( $count ) {
5015 $ticket_data['ard'] = ceil( $delay / $count );
5016 }
5017 $ticket_data['cg'] = $cg;
5018 if ( $ticket->status == $gs['close-ticket-status'] || in_array( $ticket->status, $tl_advanced['closed-ticket-statuses'] ) ) {
5019 $ticket_data['cd'] = ceil( abs( ( new DateTime( $ticket->date_created ) )->getTimestamp() - ( new DateTime( $ticket->date_closed ) )->getTimestamp() ) / 60 );
5020 }
5021 }
5022
5023 // import addtional recepients usergroup.
5024 if ( $installed_addons[7]['is_installed'] ) {
5025 $ug_map = get_option( 'wpsc_upgrade_ug_term_id_map' );
5026 $u_groups = array_filter(
5027 array_map(
5028 function ( $ug_id ) use ( $ug_map ) {
5029 return $ug_id ? $ug_map[ $ug_id ] : '';
5030 },
5031 get_ticket_meta( $ticket->id, 'usergroups' )
5032 )
5033 );
5034 $ticket_data['ar_usergroups'] = implode( '|', $u_groups );
5035 }
5036
5037 // import en_from email piping.
5038 if ( $installed_addons[3]['is_installed'] ) {
5039 $ticket_data['en_from'] = get_ticket_meta( $ticket->id, 'to_email', true );
5040 }
5041
5042 // import Private credentials.
5043 if ( $installed_addons[17]['is_installed'] ) {
5044
5045 $new_pc = array();
5046 $pc = get_ticket_meta( $ticket->id, 'private_credentials' );
5047 if ( $pc ) {
5048
5049 $new_pc['secure_key'] = get_ticket_meta( $ticket->id, 'secure_key', true );
5050 $new_pc['secure_iv'] = get_ticket_meta( $ticket->id, 'secure_iv', true );
5051 $data = array();
5052 $index = 1;
5053 foreach ( $pc as $crd ) {
5054
5055 $old_pc = json_decode( $crd, JSON_OBJECT_AS_ARRAY );
5056 $temp = array_map(
5057 function ( $tag ) {
5058 return array(
5059 'label' => $tag['label'],
5060 'value' => $tag['name'],
5061 'type' => $tag['type'] == 1 ? 'text' : 'textarea',
5062 );
5063 },
5064 $old_pc['data']
5065 );
5066 $old_pc['data'] = $temp;
5067 $data[ $index++ ] = $old_pc;
5068 }
5069 $new_pc['data'] = $data;
5070 $ticket_data['pc_data'] = wp_json_encode( $new_pc );
5071 }
5072 }
5073
5074 // import timer data.
5075 if ( $installed_addons[13]['is_installed'] ) {
5076
5077 if ( ! isset( $installed_addons[13]['has_db_table'] ) ) {
5078 $table = $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}wpsc_timer'" );
5079 $installed_addons[13]['has_db_table'] = $table ? 1 : 0;
5080 update_option( 'wpsc_upgrade_installed_addons', $installed_addons );
5081 }
5082
5083 $sql = "SELECT * FROM {$wpdb->prefix}wpsc_timer WHERE post_id = " . $ticket->id;
5084 $logs = $installed_addons[13]['has_db_table'] ? $wpdb->get_results( $sql ) : false;
5085 if ( $logs ) {
5086
5087 $temp_ts = array();
5088 foreach ( $logs as $log ) {
5089
5090 $auther = wpsc_get_agent_by( 'user_id', $log->started_by );
5091 if ( ! $auther ) {
5092 $timer_setting = get_option( 'wpsc-timer-settings' );
5093 $auther = wpsc_get_agent_by( 'id', $timer_setting['agent_id'] );
5094 }
5095
5096 $time_spent = 'PT0M';
5097 $status = 'running';
5098 if ( ! $log->timer_status ) {
5099 $time_spent = convert_sec_to_date_interval_string( $log->time_spend );
5100 if ( $time_spent != 'PT0M' ) {
5101 $temp_ts[] = new DateInterval( $time_spent );
5102 }
5103 $status = 'stopped';
5104 }
5105 $temp_start = $log->start_time;
5106
5107 $wpdb->insert(
5108 $wpdb->prefix . 'psmsc_timer_logs',
5109 array(
5110 'ticket' => $ticket->id,
5111 'author' => $auther->id,
5112 'date_started' => $log->start_time,
5113 'time_spent' => $time_spent,
5114 'temp_start' => $temp_start,
5115 'description' => $log->note,
5116 'status' => $status,
5117 )
5118 );
5119 }
5120 $total_time = $temp_ts ? wpsc_date_interval_to_string( wpsc_date_interval_sum( $temp_ts ) ) : 'PT0M';
5121 $ticket_data['time_spent'] = $total_time;
5122 }
5123 }
5124
5125 // insert sf_date if only rating is available.
5126 if ( $ticket->rating && ! isset( $ticket_data['sf_date'] ) ) {
5127 $date_closed = isset( $ticket->date_closed ) ? $ticket->date_closed : '';
5128 $date_closed = ! $date_closed && isset( $ticket_data['date_closed'] ) ? $ticket_data['date_closed'] : $date_closed;
5129 if ( $date_closed ) {
5130 $ticket_data['sf_date'] = $date_closed;
5131 }
5132 }
5133
5134 // update ticket data.
5135 $wpdb->update(
5136 $wpdb->prefix . 'psmsc_tickets',
5137 $ticket_data,
5138 array( 'id' => $ticket->id )
5139 );
5140 }
5141
5142 /**
5143 * Import uploaded thread images
5144 *
5145 * @param string $thread_content - thread html.
5146 * @param stdClass $thread - thread db object.
5147 * @param stdClass $ticket - ticket db object.
5148 * @return string
5149 */
5150 public static function import_uploaded_thread_images( $thread_content, $thread, $ticket ) {
5151
5152 global $wpdb;
5153 $upload_dir = wp_upload_dir();
5154 $regex = 'src="' . preg_quote( home_url(), '/' ) . '\?wpsc_img_attachment=(.*?)"';
5155 preg_match_all( '/' . $regex . '/', $thread_content, $matches );
5156 if ( $matches[1] ) {
5157 $count = count( $matches[1] );
5158 for ( $i = 0; $i < $count; $i++ ) {
5159
5160 $file_path = get_term_meta( $matches[1][ $i ], 'file_path', true );
5161 if ( ! file_exists( $file_path ) ) {
5162 continue;
5163 }
5164
5165 $file_path = str_replace( $upload_dir['basedir'], '', $file_path );
5166 $file_name = basename( $file_path );
5167
5168 $wpdb->insert(
5169 $wpdb->prefix . 'psmsc_attachments',
5170 array(
5171 'name' => $file_name,
5172 'file_path' => $file_path,
5173 'is_image' => 1,
5174 'is_active' => 1,
5175 'date_created' => ( new DateTime() )->format( 'Y-m-d H:i:s' ),
5176 'source' => 'img_editor',
5177 'source_id' => $thread->id,
5178 'ticket_id' => $ticket->id,
5179 )
5180 );
5181
5182 $thread_content = str_replace(
5183 home_url() . '?wpsc_img_attachment=' . $matches[1][ $i ],
5184 home_url( '/' ) . '?wpsc_attachment=' . $wpdb->insert_id,
5185 $thread_content
5186 );
5187 }
5188 }
5189 return $thread_content;
5190 }
5191
5192 /**
5193 * Import email notification conditions
5194 *
5195 * @return void
5196 */
5197 public static function import_en_conditions() {
5198
5199 $en_template_map = get_option( 'wpsc_upgrade_en_term_id_map' );
5200 $new_templates = get_option( 'wpsc-email-templates' );
5201 $email_templates = get_terms(
5202 array(
5203 'taxonomy' => 'wpsc_en',
5204 'hide_empty' => false,
5205 'orderby' => 'ID',
5206 'order' => 'ASC',
5207 )
5208 );
5209
5210 foreach ( $email_templates as $template ) {
5211
5212 $prev_conditions = get_term_meta( $template->term_id, 'conditions', true );
5213 $new_template = $new_templates[ $en_template_map[ $template->term_id ] ];
5214 $new_template['conditions'] = upgrade_conditions( $prev_conditions );
5215 $new_templates[ $en_template_map[ $template->term_id ] ] = $new_template;
5216 }
5217
5218 // Email notifications.
5219 foreach ( $new_templates as $index => $properties ) {
5220 if ( ! $properties['conditions'] ) {
5221 continue;
5222 }
5223 $new_templates[ $index ]['conditions'] = WPSC_SC_Upgrade::upgrade_condition( $properties['conditions'], $properties['relation'] );
5224 }
5225 update_option( 'wpsc-email-templates', $new_templates );
5226 }
5227
5228 /**
5229 * Import assign agent rules conditions
5230 *
5231 * @return void
5232 */
5233 public static function import_aar_conditions() {
5234
5235 $rules_map = get_option( 'wpsc_upgrade_aar_map' );
5236 $new_rules = get_option( 'wpsc-aar-rules' );
5237 $prev_rules = get_terms(
5238 array(
5239 'taxonomy' => 'wpsc_caa',
5240 'hide_empty' => false,
5241 )
5242 );
5243
5244 foreach ( $prev_rules as $prev ) {
5245
5246 $prev_conditions = get_term_meta( $prev->term_id, 'conditions', true );
5247
5248 $new_rule = $new_rules[ $rules_map[ $prev->term_id ] ];
5249 $new_rule['conditions'] = upgrade_conditions( $prev_conditions );
5250 $new_rules[ $rules_map[ $prev->term_id ] ] = $new_rule;
5251 }
5252
5253 // Assigned agent rules filters.
5254 foreach ( $new_rules as $index => $properties ) {
5255 if ( ! $properties['conditions'] ) {
5256 continue;
5257 }
5258 $new_rules[ $index ]['conditions'] = WPSC_SC_Upgrade::upgrade_condition( $properties['conditions'], $properties['relation'] );
5259 }
5260 update_option( 'wpsc-aar-rules', $new_rules );
5261 }
5262
5263 /**
5264 * Import sla conditions
5265 *
5266 * @return void
5267 */
5268 public static function import_sla_conditions() {
5269
5270 $new_policies = get_option( 'wpsc-sla-policies' );
5271 $map = get_option( 'wpsc_upgrade_sla_policy_map' );
5272
5273 $policies = get_terms(
5274 array(
5275 'taxonomy' => 'wpsc_sla',
5276 'hide_empty' => false,
5277 'orderby' => 'meta_value_num',
5278 'order' => 'ASC',
5279 'meta_query' => array( 'order_clause' => array( 'key' => 'load_order' ) ),
5280 )
5281 );
5282
5283 foreach ( $policies as $prev ) {
5284 $prev_conditions = get_term_meta( $prev->term_id, 'conditions', true );
5285
5286 $new_policy = $new_policies[ $map[ $prev->term_id ] ];
5287 $new_policy['conditions'] = upgrade_conditions( $prev_conditions );
5288 $new_policies[ $map[ $prev->term_id ] ] = $new_policy;
5289 }
5290
5291 // SLA policy filters.
5292 foreach ( $new_policies as $index => $properties ) {
5293 if ( ! $properties['conditions'] ) {
5294 continue;
5295 }
5296 $new_policies[ $index ]['conditions'] = WPSC_SC_Upgrade::upgrade_condition( $properties['conditions'], $properties['relation'] );
5297 }
5298 update_option( 'wpsc-sla-policies', $new_policies );
5299 }
5300
5301 /**
5302 * Import add-on licences
5303 *
5304 * @return void
5305 */
5306 public static function import_licences() {
5307
5308 $licenses = array();
5309 $installed_addons = get_option( 'wpsc_upgrade_installed_addons' );
5310
5311 if ( $installed_addons[0]['is_installed'] ) {
5312 $key = get_option( 'wpsc_atc_license_key', '' );
5313 $expiry = get_option( 'wpsc_atc_license_expiry', '' );
5314 $licenses['atc'] = array(
5315 'key' => $key,
5316 'expiry' => $expiry,
5317 );
5318 }
5319
5320 if ( $installed_addons[1]['is_installed'] ) {
5321 $key = get_option( 'wpsc_canned_reply_license_key', '' );
5322 $expiry = get_option( 'wpsc_canned_reply_license_expiry', '' );
5323 $licenses['canned-reply'] = array(
5324 'key' => $key,
5325 'expiry' => $expiry,
5326 );
5327 }
5328
5329 if ( $installed_addons[2]['is_installed'] ) {
5330 $key = get_option( 'wpsc_export_ticket_license_key', '' );
5331 $expiry = get_option( 'wpsc_export_ticket_license_expiry', '' );
5332 $licenses['export'] = array(
5333 'key' => $key,
5334 'expiry' => $expiry,
5335 );
5336 }
5337
5338 if ( $installed_addons[3]['is_installed'] ) {
5339 $key = get_option( 'wpsc_ep_license_key', '' );
5340 $expiry = get_option( 'wpsc_ep_license_expiry', '' );
5341 $licenses['email-piping'] = array(
5342 'key' => $key,
5343 'expiry' => $expiry,
5344 );
5345 }
5346
5347 if ( $installed_addons[4]['is_installed'] ) {
5348 $key = get_option( 'wpsc_sla_license_key', '' );
5349 $expiry = get_option( 'wpsc_sla_license_expiry', '' );
5350 $licenses['sla'] = array(
5351 'key' => $key,
5352 'expiry' => $expiry,
5353 );
5354 }
5355
5356 if ( $installed_addons[5]['is_installed'] ) {
5357 $key = get_option( 'wpsc_woo_license_key', '' );
5358 $expiry = get_option( 'wpsc_woo_license_expiry', '' );
5359 $licenses['woo'] = array(
5360 'key' => $key,
5361 'expiry' => $expiry,
5362 );
5363 }
5364
5365 if ( $installed_addons[6]['is_installed'] ) {
5366 $key = get_option( 'wpsc_rp_license_key', '' );
5367 $expiry = get_option( 'wpsc_rp_license_expiry', '' );
5368 $licenses['reports'] = array(
5369 'key' => $key,
5370 'expiry' => $expiry,
5371 );
5372 }
5373
5374 if ( $installed_addons[7]['is_installed'] ) {
5375 $key = get_option( 'wpsc_usergroup_license_key', '' );
5376 $expiry = get_option( 'wpsc_usergroup_license_expiry', '' );
5377 $licenses['usergroup'] = array(
5378 'key' => $key,
5379 'expiry' => $expiry,
5380 );
5381 }
5382
5383 if ( $installed_addons[8]['is_installed'] ) {
5384 $key = get_option( 'wpsc_edd_license_key', '' );
5385 $expiry = get_option( 'wpsc_edd_license_expiry', '' );
5386 $licenses['edd'] = array(
5387 'key' => $key,
5388 'expiry' => $expiry,
5389 );
5390 }
5391
5392 if ( $installed_addons[9]['is_installed'] ) {
5393 $key = get_option( 'wpsc_gf_license_key', '' );
5394 $expiry = get_option( 'wpsc_gf_license_expiry', '' );
5395 $licenses['gf'] = array(
5396 'key' => $key,
5397 'expiry' => $expiry,
5398 );
5399 }
5400
5401 if ( $installed_addons[10]['is_installed'] ) {
5402 $key = get_option( 'wpsc_caa_license_key', '' );
5403 $expiry = get_option( 'wpsc_caa_license_expiry', '' );
5404 $licenses['aar'] = array(
5405 'key' => $key,
5406 'expiry' => $expiry,
5407 );
5408 }
5409
5410 if ( $installed_addons[11]['is_installed'] ) {
5411 $key = get_option( 'wpsc_ultfaq_license_key', '' );
5412 $expiry = get_option( 'wpsc_ultfaq_license_expiry', '' );
5413 $licenses['faq'] = array(
5414 'key' => $key,
5415 'expiry' => $expiry,
5416 );
5417 }
5418
5419 if ( $installed_addons[12]['is_installed'] ) {
5420 $key = get_option( 'wpsc_prass_kb_license_key', '' );
5421 $expiry = get_option( 'wpsc_prass_kb_license_expiry', '' );
5422 $licenses['kb'] = array(
5423 'key' => $key,
5424 'expiry' => $expiry,
5425 );
5426 }
5427
5428 if ( $installed_addons[13]['is_installed'] ) {
5429 $key = get_option( 'wpsc_timer_license_key', '' );
5430 $expiry = get_option( 'wpsc_timer_license_expiry', '' );
5431 $licenses['timer'] = array(
5432 'key' => $key,
5433 'expiry' => $expiry,
5434 );
5435 }
5436
5437 if ( $installed_addons[14]['is_installed'] ) {
5438 $key = get_option( 'wpsc_st_license_key', '' );
5439 $expiry = get_option( 'wpsc_st_license_expiry', '' );
5440 $licenses['schedule-tickets'] = array(
5441 'key' => $key,
5442 'expiry' => $expiry,
5443 );
5444 }
5445
5446 if ( $installed_addons[15]['is_installed'] ) {
5447 $key = get_option( 'wpsc_sf_license_key', '' );
5448 $expiry = get_option( 'wpsc_sf_license_expiry', '' );
5449 $licenses['sf'] = array(
5450 'key' => $key,
5451 'expiry' => $expiry,
5452 );
5453 }
5454
5455 if ( $installed_addons[16]['is_installed'] ) {
5456 $key = get_option( 'wpsc_agentgroup_license_key', '' );
5457 $expiry = get_option( 'wpsc_agentgroup_license_expiry', '' );
5458 $licenses['agentgroups'] = array(
5459 'key' => $key,
5460 'expiry' => $expiry,
5461 );
5462 }
5463
5464 if ( $installed_addons[17]['is_installed'] ) {
5465 $key = get_option( 'wpsc_pc_license_key', '' );
5466 $expiry = get_option( 'wpsc_pc_license_expiry', '' );
5467 $licenses['pc'] = array(
5468 'key' => $key,
5469 'expiry' => $expiry,
5470 );
5471 }
5472
5473 if ( $installed_addons[18]['is_installed'] ) {
5474 $key = get_option( 'wpsc_pt_license_key', '' );
5475 $expiry = get_option( 'wpsc_pt_license_expiry', '' );
5476 $licenses['print'] = array(
5477 'key' => $key,
5478 'expiry' => $expiry,
5479 );
5480 }
5481 update_option( 'wpsc-licenses', $licenses );
5482 }
5483 }
5484
5485 endif;
5486
5487 WPSC_Upgrade_DB_V2::init();
5488
5489 require_once __DIR__ . '/functions.php';
5490