| 1 |
<?php |
| 2 |
|
| 3 |
if ( ! defined( 'ABSPATH' ) ) { |
| 4 |
exit; // Exit if accessed directly! |
| 5 |
} |
| 6 |
|
| 7 |
if ( ! class_exists( 'WPSC_Upgrade_DB_V1' ) ) : |
| 8 |
|
| 9 |
final class WPSC_Upgrade_DB_V1 { |
| 10 |
|
| 11 |
/** |
| 12 |
* Number of posts to be processed per page |
| 13 |
* |
| 14 |
* @var integer |
| 15 |
*/ |
| 16 |
public static $posts_per_page = 20; |
| 17 |
|
| 18 |
/** |
| 19 |
* Initialize this class |
| 20 |
* |
| 21 |
* @return void |
| 22 |
*/ |
| 23 |
public static function init() { |
| 24 |
|
| 25 |
add_action( 'init', 'wpsc_upgrade_send_admin_email' ); |
| 26 |
add_action( 'admin_menu', array( __CLASS__, 'load_admin_menus' ), 11 ); |
| 27 |
add_action( 'admin_enqueue_scripts', 'wpsc_upgrade_enqueue_scripts' ); |
| 28 |
|
| 29 |
// register custom post typs for upgrade. |
| 30 |
add_action( 'init', 'wpsc_upgrade_register_post_type' ); |
| 31 |
|
| 32 |
// check compatibility. |
| 33 |
add_action( 'wp_ajax_wpsc_authorize_v1_upgrade', array( __CLASS__, 'authorize' ) ); |
| 34 |
add_action( 'wp_ajax_wpsc_upgrade_v1_check_compatibility', array( __CLASS__, 'check_compatibility' ) ); |
| 35 |
|
| 36 |
// cron manager. |
| 37 |
add_action( 'init', array( __CLASS__, 'cron_manager' ) ); |
| 38 |
add_action( 'wp_ajax_wpsc_v1_upgrade_status', array( __CLASS__, 'get_v1_upgrade_cron_status' ) ); |
| 39 |
add_action( 'wpsc_upgrade_v1', array( __CLASS__, 'upgrade' ) ); |
| 40 |
} |
| 41 |
|
| 42 |
/** |
| 43 |
* Load upgrade screen for admin menu |
| 44 |
* |
| 45 |
* @return void |
| 46 |
*/ |
| 47 |
public static function load_admin_menus() { |
| 48 |
|
| 49 |
add_menu_page( |
| 50 |
esc_attr__( 'Support', 'supportcandy' ), |
| 51 |
esc_attr__( 'Support', 'supportcandy' ), |
| 52 |
'manage_options', |
| 53 |
'wpsc-tickets', |
| 54 |
array( __CLASS__, 'upgrade_layout' ), |
| 55 |
'dashicons-sos', |
| 56 |
25 |
| 57 |
); |
| 58 |
} |
| 59 |
|
| 60 |
/** |
| 61 |
* Authorize upgrade by an administrator |
| 62 |
* |
| 63 |
* @return void |
| 64 |
*/ |
| 65 |
public static function authorize() { |
| 66 |
|
| 67 |
if ( ! wpsc_upgrade_is_site_admin() ) { |
| 68 |
wp_send_json_error( 'Unauthorized request!', 401 ); |
| 69 |
} |
| 70 |
|
| 71 |
if ( check_ajax_referer( 'wpsc_authorize_v1_upgrade', '_ajax_nonce', false ) != 1 ) { |
| 72 |
wp_send_json_error( 'Unauthorized request!', 401 ); |
| 73 |
} |
| 74 |
|
| 75 |
update_option( 'wpsc_upgrade_permission_v1', 1 ); |
| 76 |
wp_send_json( array( 'success' => true ) ); |
| 77 |
} |
| 78 |
|
| 79 |
/** |
| 80 |
* Upgrade layout caller |
| 81 |
* |
| 82 |
* @return void |
| 83 |
*/ |
| 84 |
public static function upgrade_layout() { |
| 85 |
|
| 86 |
$upgrade_permission = get_option( 'wpsc_upgrade_permission_v1', 0 ); |
| 87 |
?> |
| 88 |
<div class="wrap"> |
| 89 |
<hr class="wp-header-end"> |
| 90 |
<h1>SupportCandy v3.0</h1> |
| 91 |
<div class="wpsc-upgrade-container"> |
| 92 |
<?php |
| 93 |
if ( ! $upgrade_permission ) { |
| 94 |
?> |
| 95 |
<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> |
| 96 |
<ol> |
| 97 |
<li>You must update all premium add-ons (if any).</li> |
| 98 |
<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> |
| 99 |
<li>All hooks and filters are changed.</li> |
| 100 |
<li>Translations are subject to availability. <a href="https://wordpress.org/plugins/supportcandy/">Click here</a> to see list of translations available.</li> |
| 101 |
<li>User interface design is changed. Previous appearance settings will not work on the new interface.</li> |
| 102 |
</ol> |
| 103 |
<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> |
| 104 |
<p><input type="checkbox" class="wpsc-confirm-backup"> I have secured a backup of my website data.</p> |
| 105 |
<p><input type="checkbox" class="wpsc-confirm-read"> I have read and understood all the points above.</p> |
| 106 |
<p> |
| 107 |
<button disabled class="button action proceed">Proceed to upgrade</button> |
| 108 |
<script> |
| 109 |
jQuery('.wpsc-confirm-backup, .wpsc-confirm-read').change(function(){ |
| 110 |
let cb1 = jQuery('.wpsc-confirm-backup'); |
| 111 |
let cb2 = jQuery('.wpsc-confirm-read'); |
| 112 |
if ( cb1.is(":checked") && cb2.is(":checked") ) { |
| 113 |
jQuery('button.proceed').attr( 'disabled', false ); |
| 114 |
} else { |
| 115 |
jQuery('button.proceed').attr( 'disabled', true ); |
| 116 |
} |
| 117 |
}); |
| 118 |
</script> |
| 119 |
</p> |
| 120 |
<h3 style="margin-top: 50px;">How do I revert this to the previous version?</h3> |
| 121 |
<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> |
| 122 |
<h4 style="margin-top: 30px;">Revert core plugin</h4> |
| 123 |
<p> |
| 124 |
<ol> |
| 125 |
<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> |
| 126 |
<li>Go to the Plugins page in your WordPress dashboard.</li> |
| 127 |
<li>Deactivate and delete SupportCandy.</li> |
| 128 |
<li>Click Add New plugin.</li> |
| 129 |
<li>Click Upload Plugin.</li> |
| 130 |
<li>Upload the downloaded zip file in step 1.</li> |
| 131 |
<li>Activate</li> |
| 132 |
</ol> |
| 133 |
</p> |
| 134 |
<h4 style="margin-top: 30px;">Revert add-ons (if any)</h4> |
| 135 |
<p> |
| 136 |
If you have premium add-ons installed for SupportCandy, you can follow the below steps to revert them: |
| 137 |
<ol> |
| 138 |
<li><a href="https://supportcandy.net/account/" target="_blank">Click here</a> to go to the My Account page on our website.</li> |
| 139 |
<li>Login to your account.</li> |
| 140 |
<li>Click on View Details and Downloads for your recent order.</li> |
| 141 |
<li>Download previous versions for each add-on ( less than 3.0.0 ).</li> |
| 142 |
<li>Go to the Plugins page in your WordPress dashboard.</li> |
| 143 |
<li>Deactivate and delete each SupportCandy add-on.</li> |
| 144 |
<li>Click Add New and then install each add-on by uploading it.</li> |
| 145 |
<li>Activate each add-on.</li> |
| 146 |
</ol> |
| 147 |
</p> |
| 148 |
<?php |
| 149 |
} |
| 150 |
?> |
| 151 |
</div> |
| 152 |
</div> |
| 153 |
<script> |
| 154 |
<?php |
| 155 |
if ( $upgrade_permission ) { |
| 156 |
?> |
| 157 |
jQuery(document).ready(function(){ |
| 158 |
wpsc_upgrade_v1_load_compatibilty(); |
| 159 |
}); |
| 160 |
<?php |
| 161 |
} else { |
| 162 |
?> |
| 163 |
jQuery('button.proceed').click(function(){ |
| 164 |
jQuery('div.wpsc-upgrade-container').html(supportcandy.loader_html); |
| 165 |
var data = { |
| 166 |
action: 'wpsc_authorize_v1_upgrade', |
| 167 |
_ajax_nonce: '<?php echo esc_attr( wp_create_nonce( 'wpsc_authorize_v1_upgrade' ) ); ?>' |
| 168 |
}; |
| 169 |
jQuery.post(supportcandy.ajax_url, data, function (response) { |
| 170 |
if ( response.success ) { |
| 171 |
wpsc_upgrade_v1_load_compatibilty(); |
| 172 |
} |
| 173 |
}); |
| 174 |
}); |
| 175 |
<?php |
| 176 |
} |
| 177 |
?> |
| 178 |
/** |
| 179 |
* Load compatibility section |
| 180 |
* |
| 181 |
* @return void |
| 182 |
*/ |
| 183 |
function wpsc_upgrade_v1_load_compatibilty() { |
| 184 |
jQuery('div.wpsc-upgrade-container').html(supportcandy.loader_html); |
| 185 |
var data = { |
| 186 |
action: 'wpsc_upgrade_v1_check_compatibility', |
| 187 |
_ajax_nonce: '<?php echo esc_attr( wp_create_nonce( 'wpsc_upgrade_v1_check_compatibility' ) ); ?>' |
| 188 |
}; |
| 189 |
jQuery.post(supportcandy.ajax_url, data, function (response) { |
| 190 |
jQuery('div.wpsc-upgrade-container').html(response); |
| 191 |
}); |
| 192 |
} |
| 193 |
</script> |
| 194 |
<style> |
| 195 |
body { |
| 196 |
background-color: #fff; |
| 197 |
} |
| 198 |
p, ol { |
| 199 |
font-size: 15px; |
| 200 |
} |
| 201 |
</style> |
| 202 |
<?php |
| 203 |
} |
| 204 |
|
| 205 |
/** |
| 206 |
* Check v3 compatiblity of current installation |
| 207 |
* |
| 208 |
* @return void |
| 209 |
*/ |
| 210 |
public static function check_compatibility() { |
| 211 |
|
| 212 |
global $wpdb, $current_user; |
| 213 |
|
| 214 |
$upgrade_permission = get_option( 'wpsc_upgrade_permission_v1', 0 ); |
| 215 |
|
| 216 |
if ( ! wpsc_upgrade_is_site_admin() || ! $upgrade_permission ) { |
| 217 |
wp_send_json_error( 'Unauthorized request!', 401 ); |
| 218 |
} |
| 219 |
|
| 220 |
if ( check_ajax_referer( 'wpsc_upgrade_v1_check_compatibility', '_ajax_nonce', false ) != 1 ) { |
| 221 |
wp_send_json_error( 'Unauthorized request!', 401 ); |
| 222 |
} |
| 223 |
|
| 224 |
$errors = array(); |
| 225 |
|
| 226 |
// check php version. |
| 227 |
if ( version_compare( PHP_VERSION, '7.4.0', '<' ) ) { |
| 228 |
$errors[] = 'PHP version must be 7.4 and above, current version is ' . PHP_VERSION; |
| 229 |
} |
| 230 |
|
| 231 |
// check WordPress version. |
| 232 |
$wp_version = get_bloginfo( 'version' ); |
| 233 |
if ( $wp_version < '5.6' ) { |
| 234 |
$errors[] = 'WordPress version must be 5.2 and above, current version is ' . $wp_version; |
| 235 |
} |
| 236 |
|
| 237 |
// check add-on versions. |
| 238 |
$installed_addons = wpsc_upgrade_get_installed_plugin_info(); |
| 239 |
update_option( 'wpsc_upgrade_installed_addons', $installed_addons ); |
| 240 |
|
| 241 |
$plugins_url = admin_url( 'plugins.php' ); |
| 242 |
foreach ( $installed_addons as $addon ) { |
| 243 |
if ( $addon['is_installed'] && $addon['version'] < '3.0.0' ) { |
| 244 |
|
| 245 |
$errors[] = '<strong>' . $addon['name'] . '</strong> must be v3.0 and above. <a href="' . $plugins_url . '">Click here</a> to see updates.'; |
| 246 |
|
| 247 |
} elseif ( $addon['is_installed'] && $addon['version'] == '3.0.0' && ! $addon['is_active'] ) { |
| 248 |
|
| 249 |
$errors[] = '<strong>' . $addon['name'] . '</strong> must be active in order to upgrade data related to it.'; |
| 250 |
} |
| 251 |
} |
| 252 |
|
| 253 |
// check for customizations. |
| 254 |
if ( class_exists( 'WPSC_CUST' ) ) { |
| 255 |
$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.'; |
| 256 |
} |
| 257 |
|
| 258 |
if ( $errors ) { |
| 259 |
|
| 260 |
delete_option( 'wpsc_upgrade_permission_v1' ); |
| 261 |
|
| 262 |
?> |
| 263 |
<p>Please fix below problems:</p> |
| 264 |
<ol> |
| 265 |
<?php |
| 266 |
foreach ( $errors as $error ) { |
| 267 |
echo '<li>' . wp_kses_post( $error ) . '</li>'; |
| 268 |
} |
| 269 |
?> |
| 270 |
</ol> |
| 271 |
<?php |
| 272 |
|
| 273 |
} else { |
| 274 |
|
| 275 |
$cron_status = get_option( 'wpsc_v1_upgrade_cron_status' ); |
| 276 |
$percentage = 100; |
| 277 |
if ( $cron_status['total_pages'] ) { |
| 278 |
$percentage = round( ( $cron_status['page'] / $cron_status['total_pages'] ) * 100, 2 ); |
| 279 |
} |
| 280 |
?> |
| 281 |
<p>This process can take several hours to complete depending your database size.</p> |
| 282 |
<p>Please keep this tab open for faster upgrade. If you close this tab, you need server scheduled cron job for the site.</p> |
| 283 |
<i class="wpsc-progressbar-title"><?php echo esc_html( $cron_status['title'] ); ?></i> |
| 284 |
<div id="wpsc-progressbar"><div class="progress-label"><?php echo esc_html( $percentage ) . '%'; ?></div></div> |
| 285 |
|
| 286 |
<!-- Server cron setup instructions --> |
| 287 |
<h3 style="margin-top: 50px;">Why server scheduled cron job?</h3> |
| 288 |
<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> |
| 289 |
<h3 style="margin-top: 50px;">How to setup server scheduled cron job?</h3> |
| 290 |
<h4>Step 1: Disable WP-Cron</h4> |
| 291 |
<p>You can disable WP-Cron by adding the below line to your wp-config.php file.</p> |
| 292 |
<code>define('DISABLE_WP_CRON', true);</code> |
| 293 |
<h4>Step 2: Schedule cron on your server</h4> |
| 294 |
<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> |
| 295 |
<code>*/1 * * * * wget -qO- <?php echo esc_url( site_url( '/wp-cron.php' ) ); ?> &> /dev/null</code> |
| 296 |
<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> |
| 297 |
|
| 298 |
|
| 299 |
<style> |
| 300 |
.ui-progressbar { |
| 301 |
position: relative; |
| 302 |
} |
| 303 |
.progress-label { |
| 304 |
position: absolute; |
| 305 |
left: 50%; |
| 306 |
top: 4px; |
| 307 |
font-weight: bold; |
| 308 |
text-shadow: 1px 1px 0 #fff; |
| 309 |
} |
| 310 |
</style> |
| 311 |
<script> |
| 312 |
var progressbar = jQuery( "#wpsc-progressbar" ); |
| 313 |
var progressLabel = jQuery( ".progress-label" ); |
| 314 |
var progressbarTitle = jQuery( ".wpsc-progressbar-title" ); |
| 315 |
progressbar.progressbar({ value: <?php echo intval( $percentage ); ?> }); |
| 316 |
wpsc_v1_upgrade_status(); |
| 317 |
|
| 318 |
/** |
| 319 |
* Get cron status |
| 320 |
* |
| 321 |
* @return void |
| 322 |
*/ |
| 323 |
function wpsc_v1_upgrade_status() { |
| 324 |
var data = { action: 'wpsc_v1_upgrade_status' }; |
| 325 |
jQuery.post(supportcandy.ajax_url, data, function (response) { |
| 326 |
if ( response.success && response.status == 'running' ) { |
| 327 |
let percentage = 100; |
| 328 |
if ( response.total_pages ) { |
| 329 |
percentage = ( ( response.page/response.total_pages ) * 100 ).toFixed(2); |
| 330 |
} |
| 331 |
progressbar.progressbar({ value: parseInt( percentage ) }); |
| 332 |
progressLabel.text( percentage + '%' ); |
| 333 |
progressbarTitle.text( response.title ); |
| 334 |
wpsc_v1_upgrade_status(); |
| 335 |
} else if ( response.success && response.status == 'complete' ) { |
| 336 |
window.location.reload(); |
| 337 |
} |
| 338 |
}).fail( function( xhr, status, error ) { |
| 339 |
window.location.reload(); |
| 340 |
}); |
| 341 |
} |
| 342 |
</script> |
| 343 |
<?php |
| 344 |
} |
| 345 |
|
| 346 |
wp_die(); |
| 347 |
} |
| 348 |
|
| 349 |
/** |
| 350 |
* Cron manager for upgrade |
| 351 |
* |
| 352 |
* @return void |
| 353 |
*/ |
| 354 |
public static function cron_manager() { |
| 355 |
|
| 356 |
$cron_status = get_option( 'wpsc_v1_upgrade_cron_status', array() ); |
| 357 |
if ( ! $cron_status ) { |
| 358 |
$cron_status = array( |
| 359 |
'status' => 'running', |
| 360 |
'title' => 'Installing database tables', |
| 361 |
'resource' => 'db_tables', |
| 362 |
'page' => 0, |
| 363 |
'total_pages' => 1, |
| 364 |
); |
| 365 |
update_option( 'wpsc_v1_upgrade_cron_status', $cron_status ); |
| 366 |
} |
| 367 |
|
| 368 |
// Do not proceed for the first iteration via cron. |
| 369 |
if ( $cron_status['resource'] == 'db_tables' ) { |
| 370 |
return; |
| 371 |
} |
| 372 |
|
| 373 |
// Do not allow parallel process to run. |
| 374 |
if ( 'yes' === get_transient( 'wpsc_ui_upgrading' ) ) { |
| 375 |
return; |
| 376 |
} |
| 377 |
|
| 378 |
$upgrade_permission = get_option( 'wpsc_upgrade_permission_v1', 0 ); |
| 379 |
if ( $upgrade_permission && $cron_status['status'] == 'running' && ! wp_next_scheduled( 'wpsc_upgrade_v1' ) ) { |
| 380 |
wp_schedule_single_event( time(), 'wpsc_upgrade_v1' ); |
| 381 |
} |
| 382 |
} |
| 383 |
|
| 384 |
/** |
| 385 |
* Return cron status for v1 upgrade |
| 386 |
* |
| 387 |
* @return void |
| 388 |
*/ |
| 389 |
public static function get_v1_upgrade_cron_status() { |
| 390 |
|
| 391 |
if ( ! wpsc_upgrade_is_site_admin() ) { |
| 392 |
wp_send_json_error( 'Unauthorized request!', 401 ); |
| 393 |
} |
| 394 |
|
| 395 |
// Set transient. |
| 396 |
set_transient( 'wpsc_ui_upgrading', 'yes', MINUTE_IN_SECONDS * 2 ); |
| 397 |
|
| 398 |
do_action( 'wpsc_upgrade_v1' ); |
| 399 |
|
| 400 |
$cron_status = get_option( 'wpsc_v1_upgrade_cron_status' ); |
| 401 |
$cron_status['success'] = true; |
| 402 |
wp_send_json( $cron_status ); |
| 403 |
} |
| 404 |
|
| 405 |
/** |
| 406 |
* Upgrade the resource |
| 407 |
* |
| 408 |
* @return void |
| 409 |
*/ |
| 410 |
public static function upgrade() { |
| 411 |
|
| 412 |
global $wpdb; |
| 413 |
|
| 414 |
// Do not allow parallel process to run. |
| 415 |
if ( 'yes' === get_transient( 'wpsc_upgrading' ) ) { |
| 416 |
return; |
| 417 |
} |
| 418 |
|
| 419 |
// Set transient. |
| 420 |
set_transient( 'wpsc_upgrading', 'yes', MINUTE_IN_SECONDS * 2 ); |
| 421 |
|
| 422 |
$cron_status = get_option( 'wpsc_v1_upgrade_cron_status' ); |
| 423 |
switch ( $cron_status['resource'] ) { |
| 424 |
|
| 425 |
case 'db_tables': |
| 426 |
if ( $cron_status['page'] == $cron_status['total_pages'] ) { |
| 427 |
$total_fields = count( |
| 428 |
get_terms( |
| 429 |
array( |
| 430 |
'taxonomy' => 'wpsc_ticket_custom_fields', |
| 431 |
'hide_empty' => false, |
| 432 |
) |
| 433 |
) |
| 434 |
); |
| 435 |
|
| 436 |
$total_pages = $total_fields ? ceil( $total_fields / 10 ) : 0; |
| 437 |
$cron_status = array( |
| 438 |
'status' => 'running', |
| 439 |
'title' => 'Importing custom fields', |
| 440 |
'resource' => 'custom_fields', |
| 441 |
'page' => 0, |
| 442 |
'total_pages' => $total_pages, |
| 443 |
); |
| 444 |
} |
| 445 |
break; |
| 446 |
|
| 447 |
case 'custom_fields': |
| 448 |
if ( $cron_status['page'] == $cron_status['total_pages'] ) { |
| 449 |
$cron_status = array( |
| 450 |
'status' => 'running', |
| 451 |
'title' => 'Importing settings', |
| 452 |
'resource' => 'settings', |
| 453 |
'page' => 0, |
| 454 |
'total_pages' => 6, |
| 455 |
); |
| 456 |
} |
| 457 |
break; |
| 458 |
|
| 459 |
case 'settings': |
| 460 |
if ( $cron_status['page'] == $cron_status['total_pages'] ) { |
| 461 |
$results = new WP_Query( |
| 462 |
array( |
| 463 |
'post_type' => 'wpsc_ticket', |
| 464 |
'post_status' => array( 'publish', 'trash' ), |
| 465 |
) |
| 466 |
); |
| 467 |
$total_pages = $results->found_posts ? ceil( $results->found_posts / 5 ) : 0; |
| 468 |
$cron_status = array( |
| 469 |
'status' => 'running', |
| 470 |
'title' => 'Importing tickets', |
| 471 |
'resource' => 'tickets', |
| 472 |
'page' => 0, |
| 473 |
'total_pages' => $total_pages, |
| 474 |
); |
| 475 |
} |
| 476 |
break; |
| 477 |
|
| 478 |
case 'tickets': |
| 479 |
if ( $cron_status['page'] == $cron_status['total_pages'] ) { |
| 480 |
$total_customers = $wpdb->get_var( 'SELECT COUNT(id) FROM ' . $wpdb->prefix . 'psmsc_customers' ); |
| 481 |
$total_pages = $total_customers ? ceil( $total_customers / 40 ) : 0; |
| 482 |
$cron_status = array( |
| 483 |
'status' => 'running', |
| 484 |
'title' => 'Importing customers', |
| 485 |
'resource' => 'customers', |
| 486 |
'page' => 0, |
| 487 |
'total_pages' => $total_pages, |
| 488 |
); |
| 489 |
} |
| 490 |
break; |
| 491 |
|
| 492 |
case 'customers': |
| 493 |
if ( $cron_status['page'] == $cron_status['total_pages'] ) { |
| 494 |
$total_agents = $wpdb->get_var( 'SELECT COUNT(id) FROM ' . $wpdb->prefix . 'psmsc_agents' ); |
| 495 |
$total_pages = $total_agents ? ceil( $total_agents / 20 ) : 0; |
| 496 |
$cron_status = array( |
| 497 |
'status' => 'running', |
| 498 |
'title' => 'Importing agents', |
| 499 |
'resource' => 'agents', |
| 500 |
'page' => 0, |
| 501 |
'total_pages' => $total_pages, |
| 502 |
); |
| 503 |
} |
| 504 |
break; |
| 505 |
|
| 506 |
case 'agents': |
| 507 |
if ( $cron_status['page'] == $cron_status['total_pages'] ) { |
| 508 |
WPSC_Installation::set_upgrade_complete(); |
| 509 |
update_option( |
| 510 |
'wpsc_upgrade_cleanup', |
| 511 |
array( |
| 512 |
'version' => 1, |
| 513 |
'status' => 'texonomy', |
| 514 |
) |
| 515 |
); |
| 516 |
$cron_status = array( |
| 517 |
'status' => 'complete', |
| 518 |
); |
| 519 |
update_option( 'wpsc_v1_upgrade_cron_status', $cron_status ); |
| 520 |
} |
| 521 |
break; |
| 522 |
} |
| 523 |
|
| 524 |
if ( $cron_status['status'] == 'complete' ) { |
| 525 |
return; |
| 526 |
} |
| 527 |
|
| 528 |
if ( $cron_status['total_pages'] == 0 ) { |
| 529 |
update_option( 'wpsc_v1_upgrade_cron_status', $cron_status ); |
| 530 |
delete_transient( 'wpsc_upgrading' ); |
| 531 |
return; |
| 532 |
} |
| 533 |
|
| 534 |
// execute the cron. |
| 535 |
$page = intval( $cron_status['page'] ) + 1; |
| 536 |
|
| 537 |
switch ( $cron_status['resource'] ) { |
| 538 |
|
| 539 |
case 'db_tables': |
| 540 |
WPSC_Installation::create_db_tables(); |
| 541 |
WPSC_Installation::initial_setup(); |
| 542 |
do_action( 'wpsc_upgrade_install_addons' ); |
| 543 |
break; |
| 544 |
|
| 545 |
case 'custom_fields': |
| 546 |
self::import_custom_fields( $page ); |
| 547 |
break; |
| 548 |
|
| 549 |
case 'settings': |
| 550 |
self::upgrade_settings( $page ); |
| 551 |
break; |
| 552 |
|
| 553 |
case 'tickets': |
| 554 |
self::upgrade_tickets( $page ); |
| 555 |
break; |
| 556 |
|
| 557 |
case 'customers': |
| 558 |
self::customer_ticket_count( $page ); |
| 559 |
break; |
| 560 |
|
| 561 |
case 'agents': |
| 562 |
self::agent_ticket_count( $page ); |
| 563 |
break; |
| 564 |
} |
| 565 |
|
| 566 |
$cron_status['page'] = $page; |
| 567 |
update_option( 'wpsc_v1_upgrade_cron_status', $cron_status ); |
| 568 |
|
| 569 |
// Delete transient. |
| 570 |
delete_transient( 'wpsc_upgrading' ); |
| 571 |
} |
| 572 |
|
| 573 |
/** |
| 574 |
* Upgrade settings |
| 575 |
* |
| 576 |
* @param int $page - page number. |
| 577 |
* @return void |
| 578 |
*/ |
| 579 |
public static function upgrade_settings( $page ) { |
| 580 |
|
| 581 |
switch ( $page ) { |
| 582 |
|
| 583 |
case 1: |
| 584 |
self::import_statuses(); |
| 585 |
self::import_categories(); |
| 586 |
self::import_priorities(); |
| 587 |
self::import_agents(); |
| 588 |
break; |
| 589 |
|
| 590 |
case 2: |
| 591 |
self::import_ticket_form_fields(); |
| 592 |
self::import_ticket_list_items(); |
| 593 |
self::import_tl_more_settings(); |
| 594 |
self::import_en_general(); |
| 595 |
self::import_en_ticket_notifications(); |
| 596 |
break; |
| 597 |
|
| 598 |
case 3: |
| 599 |
self::import_general_settings(); |
| 600 |
self::reorder_widgets(); |
| 601 |
self::import_thankyou_settings(); |
| 602 |
self::import_terms_and_conditions(); |
| 603 |
self::import_advanced_settings(); |
| 604 |
break; |
| 605 |
|
| 606 |
case 4: |
| 607 |
self::import_captcha(); |
| 608 |
self::import_assign_agent_rules(); |
| 609 |
self::import_automatic_close_tickets(); |
| 610 |
self::import_canned_reply(); |
| 611 |
self::import_report_settings(); |
| 612 |
break; |
| 613 |
|
| 614 |
case 5: |
| 615 |
self::import_satisfaction_survey(); |
| 616 |
self::import_email_piping(); |
| 617 |
self::import_faq_integration(); |
| 618 |
self::import_knowledgebase_integration(); |
| 619 |
self::import_export_addon(); |
| 620 |
break; |
| 621 |
|
| 622 |
case 6: |
| 623 |
self::import_woocommerce_addon(); |
| 624 |
self::import_shedule_tickets(); |
| 625 |
self::import_sla_settings(); |
| 626 |
self::import_usergroup_settings(); |
| 627 |
break; |
| 628 |
} |
| 629 |
} |
| 630 |
|
| 631 |
/** |
| 632 |
* Upgrade tickets |
| 633 |
* |
| 634 |
* @param int $page - page number. |
| 635 |
* @return void |
| 636 |
*/ |
| 637 |
public static function upgrade_tickets( $page ) { |
| 638 |
|
| 639 |
$posts_per_page = 5; |
| 640 |
$results = get_posts( |
| 641 |
array( |
| 642 |
'post_type' => 'wpsc_ticket', |
| 643 |
'post_status' => array( 'publish', 'trash' ), |
| 644 |
'posts_per_page' => $posts_per_page, |
| 645 |
'offset' => ( $page - 1 ) * $posts_per_page, |
| 646 |
'orderby' => 'ID', |
| 647 |
'order' => 'ASC', |
| 648 |
) |
| 649 |
); |
| 650 |
|
| 651 |
foreach ( $results as $ticket ) { |
| 652 |
self::import_individual_ticket( $ticket ); |
| 653 |
} |
| 654 |
} |
| 655 |
|
| 656 |
/** |
| 657 |
* Customer ticket count |
| 658 |
* |
| 659 |
* @param int $page - page number. |
| 660 |
* @return void |
| 661 |
*/ |
| 662 |
public static function customer_ticket_count( $page ) { |
| 663 |
|
| 664 |
global $wpdb; |
| 665 |
$installed_addons = get_option( 'wpsc_upgrade_installed_addons' ); |
| 666 |
$offset = ( $page - 1 ) * 40; |
| 667 |
$sql = "SELECT * FROM {$wpdb->prefix}psmsc_customers ORDER BY id ASC LIMIT 40 OFFSET " . $offset; |
| 668 |
$customers = $wpdb->get_results( $sql ); |
| 669 |
foreach ( $customers as $customer ) { |
| 670 |
wpsc_update_customer_ticket_count( $customer ); |
| 671 |
if ( $installed_addons[7]['is_installed'] ) { |
| 672 |
wpsc_update_customer_usergroups( $customer ); |
| 673 |
} |
| 674 |
self::import_saved_filters( $customer ); |
| 675 |
} |
| 676 |
} |
| 677 |
|
| 678 |
/** |
| 679 |
* Agent ticket count |
| 680 |
* |
| 681 |
* @param int $page - page number. |
| 682 |
* @return void |
| 683 |
*/ |
| 684 |
public static function agent_ticket_count( $page ) { |
| 685 |
|
| 686 |
global $wpdb; |
| 687 |
$offset = ( $page - 1 ) * 20; |
| 688 |
$sql = "SELECT * FROM {$wpdb->prefix}psmsc_agents WHERE is_agentgroup = 0 ORDER BY id ASC LIMIT 20 OFFSET " . $offset; |
| 689 |
$agents = $wpdb->get_results( $sql ); |
| 690 |
foreach ( $agents as $agent ) { |
| 691 |
wpsc_agent_reset_unresolved_count( $agent ); |
| 692 |
wpsc_agent_reset_workload( $agent ); |
| 693 |
self::import_saved_filters( wpsc_get_customer_by( 'id', $agent->customer ) ); |
| 694 |
self::import_agent_settings( $agent ); |
| 695 |
} |
| 696 |
} |
| 697 |
|
| 698 |
/** |
| 699 |
* Import saved ticket filters |
| 700 |
* |
| 701 |
* @param stdClass $customer - customer object. |
| 702 |
* @return void |
| 703 |
*/ |
| 704 |
public static function import_saved_filters( $customer ) { |
| 705 |
|
| 706 |
global $wpdb; |
| 707 |
|
| 708 |
// return if customer is guest. |
| 709 |
if ( ! $customer->user ) { |
| 710 |
return; |
| 711 |
} |
| 712 |
|
| 713 |
$cf_slug_map = get_option( 'wpsc_upgrade_cf_slug_map' ); |
| 714 |
$options_map = get_option( 'wpsc_upgrade_cf_options_map' ); |
| 715 |
$status_map = get_option( 'wpsc_upgrade_status_map' ); |
| 716 |
$category_map = get_option( 'wpsc_upgrade_category_map' ); |
| 717 |
$priority_map = get_option( 'wpsc_upgrade_priority_map' ); |
| 718 |
$rating_map = get_option( 'wpsc_upgrade_sf_rating_map' ); |
| 719 |
$agent_map = get_option( 'wpsc_upgrade_agent_map' ); |
| 720 |
$old_date_format = get_option( 'wpsc_calender_date_format' ); |
| 721 |
$parent_filter_map = array( |
| 722 |
'all' => 'all', |
| 723 |
'unresolved_agent' => 'unresolved', |
| 724 |
'unresolved_customer' => 'unresolved', |
| 725 |
'unassigned' => 'unassigned', |
| 726 |
'mine' => 'mine', |
| 727 |
'closed' => 'closed', |
| 728 |
'deleted' => 'deleted', |
| 729 |
); |
| 730 |
|
| 731 |
$date_formats = array( |
| 732 |
'dd-mm-yy' => 'd-m-Y', |
| 733 |
'dd-yy-mm' => 'd-Y-m', |
| 734 |
'mm-dd-yy' => 'm-d-Y', |
| 735 |
'mm-yy-dd' => 'm-Y-d', |
| 736 |
'yy-mm-dd' => 'Y-m-d', |
| 737 |
'yy-dd-mm' => 'Y-d-m', |
| 738 |
); |
| 739 |
|
| 740 |
// previous filters. |
| 741 |
$prev_filters = get_user_meta( $customer->user, get_current_blog_id() . '_wpsc_filter', true ); |
| 742 |
if ( ! $prev_filters ) { |
| 743 |
return; |
| 744 |
} |
| 745 |
|
| 746 |
// new filters. |
| 747 |
$index = 1; |
| 748 |
$new_filters = array(); |
| 749 |
|
| 750 |
// import filters. |
| 751 |
foreach ( $prev_filters as $prev ) { |
| 752 |
|
| 753 |
$new = array( |
| 754 |
'label' => $prev['save_label'], |
| 755 |
'parent-filter' => $parent_filter_map[ $prev['label'] ], |
| 756 |
'sort-by' => $cf_slug_map[ $prev['orderby'] ], |
| 757 |
'sort-order' => $prev['order'], |
| 758 |
); |
| 759 |
|
| 760 |
$filters = array(); |
| 761 |
foreach ( $prev['custom_filter'] as $slug => $filter ) { |
| 762 |
|
| 763 |
if ( $slug == 's' ) { |
| 764 |
continue; |
| 765 |
} |
| 766 |
|
| 767 |
if ( $slug == 'id' ) { |
| 768 |
$slug = 'ticket_id'; |
| 769 |
} |
| 770 |
|
| 771 |
$cf = wpsc_get_cf_by( 'slug', $cf_slug_map[ $slug ] ); |
| 772 |
if ( ! $cf ) { |
| 773 |
continue; |
| 774 |
} |
| 775 |
|
| 776 |
switch ( $cf->type ) { |
| 777 |
|
| 778 |
case 'df_category': |
| 779 |
$filters[ $cf->slug ] = array( |
| 780 |
'operator' => 'IN', |
| 781 |
'operand_val_1' => array_map( |
| 782 |
function ( $prev_category ) use ( $category_map ) { |
| 783 |
return $category_map[ $prev_category ]; |
| 784 |
}, |
| 785 |
$filter |
| 786 |
), |
| 787 |
); |
| 788 |
break; |
| 789 |
|
| 790 |
case 'df_status': |
| 791 |
$filters[ $cf->slug ] = array( |
| 792 |
'operator' => 'IN', |
| 793 |
'operand_val_1' => array_map( |
| 794 |
function ( $prev_status ) use ( $status_map ) { |
| 795 |
return $status_map[ $prev_status ]; |
| 796 |
}, |
| 797 |
$filter |
| 798 |
), |
| 799 |
); |
| 800 |
break; |
| 801 |
|
| 802 |
case 'df_priority': |
| 803 |
$filters[ $cf->slug ] = array( |
| 804 |
'operator' => 'IN', |
| 805 |
'operand_val_1' => array_map( |
| 806 |
function ( $prev_priority ) use ( $priority_map ) { |
| 807 |
return $priority_map[ $prev_priority ]; |
| 808 |
}, |
| 809 |
$filter |
| 810 |
), |
| 811 |
); |
| 812 |
break; |
| 813 |
|
| 814 |
case 'df_customer_name': |
| 815 |
case 'df_customer_email': |
| 816 |
$slug = $cf->type == 'df_customer_name' ? 'name' : 'email'; |
| 817 |
$sql = "SELECT * FROM {$wpdb->prefix}psmsc_customers WHERE " . $slug . " IN( '" . implode( "', '", $filter ) . "' )"; |
| 818 |
$customers = $wpdb->get_results( $sql ); |
| 819 |
if ( ! $customers ) { |
| 820 |
break; |
| 821 |
} |
| 822 |
if ( isset( $filters['customer'] ) ) { |
| 823 |
|
| 824 |
$filters['customer']['operand_val_1'] = array_unique( |
| 825 |
array_merge( |
| 826 |
$filters['customer']['operand_val_1'], |
| 827 |
array_map( |
| 828 |
function ( $cust ) { |
| 829 |
return $cust->id; |
| 830 |
}, |
| 831 |
$customers |
| 832 |
) |
| 833 |
) |
| 834 |
); |
| 835 |
|
| 836 |
} else { |
| 837 |
|
| 838 |
$filters['customer'] = array( |
| 839 |
'operator' => 'IN', |
| 840 |
'operand_val_1' => array_map( |
| 841 |
function ( $cust ) { |
| 842 |
return $cust->id; |
| 843 |
}, |
| 844 |
$customers |
| 845 |
), |
| 846 |
); |
| 847 |
} |
| 848 |
break; |
| 849 |
|
| 850 |
case 'df_assigned_agent': |
| 851 |
case 'df_agent_created': |
| 852 |
$filters[ $cf->slug ] = array( |
| 853 |
'operator' => 'IN', |
| 854 |
'operand_val_1' => array_map( |
| 855 |
function ( $prev_agent ) use ( $agent_map ) { |
| 856 |
return $agent_map[ $prev_agent ]; |
| 857 |
}, |
| 858 |
$filter |
| 859 |
), |
| 860 |
); |
| 861 |
break; |
| 862 |
|
| 863 |
case 'df_date_created': |
| 864 |
case 'cf_date': |
| 865 |
if ( ! ( $filter['from'] && $filter['to'] ) ) { |
| 866 |
break; |
| 867 |
} |
| 868 |
$from = DateTime::createFromFormat( $date_formats[ $old_date_format ], $filter['from'] ); |
| 869 |
$to = DateTime::createFromFormat( $date_formats[ $old_date_format ], $filter['to'] ); |
| 870 |
if ( ! ( $from && $to ) ) { |
| 871 |
break; |
| 872 |
} |
| 873 |
$filters[ $cf->slug ] = array( |
| 874 |
'operator' => 'BETWEEN', |
| 875 |
'operand_val_1' => $from->format( 'Y-m-d' ), |
| 876 |
'operand_val_2' => $to->format( 'Y-m-d' ), |
| 877 |
); |
| 878 |
break; |
| 879 |
|
| 880 |
case 'df_sf_rating': |
| 881 |
$filters[ $cf->slug ] = array( |
| 882 |
'operator' => 'IN', |
| 883 |
'operand_val_1' => array_map( |
| 884 |
function ( $prev_rating ) use ( $rating_map ) { |
| 885 |
return $rating_map[ $prev_rating ]; |
| 886 |
}, |
| 887 |
$filter |
| 888 |
), |
| 889 |
); |
| 890 |
break; |
| 891 |
|
| 892 |
case 'df_id': |
| 893 |
case 'cf_textfield': |
| 894 |
case 'cf_email': |
| 895 |
case 'cf_number': |
| 896 |
case 'cf_url': |
| 897 |
$filters[ $cf->slug ] = array( |
| 898 |
'operator' => 'IN', |
| 899 |
'operand_val_1' => implode( '^^', $filter ), |
| 900 |
); |
| 901 |
break; |
| 902 |
|
| 903 |
case 'cf_checkbox': |
| 904 |
case 'cf_multi_select': |
| 905 |
case 'cf_radio_button': |
| 906 |
case 'cf_single_select': |
| 907 |
$filters[ $cf->slug ] = array( |
| 908 |
'operator' => 'IN', |
| 909 |
'operand_val_1' => array_map( |
| 910 |
function ( $prev_option ) use ( $options_map, $cf ) { |
| 911 |
return $options_map[ $cf->id ][ $prev_option ]; |
| 912 |
}, |
| 913 |
$filter |
| 914 |
), |
| 915 |
); |
| 916 |
break; |
| 917 |
|
| 918 |
case 'cf_woo_product': |
| 919 |
case 'cf_woo_order': |
| 920 |
$filters[ $cf->slug ] = array( |
| 921 |
'operator' => 'IN', |
| 922 |
'operand_val_1' => $filter, |
| 923 |
); |
| 924 |
break; |
| 925 |
} |
| 926 |
} |
| 927 |
|
| 928 |
$new['filters'] = wp_json_encode( $filters ); |
| 929 |
|
| 930 |
$new_filters[ $index++ ] = $new; |
| 931 |
} |
| 932 |
|
| 933 |
// import Visibility conditions. |
| 934 |
foreach ( $new_filters as $slug => $properties ) { |
| 935 |
if ( ! $properties['filters'] ) { |
| 936 |
continue; |
| 937 |
} |
| 938 |
$new_filters[ $slug ]['filters'] = WPSC_SC_Upgrade::upgrade_condition( $properties['filters'], 'AND' ); |
| 939 |
} |
| 940 |
update_user_meta( $customer->user, get_current_blog_id() . '-wpsc-tl-saved-filters', $new_filters ); |
| 941 |
update_user_meta( $customer->user, get_current_blog_id() . '-wpsc-tl-cf-auto-increament', ++$index ); |
| 942 |
} |
| 943 |
|
| 944 |
/** |
| 945 |
* Import agent settings |
| 946 |
* |
| 947 |
* @param stdClass $agent - agent object. |
| 948 |
* @return void |
| 949 |
*/ |
| 950 |
public static function import_agent_settings( $agent ) { |
| 951 |
|
| 952 |
$signature = get_user_meta( $agent->user, 'wpsc_agent_signature', true ); |
| 953 |
if ( ! $signature ) { |
| 954 |
update_user_meta( $agent->user, get_current_blog_id() . '_wpsc_email_signature', $signature ); |
| 955 |
} |
| 956 |
} |
| 957 |
|
| 958 |
/** |
| 959 |
* Import statuses |
| 960 |
* |
| 961 |
* @return void |
| 962 |
*/ |
| 963 |
public static function import_statuses() { |
| 964 |
|
| 965 |
global $wpdb; |
| 966 |
$wpdb->query( 'DELETE FROM ' . $wpdb->prefix . 'psmsc_statuses' ); |
| 967 |
$wpdb->query( 'ALTER TABLE ' . $wpdb->prefix . 'psmsc_statuses AUTO_INCREMENT = 1' ); |
| 968 |
|
| 969 |
$statuses = get_terms( |
| 970 |
array( |
| 971 |
'taxonomy' => 'wpsc_statuses', |
| 972 |
'hide_empty' => false, |
| 973 |
'orderby' => 'meta_value_num', |
| 974 |
'order' => 'ASC', |
| 975 |
'meta_query' => array( 'order_clause' => array( 'key' => 'wpsc_status_load_order' ) ), |
| 976 |
) |
| 977 |
); |
| 978 |
|
| 979 |
$string_translations = get_option( 'wpsc-string-translation' ); |
| 980 |
$map = array(); |
| 981 |
$load_order = 1; |
| 982 |
foreach ( $statuses as $prev ) { |
| 983 |
|
| 984 |
$wpdb->insert( |
| 985 |
$wpdb->prefix . 'psmsc_statuses', |
| 986 |
array( |
| 987 |
'name' => $prev->name, |
| 988 |
'color' => get_term_meta( $prev->term_id, 'wpsc_status_color', true ), |
| 989 |
'bg_color' => get_term_meta( $prev->term_id, 'wpsc_status_background_color', true ), |
| 990 |
'load_order' => $load_order++, |
| 991 |
) |
| 992 |
); |
| 993 |
|
| 994 |
$string_translations[ 'wpsc-status-' . $wpdb->insert_id ] = $prev->name; |
| 995 |
$map[ $prev->term_id ] = $wpdb->insert_id; |
| 996 |
} |
| 997 |
|
| 998 |
update_option( 'wpsc-string-translation', $string_translations ); |
| 999 |
update_option( 'wpsc_upgrade_status_map', $map ); |
| 1000 |
} |
| 1001 |
|
| 1002 |
/** |
| 1003 |
* Import categories |
| 1004 |
* |
| 1005 |
* @return void |
| 1006 |
*/ |
| 1007 |
public static function import_categories() { |
| 1008 |
|
| 1009 |
global $wpdb; |
| 1010 |
$wpdb->query( 'DELETE FROM ' . $wpdb->prefix . 'psmsc_categories' ); |
| 1011 |
$wpdb->query( 'ALTER TABLE ' . $wpdb->prefix . 'psmsc_categories AUTO_INCREMENT = 1' ); |
| 1012 |
|
| 1013 |
$categories = get_terms( |
| 1014 |
array( |
| 1015 |
'taxonomy' => 'wpsc_categories', |
| 1016 |
'hide_empty' => false, |
| 1017 |
'orderby' => 'meta_value_num', |
| 1018 |
'order' => 'ASC', |
| 1019 |
'meta_query' => array( 'order_clause' => array( 'key' => 'wpsc_category_load_order' ) ), |
| 1020 |
) |
| 1021 |
); |
| 1022 |
|
| 1023 |
$string_translations = get_option( 'wpsc-string-translation' ); |
| 1024 |
$map = array(); |
| 1025 |
$load_order = 1; |
| 1026 |
foreach ( $categories as $prev ) { |
| 1027 |
|
| 1028 |
$wpdb->insert( |
| 1029 |
$wpdb->prefix . 'psmsc_categories', |
| 1030 |
array( |
| 1031 |
'name' => $prev->name, |
| 1032 |
'load_order' => $load_order++, |
| 1033 |
) |
| 1034 |
); |
| 1035 |
|
| 1036 |
$string_translations[ 'wpsc-category-' . $wpdb->insert_id ] = $prev->name; |
| 1037 |
$map[ $prev->term_id ] = $wpdb->insert_id; |
| 1038 |
} |
| 1039 |
|
| 1040 |
update_option( 'wpsc-string-translation', $string_translations ); |
| 1041 |
update_option( 'wpsc_upgrade_category_map', $map ); |
| 1042 |
} |
| 1043 |
|
| 1044 |
/** |
| 1045 |
* Import priorities |
| 1046 |
* |
| 1047 |
* @return void |
| 1048 |
*/ |
| 1049 |
public static function import_priorities() { |
| 1050 |
|
| 1051 |
global $wpdb; |
| 1052 |
$wpdb->query( 'DELETE FROM ' . $wpdb->prefix . 'psmsc_priorities' ); |
| 1053 |
$wpdb->query( 'ALTER TABLE ' . $wpdb->prefix . 'psmsc_priorities AUTO_INCREMENT = 1' ); |
| 1054 |
|
| 1055 |
$priorities = get_terms( |
| 1056 |
array( |
| 1057 |
'taxonomy' => 'wpsc_priorities', |
| 1058 |
'hide_empty' => false, |
| 1059 |
'orderby' => 'meta_value_num', |
| 1060 |
'order' => 'ASC', |
| 1061 |
'meta_query' => array( 'order_clause' => array( 'key' => 'wpsc_priority_load_order' ) ), |
| 1062 |
) |
| 1063 |
); |
| 1064 |
|
| 1065 |
$string_translations = get_option( 'wpsc-string-translation' ); |
| 1066 |
$map = array(); |
| 1067 |
$load_order = 1; |
| 1068 |
foreach ( $priorities as $prev ) { |
| 1069 |
|
| 1070 |
$wpdb->insert( |
| 1071 |
$wpdb->prefix . 'psmsc_priorities', |
| 1072 |
array( |
| 1073 |
'name' => $prev->name, |
| 1074 |
'color' => get_term_meta( $prev->term_id, 'wpsc_priority_color', true ), |
| 1075 |
'bg_color' => get_term_meta( $prev->term_id, 'wpsc_priority_background_color', true ), |
| 1076 |
'load_order' => $load_order++, |
| 1077 |
) |
| 1078 |
); |
| 1079 |
|
| 1080 |
$string_translations[ 'wpsc-priority-' . $wpdb->insert_id ] = $prev->name; |
| 1081 |
$map[ $prev->term_id ] = $wpdb->insert_id; |
| 1082 |
} |
| 1083 |
|
| 1084 |
update_option( 'wpsc-string-translation', $string_translations ); |
| 1085 |
update_option( 'wpsc_upgrade_priority_map', $map ); |
| 1086 |
} |
| 1087 |
|
| 1088 |
/** |
| 1089 |
* Import custom fields |
| 1090 |
* |
| 1091 |
* @param int $page - current page number. |
| 1092 |
* @return void |
| 1093 |
*/ |
| 1094 |
public static function import_custom_fields( $page ) { |
| 1095 |
|
| 1096 |
global $wpdb; |
| 1097 |
|
| 1098 |
// Disable InnoDB strict mode if enabled to avoid limit of number of columns in tables. |
| 1099 |
$strict_mode = $wpdb->get_var( "SHOW VARIABLES LIKE 'innodb_strict_mode'", 1 ); |
| 1100 |
if ( $strict_mode == 'ON' ) { |
| 1101 |
$wpdb->query( "SET innodb_strict_mode = 'OFF'" ); |
| 1102 |
} |
| 1103 |
|
| 1104 |
// Change load order of all existing custom fields to higher number. |
| 1105 |
if ( $page == 1 ) { |
| 1106 |
$wpdb->query( 'UPDATE ' . $wpdb->prefix . 'psmsc_custom_fields SET load_order=1000 WHERE id NOT IN(1,2,7)' ); |
| 1107 |
} |
| 1108 |
|
| 1109 |
$offset = ( $page - 1 ) * 10; |
| 1110 |
$args = array( |
| 1111 |
'taxonomy' => 'wpsc_ticket_custom_fields', |
| 1112 |
'hide_empty' => false, |
| 1113 |
'number' => 10, |
| 1114 |
'offset' => $offset, |
| 1115 |
'orderby' => 'term_id', |
| 1116 |
'order' => 'ASC', |
| 1117 |
); |
| 1118 |
|
| 1119 |
$fields = get_terms( $args ); |
| 1120 |
$string_translations = get_option( 'wpsc-string-translation' ); |
| 1121 |
$installed_addons = get_option( 'wpsc_upgrade_installed_addons' ); |
| 1122 |
$term_id_map = get_option( 'wpsc_upgrade_cf_term_id_map', array() ); |
| 1123 |
$slug_map = get_option( 'wpsc_upgrade_cf_slug_map', array() ); |
| 1124 |
$load_order = get_option( 'wpsc_upgrade_cf_load_order', 8 ); |
| 1125 |
foreach ( $fields as $prev ) { |
| 1126 |
|
| 1127 |
$label = get_term_meta( $prev->term_id, 'wpsc_tf_label', true ); |
| 1128 |
$extra_info = get_term_meta( $prev->term_id, 'wpsc_tf_extra_info', true ); |
| 1129 |
$type = get_term_meta( $prev->term_id, 'wpsc_tf_type', true ); |
| 1130 |
|
| 1131 |
if ( intval( $type ) === 0 ) { |
| 1132 |
|
| 1133 |
switch ( $prev->slug ) { |
| 1134 |
|
| 1135 |
case 'ticket_id': |
| 1136 |
$term_id_map[ $prev->term_id ] = 1; |
| 1137 |
$slug_map[ $prev->slug ] = 'id'; |
| 1138 |
break; |
| 1139 |
|
| 1140 |
case 'ticket_status': |
| 1141 |
$term_id_map[ $prev->term_id ] = 7; |
| 1142 |
$slug_map[ $prev->slug ] = 'status'; |
| 1143 |
break; |
| 1144 |
|
| 1145 |
case 'customer_name': |
| 1146 |
$wpdb->update( |
| 1147 |
$wpdb->prefix . 'psmsc_custom_fields', |
| 1148 |
array( |
| 1149 |
'name' => $label, |
| 1150 |
'extra_info' => $extra_info, |
| 1151 |
'load_order' => $load_order++, |
| 1152 |
), |
| 1153 |
array( 'id' => 3 ) |
| 1154 |
); |
| 1155 |
$term_id_map[ $prev->term_id ] = 3; |
| 1156 |
$slug_map[ $prev->slug ] = 'name'; |
| 1157 |
$string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $label; |
| 1158 |
break; |
| 1159 |
|
| 1160 |
case 'customer_email': |
| 1161 |
$wpdb->update( |
| 1162 |
$wpdb->prefix . 'psmsc_custom_fields', |
| 1163 |
array( |
| 1164 |
'name' => $label, |
| 1165 |
'extra_info' => $extra_info, |
| 1166 |
'load_order' => $load_order++, |
| 1167 |
), |
| 1168 |
array( 'id' => 4 ) |
| 1169 |
); |
| 1170 |
$term_id_map[ $prev->term_id ] = 4; |
| 1171 |
$slug_map[ $prev->slug ] = 'email'; |
| 1172 |
$string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $label; |
| 1173 |
break; |
| 1174 |
|
| 1175 |
case 'ticket_subject': |
| 1176 |
$wpdb->update( |
| 1177 |
$wpdb->prefix . 'psmsc_custom_fields', |
| 1178 |
array( |
| 1179 |
'name' => $label, |
| 1180 |
'extra_info' => $extra_info, |
| 1181 |
'load_order' => $load_order++, |
| 1182 |
), |
| 1183 |
array( 'id' => 5 ) |
| 1184 |
); |
| 1185 |
$term_id_map[ $prev->term_id ] = 5; |
| 1186 |
$slug_map[ $prev->slug ] = 'subject'; |
| 1187 |
$string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $label; |
| 1188 |
break; |
| 1189 |
|
| 1190 |
case 'ticket_description': |
| 1191 |
$wpdb->update( |
| 1192 |
$wpdb->prefix . 'psmsc_custom_fields', |
| 1193 |
array( |
| 1194 |
'name' => $label, |
| 1195 |
'extra_info' => $extra_info, |
| 1196 |
'load_order' => $load_order++, |
| 1197 |
), |
| 1198 |
array( 'id' => 6 ) |
| 1199 |
); |
| 1200 |
$term_id_map[ $prev->term_id ] = 6; |
| 1201 |
$slug_map[ $prev->slug ] = 'description'; |
| 1202 |
$string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $label; |
| 1203 |
break; |
| 1204 |
|
| 1205 |
case 'ticket_category': |
| 1206 |
$wpdb->update( |
| 1207 |
$wpdb->prefix . 'psmsc_custom_fields', |
| 1208 |
array( |
| 1209 |
'name' => $label, |
| 1210 |
'extra_info' => $extra_info, |
| 1211 |
'load_order' => $load_order++, |
| 1212 |
), |
| 1213 |
array( 'id' => 9 ) |
| 1214 |
); |
| 1215 |
$term_id_map[ $prev->term_id ] = 9; |
| 1216 |
$slug_map[ $prev->slug ] = 'category'; |
| 1217 |
$string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $label; |
| 1218 |
break; |
| 1219 |
|
| 1220 |
case 'ticket_priority': |
| 1221 |
$wpdb->update( |
| 1222 |
$wpdb->prefix . 'psmsc_custom_fields', |
| 1223 |
array( |
| 1224 |
'name' => $label, |
| 1225 |
'extra_info' => $extra_info, |
| 1226 |
'load_order' => $load_order++, |
| 1227 |
), |
| 1228 |
array( 'id' => 8 ) |
| 1229 |
); |
| 1230 |
$term_id_map[ $prev->term_id ] = 8; |
| 1231 |
$slug_map[ $prev->slug ] = 'priority'; |
| 1232 |
$string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $label; |
| 1233 |
break; |
| 1234 |
|
| 1235 |
case 'assigned_agent': |
| 1236 |
$wpdb->update( |
| 1237 |
$wpdb->prefix . 'psmsc_custom_fields', |
| 1238 |
array( |
| 1239 |
'name' => $label, |
| 1240 |
'load_order' => $load_order++, |
| 1241 |
), |
| 1242 |
array( 'id' => 10 ) |
| 1243 |
); |
| 1244 |
$term_id_map[ $prev->term_id ] = 10; |
| 1245 |
$slug_map[ $prev->slug ] = 'assigned_agent'; |
| 1246 |
$string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $label; |
| 1247 |
break; |
| 1248 |
|
| 1249 |
case 'date_created': |
| 1250 |
$wpdb->update( |
| 1251 |
$wpdb->prefix . 'psmsc_custom_fields', |
| 1252 |
array( |
| 1253 |
'name' => $label, |
| 1254 |
'load_order' => $load_order++, |
| 1255 |
), |
| 1256 |
array( 'id' => 11 ) |
| 1257 |
); |
| 1258 |
$term_id_map[ $prev->term_id ] = 11; |
| 1259 |
$slug_map[ $prev->slug ] = 'date_created'; |
| 1260 |
$string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $label; |
| 1261 |
break; |
| 1262 |
|
| 1263 |
case 'date_updated': |
| 1264 |
$wpdb->update( |
| 1265 |
$wpdb->prefix . 'psmsc_custom_fields', |
| 1266 |
array( |
| 1267 |
'name' => $label, |
| 1268 |
'load_order' => $load_order++, |
| 1269 |
), |
| 1270 |
array( 'id' => 12 ) |
| 1271 |
); |
| 1272 |
$term_id_map[ $prev->term_id ] = 12; |
| 1273 |
$slug_map[ $prev->slug ] = 'date_updated'; |
| 1274 |
$string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $label; |
| 1275 |
break; |
| 1276 |
|
| 1277 |
case 'agent_created': |
| 1278 |
$wpdb->update( |
| 1279 |
$wpdb->prefix . 'psmsc_custom_fields', |
| 1280 |
array( |
| 1281 |
'name' => $label, |
| 1282 |
'load_order' => $load_order++, |
| 1283 |
), |
| 1284 |
array( 'id' => 13 ) |
| 1285 |
); |
| 1286 |
$term_id_map[ $prev->term_id ] = 13; |
| 1287 |
$slug_map[ $prev->slug ] = 'agent_created'; |
| 1288 |
$string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $label; |
| 1289 |
break; |
| 1290 |
|
| 1291 |
case 'sf_rating': |
| 1292 |
$id = $wpdb->get_var( "SELECT id from {$wpdb->prefix}psmsc_custom_fields WHERE slug = 'rating'" ); |
| 1293 |
if ( $id ) { |
| 1294 |
$wpdb->update( |
| 1295 |
$wpdb->prefix . 'psmsc_custom_fields', |
| 1296 |
array( |
| 1297 |
'name' => $label, |
| 1298 |
'load_order' => $load_order++, |
| 1299 |
), |
| 1300 |
array( 'id' => $id ) |
| 1301 |
); |
| 1302 |
$term_id_map[ $prev->term_id ] = $id; |
| 1303 |
$slug_map[ $prev->slug ] = 'rating'; |
| 1304 |
$string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $label; |
| 1305 |
} |
| 1306 |
break; |
| 1307 |
|
| 1308 |
case 'sla': |
| 1309 |
$id = $wpdb->get_var( "SELECT id from {$wpdb->prefix}psmsc_custom_fields WHERE slug = 'sla'" ); |
| 1310 |
if ( $id ) { |
| 1311 |
$wpdb->update( |
| 1312 |
$wpdb->prefix . 'psmsc_custom_fields', |
| 1313 |
array( |
| 1314 |
'name' => $label, |
| 1315 |
'load_order' => $load_order++, |
| 1316 |
), |
| 1317 |
array( 'id' => $id ) |
| 1318 |
); |
| 1319 |
$term_id_map[ $prev->term_id ] = $id; |
| 1320 |
$slug_map[ $prev->slug ] = 'sla'; |
| 1321 |
$string_translations[ 'wpsc-cf-name-' . $wpdb->insert_id ] = $label; |
| 1322 |
} |
| 1323 |
break; |
| 1324 |
} |
| 1325 |
} else { |
| 1326 |
|
| 1327 |
$personal_info = get_term_meta( $prev->term_id, 'wpsc_tf_personal_info', true ); |
| 1328 |
$field = get_term_meta( $prev->term_id, 'agentonly', true ) == 1 ? 'agentonly' : 'ticket'; |
| 1329 |
|
| 1330 |
switch ( intval( $type ) ) { |
| 1331 |
|
| 1332 |
case 1: |
| 1333 |
$response = wpsc_upgrade_insert_custom_field( |
| 1334 |
array( |
| 1335 |
'name' => $label, |
| 1336 |
'extra_info' => $extra_info, |
| 1337 |
'field' => $field, |
| 1338 |
'type' => 'cf_textfield', |
| 1339 |
'is_personal_info' => $personal_info, |
| 1340 |
'load_order' => $load_order++, |
| 1341 |
) |
| 1342 |
); |
| 1343 |
$wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_tickets ADD " . $response['slug'] . ' TINYTEXT NULL' ); |
| 1344 |
$wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_archived_tickets ADD " . $response['slug'] . ' TINYTEXT NULL' ); |
| 1345 |
$term_id_map[ $prev->term_id ] = $response['id']; |
| 1346 |
$slug_map[ $prev->slug ] = $response['slug']; |
| 1347 |
$string_translations[ 'wpsc-cf-name-' . $response['id'] ] = $label; |
| 1348 |
$string_translations[ 'wpsc-cf-exi-' . $response['id'] ] = $extra_info; |
| 1349 |
break; |
| 1350 |
|
| 1351 |
case 2: |
| 1352 |
$response = wpsc_upgrade_insert_custom_field( |
| 1353 |
array( |
| 1354 |
'name' => $label, |
| 1355 |
'extra_info' => $extra_info, |
| 1356 |
'field' => $field, |
| 1357 |
'type' => 'cf_single_select', |
| 1358 |
'is_personal_info' => $personal_info, |
| 1359 |
'load_order' => $load_order++, |
| 1360 |
) |
| 1361 |
); |
| 1362 |
$wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_tickets ADD " . $response['slug'] . ' TINYTEXT NULL' ); |
| 1363 |
$wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_archived_tickets ADD " . $response['slug'] . ' TINYTEXT NULL' ); |
| 1364 |
$option_strings = self::import_options( $prev, $response['id'] ); |
| 1365 |
$string_translations = array_merge( $string_translations, $option_strings ); |
| 1366 |
$term_id_map[ $prev->term_id ] = $response['id']; |
| 1367 |
$slug_map[ $prev->slug ] = $response['slug']; |
| 1368 |
$string_translations[ 'wpsc-cf-name-' . $response['id'] ] = $label; |
| 1369 |
$string_translations[ 'wpsc-cf-exi-' . $response['id'] ] = $extra_info; |
| 1370 |
break; |
| 1371 |
|
| 1372 |
case 3: |
| 1373 |
$response = wpsc_upgrade_insert_custom_field( |
| 1374 |
array( |
| 1375 |
'name' => $label, |
| 1376 |
'extra_info' => $extra_info, |
| 1377 |
'field' => $field, |
| 1378 |
'type' => 'cf_checkbox', |
| 1379 |
'is_personal_info' => $personal_info, |
| 1380 |
'load_order' => $load_order++, |
| 1381 |
) |
| 1382 |
); |
| 1383 |
$wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_tickets ADD " . $response['slug'] . ' TINYTEXT NULL' ); |
| 1384 |
$wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_archived_tickets ADD " . $response['slug'] . ' TINYTEXT NULL' ); |
| 1385 |
$option_strings = self::import_options( $prev, $response['id'] ); |
| 1386 |
$string_translations = array_merge( $string_translations, $option_strings ); |
| 1387 |
$term_id_map[ $prev->term_id ] = $response['id']; |
| 1388 |
$slug_map[ $prev->slug ] = $response['slug']; |
| 1389 |
$string_translations[ 'wpsc-cf-name-' . $response['id'] ] = $label; |
| 1390 |
$string_translations[ 'wpsc-cf-exi-' . $response['id'] ] = $extra_info; |
| 1391 |
break; |
| 1392 |
|
| 1393 |
case 4: |
| 1394 |
$response = wpsc_upgrade_insert_custom_field( |
| 1395 |
array( |
| 1396 |
'name' => $label, |
| 1397 |
'extra_info' => $extra_info, |
| 1398 |
'field' => $field, |
| 1399 |
'type' => 'cf_radio_button', |
| 1400 |
'is_personal_info' => $personal_info, |
| 1401 |
'load_order' => $load_order++, |
| 1402 |
) |
| 1403 |
); |
| 1404 |
$wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_tickets ADD " . $response['slug'] . ' TINYTEXT NULL' ); |
| 1405 |
$wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_archived_tickets ADD " . $response['slug'] . ' TINYTEXT NULL' ); |
| 1406 |
$option_strings = self::import_options( $prev, $response['id'] ); |
| 1407 |
$string_translations = array_merge( $string_translations, $option_strings ); |
| 1408 |
$term_id_map[ $prev->term_id ] = $response['id']; |
| 1409 |
$slug_map[ $prev->slug ] = $response['slug']; |
| 1410 |
$string_translations[ 'wpsc-cf-name-' . $response['id'] ] = $label; |
| 1411 |
$string_translations[ 'wpsc-cf-exi-' . $response['id'] ] = $extra_info; |
| 1412 |
break; |
| 1413 |
|
| 1414 |
case 5: |
| 1415 |
$response = wpsc_upgrade_insert_custom_field( |
| 1416 |
array( |
| 1417 |
'name' => $label, |
| 1418 |
'extra_info' => $extra_info, |
| 1419 |
'field' => $field, |
| 1420 |
'type' => 'cf_textarea', |
| 1421 |
'is_personal_info' => $personal_info, |
| 1422 |
'load_order' => $load_order++, |
| 1423 |
) |
| 1424 |
); |
| 1425 |
$wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_tickets ADD " . $response['slug'] . ' LONGTEXT NULL' ); |
| 1426 |
$wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_archived_tickets ADD " . $response['slug'] . ' LONGTEXT NULL' ); |
| 1427 |
$term_id_map[ $prev->term_id ] = $response['id']; |
| 1428 |
$slug_map[ $prev->slug ] = $response['slug']; |
| 1429 |
$string_translations[ 'wpsc-cf-name-' . $response['id'] ] = $label; |
| 1430 |
$string_translations[ 'wpsc-cf-exi-' . $response['id'] ] = $extra_info; |
| 1431 |
break; |
| 1432 |
|
| 1433 |
case 6: |
| 1434 |
$response = wpsc_upgrade_insert_custom_field( |
| 1435 |
array( |
| 1436 |
'name' => $label, |
| 1437 |
'extra_info' => $extra_info, |
| 1438 |
'field' => $field, |
| 1439 |
'type' => 'cf_date', |
| 1440 |
'is_personal_info' => $personal_info, |
| 1441 |
'load_order' => $load_order++, |
| 1442 |
) |
| 1443 |
); |
| 1444 |
$wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_tickets ADD " . $response['slug'] . ' DATETIME NULL DEFAULT NULL' ); |
| 1445 |
$wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_archived_tickets ADD " . $response['slug'] . ' DATETIME NULL DEFAULT NULL' ); |
| 1446 |
$term_id_map[ $prev->term_id ] = $response['id']; |
| 1447 |
$slug_map[ $prev->slug ] = $response['slug']; |
| 1448 |
$string_translations[ 'wpsc-cf-name-' . $response['id'] ] = $label; |
| 1449 |
$string_translations[ 'wpsc-cf-exi-' . $response['id'] ] = $extra_info; |
| 1450 |
break; |
| 1451 |
|
| 1452 |
case 7: |
| 1453 |
$response = wpsc_upgrade_insert_custom_field( |
| 1454 |
array( |
| 1455 |
'name' => $label, |
| 1456 |
'extra_info' => $extra_info, |
| 1457 |
'field' => $field, |
| 1458 |
'type' => 'cf_url', |
| 1459 |
'is_personal_info' => $personal_info, |
| 1460 |
'load_order' => $load_order++, |
| 1461 |
) |
| 1462 |
); |
| 1463 |
$wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_tickets ADD " . $response['slug'] . ' TINYTEXT NULL' ); |
| 1464 |
$wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_archived_tickets ADD " . $response['slug'] . ' TINYTEXT NULL' ); |
| 1465 |
$term_id_map[ $prev->term_id ] = $response['id']; |
| 1466 |
$slug_map[ $prev->slug ] = $response['slug']; |
| 1467 |
$string_translations[ 'wpsc-cf-name-' . $response['id'] ] = $label; |
| 1468 |
$string_translations[ 'wpsc-cf-exi-' . $response['id'] ] = $extra_info; |
| 1469 |
break; |
| 1470 |
|
| 1471 |
case 8: |
| 1472 |
$response = wpsc_upgrade_insert_custom_field( |
| 1473 |
array( |
| 1474 |
'name' => $label, |
| 1475 |
'extra_info' => $extra_info, |
| 1476 |
'field' => $field, |
| 1477 |
'type' => 'cf_email', |
| 1478 |
'is_personal_info' => $personal_info, |
| 1479 |
'load_order' => $load_order++, |
| 1480 |
) |
| 1481 |
); |
| 1482 |
$wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_tickets ADD " . $response['slug'] . ' TINYTEXT NULL' ); |
| 1483 |
$wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_archived_tickets ADD " . $response['slug'] . ' TINYTEXT NULL' ); |
| 1484 |
$term_id_map[ $prev->term_id ] = $response['id']; |
| 1485 |
$slug_map[ $prev->slug ] = $response['slug']; |
| 1486 |
$string_translations[ 'wpsc-cf-name-' . $response['id'] ] = $label; |
| 1487 |
$string_translations[ 'wpsc-cf-exi-' . $response['id'] ] = $extra_info; |
| 1488 |
break; |
| 1489 |
|
| 1490 |
case 9: |
| 1491 |
$response = wpsc_upgrade_insert_custom_field( |
| 1492 |
array( |
| 1493 |
'name' => $label, |
| 1494 |
'extra_info' => $extra_info, |
| 1495 |
'field' => $field, |
| 1496 |
'type' => 'cf_number', |
| 1497 |
'is_personal_info' => $personal_info, |
| 1498 |
'load_order' => $load_order++, |
| 1499 |
) |
| 1500 |
); |
| 1501 |
$wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_tickets ADD " . $response['slug'] . ' TINYTEXT NULL' ); |
| 1502 |
$wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_archived_tickets ADD " . $response['slug'] . ' TINYTEXT NULL' ); |
| 1503 |
$term_id_map[ $prev->term_id ] = $response['id']; |
| 1504 |
$slug_map[ $prev->slug ] = $response['slug']; |
| 1505 |
$string_translations[ 'wpsc-cf-name-' . $response['id'] ] = $label; |
| 1506 |
$string_translations[ 'wpsc-cf-exi-' . $response['id'] ] = $extra_info; |
| 1507 |
break; |
| 1508 |
|
| 1509 |
case 10: |
| 1510 |
$response = wpsc_upgrade_insert_custom_field( |
| 1511 |
array( |
| 1512 |
'name' => $label, |
| 1513 |
'extra_info' => $extra_info, |
| 1514 |
'field' => $field, |
| 1515 |
'type' => 'cf_file_attachment_multiple', |
| 1516 |
'is_personal_info' => $personal_info, |
| 1517 |
'load_order' => $load_order++, |
| 1518 |
) |
| 1519 |
); |
| 1520 |
$wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_tickets ADD " . $response['slug'] . ' TINYTEXT NULL' ); |
| 1521 |
$wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_archived_tickets ADD " . $response['slug'] . ' TINYTEXT NULL' ); |
| 1522 |
$term_id_map[ $prev->term_id ] = $response['id']; |
| 1523 |
$slug_map[ $prev->slug ] = $response['slug']; |
| 1524 |
$string_translations[ 'wpsc-cf-name-' . $response['id'] ] = $label; |
| 1525 |
$string_translations[ 'wpsc-cf-exi-' . $response['id'] ] = $extra_info; |
| 1526 |
break; |
| 1527 |
|
| 1528 |
case 11: |
| 1529 |
if ( $installed_addons[5]['is_installed'] ) { |
| 1530 |
$response = wpsc_upgrade_insert_custom_field( |
| 1531 |
array( |
| 1532 |
'name' => $label, |
| 1533 |
'extra_info' => $extra_info, |
| 1534 |
'field' => $field, |
| 1535 |
'type' => 'cf_woo_product', |
| 1536 |
'is_personal_info' => $personal_info, |
| 1537 |
'load_order' => $load_order++, |
| 1538 |
) |
| 1539 |
); |
| 1540 |
$wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_tickets ADD " . $response['slug'] . ' BIGINT NULL DEFAULT 0' ); |
| 1541 |
$wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_archived_tickets ADD " . $response['slug'] . ' BIGINT NULL DEFAULT 0' ); |
| 1542 |
$term_id_map[ $prev->term_id ] = $response['id']; |
| 1543 |
$slug_map[ $prev->slug ] = $response['slug']; |
| 1544 |
$string_translations[ 'wpsc-cf-name-' . $response['id'] ] = $label; |
| 1545 |
$string_translations[ 'wpsc-cf-exi-' . $response['id'] ] = $extra_info; |
| 1546 |
} |
| 1547 |
break; |
| 1548 |
|
| 1549 |
case 12: |
| 1550 |
if ( $installed_addons[5]['is_installed'] ) { |
| 1551 |
$response = wpsc_upgrade_insert_custom_field( |
| 1552 |
array( |
| 1553 |
'name' => $label, |
| 1554 |
'extra_info' => $extra_info, |
| 1555 |
'field' => $field, |
| 1556 |
'type' => 'cf_woo_order', |
| 1557 |
'is_personal_info' => $personal_info, |
| 1558 |
'load_order' => $load_order++, |
| 1559 |
) |
| 1560 |
); |
| 1561 |
$wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_tickets ADD " . $response['slug'] . ' BIGINT NULL DEFAULT 0' ); |
| 1562 |
$wpdb->query( "ALTER TABLE {$wpdb->prefix}psmsc_archived_tickets ADD " . $response['slug'] . ' BIGINT NULL DEFAULT 0' ); |
| 1563 |
$term_id_map[ $prev->term_id ] = $response['id']; |
| 1564 |
$slug_map[ $prev->slug ] = $response['slug']; |
| 1565 |
$string_translations[ 'wpsc-cf-name-' . $response['id'] ] = $label; |
| 1566 |
$string_translations[ 'wpsc-cf-exi-' . $response['id'] ] = $extra_info; |
| 1567 |
} |
| 1568 |
break; |
| 1569 |
} |
| 1570 |
} |
| 1571 |
} |
| 1572 |
|
| 1573 |
update_option( 'wpsc-string-translation', $string_translations ); |
| 1574 |
update_option( 'wpsc_upgrade_cf_term_id_map', $term_id_map ); |
| 1575 |
update_option( 'wpsc_upgrade_cf_slug_map', $slug_map ); |
| 1576 |
update_option( 'wpsc_upgrade_cf_load_order', $load_order ); |
| 1577 |
} |
| 1578 |
|
| 1579 |
/** |
| 1580 |
* Import options for custom field |
| 1581 |
* |
| 1582 |
* @param mixed $prev - previous custom field object. |
| 1583 |
* @param int $id - new custom field id. |
| 1584 |
* @return void |
| 1585 |
*/ |
| 1586 |
public static function import_options( $prev, $id ) { |
| 1587 |
|
| 1588 |
global $wpdb; |
| 1589 |
$string_translations = get_option( 'wpsc-string-translation' ); |
| 1590 |
$options = get_term_meta( $prev->term_id, 'wpsc_tf_options', true ); |
| 1591 |
$load_order = 1; |
| 1592 |
$options_map = get_option( 'wpsc_upgrade_cf_options_map', array() ); |
| 1593 |
foreach ( $options as $name ) { |
| 1594 |
$wpdb->insert( |
| 1595 |
$wpdb->prefix . 'psmsc_options', |
| 1596 |
array( |
| 1597 |
'name' => $name, |
| 1598 |
'date_created' => ( new DateTime( 'now' ) )->format( 'Y-m-d H:m:s' ), |
| 1599 |
'custom_field' => $id, |
| 1600 |
'load_order' => $load_order++, |
| 1601 |
) |
| 1602 |
); |
| 1603 |
$string_translations[ 'wpsc-option-' . $wpdb->insert_id ] = $name; |
| 1604 |
$options_map[ $id ][ $name ] = $wpdb->insert_id; |
| 1605 |
} |
| 1606 |
update_option( 'wpsc-string-translation', $string_translations ); |
| 1607 |
update_option( 'wpsc_upgrade_cf_options_map', $options_map ); |
| 1608 |
} |
| 1609 |
|
| 1610 |
/** |
| 1611 |
* Import agent and agentgroups |
| 1612 |
* |
| 1613 |
* @return void |
| 1614 |
*/ |
| 1615 |
public static function import_agents() { |
| 1616 |
|
| 1617 |
global $wpdb; |
| 1618 |
|
| 1619 |
// removing agent role cap. |
| 1620 |
$agents = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}psmsc_agents" ); |
| 1621 |
foreach ( $agents as $agent ) { |
| 1622 |
$user = get_user_by( 'id', $agent->user ); |
| 1623 |
if ( $user ) { |
| 1624 |
$user->remove_cap( 'wpsc_agent' ); |
| 1625 |
} |
| 1626 |
} |
| 1627 |
|
| 1628 |
$wpdb->query( 'DELETE FROM ' . $wpdb->prefix . 'psmsc_agents' ); |
| 1629 |
$wpdb->query( 'ALTER TABLE ' . $wpdb->prefix . 'psmsc_agents AUTO_INCREMENT = 1' ); |
| 1630 |
$wpdb->query( 'DELETE FROM ' . $wpdb->prefix . 'psmsc_customers' ); |
| 1631 |
$wpdb->query( 'ALTER TABLE ' . $wpdb->prefix . 'psmsc_customers AUTO_INCREMENT = 1' ); |
| 1632 |
|
| 1633 |
// import agent roles. |
| 1634 |
$new = array(); |
| 1635 |
$prev = get_option( 'wpsc_agent_role' ); |
| 1636 |
foreach ( $prev as $key => $role ) { |
| 1637 |
$new[ $key ] = array( |
| 1638 |
'label' => $role['label'], |
| 1639 |
'caps' => array( |
| 1640 |
'view-unassigned' => $role['view_unassigned'] == 1 ? true : false, // View ticket. |
| 1641 |
'view-assigned-me' => $role['view_assigned_me'] == 1 ? true : false, |
| 1642 |
'view-assigned-others' => $role['view_assigned_others'] == 1 ? true : false, |
| 1643 |
'reply-unassigned' => $role['reply_unassigned'] == 1 ? true : false, // Reply ticket. |
| 1644 |
'reply-assigned-me' => $role['reply_assigned_me'] == 1 ? true : false, |
| 1645 |
'reply-assigned-others' => $role['reply_assigned_others'] == 1 ? true : false, |
| 1646 |
'pn-unassigned' => true, // Private notes. |
| 1647 |
'pn-assigned-me' => true, |
| 1648 |
'pn-assigned-others' => true, |
| 1649 |
'aa-unassigned' => $role['assign_unassigned'] == 1 ? true : false, // Assignee. |
| 1650 |
'aa-assigned-me' => $role['assign_assigned_me'] == 1 ? true : false, |
| 1651 |
'aa-assigned-others' => $role['assign_assigned_others'] == 1 ? true : false, |
| 1652 |
'cs-unassigned' => $role['cng_tkt_sts_unassigned'] == 1 ? true : false, // Change status. |
| 1653 |
'cs-assigned-me' => $role['cng_tkt_sts_assigned_me'] == 1 ? true : false, |
| 1654 |
'cs-assigned-others' => $role['cng_tkt_sts_assigned_others'] == 1 ? true : false, |
| 1655 |
'ctf-unassigned' => $role['cng_tkt_field_unassigned'] == 1 ? true : false, // Change ticket fields. |
| 1656 |
'ctf-assigned-me' => $role['cng_tkt_field_assigned_me'] == 1 ? true : false, |
| 1657 |
'ctf-assigned-others' => $role['cng_tkt_field_assigned_others'] == 1 ? true : false, |
| 1658 |
'caof-unassigned' => $role['cng_tkt_ao_unassigned'] == 1 ? true : false, // Change agent only fields. |
| 1659 |
'caof-assigned-me' => $role['cng_tkt_ao_assigned_me'] == 1 ? true : false, |
| 1660 |
'caof-assigned-others' => $role['cng_tkt_ao_assigned_others'] == 1 ? true : false, |
| 1661 |
'crb-unassigned' => $role['cng_tkt_rb_unassigned'] == 1 ? true : false, // Change raised by. |
| 1662 |
'crb-assigned-me' => $role['cng_tkt_rb_assigned_me'] == 1 ? true : false, |
| 1663 |
'crb-assigned-others' => $role['cng_tkt_rb_assigned_others'] == 1 ? true : false, |
| 1664 |
'eth-unassigned' => $role['delete_unassigned'] == 1 ? true : false, // Edit thread. |
| 1665 |
'eth-assigned-me' => $role['delete_assigned_me'] == 1 ? true : false, |
| 1666 |
'eth-assigned-others' => $role['delete_assigned_others'] == 1 ? true : false, |
| 1667 |
'dth-unassigned' => $role['delete_unassigned'] == 1 ? true : false, // Delete thread. |
| 1668 |
'dth-assigned-me' => $role['delete_assigned_me'] == 1 ? true : false, |
| 1669 |
'dth-assigned-others' => $role['delete_assigned_others'] == 1 ? true : false, |
| 1670 |
'vl-unassigned' => true, // View logs. |
| 1671 |
'vl-assigned-me' => true, |
| 1672 |
'vl-assigned-others' => true, |
| 1673 |
'dtt-unassigned' => $role['delete_unassigned'] == 1 ? true : false, // Delete ticket. |
| 1674 |
'dtt-assigned-me' => $role['delete_assigned_me'] == 1 ? true : false, |
| 1675 |
'dtt-assigned-others' => $role['delete_assigned_others'] == 1 ? true : false, |
| 1676 |
'ar-unassigned' => true, // Additional recipients. |
| 1677 |
'ar-assigned-me' => true, |
| 1678 |
'ar-assigned-others' => true, |
| 1679 |
'dt-unassigned' => true, // Duplicate ticket. |
| 1680 |
'dt-assigned-me' => true, |
| 1681 |
'dt-assigned-others' => true, |
| 1682 |
'backend-access' => true, // Dashboard support menu access. |
| 1683 |
'create-as' => true, // Create ticket on others behalf. |
| 1684 |
'eci-access' => true, // Edit customer info. |
| 1685 |
'dash-access' => true, // Dashboard access. |
| 1686 |
), |
| 1687 |
); |
| 1688 |
} |
| 1689 |
update_option( 'wpsc-agent-roles', $new ); |
| 1690 |
|
| 1691 |
$map = array(); |
| 1692 |
$agents = get_terms( |
| 1693 |
array( |
| 1694 |
'taxonomy' => 'wpsc_agents', |
| 1695 |
'hide_empty' => false, |
| 1696 |
) |
| 1697 |
); |
| 1698 |
|
| 1699 |
// import agents. |
| 1700 |
foreach ( $agents as $prev ) { |
| 1701 |
|
| 1702 |
$is_agentgroup = get_term_meta( $prev->term_id, 'agentgroup', true ); |
| 1703 |
if ( $is_agentgroup ) { |
| 1704 |
continue; |
| 1705 |
} |
| 1706 |
|
| 1707 |
$user_id = get_term_meta( $prev->term_id, 'user_id', true ); |
| 1708 |
$user = get_user_by( 'id', $user_id ); |
| 1709 |
if ( ! $user->ID ) { |
| 1710 |
continue; |
| 1711 |
} |
| 1712 |
|
| 1713 |
// create customer record. |
| 1714 |
$wpdb->insert( |
| 1715 |
$wpdb->prefix . 'psmsc_customers', |
| 1716 |
array( |
| 1717 |
'user' => $user_id, |
| 1718 |
'name' => $user->display_name, |
| 1719 |
'email' => $user->user_email, |
| 1720 |
) |
| 1721 |
); |
| 1722 |
|
| 1723 |
// insert agent record. |
| 1724 |
$wpdb->insert( |
| 1725 |
$wpdb->prefix . 'psmsc_agents', |
| 1726 |
array( |
| 1727 |
'user' => $user_id, |
| 1728 |
'customer' => $wpdb->insert_id, |
| 1729 |
'role' => get_term_meta( $prev->term_id, 'role', true ), |
| 1730 |
'name' => $user->display_name, |
| 1731 |
'is_active' => 1, |
| 1732 |
) |
| 1733 |
); |
| 1734 |
|
| 1735 |
// adding agent role cap. |
| 1736 |
$user->add_cap( 'wpsc_agent' ); |
| 1737 |
|
| 1738 |
// agent working hrs. |
| 1739 |
$agent_id = $wpdb->insert_id; |
| 1740 |
for ( $i = 1; $i <= 7; $i++ ) { |
| 1741 |
$wpdb->insert( |
| 1742 |
$wpdb->prefix . 'psmsc_working_hrs', |
| 1743 |
array( |
| 1744 |
'agent' => $agent_id, |
| 1745 |
'day' => $i, |
| 1746 |
'start_time' => '00:00:00', |
| 1747 |
'end_time' => '23:59:59', |
| 1748 |
) |
| 1749 |
); |
| 1750 |
} |
| 1751 |
|
| 1752 |
$map[ $prev->term_id ] = $agent_id; |
| 1753 |
} |
| 1754 |
|
| 1755 |
// import agentgroups. |
| 1756 |
$installed_addons = get_option( 'wpsc_upgrade_installed_addons' ); |
| 1757 |
if ( $installed_addons[16]['is_installed'] ) { |
| 1758 |
|
| 1759 |
foreach ( $agents as $prev ) { |
| 1760 |
|
| 1761 |
$is_agentgroup = get_term_meta( $prev->term_id, 'agentgroup', true ); |
| 1762 |
if ( ! $is_agentgroup ) { |
| 1763 |
continue; |
| 1764 |
} |
| 1765 |
|
| 1766 |
// insert agent record for the group. |
| 1767 |
$wpdb->insert( |
| 1768 |
$wpdb->prefix . 'psmsc_agents', |
| 1769 |
array( |
| 1770 |
'name' => $prev->name, |
| 1771 |
'is_agentgroup' => 1, |
| 1772 |
'is_active' => 1, |
| 1773 |
) |
| 1774 |
); |
| 1775 |
$map[ $prev->term_id ] = $wpdb->insert_id; |
| 1776 |
|
| 1777 |
// get members of the group. |
| 1778 |
$group_user_ids = get_term_meta( $prev->term_id, 'agentgroup_user_id', false ); |
| 1779 |
$member_ids = array(); |
| 1780 |
foreach ( $group_user_ids as $user_id ) { |
| 1781 |
$member_ids[] = $map[ $user_id ]; |
| 1782 |
} |
| 1783 |
|
| 1784 |
// create agentgroup record. |
| 1785 |
$wpdb->insert( |
| 1786 |
$wpdb->prefix . 'psmsc_agentgroups', |
| 1787 |
array( |
| 1788 |
'agent_id' => $wpdb->insert_id, |
| 1789 |
'name' => $prev->name, |
| 1790 |
'agents' => implode( '|', $member_ids ), |
| 1791 |
'supervisors' => implode( '|', $member_ids ), |
| 1792 |
) |
| 1793 |
); |
| 1794 |
} |
| 1795 |
} |
| 1796 |
|
| 1797 |
update_option( 'wpsc_upgrade_agent_map', $map ); |
| 1798 |
} |
| 1799 |
|
| 1800 |
/** |
| 1801 |
* Import ticket form field settings |
| 1802 |
* |
| 1803 |
* @return void |
| 1804 |
*/ |
| 1805 |
public static function import_ticket_form_fields() { |
| 1806 |
|
| 1807 |
$form_fields = array(); |
| 1808 |
$cf_map = get_option( 'wpsc_upgrade_cf_term_id_map' ); |
| 1809 |
$options_map = get_option( 'wpsc_upgrade_cf_options_map' ); |
| 1810 |
$category_map = get_option( 'wpsc_upgrade_category_map' ); |
| 1811 |
$priority_map = get_option( 'wpsc_upgrade_priority_map' ); |
| 1812 |
$fields = get_terms( |
| 1813 |
array( |
| 1814 |
'taxonomy' => 'wpsc_ticket_custom_fields', |
| 1815 |
'hide_empty' => false, |
| 1816 |
'orderby' => 'meta_value_num', |
| 1817 |
'meta_key' => 'wpsc_tf_load_order', |
| 1818 |
'order' => 'ASC', |
| 1819 |
'meta_query' => array( |
| 1820 |
array( |
| 1821 |
'key' => 'agentonly', |
| 1822 |
'value' => '0', |
| 1823 |
'compare' => '=', |
| 1824 |
), |
| 1825 |
), |
| 1826 |
) |
| 1827 |
); |
| 1828 |
|
| 1829 |
foreach ( $fields as $field ) { |
| 1830 |
|
| 1831 |
$status = get_term_meta( $field->term_id, 'wpsc_tf_status', true ); |
| 1832 |
if ( $status == 0 ) { |
| 1833 |
continue; |
| 1834 |
} |
| 1835 |
|
| 1836 |
$is_required = get_term_meta( $field->term_id, 'wpsc_tf_required', true ); |
| 1837 |
|
| 1838 |
$width = get_term_meta( $field->term_id, 'wpsc_tf_width', true ); |
| 1839 |
switch ( $width ) { |
| 1840 |
|
| 1841 |
case '1/2': |
| 1842 |
$width = 'half'; |
| 1843 |
break; |
| 1844 |
|
| 1845 |
case '1': |
| 1846 |
$width = 'full'; |
| 1847 |
} |
| 1848 |
|
| 1849 |
$visibility = array(); |
| 1850 |
$prev_visibility = get_term_meta( $field->term_id, 'wpsc_tf_visibility', true ); |
| 1851 |
if ( $prev_visibility ) { |
| 1852 |
foreach ( $prev_visibility as $condition ) { |
| 1853 |
$condition = explode( '--', $condition ); |
| 1854 |
$cf = wpsc_get_cf_by( 'id', $cf_map[ $condition[0] ] ); |
| 1855 |
switch ( $cf->slug ) { |
| 1856 |
|
| 1857 |
case 'category': |
| 1858 |
if ( isset( $visibility[ $cf->slug ] ) ) { |
| 1859 |
$visibility[ $cf->slug ]['operand_val_1'][] = $category_map[ $condition[1] ]; |
| 1860 |
} else { |
| 1861 |
$visibility[ $cf->slug ] = array( |
| 1862 |
'operator' => 'IN', |
| 1863 |
'operand_val_1' => array( |
| 1864 |
$category_map[ $condition[1] ], |
| 1865 |
), |
| 1866 |
); |
| 1867 |
} |
| 1868 |
break; |
| 1869 |
|
| 1870 |
case 'priority': |
| 1871 |
if ( isset( $visibility[ $cf->slug ] ) ) { |
| 1872 |
$visibility[ $cf->slug ]['operand_val_1'][] = $priority_map[ $condition[1] ]; |
| 1873 |
} else { |
| 1874 |
$visibility[ $cf->slug ] = array( |
| 1875 |
'operator' => 'IN', |
| 1876 |
'operand_val_1' => array( |
| 1877 |
$priority_map[ $condition[1] ], |
| 1878 |
), |
| 1879 |
); |
| 1880 |
} |
| 1881 |
break; |
| 1882 |
|
| 1883 |
default: |
| 1884 |
if ( isset( $visibility[ $cf->slug ] ) ) { |
| 1885 |
$visibility[ $cf->slug ]['operand_val_1'][] = $options_map[ $cf->id ][ $condition[1] ]; |
| 1886 |
} else { |
| 1887 |
$visibility[ $cf->slug ] = array( |
| 1888 |
'operator' => 'IN', |
| 1889 |
'operand_val_1' => array( |
| 1890 |
$options_map[ $cf->id ][ $condition[1] ], |
| 1891 |
), |
| 1892 |
); |
| 1893 |
} |
| 1894 |
} |
| 1895 |
} |
| 1896 |
} |
| 1897 |
|
| 1898 |
$cf = wpsc_get_cf_by( 'id', $cf_map[ $field->term_id ] ); |
| 1899 |
$form_fields[ $cf->slug ] = array( |
| 1900 |
'is-required' => $is_required, |
| 1901 |
'width' => $width, |
| 1902 |
'relation' => 'OR', |
| 1903 |
'visibility' => $visibility ? wp_json_encode( $visibility ) : '{}', |
| 1904 |
); |
| 1905 |
} |
| 1906 |
|
| 1907 |
// import tff conditions. |
| 1908 |
foreach ( $form_fields as $slug => $properties ) { |
| 1909 |
if ( ! $properties['visibility'] ) { |
| 1910 |
continue; |
| 1911 |
} |
| 1912 |
$form_fields[ $slug ]['visibility'] = WPSC_SC_Upgrade::upgrade_condition( $properties['visibility'], $properties['relation'] ); |
| 1913 |
} |
| 1914 |
update_option( 'wpsc-tff', $form_fields ); |
| 1915 |
} |
| 1916 |
|
| 1917 |
/** |
| 1918 |
* Import agent and customer ticket list and filter items |
| 1919 |
* |
| 1920 |
* @return void |
| 1921 |
*/ |
| 1922 |
public static function import_ticket_list_items() { |
| 1923 |
|
| 1924 |
$map = get_option( 'wpsc_upgrade_cf_term_id_map' ); |
| 1925 |
// import agent ticket list. |
| 1926 |
$items = array(); |
| 1927 |
$fields = get_terms( |
| 1928 |
array( |
| 1929 |
'taxonomy' => 'wpsc_ticket_custom_fields', |
| 1930 |
'hide_empty' => false, |
| 1931 |
'orderby' => 'meta_value_num', |
| 1932 |
'meta_key' => 'wpsc_tl_agent_load_order', |
| 1933 |
'order' => 'ASC', |
| 1934 |
'meta_query' => array( |
| 1935 |
'relation' => 'AND', |
| 1936 |
array( |
| 1937 |
'key' => 'wpsc_allow_ticket_list', |
| 1938 |
'value' => '1', |
| 1939 |
'compare' => '=', |
| 1940 |
), |
| 1941 |
array( |
| 1942 |
'key' => 'wpsc_agent_ticket_list_status', |
| 1943 |
'value' => '1', |
| 1944 |
'compare' => '=', |
| 1945 |
), |
| 1946 |
), |
| 1947 |
) |
| 1948 |
); |
| 1949 |
foreach ( $fields as $field ) { |
| 1950 |
$cf = wpsc_get_cf_by( 'id', $map[ $field->term_id ] ); |
| 1951 |
$items[] = $cf->slug; |
| 1952 |
} |
| 1953 |
update_option( 'wpsc-atl-list-items', $items ); |
| 1954 |
// import agent filter items. |
| 1955 |
$items = array(); |
| 1956 |
$fields = get_terms( |
| 1957 |
array( |
| 1958 |
'taxonomy' => 'wpsc_ticket_custom_fields', |
| 1959 |
'hide_empty' => false, |
| 1960 |
'orderby' => 'meta_value_num', |
| 1961 |
'meta_key' => 'wpsc_filter_agent_load_order', |
| 1962 |
'order' => 'ASC', |
| 1963 |
'meta_query' => array( |
| 1964 |
'relation' => 'AND', |
| 1965 |
array( |
| 1966 |
'key' => 'wpsc_allow_ticket_filter', |
| 1967 |
'value' => '1', |
| 1968 |
'compare' => '=', |
| 1969 |
), |
| 1970 |
array( |
| 1971 |
'key' => 'wpsc_agent_ticket_filter_status', |
| 1972 |
'value' => '1', |
| 1973 |
'compare' => '=', |
| 1974 |
), |
| 1975 |
), |
| 1976 |
) |
| 1977 |
); |
| 1978 |
foreach ( $fields as $field ) { |
| 1979 |
$cf = wpsc_get_cf_by( 'id', $map[ $field->term_id ] ); |
| 1980 |
if ( $cf->slug == 'name' ) { |
| 1981 |
$items[] = 'customer'; |
| 1982 |
} else { |
| 1983 |
$items[] = $cf->slug; |
| 1984 |
} |
| 1985 |
} |
| 1986 |
update_option( 'wpsc-atl-filter-items', $items ); |
| 1987 |
// import customer list items. |
| 1988 |
$items = array(); |
| 1989 |
$fields = get_terms( |
| 1990 |
array( |
| 1991 |
'taxonomy' => 'wpsc_ticket_custom_fields', |
| 1992 |
'hide_empty' => false, |
| 1993 |
'orderby' => 'meta_value_num', |
| 1994 |
'meta_key' => 'wpsc_tl_customer_load_order', |
| 1995 |
'order' => 'ASC', |
| 1996 |
'meta_query' => array( |
| 1997 |
'relation' => 'AND', |
| 1998 |
array( |
| 1999 |
'key' => 'wpsc_allow_ticket_list', |
| 2000 |
'value' => '1', |
| 2001 |
'compare' => '=', |
| 2002 |
), |
| 2003 |
array( |
| 2004 |
'key' => 'wpsc_customer_ticket_list_status', |
| 2005 |
'value' => '1', |
| 2006 |
'compare' => '=', |
| 2007 |
), |
| 2008 |
), |
| 2009 |
) |
| 2010 |
); |
| 2011 |
foreach ( $fields as $field ) { |
| 2012 |
$cf = wpsc_get_cf_by( 'id', $map[ $field->term_id ] ); |
| 2013 |
$items[] = $cf->slug; |
| 2014 |
} |
| 2015 |
update_option( 'wpsc-ctl-list-items', $items ); |
| 2016 |
// import customer filter items. |
| 2017 |
$items = array(); |
| 2018 |
$fields = get_terms( |
| 2019 |
array( |
| 2020 |
'taxonomy' => 'wpsc_ticket_custom_fields', |
| 2021 |
'hide_empty' => false, |
| 2022 |
'orderby' => 'meta_value_num', |
| 2023 |
'meta_key' => 'wpsc_filter_customer_load_order', |
| 2024 |
'order' => 'ASC', |
| 2025 |
'meta_query' => array( |
| 2026 |
'relation' => 'AND', |
| 2027 |
array( |
| 2028 |
'key' => 'wpsc_allow_ticket_filter', |
| 2029 |
'value' => '1', |
| 2030 |
'compare' => '=', |
| 2031 |
), |
| 2032 |
array( |
| 2033 |
'key' => 'wpsc_customer_ticket_filter_status', |
| 2034 |
'value' => '1', |
| 2035 |
'compare' => '=', |
| 2036 |
), |
| 2037 |
), |
| 2038 |
) |
| 2039 |
); |
| 2040 |
foreach ( $fields as $field ) { |
| 2041 |
$cf = wpsc_get_cf_by( 'id', $map[ $field->term_id ] ); |
| 2042 |
if ( $cf->slug == 'name' ) { |
| 2043 |
$items[] = 'customer'; |
| 2044 |
} else { |
| 2045 |
$items[] = $cf->slug; |
| 2046 |
} |
| 2047 |
} |
| 2048 |
update_option( 'wpsc-ctl-filter-items', $items ); |
| 2049 |
} |
| 2050 |
|
| 2051 |
/** |
| 2052 |
* Import ticket list more settings |
| 2053 |
* |
| 2054 |
* @return void |
| 2055 |
*/ |
| 2056 |
public static function import_tl_more_settings() { |
| 2057 |
|
| 2058 |
$cf_map = get_option( 'wpsc_upgrade_cf_term_id_map' ); |
| 2059 |
$status_map = get_option( 'wpsc_upgrade_status_map' ); |
| 2060 |
// agent view. |
| 2061 |
$aview = get_option( 'wpsc-tl-ms-agent-view' ); |
| 2062 |
$orderby = get_option( 'wpsc_tl_agent_orderby' ); |
| 2063 |
$orderby = get_term_by( 'slug', $orderby, 'wpsc_ticket_custom_fields' ); |
| 2064 |
$orderby = wpsc_get_cf_by( 'id', $cf_map[ $orderby->term_id ] ); |
| 2065 |
$aview['default-sort-by'] = $orderby->slug; |
| 2066 |
$aview['default-sort-order'] = get_option( 'wpsc_tl_agent_orderby_order' ); |
| 2067 |
$aview['number-of-tickets'] = get_option( 'wpsc_tl_agent_no_of_tickets' ); |
| 2068 |
$aview['unresolved-ticket-statuses'] = array_filter( |
| 2069 |
array_unique( |
| 2070 |
array_map( |
| 2071 |
function ( $status_id ) use ( $status_map ) { |
| 2072 |
return $status_map[ $status_id ]; |
| 2073 |
}, |
| 2074 |
get_option( 'wpsc_tl_agent_unresolve_statuses', array() ) |
| 2075 |
) |
| 2076 |
) |
| 2077 |
); |
| 2078 |
update_option( 'wpsc-tl-ms-agent-view', $aview ); |
| 2079 |
// customer view. |
| 2080 |
$cview = get_option( 'wpsc-tl-ms-customer-view' ); |
| 2081 |
$orderby = get_option( 'wpsc_tl_customer_orderby' ); |
| 2082 |
$orderby = get_term_by( 'slug', $orderby, 'wpsc_ticket_custom_fields' ); |
| 2083 |
$orderby = wpsc_get_cf_by( 'id', $cf_map[ $orderby->term_id ] ); |
| 2084 |
$cview['default-sort-by'] = $orderby->slug; |
| 2085 |
$cview['default-sort-order'] = get_option( 'wpsc_tl_customer_orderby_order' ); |
| 2086 |
$cview['number-of-tickets'] = get_option( 'wpsc_tl_customer_no_of_tickets' ); |
| 2087 |
$cview['unresolved-ticket-statuses'] = array_filter( |
| 2088 |
array_unique( |
| 2089 |
array_map( |
| 2090 |
function ( $status_id ) use ( $status_map ) { |
| 2091 |
return $status_map[ $status_id ]; |
| 2092 |
}, |
| 2093 |
get_option( 'wpsc_tl_customer_unresolve_statuses', array() ) |
| 2094 |
) |
| 2095 |
) |
| 2096 |
); |
| 2097 |
update_option( 'wpsc-tl-ms-customer-view', $cview ); |
| 2098 |
} |
| 2099 |
|
| 2100 |
/** |
| 2101 |
* Import email notifications general settings |
| 2102 |
* |
| 2103 |
* @return void |
| 2104 |
*/ |
| 2105 |
public static function import_en_general() { |
| 2106 |
|
| 2107 |
$settings = get_option( 'wpsc-en-general', array() ); |
| 2108 |
$settings['from-name'] = get_option( 'wpsc_en_from_name' ); |
| 2109 |
$settings['from-email'] = get_option( 'wpsc_en_from_email' ); |
| 2110 |
$settings['reply-to'] = get_option( 'wpsc_en_reply_to' ); |
| 2111 |
$settings['blocked-emails'] = get_option( 'wpsc_en_ignore_emails', array() ); |
| 2112 |
update_option( 'wpsc-en-general', $settings ); |
| 2113 |
} |
| 2114 |
|
| 2115 |
/** |
| 2116 |
* Import ticket notifications |
| 2117 |
* |
| 2118 |
* @return void |
| 2119 |
*/ |
| 2120 |
public static function import_en_ticket_notifications() { |
| 2121 |
|
| 2122 |
$cf_map = get_option( 'wpsc_upgrade_cf_term_id_map' ); |
| 2123 |
$options_map = get_option( 'wpsc_upgrade_cf_options_map' ); |
| 2124 |
$status_map = get_option( 'wpsc_upgrade_status_map' ); |
| 2125 |
$category_map = get_option( 'wpsc_upgrade_category_map' ); |
| 2126 |
$priority_map = get_option( 'wpsc_upgrade_priority_map' ); |
| 2127 |
|
| 2128 |
$new_templates = array(); |
| 2129 |
$event_map = wpsc_get_en_event_map(); |
| 2130 |
$email_templates = get_terms( |
| 2131 |
array( |
| 2132 |
'taxonomy' => 'wpsc_en', |
| 2133 |
'hide_empty' => false, |
| 2134 |
'orderby' => 'ID', |
| 2135 |
'order' => 'ASC', |
| 2136 |
) |
| 2137 |
); |
| 2138 |
|
| 2139 |
$string_translations = get_option( 'wpsc-string-translation' ); |
| 2140 |
foreach ( $email_templates as $template ) { |
| 2141 |
|
| 2142 |
$type = get_term_meta( $template->term_id, 'type', true ); |
| 2143 |
$subject = get_term_meta( $template->term_id, 'subject', true ); |
| 2144 |
$body = get_term_meta( $template->term_id, 'body', true ); |
| 2145 |
|
| 2146 |
// conditions. |
| 2147 |
$conditions = array(); |
| 2148 |
$prev_conditions = get_term_meta( $template->term_id, 'conditions', true ); |
| 2149 |
if ( $prev_conditions ) { |
| 2150 |
foreach ( $prev_conditions as $key => $val ) { |
| 2151 |
$cf = wpsc_get_cf_by( 'id', $cf_map[ $key ] ); |
| 2152 |
switch ( $cf->slug ) { |
| 2153 |
|
| 2154 |
case 'status': |
| 2155 |
$conditions['cf_status'] = array( |
| 2156 |
'operator' => 'IN', |
| 2157 |
'operand_val_1' => array_map( |
| 2158 |
function ( $status ) use ( $status_map ) { |
| 2159 |
return $status_map[ $status ]; |
| 2160 |
}, |
| 2161 |
$val |
| 2162 |
), |
| 2163 |
); |
| 2164 |
break; |
| 2165 |
|
| 2166 |
case 'category': |
| 2167 |
$conditions['cf_category'] = array( |
| 2168 |
'operator' => 'IN', |
| 2169 |
'operand_val_1' => array_map( |
| 2170 |
function ( $category ) use ( $category_map ) { |
| 2171 |
return $category_map[ $category ]; |
| 2172 |
}, |
| 2173 |
$val |
| 2174 |
), |
| 2175 |
); |
| 2176 |
break; |
| 2177 |
|
| 2178 |
case 'priority': |
| 2179 |
$conditions['cf_priority'] = array( |
| 2180 |
'operator' => 'IN', |
| 2181 |
'operand_val_1' => array_map( |
| 2182 |
function ( $priority ) use ( $priority_map ) { |
| 2183 |
return $priority_map[ $priority ]; |
| 2184 |
}, |
| 2185 |
$val |
| 2186 |
), |
| 2187 |
); |
| 2188 |
break; |
| 2189 |
|
| 2190 |
default: |
| 2191 |
$conditions[ 'cf_' . $cf->slug ] = array( |
| 2192 |
'operator' => 'IN', |
| 2193 |
'operand_val_1' => array_map( |
| 2194 |
function ( $option ) use ( $options_map, $cf ) { |
| 2195 |
return $options_map[ $cf->id ][ $option ]; |
| 2196 |
}, |
| 2197 |
$val |
| 2198 |
), |
| 2199 |
); |
| 2200 |
} |
| 2201 |
} |
| 2202 |
} |
| 2203 |
|
| 2204 |
$subject = wpsc_upgrade_macros( $subject ); |
| 2205 |
$body = wpsc_upgrade_macros( $body ); |
| 2206 |
$et = array( |
| 2207 |
'title' => $template->name, |
| 2208 |
'event' => $event_map[ $type ], |
| 2209 |
'is_enable' => 1, |
| 2210 |
'subject' => $subject, |
| 2211 |
'body' => array( |
| 2212 |
'text' => $body, |
| 2213 |
'editor' => 'html', |
| 2214 |
), |
| 2215 |
'to' => array( |
| 2216 |
'general-recipients' => array(), |
| 2217 |
'agent-roles' => array(), |
| 2218 |
'custom' => array(), |
| 2219 |
), |
| 2220 |
'cc' => array( |
| 2221 |
'general-recipients' => array(), |
| 2222 |
'agent-roles' => array(), |
| 2223 |
'custom' => array(), |
| 2224 |
), |
| 2225 |
'bcc' => wpsc_en_extract_bcc( $template ), |
| 2226 |
'relation' => 'AND', |
| 2227 |
'conditions' => $conditions ? wp_json_encode( $conditions ) : '{}', |
| 2228 |
); |
| 2229 |
|
| 2230 |
if ( count( $new_templates ) == 0 ) { |
| 2231 |
$new_templates[1] = $et; |
| 2232 |
} else { |
| 2233 |
$new_templates[] = $et; |
| 2234 |
} |
| 2235 |
$template_id = array_key_last( $new_templates ); |
| 2236 |
$string_translations[ 'wpsc-en-tn-subject-' . $template_id ] = $subject; |
| 2237 |
$string_translations[ 'wpsc-en-tn-body-' . $template_id ] = $body; |
| 2238 |
} |
| 2239 |
|
| 2240 |
update_option( 'wpsc-string-translation', $string_translations ); |
| 2241 |
|
| 2242 |
// Email notifications. |
| 2243 |
foreach ( $new_templates as $index => $properties ) { |
| 2244 |
if ( ! $properties['conditions'] ) { |
| 2245 |
continue; |
| 2246 |
} |
| 2247 |
$new_templates[ $index ]['conditions'] = WPSC_SC_Upgrade::upgrade_condition( $properties['conditions'], $properties['relation'] ); |
| 2248 |
} |
| 2249 |
update_option( 'wpsc-email-templates', $new_templates ); |
| 2250 |
} |
| 2251 |
|
| 2252 |
/** |
| 2253 |
* Import general settings |
| 2254 |
* |
| 2255 |
* @return void |
| 2256 |
*/ |
| 2257 |
public static function import_general_settings() { |
| 2258 |
|
| 2259 |
global $wpdb; |
| 2260 |
$gs = get_option( 'wpsc-gs-general' ); |
| 2261 |
$page_settings = get_option( 'wpsc-gs-page-settings' ); |
| 2262 |
$file_attachments = get_option( 'wpsc-gs-file-attachments' ); |
| 2263 |
$guest_rich_text = get_option( 'wpsc-te-guest-user' ); |
| 2264 |
$advanced = get_option( 'wpsc-ms-advanced-settings', array() ); |
| 2265 |
$roles = get_option( 'wpsc-agent-roles' ); |
| 2266 |
$status_map = get_option( 'wpsc_upgrade_status_map' ); |
| 2267 |
$category_map = get_option( 'wpsc_upgrade_category_map' ); |
| 2268 |
$priority_map = get_option( 'wpsc_upgrade_priority_map' ); |
| 2269 |
// support page. |
| 2270 |
$page_settings['support-page'] = get_option( 'wpsc_support_page_id' ); |
| 2271 |
// default ticket status. |
| 2272 |
$default_value = get_option( 'wpsc_default_ticket_status' ); |
| 2273 |
$default_value = $default_value ? $status_map[ $default_value ] : '1'; |
| 2274 |
$wpdb->update( |
| 2275 |
$wpdb->prefix . 'psmsc_custom_fields', |
| 2276 |
array( 'default_value' => $default_value ), |
| 2277 |
array( 'id' => 7 ) |
| 2278 |
); |
| 2279 |
// default ticket category. |
| 2280 |
$default_value = get_option( 'wpsc_default_ticket_category' ); |
| 2281 |
$default_value = $default_value ? $category_map[ $default_value ] : ''; |
| 2282 |
$wpdb->update( |
| 2283 |
$wpdb->prefix . 'psmsc_custom_fields', |
| 2284 |
array( 'default_value' => $default_value ), |
| 2285 |
array( 'id' => 9 ) |
| 2286 |
); |
| 2287 |
// default ticket priority. |
| 2288 |
$default_value = get_option( 'wpsc_default_ticket_priority' ); |
| 2289 |
$default_value = $default_value ? $priority_map[ $default_value ] : ''; |
| 2290 |
$wpdb->update( |
| 2291 |
$wpdb->prefix . 'psmsc_custom_fields', |
| 2292 |
array( 'default_value' => $default_value ), |
| 2293 |
array( 'id' => 8 ) |
| 2294 |
); |
| 2295 |
// ticket status after customer reply. |
| 2296 |
$status = get_option( 'wpsc_ticket_status_after_customer_reply' ); |
| 2297 |
$gs['ticket-status-after-customer-reply'] = $status ? $status_map[ $status ] : ''; |
| 2298 |
// ticket status after agent reply. |
| 2299 |
$status = get_option( 'wpsc_ticket_status_after_agent_reply' ); |
| 2300 |
$gs['ticket-status-after-agent-reply'] = $status ? $status_map[ $status ] : ''; |
| 2301 |
// close ticket status. |
| 2302 |
$status = get_option( 'wpsc_close_ticket_status' ); |
| 2303 |
$gs['close-ticket-status'] = $status ? $status_map[ $status ] : ''; |
| 2304 |
// allow customer to close ticket. |
| 2305 |
$customer = get_option( 'wpsc_allow_customer_close_ticket', 1 ); |
| 2306 |
$allow_close_ticket = $customer ? array( 'customer' ) : array(); |
| 2307 |
foreach ( $roles as $key => $role ) { |
| 2308 |
$allow_close_ticket[] = $key; |
| 2309 |
} |
| 2310 |
$gs['allow-close-ticket'] = $allow_close_ticket; |
| 2311 |
// reply form position. |
| 2312 |
$position = get_option( 'wpsc_reply_form_position' ); |
| 2313 |
$gs['reply-form-position'] = $position == 1 ? 'top' : 'bottom'; |
| 2314 |
// ticket alice. |
| 2315 |
$gs['ticket-alice'] = get_option( 'wpsc_ticket_alice' ); |
| 2316 |
// Attachment max filesize. |
| 2317 |
$file_attachments['attachments-max-filesize'] = get_option( 'wpsc_attachment_max_filesize' ); |
| 2318 |
// allow guest tickets. |
| 2319 |
$allow_create_ticket = array( 'registered-user' ); |
| 2320 |
if ( get_option( 'wpsc_allow_guest_ticket' ) == 1 ) { |
| 2321 |
$allow_create_ticket[] = 'guest'; |
| 2322 |
} |
| 2323 |
foreach ( $roles as $key => $role ) { |
| 2324 |
$allow_create_ticket[] = $key; |
| 2325 |
} |
| 2326 |
$gs['allow-create-ticket'] = $allow_create_ticket; |
| 2327 |
// enable otp login if guest tickets are allowed. |
| 2328 |
if ( in_array( 'guest', $gs['allow-create-ticket'] ) ) { |
| 2329 |
$page_settings['otp-login'] = 1; |
| 2330 |
} |
| 2331 |
// allow rich text editor for guest user. |
| 2332 |
$guest_rich_text['enable'] = get_option( 'wpsc_allow_tinymce_in_guest_ticket', 0 ); |
| 2333 |
// allow reply to closed ticket after SUP-483. |
| 2334 |
$allow_reply_to_closed = intval( get_option( 'wpsc_reply_to_close_ticket', 1 ) ); |
| 2335 |
if ( ! $allow_reply_to_closed ) { |
| 2336 |
$options = $advanced['allow-reply-to-close-ticket']; |
| 2337 |
unset( $options[0] ); |
| 2338 |
$advanced['allow-reply-to-close-ticket'] = $options; |
| 2339 |
} |
| 2340 |
// default login. |
| 2341 |
$default_login = get_option( 'wpsc_default_login_setting', 1 ); |
| 2342 |
switch ( intval( $default_login ) ) { |
| 2343 |
case 1: |
| 2344 |
$page_settings['user-login'] = 'default'; |
| 2345 |
break; |
| 2346 |
case 2: |
| 2347 |
$page_settings['user-login'] = 'wp-default'; |
| 2348 |
break; |
| 2349 |
case 3: |
| 2350 |
$page_settings['user-login'] = 'custom'; |
| 2351 |
$page_settings['custom-login-url'] = get_option( 'wpsc_custom_login_url' ); |
| 2352 |
break; |
| 2353 |
} |
| 2354 |
// user registration. |
| 2355 |
$user_registration = get_option( 'wpsc_user_registration', 0 ); |
| 2356 |
if ( $user_registration == 0 ) { |
| 2357 |
$page_settings['user-registration'] = 'disable'; |
| 2358 |
} else { |
| 2359 |
$registration_method = get_option( 'wpsc_user_registration_method', 1 ); |
| 2360 |
switch ( intval( $registration_method ) ) { |
| 2361 |
case 1: |
| 2362 |
$page_settings['user-registration'] = 'default'; |
| 2363 |
break; |
| 2364 |
case 2: |
| 2365 |
$page_settings['user-registration'] = 'wp-default'; |
| 2366 |
break; |
| 2367 |
case 3: |
| 2368 |
$page_settings['user-registration'] = 'custom'; |
| 2369 |
$page_settings['custom-registration-url'] = get_option( 'wpsc_custom_registration_url' ); |
| 2370 |
break; |
| 2371 |
} |
| 2372 |
} |
| 2373 |
// update options. |
| 2374 |
update_option( 'wpsc-gs-general', $gs ); |
| 2375 |
update_option( 'wpsc-gs-page-settings', $page_settings ); |
| 2376 |
update_option( 'wpsc-gs-file-attachments', $file_attachments ); |
| 2377 |
update_option( 'wpsc-te-guest-user', $guest_rich_text ); |
| 2378 |
update_option( 'wpsc-ms-advanced-settings', $advanced ); |
| 2379 |
} |
| 2380 |
|
| 2381 |
/** |
| 2382 |
* Re-order widgets as per old records |
| 2383 |
* |
| 2384 |
* @return void |
| 2385 |
*/ |
| 2386 |
public static function reorder_widgets() { |
| 2387 |
|
| 2388 |
$installed_addons = get_option( 'wpsc_upgrade_installed_addons' ); |
| 2389 |
$new = get_option( 'wpsc-ticket-widget', array() ); |
| 2390 |
$prev = get_terms( |
| 2391 |
array( |
| 2392 |
'taxonomy' => 'wpsc_ticket_widget', |
| 2393 |
'hide_empty' => false, |
| 2394 |
'orderby' => 'meta_value_num', |
| 2395 |
'order' => 'ASC', |
| 2396 |
'meta_query' => array( 'order_clause' => array( 'key' => 'wpsc_ticket_widget_load_order' ) ), |
| 2397 |
) |
| 2398 |
); |
| 2399 |
$map = array( |
| 2400 |
'status' => 'change-status', |
| 2401 |
'raised-by' => 'raised-by', |
| 2402 |
'assign-agent' => 'assignee', |
| 2403 |
'ticket-fields' => 'ticket-fields', |
| 2404 |
'agent-only-fields' => 'agentonly-fields', |
| 2405 |
'rating' => 'rating', |
| 2406 |
'woo-order' => 'woo-order', |
| 2407 |
); |
| 2408 |
|
| 2409 |
$string_translations = get_option( 'wpsc-string-translation' ); |
| 2410 |
$reordered = array(); |
| 2411 |
foreach ( $prev as $widget ) { |
| 2412 |
$flag = true; |
| 2413 |
switch ( $widget->slug ) { |
| 2414 |
case 'rating': |
| 2415 |
if ( ! $installed_addons[15]['is_installed'] ) { |
| 2416 |
$flag = false; |
| 2417 |
} |
| 2418 |
break; |
| 2419 |
case 'woo-order': |
| 2420 |
if ( ! $installed_addons[5]['is_installed'] ) { |
| 2421 |
$flag = false; |
| 2422 |
} |
| 2423 |
break; |
| 2424 |
} |
| 2425 |
if ( $flag ) { |
| 2426 |
$reordered[ $map[ $widget->slug ] ] = $new[ $map[ $widget->slug ] ]; |
| 2427 |
unset( $new[ $map[ $widget->slug ] ] ); |
| 2428 |
} |
| 2429 |
} |
| 2430 |
|
| 2431 |
foreach ( $reordered as $key => $widget ) { |
| 2432 |
$string_translations[ 'wpsc-twt-' . $key ] = $widget['title']; |
| 2433 |
} |
| 2434 |
|
| 2435 |
foreach ( $new as $key => $widget ) { |
| 2436 |
$reordered[ $key ] = $widget; |
| 2437 |
} |
| 2438 |
update_option( 'wpsc-string-translation', $string_translations ); |
| 2439 |
update_option( 'wpsc-ticket-widget', $reordered ); |
| 2440 |
} |
| 2441 |
|
| 2442 |
/** |
| 2443 |
* Thank you page import |
| 2444 |
* |
| 2445 |
* @return void |
| 2446 |
*/ |
| 2447 |
public static function import_thankyou_settings() { |
| 2448 |
|
| 2449 |
$string_translations = get_option( 'wpsc-string-translation' ); |
| 2450 |
|
| 2451 |
$thankyou_html = wpsc_upgrade_macros( get_option( 'wpsc_thankyou_html' ) ); |
| 2452 |
$thankyou_url = get_option( 'wpsc_thankyou_url' ); |
| 2453 |
if ( $thankyou_url ) { |
| 2454 |
$action = 'url'; |
| 2455 |
} else { |
| 2456 |
$action = 'text'; |
| 2457 |
} |
| 2458 |
|
| 2459 |
update_option( |
| 2460 |
'wpsc-gs-thankyou-page-settings', |
| 2461 |
array( |
| 2462 |
'action-agent' => $action, |
| 2463 |
'action-customer' => $action, |
| 2464 |
'html-agent' => $thankyou_html, |
| 2465 |
'html-customer' => $thankyou_html, |
| 2466 |
'page-url-agent' => $thankyou_url, |
| 2467 |
'page-url-customer' => $thankyou_url, |
| 2468 |
'editor-agent' => 'html', |
| 2469 |
'editor-customer' => 'html', |
| 2470 |
) |
| 2471 |
); |
| 2472 |
|
| 2473 |
$string_translations['wpsc-thankyou-html'] = $thankyou_html; |
| 2474 |
$string_translations['wpsc-thankyou-html-agent'] = $thankyou_html; |
| 2475 |
|
| 2476 |
update_option( 'wpsc-string-translation', $string_translations ); |
| 2477 |
} |
| 2478 |
|
| 2479 |
/** |
| 2480 |
* Import terms and conditions |
| 2481 |
* |
| 2482 |
* @return void |
| 2483 |
*/ |
| 2484 |
public static function import_terms_and_conditions() { |
| 2485 |
|
| 2486 |
$string_translations = get_option( 'wpsc-string-translation' ); |
| 2487 |
$tc = get_option( 'wpsc-term-and-conditions' ); |
| 2488 |
$tandc_text = get_option( 'wpsc_terms_and_conditions_html', $tc['tandc-text'] ); |
| 2489 |
$tc['allow-term-and-conditions'] = intval( get_option( 'wpsc_terms_and_conditions', $tc['allow-term-and-conditions'] ) ); |
| 2490 |
$tc['tandc-text'] = $tandc_text; |
| 2491 |
$string_translations['wpsc-term-and-conditions'] = $tandc_text; |
| 2492 |
update_option( 'wpsc-term-and-conditions', $tc ); |
| 2493 |
|
| 2494 |
$gdpr = get_option( 'wpsc-gdpr-settings' ); |
| 2495 |
$gdpr_text = get_option( 'wpsc_gdpr_html', $gdpr['gdpr-text'] ); |
| 2496 |
$gdpr['allow-gdpr'] = intval( get_option( 'wpsc_set_in_gdpr', $gdpr['allow-gdpr'] ) ); |
| 2497 |
$gdpr['gdpr-text'] = $gdpr_text; |
| 2498 |
$gdpr['personal-data-retention-time'] = intval( get_option( 'wpsc_personal_data_retention_period_time', $gdpr['personal-data-retention-time'] ) ); |
| 2499 |
$unit_map = array( |
| 2500 |
'days' => 'days', |
| 2501 |
'months' => 'month', |
| 2502 |
'years' => 'year', |
| 2503 |
); |
| 2504 |
$unit = get_option( 'wpsc_personal_data_retention_period_unit' ); |
| 2505 |
$gdpr['personal-data-retention-unit'] = isset( $unit_map[ $unit ] ) ? $unit_map[ $unit ] : 'days'; |
| 2506 |
$string_translations['wpsc-gdpr'] = $gdpr_text; |
| 2507 |
|
| 2508 |
update_option( 'wpsc-string-translation', $string_translations ); |
| 2509 |
update_option( 'wpsc-gdpr-settings', $gdpr ); |
| 2510 |
} |
| 2511 |
|
| 2512 |
/** |
| 2513 |
* Import advanced settings |
| 2514 |
* |
| 2515 |
* @return void |
| 2516 |
*/ |
| 2517 |
public static function import_advanced_settings() { |
| 2518 |
|
| 2519 |
$advanced = get_option( 'wpsc-ms-advanced-settings' ); |
| 2520 |
$agent_editor = get_option( 'wpsc-te-agent' ); |
| 2521 |
$reg_user_editor = get_option( 'wpsc-te-registered-user' ); |
| 2522 |
$guest_editor = get_option( 'wpsc-te-guest-user' ); |
| 2523 |
// Guest can upload files. |
| 2524 |
$guest_editor['allow-attachments'] = intval( get_option( 'wpsc_guest_can_upload_files', $guest_editor['allow-attachments'] ) ); |
| 2525 |
// public mode. |
| 2526 |
$advanced['public-mode'] = intval( get_option( 'wpsc_ticket_public_mode', $advanced['public-mode'] ) ); |
| 2527 |
// Allow Reply Confirmation. |
| 2528 |
$advanced['reply-confirmation'] = intval( get_option( 'wpsc_allow_reply_confirmation', $advanced['reply-confirmation'] ) ); |
| 2529 |
// Tinymce toolbar. |
| 2530 |
$wpsc_toolbar = get_option( 'wpsc_tinymce_toolbar' ); |
| 2531 |
if ( $wpsc_toolbar !== false ) { |
| 2532 |
$old = get_option( 'wpsc_tinymce_toolbar_active' ); |
| 2533 |
$new = array(); |
| 2534 |
foreach ( $old as $key ) { |
| 2535 |
$new[] = $wpsc_toolbar[ $key ]['value']; |
| 2536 |
} |
| 2537 |
$agent_editor['toolbar'] = $new; |
| 2538 |
$reg_user_editor['toolbar'] = $new; |
| 2539 |
$guest_editor['toolbar'] = $new; |
| 2540 |
} |
| 2541 |
// Thread Date Format. |
| 2542 |
$display_as = get_option( 'wpsc_thread_date_format' ); |
| 2543 |
$advanced['thread-date-display-as'] = $display_as == 'string' ? 'diff' : 'date'; |
| 2544 |
$advanced['thread-date-format'] = get_option( 'wpsc_thread_date_time_format', $advanced['thread-date-format'] ); |
| 2545 |
// Do not notify owner. |
| 2546 |
$advanced['do-not-notify-owner'] = get_option( 'wpsc_do_not_notify_setting', $advanced['do-not-notify-owner'] ); |
| 2547 |
// update options. |
| 2548 |
update_option( 'wpsc-ms-advanced-settings', $advanced ); |
| 2549 |
update_option( 'wpsc-te-agent', $agent_editor ); |
| 2550 |
update_option( 'wpsc-te-registered-user', $reg_user_editor ); |
| 2551 |
update_option( 'wpsc-te-guest-user', $guest_editor ); |
| 2552 |
} |
| 2553 |
|
| 2554 |
/** |
| 2555 |
* Import captcha |
| 2556 |
* |
| 2557 |
* @return void |
| 2558 |
*/ |
| 2559 |
public static function import_captcha() { |
| 2560 |
|
| 2561 |
if ( |
| 2562 |
get_option( 'wpsc_captcha' ) == 1 && |
| 2563 |
get_option( 'wpsc_recaptcha_type', 1 ) == 0 |
| 2564 |
) { |
| 2565 |
$recaptcha = get_option( 'wpsc-recaptcha-settings' ); |
| 2566 |
$recaptcha['allow-recaptcha'] = 1; |
| 2567 |
$recaptcha['recaptcha-version'] = 2; |
| 2568 |
$recaptcha['recaptcha-site-key'] = get_option( 'wpsc_get_site_key', '' ); |
| 2569 |
$recaptcha['recaptcha-secret-key'] = get_option( 'wpsc_get_secret_key', '' ); |
| 2570 |
update_option( 'wpsc-recaptcha-settings', $recaptcha ); |
| 2571 |
} |
| 2572 |
} |
| 2573 |
|
| 2574 |
/** |
| 2575 |
* Import assign agent rules. |
| 2576 |
* |
| 2577 |
* @return void |
| 2578 |
*/ |
| 2579 |
public static function import_assign_agent_rules() { |
| 2580 |
|
| 2581 |
global $wpdb; |
| 2582 |
$installed_addons = get_option( 'wpsc_upgrade_installed_addons' ); |
| 2583 |
if ( ! $installed_addons[10]['is_installed'] ) { |
| 2584 |
return; |
| 2585 |
} |
| 2586 |
|
| 2587 |
$cf_map = get_option( 'wpsc_upgrade_cf_term_id_map' ); |
| 2588 |
$options_map = get_option( 'wpsc_upgrade_cf_options_map' ); |
| 2589 |
$category_map = get_option( 'wpsc_upgrade_category_map' ); |
| 2590 |
$priority_map = get_option( 'wpsc_upgrade_priority_map' ); |
| 2591 |
$status_map = get_option( 'wpsc_upgrade_status_map' ); |
| 2592 |
|
| 2593 |
// import settings. |
| 2594 |
$general = get_option( 'wpsc-aar-general-settings' ); |
| 2595 |
$general['auto-assign-agent'] = get_option( 'wpsc_assign_auto_responder', 0 ); |
| 2596 |
update_option( 'wpsc-aar-general-settings', $general ); |
| 2597 |
|
| 2598 |
// import rules. |
| 2599 |
$agent_map = get_option( 'wpsc_upgrade_agent_map' ); |
| 2600 |
$new_rules = array(); |
| 2601 |
$prev_rules = get_terms( |
| 2602 |
array( |
| 2603 |
'taxonomy' => 'wpsc_caa', |
| 2604 |
'hide_empty' => false, |
| 2605 |
) |
| 2606 |
); |
| 2607 |
|
| 2608 |
foreach ( $prev_rules as $prev ) { |
| 2609 |
|
| 2610 |
$prev_agents = get_term_meta( $prev->term_id, 'agent_ids', true ); |
| 2611 |
$new_agents = array_map( |
| 2612 |
function ( $old_id ) use ( $wpdb, $agent_map ) { |
| 2613 |
return $wpdb->get_row( "SELECT * from {$wpdb->prefix}psmsc_agents WHERE id = " . $agent_map[ $old_id ] ); |
| 2614 |
}, |
| 2615 |
$prev_agents |
| 2616 |
); |
| 2617 |
$agents = array(); |
| 2618 |
$agentgroups = array(); |
| 2619 |
foreach ( $new_agents as $agent ) { |
| 2620 |
if ( $agent->is_agentgroup ) { |
| 2621 |
$agentgroups[] = $agent->id; |
| 2622 |
} else { |
| 2623 |
$agents[] = $agent->id; |
| 2624 |
} |
| 2625 |
} |
| 2626 |
|
| 2627 |
$conditions = array(); |
| 2628 |
$prev_conditions = get_term_meta( $prev->term_id, 'conditions', true ); |
| 2629 |
if ( $prev_conditions ) { |
| 2630 |
|
| 2631 |
foreach ( $prev_conditions as $key => $val ) { |
| 2632 |
|
| 2633 |
$cf = wpsc_get_cf_by( 'id', $cf_map[ $key ] ); |
| 2634 |
switch ( $cf->slug ) { |
| 2635 |
|
| 2636 |
case 'status': |
| 2637 |
$conditions['cf_status'] = array( |
| 2638 |
'operator' => 'IN', |
| 2639 |
'operand_val_1' => array_map( |
| 2640 |
function ( $status ) use ( $status_map ) { |
| 2641 |
return $status_map[ $status ]; |
| 2642 |
}, |
| 2643 |
$val |
| 2644 |
), |
| 2645 |
); |
| 2646 |
break; |
| 2647 |
|
| 2648 |
case 'category': |
| 2649 |
$conditions['cf_category'] = array( |
| 2650 |
'operator' => 'IN', |
| 2651 |
'operand_val_1' => array_map( |
| 2652 |
function ( $category ) use ( $category_map ) { |
| 2653 |
return $category_map[ $category ]; |
| 2654 |
}, |
| 2655 |
$val |
| 2656 |
), |
| 2657 |
); |
| 2658 |
break; |
| 2659 |
|
| 2660 |
case 'priority': |
| 2661 |
$conditions['cf_priority'] = array( |
| 2662 |
'operator' => 'IN', |
| 2663 |
'operand_val_1' => array_map( |
| 2664 |
function ( $priority ) use ( $priority_map ) { |
| 2665 |
return $priority_map[ $priority ]; |
| 2666 |
}, |
| 2667 |
$val |
| 2668 |
), |
| 2669 |
); |
| 2670 |
break; |
| 2671 |
|
| 2672 |
default: |
| 2673 |
$conditions[ 'cf_' . $cf->slug ] = array( |
| 2674 |
'operator' => 'IN', |
| 2675 |
'operand_val_1' => array_map( |
| 2676 |
function ( $option ) use ( $options_map, $cf ) { |
| 2677 |
return $options_map[ $cf->id ][ $option ]; |
| 2678 |
}, |
| 2679 |
$val |
| 2680 |
), |
| 2681 |
); |
| 2682 |
} |
| 2683 |
} |
| 2684 |
} |
| 2685 |
|
| 2686 |
$rule = array( |
| 2687 |
'title' => $prev->name, |
| 2688 |
'agents' => implode( '|', $agents ), |
| 2689 |
'assign_method' => 'assign_all', |
| 2690 |
'agentgroups' => implode( '|', $agentgroups ), |
| 2691 |
'assign_group_method' => 'assign_all_groups', |
| 2692 |
'relation' => 'AND', |
| 2693 |
'conditions' => $conditions ? wp_json_encode( $conditions ) : '{}', |
| 2694 |
); |
| 2695 |
|
| 2696 |
if ( $new_rules ) { |
| 2697 |
$new_rules[] = $rule; |
| 2698 |
} else { |
| 2699 |
$new_rules[1] = $rule; |
| 2700 |
} |
| 2701 |
} |
| 2702 |
|
| 2703 |
// Assigned agent rules filters. |
| 2704 |
foreach ( $new_rules as $index => $properties ) { |
| 2705 |
$new_rules[ $index ]['conditions'] = WPSC_SC_Upgrade::upgrade_condition( $properties['conditions'], $properties['relation'] ); |
| 2706 |
} |
| 2707 |
|
| 2708 |
update_option( 'wpsc-aar-rules', $new_rules ); |
| 2709 |
} |
| 2710 |
|
| 2711 |
/** |
| 2712 |
* Import automatic close tickets add-on |
| 2713 |
* |
| 2714 |
* @return void |
| 2715 |
*/ |
| 2716 |
public static function import_automatic_close_tickets() { |
| 2717 |
|
| 2718 |
$installed_addons = get_option( 'wpsc_upgrade_installed_addons' ); |
| 2719 |
if ( ! $installed_addons[0]['is_installed'] ) { |
| 2720 |
return; |
| 2721 |
} |
| 2722 |
|
| 2723 |
// import settings. |
| 2724 |
$string_translations = get_option( 'wpsc-string-translation' ); |
| 2725 |
$gs = get_option( 'wpsc-gs-general' ); |
| 2726 |
$status_map = get_option( 'wpsc_upgrade_status_map' ); |
| 2727 |
$settings = get_option( 'wpsc-atc-settings' ); |
| 2728 |
$settings['statuses-enabled'] = array_map( |
| 2729 |
function ( $status_id ) use ( $status_map ) { |
| 2730 |
return $status_map[ $status_id ]; |
| 2731 |
}, |
| 2732 |
get_option( 'wpsc_tl_statuses', array() ) |
| 2733 |
); |
| 2734 |
$settings['age'] = get_option( 'wpsc_atc_age', '0' ); |
| 2735 |
$settings['close-status'] = $gs['close-ticket-status']; |
| 2736 |
update_option( 'wpsc-atc-settings', $settings ); |
| 2737 |
|
| 2738 |
// import warning email. |
| 2739 |
$subject = wpsc_upgrade_macros( get_option( 'wpsc_atc_subject', '' ) ); |
| 2740 |
$body = wpsc_upgrade_macros( get_option( 'wpsc_atc_email_body', '' ) ); |
| 2741 |
$templates = array( |
| 2742 |
array( |
| 2743 |
'title' => 'Default template', |
| 2744 |
'days-before' => get_option( 'wpsc_atc_waring_email_age', 3 ), |
| 2745 |
'subject' => $subject, |
| 2746 |
'body' => $body, |
| 2747 |
'editor' => 'html', |
| 2748 |
), |
| 2749 |
); |
| 2750 |
$string_translations['wpsc-act-subject-0'] = $subject; |
| 2751 |
$string_translations['wpsc-act-body-0'] = $body; |
| 2752 |
update_option( 'wpsc-string-translation', $string_translations ); |
| 2753 |
update_option( 'wpsc-atc-et', $templates ); |
| 2754 |
} |
| 2755 |
|
| 2756 |
/** |
| 2757 |
* Import canned reply addon |
| 2758 |
* |
| 2759 |
* @return void |
| 2760 |
*/ |
| 2761 |
public static function import_canned_reply() { |
| 2762 |
|
| 2763 |
global $wpdb; |
| 2764 |
|
| 2765 |
$installed_addons = get_option( 'wpsc_upgrade_installed_addons' ); |
| 2766 |
if ( ! $installed_addons[1]['is_installed'] ) { |
| 2767 |
return; |
| 2768 |
} |
| 2769 |
|
| 2770 |
// reset data. |
| 2771 |
$wpdb->query( 'DELETE FROM ' . $wpdb->prefix . 'psmsc_cr_categories' ); |
| 2772 |
$wpdb->query( 'ALTER TABLE ' . $wpdb->prefix . 'psmsc_cr_categories AUTO_INCREMENT = 1' ); |
| 2773 |
$wpdb->query( 'DELETE FROM ' . $wpdb->prefix . 'psmsc_canned_reply' ); |
| 2774 |
$wpdb->query( 'ALTER TABLE ' . $wpdb->prefix . 'psmsc_canned_reply AUTO_INCREMENT = 1' ); |
| 2775 |
|
| 2776 |
// import canned reply categories. |
| 2777 |
$wpdb->insert( |
| 2778 |
$wpdb->prefix . 'psmsc_cr_categories', |
| 2779 |
array( |
| 2780 |
'name' => 'Uncategorized', |
| 2781 |
) |
| 2782 |
); |
| 2783 |
$categories = get_terms( |
| 2784 |
array( |
| 2785 |
'taxonomy' => 'wpsc_canned_reply_categories', |
| 2786 |
'hide_empty' => false, |
| 2787 |
) |
| 2788 |
); |
| 2789 |
|
| 2790 |
$string_translations = get_option( 'wpsc-string-translation' ); |
| 2791 |
$map = array(); |
| 2792 |
foreach ( $categories as $prev ) { |
| 2793 |
$wpdb->insert( |
| 2794 |
$wpdb->prefix . 'psmsc_cr_categories', |
| 2795 |
array( |
| 2796 |
'name' => $prev->name, |
| 2797 |
) |
| 2798 |
); |
| 2799 |
$string_translations[ 'wpsc-cr-category-' . $wpdb->insert_id ] = $prev->name; |
| 2800 |
$map[ $prev->term_id ] = $wpdb->insert_id; |
| 2801 |
} |
| 2802 |
|
| 2803 |
// import canned reply. |
| 2804 |
$response = get_posts( |
| 2805 |
array( |
| 2806 |
'post_type' => 'wpsc_canned_reply', |
| 2807 |
'post_status' => 'publish', |
| 2808 |
'orderby' => 'date', |
| 2809 |
'order' => 'ASC', |
| 2810 |
'posts_per_page' => -1, |
| 2811 |
) |
| 2812 |
); |
| 2813 |
foreach ( $response as $prev ) { |
| 2814 |
$prev_categories = get_the_terms( $prev->ID, 'wpsc_canned_reply_categories' ); |
| 2815 |
$categories = '1'; |
| 2816 |
if ( is_array( $prev_categories ) ) { |
| 2817 |
$categories = implode( |
| 2818 |
'|', |
| 2819 |
array_map( |
| 2820 |
function ( $category ) use ( $map ) { |
| 2821 |
return $map[ $category->term_id ]; |
| 2822 |
}, |
| 2823 |
$prev_categories |
| 2824 |
), |
| 2825 |
); |
| 2826 |
} |
| 2827 |
$author = wpsc_get_customer_by( 'user_id', $prev->post_author ); |
| 2828 |
$visibility = get_post_meta( $prev->ID, 'wpsc_agent_visibility', true ); |
| 2829 |
$wpdb->insert( |
| 2830 |
$wpdb->prefix . 'psmsc_canned_reply', |
| 2831 |
array( |
| 2832 |
'title' => $prev->post_title, |
| 2833 |
'author' => $author->id, |
| 2834 |
'body' => wpautop( wpsc_upgrade_macros( $prev->post_content ) ), |
| 2835 |
'categories' => $categories, |
| 2836 |
'visibility' => $visibility ? 'public' : 'private', |
| 2837 |
'date_created' => $prev->post_date, |
| 2838 |
) |
| 2839 |
); |
| 2840 |
} |
| 2841 |
update_option( 'wpsc-string-translation', $string_translations ); |
| 2842 |
} |
| 2843 |
|
| 2844 |
/** |
| 2845 |
* Import report settings |
| 2846 |
* |
| 2847 |
* @return void |
| 2848 |
*/ |
| 2849 |
public static function import_report_settings() { |
| 2850 |
|
| 2851 |
$installed_addons = get_option( 'wpsc_upgrade_installed_addons' ); |
| 2852 |
if ( ! $installed_addons[6]['is_installed'] ) { |
| 2853 |
return; |
| 2854 |
} |
| 2855 |
|
| 2856 |
$agent_roles = get_option( 'wpsc-agent-roles' ); |
| 2857 |
foreach ( $agent_roles as $index => $role ) { |
| 2858 |
$role['caps']['view-reports'] = $index == 1 ? true : false; |
| 2859 |
$agent_roles[ $index ] = $role; |
| 2860 |
} |
| 2861 |
update_option( 'wpsc-agent-roles', $agent_roles ); |
| 2862 |
} |
| 2863 |
|
| 2864 |
/** |
| 2865 |
* Import satisfaction survey |
| 2866 |
* |
| 2867 |
* @return void |
| 2868 |
*/ |
| 2869 |
public static function import_satisfaction_survey() { |
| 2870 |
|
| 2871 |
global $wpdb; |
| 2872 |
|
| 2873 |
$installed_addons = get_option( 'wpsc_upgrade_installed_addons' ); |
| 2874 |
if ( ! $installed_addons[15]['is_installed'] ) { |
| 2875 |
return; |
| 2876 |
} |
| 2877 |
|
| 2878 |
// reset data. |
| 2879 |
$wpdb->query( 'DELETE FROM ' . $wpdb->prefix . 'psmsc_sf_ratings' ); |
| 2880 |
$wpdb->query( 'ALTER TABLE ' . $wpdb->prefix . 'psmsc_sf_ratings AUTO_INCREMENT = 1' ); |
| 2881 |
|
| 2882 |
// import ratings. |
| 2883 |
$ratings = get_terms( |
| 2884 |
array( |
| 2885 |
'taxonomy' => 'wpsc_sf_rating', |
| 2886 |
'hide_empty' => false, |
| 2887 |
'orderby' => 'meta_value_num', |
| 2888 |
'order' => 'ASC', |
| 2889 |
'meta_query' => array( 'order_clause' => array( 'key' => 'load_order' ) ), |
| 2890 |
) |
| 2891 |
); |
| 2892 |
|
| 2893 |
$string_translations = get_option( 'wpsc-string-translation' ); |
| 2894 |
$map = array(); |
| 2895 |
$load_order = 1; |
| 2896 |
$confirmation_text = get_option( 'wpsc_sf_thankyou_text', '' ); |
| 2897 |
foreach ( $ratings as $prev ) { |
| 2898 |
$bg_color = get_term_meta( $prev->term_id, 'color', true ); |
| 2899 |
$wpdb->insert( |
| 2900 |
$wpdb->prefix . 'psmsc_sf_ratings', |
| 2901 |
array( |
| 2902 |
'name' => $prev->name, |
| 2903 |
'color' => '#FFFFFF', |
| 2904 |
'bg_color' => $bg_color, |
| 2905 |
'confirmation_text' => $confirmation_text, |
| 2906 |
'load_order' => $load_order++, |
| 2907 |
) |
| 2908 |
); |
| 2909 |
|
| 2910 |
$string_translations[ 'wpsc-rating-name-' . $wpdb->insert_id ] = $prev->name; |
| 2911 |
$string_translations[ 'wpsc-rating-ct-' . $wpdb->insert_id ] = $confirmation_text; |
| 2912 |
$map[ $prev->term_id ] = $wpdb->insert_id; |
| 2913 |
} |
| 2914 |
update_option( 'wpsc_upgrade_sf_rating_map', $map ); |
| 2915 |
|
| 2916 |
// import settings. |
| 2917 |
$settings = get_option( 'wpsc-sf-general-setting' ); |
| 2918 |
$settings['survey-page'] = get_option( 'wpsc_sf_page', 0 ); |
| 2919 |
update_option( 'wpsc-sf-general-setting', $settings ); |
| 2920 |
|
| 2921 |
// import email template. |
| 2922 |
$subject = wpsc_upgrade_macros( get_option( 'wpsc_sf_subject', '' ) ); |
| 2923 |
$body = wpsc_upgrade_macros( get_option( 'wpsc_sf_email_body', '' ) ); |
| 2924 |
$days_after = get_option( 'wpsc_sf_age', '0' ); |
| 2925 |
if ( get_option( 'wpsc_sf_age_unit', 'd' ) == 'h' ) { |
| 2926 |
$days_after = 1; |
| 2927 |
} |
| 2928 |
$new = array( |
| 2929 |
array( |
| 2930 |
'title' => 'Default template', |
| 2931 |
'days-after' => $days_after, |
| 2932 |
'subject' => $subject, |
| 2933 |
'body' => $body, |
| 2934 |
'editor' => 'html', |
| 2935 |
), |
| 2936 |
); |
| 2937 |
$string_translations['wpsc-sf-et-subject-0'] = $subject; |
| 2938 |
$string_translations['wpsc-sf-et-body-0'] = $body; |
| 2939 |
update_option( 'wpsc-string-translation', $string_translations ); |
| 2940 |
update_option( 'wpsc-sf-et', $new ); |
| 2941 |
} |
| 2942 |
|
| 2943 |
/** |
| 2944 |
* Import email piping add-on settings |
| 2945 |
* |
| 2946 |
* @return void |
| 2947 |
*/ |
| 2948 |
public static function import_email_piping() { |
| 2949 |
|
| 2950 |
$installed_addons = get_option( 'wpsc_upgrade_installed_addons' ); |
| 2951 |
if ( ! $installed_addons[3]['is_installed'] ) { |
| 2952 |
return; |
| 2953 |
} |
| 2954 |
|
| 2955 |
// import settings. |
| 2956 |
$general = get_option( 'wpsc-ep-general-settings' ); |
| 2957 |
$general['connection'] = get_option( 'wpsc_ep_piping_type', 'imap' ); |
| 2958 |
|
| 2959 |
$block_emails = get_option( 'wpsc_ep_block_emails', array() ); |
| 2960 |
$general['block-emails'] = array_filter( array_map( 'trim', $block_emails ) ); |
| 2961 |
|
| 2962 |
$block_subject = explode( PHP_EOL, get_option( 'wpsc_ep_block_subject', '' ) ); |
| 2963 |
$block_subject = $block_subject ? $block_subject : array(); |
| 2964 |
$general['block-subject'] = array_filter( array_map( 'trim', $block_subject ) ); |
| 2965 |
|
| 2966 |
$allowed_users = get_option( 'wpsc_ep_allowed_user', 0 ); |
| 2967 |
$general['allowed-users'] = $allowed_users ? 'anyone' : 'registered'; |
| 2968 |
$general['time-frequency'] = get_option( 'wpsc_ep_cron_execution_time', 5 ); |
| 2969 |
$general['body-reference'] = get_option( 'wpsc_ep_email_type', 'text' ); |
| 2970 |
update_option( 'wpsc-ep-general-settings', $general ); |
| 2971 |
|
| 2972 |
// import connection settings. |
| 2973 |
if ( $general['connection'] == 'imap' ) { |
| 2974 |
|
| 2975 |
$imap = array( |
| 2976 |
'email-address' => get_option( 'wpsc_ep_imap_email_address', '' ), |
| 2977 |
'password' => get_option( 'wpsc_ep_imap_email_password', '' ), |
| 2978 |
'encryption' => get_option( 'wpsc_ep_imap_encryption', 'ssl' ), |
| 2979 |
'incoming-mail-server' => get_option( 'wpsc_ep_imap_incoming_mail_server', '' ), |
| 2980 |
'port' => get_option( 'wpsc_ep_imap_port', '' ), |
| 2981 |
'is_active' => 0, |
| 2982 |
'last-error' => '', |
| 2983 |
); |
| 2984 |
|
| 2985 |
// check connection. |
| 2986 |
$encryption_text = ''; |
| 2987 |
if ( $imap['encryption'] == 'none' ) { |
| 2988 |
$encryption_text = 'novalidate-cert'; |
| 2989 |
} elseif ( $imap['encryption'] == 'ssl' ) { |
| 2990 |
$encryption_text = 'imap/ssl/novalidate-cert'; |
| 2991 |
} |
| 2992 |
$conn = @imap_open( '{' . $imap['incoming-mail-server'] . ':' . $imap['port'] . '/' . $encryption_text . '}INBOX', $imap['email-address'], $imap['password'] ); // phpcs:ignore |
| 2993 |
if ( $conn ) { |
| 2994 |
$imap['is_active'] = 1; |
| 2995 |
} else { |
| 2996 |
$imap['last-error'] = imap_last_error(); |
| 2997 |
} |
| 2998 |
|
| 2999 |
update_option( 'wpsc-ep-imap-settings', $imap ); |
| 3000 |
|
| 3001 |
} else { // gmail. |
| 3002 |
|
| 3003 |
$gmail = array( |
| 3004 |
'email-address' => get_option( 'wpsc_ep_email_address', '' ), |
| 3005 |
'client-id' => get_option( 'wpsc_ep_client_id', '' ), |
| 3006 |
'client-secret' => get_option( 'wpsc_ep_client_secret', '' ), |
| 3007 |
'is-active' => 0, |
| 3008 |
'last-error' => '', |
| 3009 |
'refresh-token' => get_option( 'wpsc_ep_refresh_token', '' ), |
| 3010 |
'history-id' => get_option( 'wpsc_ep_historyId', '' ), |
| 3011 |
); |
| 3012 |
if ( |
| 3013 |
$gmail['email-address'] && |
| 3014 |
$gmail['client-id'] && |
| 3015 |
$gmail['client-secret'] && |
| 3016 |
$gmail['refresh-token'] && |
| 3017 |
$gmail['history-id'] |
| 3018 |
) { |
| 3019 |
$gmail['is-active'] = 1; |
| 3020 |
} |
| 3021 |
update_option( 'wpsc-ep-gmail-settings', $gmail ); |
| 3022 |
} |
| 3023 |
|
| 3024 |
// import email piping rules. |
| 3025 |
$cf_map = get_option( 'wpsc_upgrade_cf_term_id_map' ); |
| 3026 |
$category_map = get_option( 'wpsc_upgrade_category_map' ); |
| 3027 |
$priority_map = get_option( 'wpsc_upgrade_priority_map' ); |
| 3028 |
$new_rules = array(); |
| 3029 |
|
| 3030 |
$fields = get_terms( |
| 3031 |
array( |
| 3032 |
'taxonomy' => 'wpsc_ticket_custom_fields', |
| 3033 |
'hide_empty' => false, |
| 3034 |
'meta_query' => array( |
| 3035 |
'relation' => 'AND', |
| 3036 |
array( |
| 3037 |
'key' => 'agentonly', |
| 3038 |
'value' => array( 0, 1 ), |
| 3039 |
'compare' => 'IN', |
| 3040 |
), |
| 3041 |
array( |
| 3042 |
'key' => 'wpsc_tf_type', |
| 3043 |
'value' => '0', |
| 3044 |
'compare' => '>', |
| 3045 |
), |
| 3046 |
), |
| 3047 |
) |
| 3048 |
); |
| 3049 |
|
| 3050 |
$email_piping_rules = get_terms( |
| 3051 |
array( |
| 3052 |
'taxonomy' => 'wpsc_ep_rules', |
| 3053 |
'hide_empty' => false, |
| 3054 |
'orderby' => 'meta_value_num', |
| 3055 |
'order' => 'ASC', |
| 3056 |
'meta_query' => array( 'order_clause' => array( 'key' => 'wpsc_en_rule_load_order' ) ), |
| 3057 |
) |
| 3058 |
); |
| 3059 |
|
| 3060 |
foreach ( $email_piping_rules as $prev ) { |
| 3061 |
|
| 3062 |
$rule = array( |
| 3063 |
'title' => $prev->name, |
| 3064 |
); |
| 3065 |
|
| 3066 |
// condition. |
| 3067 |
$forwarding_address = get_term_meta( $prev->term_id, 'wpsc_ep_to_address', true ); |
| 3068 |
$forwarding_address = $forwarding_address ? $forwarding_address : array(); |
| 3069 |
$rule['forwarding-address'] = array_filter( array_map( 'trim', $forwarding_address ) ); |
| 3070 |
|
| 3071 |
$has_words = get_term_meta( $prev->term_id, 'wpsc_ep_has_words', true ); |
| 3072 |
$has_words = $has_words ? $has_words : array(); |
| 3073 |
$rule['has-words'] = array_filter( array_map( 'trim', $has_words ) ); |
| 3074 |
|
| 3075 |
// category and priority. |
| 3076 |
$category = get_term_meta( $prev->term_id, 'ticket_category', true ); |
| 3077 |
if ( $category ) { |
| 3078 |
$rule['category'] = $category_map[ $category ]; |
| 3079 |
} |
| 3080 |
$priority = get_term_meta( $prev->term_id, 'ticket_priority', true ); |
| 3081 |
if ( $priority ) { |
| 3082 |
$rule['priority'] = $priority_map[ $priority ]; |
| 3083 |
} |
| 3084 |
|
| 3085 |
// custom fields. |
| 3086 |
foreach ( $fields as $field ) { |
| 3087 |
|
| 3088 |
$type = get_term_meta( $field->term_id, 'wpsc_tf_type', true ); |
| 3089 |
$cf = wpsc_get_cf_by( 'id', $cf_map[ $field->term_id ] ); |
| 3090 |
|
| 3091 |
switch ( $type ) { |
| 3092 |
|
| 3093 |
case 1: |
| 3094 |
case 5: |
| 3095 |
case 7: |
| 3096 |
case 8: |
| 3097 |
case 9: |
| 3098 |
$val = get_term_meta( $prev->term_id, $field->slug, true ); |
| 3099 |
if ( $val ) { |
| 3100 |
$rule[ $cf->slug ] = $val ? $val : ''; |
| 3101 |
} |
| 3102 |
break; |
| 3103 |
|
| 3104 |
case 2: |
| 3105 |
case 4: |
| 3106 |
$options_map = get_option( 'wpsc_upgrade_cf_options_map' ); |
| 3107 |
$val = get_term_meta( $prev->term_id, $field->slug, true ); |
| 3108 |
if ( $val ) { |
| 3109 |
$rule[ $cf->slug ] = $options_map[ $cf->id ][ $val ]; |
| 3110 |
} |
| 3111 |
break; |
| 3112 |
|
| 3113 |
case 3: |
| 3114 |
$options_map = get_option( 'wpsc_upgrade_cf_options_map' ); |
| 3115 |
$val = get_term_meta( $prev->term_id, $field->slug, false ); |
| 3116 |
if ( $val ) { |
| 3117 |
$rule[ $cf->slug ] = implode( |
| 3118 |
'|', |
| 3119 |
array_filter( |
| 3120 |
array_map( |
| 3121 |
function ( $name ) use ( $options_map, $cf ) { |
| 3122 |
return $name ? $options_map[ $cf->id ][ $name ] : false; |
| 3123 |
}, |
| 3124 |
$val |
| 3125 |
) |
| 3126 |
) |
| 3127 |
); |
| 3128 |
} |
| 3129 |
break; |
| 3130 |
|
| 3131 |
case 6: |
| 3132 |
$val = get_term_meta( $prev->term_id, $field->slug, true ); |
| 3133 |
if ( $val ) { |
| 3134 |
$val = new DateTime( $val ); |
| 3135 |
$rule[ $cf->slug ] = $val->format( 'Y-m-d' ); |
| 3136 |
} |
| 3137 |
} |
| 3138 |
} |
| 3139 |
|
| 3140 |
if ( $new_rules ) { |
| 3141 |
$new_rules[] = $rule; |
| 3142 |
} else { |
| 3143 |
$new_rules[1] = $rule; |
| 3144 |
} |
| 3145 |
} |
| 3146 |
|
| 3147 |
update_option( 'wpsc-ep-pipe-rules', $new_rules ); |
| 3148 |
} |
| 3149 |
|
| 3150 |
/** |
| 3151 |
* Import FAQ integration add-on settings |
| 3152 |
* |
| 3153 |
* @return void |
| 3154 |
*/ |
| 3155 |
public static function import_faq_integration() { |
| 3156 |
|
| 3157 |
$installed_addons = get_option( 'wpsc_upgrade_installed_addons' ); |
| 3158 |
if ( ! $installed_addons[11]['is_installed'] ) { |
| 3159 |
return; |
| 3160 |
} |
| 3161 |
|
| 3162 |
$map = array( |
| 3163 |
'WPSC_Ultimate_FAQ' => 'ultimate_faq', |
| 3164 |
'WPSC_Acronix_FAQ' => 'acronix_faq', |
| 3165 |
); |
| 3166 |
$prev = get_option( 'wpsc_select_faq_set', '' ); |
| 3167 |
if ( $prev ) { |
| 3168 |
update_option( |
| 3169 |
'wpsc-faq-settings', |
| 3170 |
array( |
| 3171 |
'faq' => $map[ $prev ], |
| 3172 |
) |
| 3173 |
); |
| 3174 |
} |
| 3175 |
} |
| 3176 |
|
| 3177 |
/** |
| 3178 |
* Import knowledgebase integration |
| 3179 |
* |
| 3180 |
* @return void |
| 3181 |
*/ |
| 3182 |
public static function import_knowledgebase_integration() { |
| 3183 |
|
| 3184 |
$installed_addons = get_option( 'wpsc_upgrade_installed_addons' ); |
| 3185 |
if ( ! $installed_addons[12]['is_installed'] ) { |
| 3186 |
return; |
| 3187 |
} |
| 3188 |
|
| 3189 |
$map = array( |
| 3190 |
'WPSC_PrassApp_Knowledgbase' => 'pressapp_kb', |
| 3191 |
'WPSC_WP_Knowledgbase' => 'wp_kb', |
| 3192 |
'WPSC_HelpGuru_Knowledgbase' => 'ht_kb', |
| 3193 |
'WPSC_BasePress_Knowledgbase' => 'basepress_kb', |
| 3194 |
'WPSC_BWL_Knowledgbase' => 'bwl_kb', |
| 3195 |
'WPSC_Echo_Knowledgbase' => 'echo_kb', |
| 3196 |
); |
| 3197 |
$prev = get_option( 'wpsc_select_knowledgbase_set', '' ); |
| 3198 |
if ( $prev ) { |
| 3199 |
update_option( |
| 3200 |
'wpsc-kb-settings', |
| 3201 |
array( |
| 3202 |
'knowledgebase' => $map[ $prev ], |
| 3203 |
) |
| 3204 |
); |
| 3205 |
} |
| 3206 |
} |
| 3207 |
|
| 3208 |
/** |
| 3209 |
* Import export add-on settings |
| 3210 |
* |
| 3211 |
* @return void |
| 3212 |
*/ |
| 3213 |
public static function import_export_addon() { |
| 3214 |
|
| 3215 |
$installed_addons = get_option( 'wpsc_upgrade_installed_addons' ); |
| 3216 |
if ( ! $installed_addons[2]['is_installed'] ) { |
| 3217 |
return; |
| 3218 |
} |
| 3219 |
|
| 3220 |
// visibility. |
| 3221 |
$new_visibility = array(); |
| 3222 |
$prev_visibility = get_option( 'wpsc_selected_user_roll_data', array() ); |
| 3223 |
foreach ( $prev_visibility as $visibility ) { |
| 3224 |
if ( $visibility == 'customer' ) { |
| 3225 |
$new_visibility[] = 'registered-user'; |
| 3226 |
$new_visibility[] = 'guest'; |
| 3227 |
continue; |
| 3228 |
} |
| 3229 |
$new_visibility[] = $visibility; |
| 3230 |
} |
| 3231 |
|
| 3232 |
update_option( |
| 3233 |
'wpsc-export-roles', |
| 3234 |
array( |
| 3235 |
'allow-export-ticket' => $new_visibility, |
| 3236 |
) |
| 3237 |
); |
| 3238 |
|
| 3239 |
// export fields. |
| 3240 |
$cf_slug_map = get_option( 'wpsc_upgrade_cf_slug_map' ); |
| 3241 |
$prev_items = get_option( 'wpsc_export_ticket_list', array() ); |
| 3242 |
$new_items = array(); |
| 3243 |
foreach ( $prev_items as $slug ) { |
| 3244 |
$new_items[] = $cf_slug_map[ $slug ]; |
| 3245 |
} |
| 3246 |
update_option( 'wpsc-agent-export-settings', $new_items ); |
| 3247 |
update_option( 'wpsc-register-export-settings', $new_items ); |
| 3248 |
} |
| 3249 |
|
| 3250 |
/** |
| 3251 |
* Import woocommerce settings |
| 3252 |
* |
| 3253 |
* @return void |
| 3254 |
*/ |
| 3255 |
public static function import_woocommerce_addon() { |
| 3256 |
|
| 3257 |
$installed_addons = get_option( 'wpsc_upgrade_installed_addons' ); |
| 3258 |
if ( ! $installed_addons[5]['is_installed'] ) { |
| 3259 |
return; |
| 3260 |
} |
| 3261 |
|
| 3262 |
$string_translations = get_option( 'wpsc-string-translation' ); |
| 3263 |
// settings. |
| 3264 |
$tab_lable = get_option( 'wpsc_dashboard_support_tab_label', '' ); |
| 3265 |
$help_lable = get_option( 'wpsc_order_help_button_label', '' ); |
| 3266 |
$settings = get_option( 'wpsc-woo-settings' ); |
| 3267 |
$settings['dashboard-support-tab'] = intval( get_option( 'wpsc_dashboard_support_tab', 1 ) ); |
| 3268 |
$settings['dashboard-support-tab-label'] = $tab_lable; |
| 3269 |
$settings['order-help-button'] = intval( get_option( 'wpsc_order_help_button', 0 ) ); |
| 3270 |
$settings['order-help-button-label'] = $help_lable; |
| 3271 |
update_option( 'wpsc-woo-settings', $settings ); |
| 3272 |
|
| 3273 |
$string_translations['wpsc-woo-dashboard-tab-label'] = $tab_lable; |
| 3274 |
$string_translations['wpsc-woo-order-help-button-label'] = $help_lable; |
| 3275 |
update_option( 'wpsc-string-translation', $string_translations ); |
| 3276 |
} |
| 3277 |
|
| 3278 |
/** |
| 3279 |
* Import schedule tickets |
| 3280 |
* |
| 3281 |
* @return void |
| 3282 |
*/ |
| 3283 |
public static function import_shedule_tickets() { |
| 3284 |
|
| 3285 |
global $wpdb; |
| 3286 |
$installed_addons = get_option( 'wpsc_upgrade_installed_addons' ); |
| 3287 |
if ( ! $installed_addons[14]['is_installed'] ) { |
| 3288 |
return; |
| 3289 |
} |
| 3290 |
|
| 3291 |
$cf_map = get_option( 'wpsc_upgrade_cf_term_id_map' ); |
| 3292 |
$category_map = get_option( 'wpsc_upgrade_category_map' ); |
| 3293 |
$priority_map = get_option( 'wpsc_upgrade_priority_map' ); |
| 3294 |
$new_rules = array(); |
| 3295 |
|
| 3296 |
$fields = get_terms( |
| 3297 |
array( |
| 3298 |
'taxonomy' => 'wpsc_ticket_custom_fields', |
| 3299 |
'hide_empty' => false, |
| 3300 |
'meta_query' => array( |
| 3301 |
'relation' => 'AND', |
| 3302 |
array( |
| 3303 |
'key' => 'agentonly', |
| 3304 |
'value' => array( 0, 1 ), |
| 3305 |
'compare' => 'IN', |
| 3306 |
), |
| 3307 |
array( |
| 3308 |
'key' => 'wpsc_tf_type', |
| 3309 |
'value' => '0', |
| 3310 |
'compare' => '>', |
| 3311 |
), |
| 3312 |
), |
| 3313 |
) |
| 3314 |
); |
| 3315 |
|
| 3316 |
$scheule_tickets = get_terms( |
| 3317 |
array( |
| 3318 |
'taxonomy' => 'wpsc_schedule_tickets', |
| 3319 |
'hide_empty' => false, |
| 3320 |
) |
| 3321 |
); |
| 3322 |
|
| 3323 |
foreach ( $scheule_tickets as $prev ) { |
| 3324 |
|
| 3325 |
$time_unit = get_term_meta( $prev->term_id, 'repeat_every_time_unit', true ); |
| 3326 |
$recurrence = get_term_meta( $prev->term_id, 'no_of_recurrence', true ); |
| 3327 |
$start_date = new DateTime( get_term_meta( $prev->term_id, 'start_date', true ) . ' 00:00:00' ); |
| 3328 |
|
| 3329 |
$rule = array( |
| 3330 |
'title' => $prev->name, |
| 3331 |
'recurrence-period' => 'daily', |
| 3332 |
'daily-recurrence-type' => 'daily-every-day', |
| 3333 |
'daily-x-days' => 1, |
| 3334 |
'daily-x-work-days' => 1, |
| 3335 |
'weekly-x-weeks' => 1, |
| 3336 |
'weekly-days' => array( 1, 2, 3, 4, 5 ), |
| 3337 |
'monthly-recurrence-type' => 'monthly-day-number', |
| 3338 |
'monthly-day-number-x-months' => 1, |
| 3339 |
'monthly-day-number-day' => 1, |
| 3340 |
'monthly-week-number-x-months' => 1, |
| 3341 |
'monthly-week-number-occurrence' => 1, |
| 3342 |
'monthly-week-number-day' => 1, |
| 3343 |
'yearly-recurrence-type' => 'yearly-day-number', |
| 3344 |
'yearly-day-number-x-years' => 1, |
| 3345 |
'yearly-day-number-day' => 1, |
| 3346 |
'yearly-day-number-month' => 1, |
| 3347 |
'yearly-week-number-x-years' => 1, |
| 3348 |
'yearly-week-number-occurrence' => 1, |
| 3349 |
'yearly-week-number-day' => 1, |
| 3350 |
'yearly-week-number-month' => 1, |
| 3351 |
'starts-on' => ( new DateTime() )->format( 'Y-m-d' ), |
| 3352 |
'ends-on' => 'no-end-date', |
| 3353 |
'ends-after-times' => 10, |
| 3354 |
'end-date' => '', |
| 3355 |
'ticket-count' => 0, |
| 3356 |
); |
| 3357 |
|
| 3358 |
if ( $time_unit == 'days' ) { |
| 3359 |
|
| 3360 |
$rule['recurrence-period'] = 'daily'; |
| 3361 |
$rule['daily-recurrence-type'] = 'daily-every-day'; |
| 3362 |
$rule['daily-x-days'] = intval( $recurrence ); |
| 3363 |
|
| 3364 |
} else { |
| 3365 |
|
| 3366 |
$rule['recurrence-period'] = 'monthly'; |
| 3367 |
$rule['monthly-recurrence-type'] = 'monthly-day-number'; |
| 3368 |
$rule['monthly-day-number-x-months'] = intval( $recurrence ); |
| 3369 |
$rule['monthly-day-number-day'] = $start_date->format( 'd' ); |
| 3370 |
} |
| 3371 |
|
| 3372 |
$rule['starts-on'] = $start_date->format( 'Y-m-d' ); |
| 3373 |
$rule['ends-on'] = 'no-end-date'; |
| 3374 |
|
| 3375 |
// customer. |
| 3376 |
$customer_name = get_term_meta( $prev->term_id, 'customer_name', true ); |
| 3377 |
$customer_email = get_term_meta( $prev->term_id, 'customer_email', true ); |
| 3378 |
$customer_id = $wpdb->get_var( "SELECT * FROM {$wpdb->prefix}psmsc_customers WHERE email = '" . $customer_email . "'" ); |
| 3379 |
if ( ! $customer_id ) { |
| 3380 |
$user = get_user_by( 'email', $customer_email ); |
| 3381 |
if ( $user ) { |
| 3382 |
$wpdb->insert( |
| 3383 |
$wpdb->prefix . 'psmsc_customers', |
| 3384 |
array( |
| 3385 |
'user' => $user->ID, |
| 3386 |
'name' => $user->display_name, |
| 3387 |
'email' => $user->user_email, |
| 3388 |
) |
| 3389 |
); |
| 3390 |
} else { |
| 3391 |
$wpdb->insert( |
| 3392 |
$wpdb->prefix . 'psmsc_customers', |
| 3393 |
array( |
| 3394 |
'user' => 0, |
| 3395 |
'name' => $customer_name, |
| 3396 |
'email' => $customer_email, |
| 3397 |
) |
| 3398 |
); |
| 3399 |
} |
| 3400 |
$customer_id = $wpdb->insert_id; |
| 3401 |
} |
| 3402 |
$rule['customer'] = $customer_id; |
| 3403 |
|
| 3404 |
// subject, description, category & priority. |
| 3405 |
$rule['subject'] = get_term_meta( $prev->term_id, 'ticket_subject', true ); |
| 3406 |
$rule['description'] = get_term_meta( $prev->term_id, 'ticket_description', true ); |
| 3407 |
$category = get_term_meta( $prev->term_id, 'ticket_category', true ); |
| 3408 |
if ( $category ) { |
| 3409 |
$rule['category'] = $category_map[ $category ]; |
| 3410 |
} |
| 3411 |
$priority = get_term_meta( $prev->term_id, 'ticket_priority', true ); |
| 3412 |
if ( $priority ) { |
| 3413 |
$rule['priority'] = $priority_map[ $priority ]; |
| 3414 |
} |
| 3415 |
|
| 3416 |
// custom fields. |
| 3417 |
foreach ( $fields as $field ) { |
| 3418 |
|
| 3419 |
$type = get_term_meta( $field->term_id, 'wpsc_tf_type', true ); |
| 3420 |
$cf = wpsc_get_cf_by( 'id', $cf_map[ $field->term_id ] ); |
| 3421 |
|
| 3422 |
switch ( $type ) { |
| 3423 |
|
| 3424 |
case 1: |
| 3425 |
case 5: |
| 3426 |
case 7: |
| 3427 |
case 8: |
| 3428 |
case 9: |
| 3429 |
$val = get_term_meta( $prev->term_id, $field->slug, true ); |
| 3430 |
if ( $val ) { |
| 3431 |
$rule[ $cf->slug ] = $val ? $val : ''; |
| 3432 |
} |
| 3433 |
break; |
| 3434 |
|
| 3435 |
case 2: |
| 3436 |
case 4: |
| 3437 |
$options_map = get_option( 'wpsc_upgrade_cf_options_map' ); |
| 3438 |
$val = get_term_meta( $prev->term_id, $field->slug, true ); |
| 3439 |
if ( $val ) { |
| 3440 |
$rule[ $cf->slug ] = $options_map[ $cf->id ][ $val ]; |
| 3441 |
} |
| 3442 |
break; |
| 3443 |
|
| 3444 |
case 3: |
| 3445 |
$options_map = get_option( 'wpsc_upgrade_cf_options_map' ); |
| 3446 |
$val = get_term_meta( $prev->term_id, $field->slug, false ); |
| 3447 |
if ( $val ) { |
| 3448 |
$rule[ $cf->slug ] = implode( |
| 3449 |
'|', |
| 3450 |
array_filter( |
| 3451 |
array_map( |
| 3452 |
function ( $name ) use ( $options_map, $cf ) { |
| 3453 |
return $name ? $options_map[ $cf->id ][ $name ] : false; |
| 3454 |
}, |
| 3455 |
$val |
| 3456 |
) |
| 3457 |
) |
| 3458 |
); |
| 3459 |
} |
| 3460 |
break; |
| 3461 |
|
| 3462 |
case 6: |
| 3463 |
$val = get_term_meta( $prev->term_id, $field->slug, true ); |
| 3464 |
if ( $val ) { |
| 3465 |
$val = new DateTime( $val ); |
| 3466 |
$rule[ $cf->slug ] = $val->format( 'Y-m-d' ); |
| 3467 |
} |
| 3468 |
} |
| 3469 |
} |
| 3470 |
|
| 3471 |
if ( ! $new_rules ) { |
| 3472 |
$new_rules[1] = $rule; |
| 3473 |
} else { |
| 3474 |
$new_rules[] = $rule; |
| 3475 |
} |
| 3476 |
} |
| 3477 |
|
| 3478 |
update_option( 'wpsc-st-rules', $new_rules ); |
| 3479 |
} |
| 3480 |
|
| 3481 |
/** |
| 3482 |
* Import SLA settings |
| 3483 |
* |
| 3484 |
* @return void |
| 3485 |
*/ |
| 3486 |
public static function import_sla_settings() { |
| 3487 |
|
| 3488 |
$installed_addons = get_option( 'wpsc_upgrade_installed_addons' ); |
| 3489 |
if ( ! $installed_addons[4]['is_installed'] ) { |
| 3490 |
return; |
| 3491 |
} |
| 3492 |
|
| 3493 |
$cf_map = get_option( 'wpsc_upgrade_cf_term_id_map' ); |
| 3494 |
$options_map = get_option( 'wpsc_upgrade_cf_options_map' ); |
| 3495 |
$category_map = get_option( 'wpsc_upgrade_category_map' ); |
| 3496 |
$priority_map = get_option( 'wpsc_upgrade_priority_map' ); |
| 3497 |
$status_map = get_option( 'wpsc_upgrade_status_map' ); |
| 3498 |
|
| 3499 |
// settings. |
| 3500 |
$settings = get_option( 'wpsc-sla-general-settings' ); |
| 3501 |
$settings['out-sla-bg-color'] = get_option( 'wpsc_out_sla_color', $settings['out-sla-bg-color'] ); |
| 3502 |
$settings['out-sla-text-color'] = '#ffffff'; |
| 3503 |
$settings['in-sla-bg-color'] = get_option( 'wpsc_in_sla_color', $settings['in-sla-bg-color'] ); |
| 3504 |
$settings['in-sla-text-color'] = '#ffffff'; |
| 3505 |
update_option( 'wpsc-sla-general-settings', $settings ); |
| 3506 |
|
| 3507 |
// sla policies. |
| 3508 |
$policies = get_terms( |
| 3509 |
array( |
| 3510 |
'taxonomy' => 'wpsc_sla', |
| 3511 |
'hide_empty' => false, |
| 3512 |
'orderby' => 'meta_value_num', |
| 3513 |
'order' => 'ASC', |
| 3514 |
'meta_query' => array( 'order_clause' => array( 'key' => 'load_order' ) ), |
| 3515 |
) |
| 3516 |
); |
| 3517 |
|
| 3518 |
$new_policies = array(); |
| 3519 |
$count = 0; |
| 3520 |
$map = array(); |
| 3521 |
|
| 3522 |
foreach ( $policies as $prev ) { |
| 3523 |
|
| 3524 |
$time_unit_map = array( |
| 3525 |
'minutes' => 'minute', |
| 3526 |
'hours' => 'hour', |
| 3527 |
'days' => 'day', |
| 3528 |
'months' => 'month', |
| 3529 |
'years' => 'year', |
| 3530 |
); |
| 3531 |
$time = get_term_meta( $prev->term_id, 'time', true ); |
| 3532 |
$time_unit = get_term_meta( $prev->term_id, 'time_unit', true ); |
| 3533 |
|
| 3534 |
$conditions = array(); |
| 3535 |
$prev_conditions = get_term_meta( $prev->term_id, 'conditions', true ); |
| 3536 |
if ( $prev_conditions ) { |
| 3537 |
|
| 3538 |
foreach ( $prev_conditions as $key => $val ) { |
| 3539 |
|
| 3540 |
$cf = wpsc_get_cf_by( 'id', $cf_map[ $key ] ); |
| 3541 |
switch ( $cf->slug ) { |
| 3542 |
|
| 3543 |
case 'status': |
| 3544 |
$conditions['cf_status'] = array( |
| 3545 |
'operator' => 'IN', |
| 3546 |
'operand_val_1' => array_map( |
| 3547 |
function ( $status ) use ( $status_map ) { |
| 3548 |
return $status_map[ $status ]; |
| 3549 |
}, |
| 3550 |
$val |
| 3551 |
), |
| 3552 |
); |
| 3553 |
break; |
| 3554 |
|
| 3555 |
case 'category': |
| 3556 |
$conditions['cf_category'] = array( |
| 3557 |
'operator' => 'IN', |
| 3558 |
'operand_val_1' => array_map( |
| 3559 |
function ( $category ) use ( $category_map ) { |
| 3560 |
return $category_map[ $category ]; |
| 3561 |
}, |
| 3562 |
$val |
| 3563 |
), |
| 3564 |
); |
| 3565 |
break; |
| 3566 |
|
| 3567 |
case 'priority': |
| 3568 |
$conditions['cf_priority'] = array( |
| 3569 |
'operator' => 'IN', |
| 3570 |
'operand_val_1' => array_map( |
| 3571 |
function ( $priority ) use ( $priority_map ) { |
| 3572 |
return $priority_map[ $priority ]; |
| 3573 |
}, |
| 3574 |
$val |
| 3575 |
), |
| 3576 |
); |
| 3577 |
break; |
| 3578 |
|
| 3579 |
default: |
| 3580 |
$conditions[ 'cf_' . $cf->slug ] = array( |
| 3581 |
'operator' => 'IN', |
| 3582 |
'operand_val_1' => array_map( |
| 3583 |
function ( $option ) use ( $options_map, $cf ) { |
| 3584 |
return $options_map[ $cf->id ][ $option ]; |
| 3585 |
}, |
| 3586 |
$val |
| 3587 |
), |
| 3588 |
); |
| 3589 |
} |
| 3590 |
} |
| 3591 |
} |
| 3592 |
|
| 3593 |
$policy = array( |
| 3594 |
'title' => $prev->name, |
| 3595 |
'time' => $time, |
| 3596 |
'time-unit' => $time_unit_map[ $time_unit ], |
| 3597 |
'calculate-from' => 'date_updated', |
| 3598 |
'relation' => 'AND', |
| 3599 |
'conditions' => $conditions ? wp_json_encode( $conditions ) : '{}', |
| 3600 |
); |
| 3601 |
|
| 3602 |
$new_policies[ ++$count ] = $policy; |
| 3603 |
$map[ $prev->term_id ] = $count; |
| 3604 |
} |
| 3605 |
|
| 3606 |
// SLA policy filters. |
| 3607 |
foreach ( $new_policies as $index => $properties ) { |
| 3608 |
$new_policies[ $index ]['conditions'] = WPSC_SC_Upgrade::upgrade_condition( $properties['conditions'], $properties['relation'] ); |
| 3609 |
} |
| 3610 |
|
| 3611 |
update_option( 'wpsc-sla-policies', $new_policies ); |
| 3612 |
update_option( 'wpsc_upgrade_sla_policy_map', $map ); |
| 3613 |
} |
| 3614 |
|
| 3615 |
/** |
| 3616 |
* Import usergroup settings |
| 3617 |
* |
| 3618 |
* @return void |
| 3619 |
*/ |
| 3620 |
public static function import_usergroup_settings() { |
| 3621 |
|
| 3622 |
global $wpdb; |
| 3623 |
$installed_addons = get_option( 'wpsc_upgrade_installed_addons' ); |
| 3624 |
if ( ! $installed_addons[7]['is_installed'] ) { |
| 3625 |
return; |
| 3626 |
} |
| 3627 |
|
| 3628 |
$category_map = get_option( 'wpsc_upgrade_category_map' ); |
| 3629 |
$usergroups = get_terms( |
| 3630 |
array( |
| 3631 |
'taxonomy' => 'wpsc_usergroup_data', |
| 3632 |
'hide_empty' => false, |
| 3633 |
) |
| 3634 |
); |
| 3635 |
|
| 3636 |
foreach ( $usergroups as $prev ) { |
| 3637 |
|
| 3638 |
$members = array(); |
| 3639 |
$prev_members = get_term_meta( $prev->term_id, 'wpsc_usergroup_userid', false ); |
| 3640 |
foreach ( $prev_members as $user_id ) { |
| 3641 |
$customer_id = $wpdb->get_var( "SELECT id FROM {$wpdb->prefix}psmsc_customers WHERE user = " . $user_id ); |
| 3642 |
if ( ! $customer_id ) { |
| 3643 |
$user = get_user_by( 'id', $user_id ); |
| 3644 |
$wpdb->insert( |
| 3645 |
$wpdb->prefix . 'psmsc_customers', |
| 3646 |
array( |
| 3647 |
'user' => $user_id, |
| 3648 |
'name' => $user->display_name, |
| 3649 |
'email' => $user->user_email, |
| 3650 |
) |
| 3651 |
); |
| 3652 |
$customer_id = $wpdb->insert_id; |
| 3653 |
} |
| 3654 |
$members[] = $customer_id; |
| 3655 |
} |
| 3656 |
|
| 3657 |
$supervisors = array(); |
| 3658 |
$prev_supervisors = get_term_meta( $prev->term_id, 'wpsc_usergroup_supervisor_id', false ); |
| 3659 |
foreach ( $prev_supervisors as $user_id ) { |
| 3660 |
$supervisors[] = $wpdb->get_var( "SELECT id FROM {$wpdb->prefix}psmsc_customers WHERE user = " . $user_id ); |
| 3661 |
} |
| 3662 |
|
| 3663 |
$category = get_term_meta( $prev->term_id, 'wpsc_usergroup_category', true ); |
| 3664 |
|
| 3665 |
$wpdb->insert( |
| 3666 |
$wpdb->prefix . 'psmsc_usergroups', |
| 3667 |
array( |
| 3668 |
'name' => $prev->name, |
| 3669 |
'members' => implode( '|', $members ), |
| 3670 |
'supervisors' => implode( '|', $supervisors ), |
| 3671 |
'category' => $category ? $category_map[ $category ] : '', |
| 3672 |
) |
| 3673 |
); |
| 3674 |
} |
| 3675 |
} |
| 3676 |
|
| 3677 |
/** |
| 3678 |
* Import single ticket |
| 3679 |
* |
| 3680 |
* @param WP_Post $ticket - ticket post object. |
| 3681 |
* @return void |
| 3682 |
*/ |
| 3683 |
public static function import_individual_ticket( $ticket ) { |
| 3684 |
|
| 3685 |
global $wpdb; |
| 3686 |
|
| 3687 |
$installed_addons = get_option( 'wpsc_upgrade_installed_addons' ); |
| 3688 |
|
| 3689 |
// destroy existing ticket if already imported. |
| 3690 |
$ticket_id = $wpdb->get_var( "SELECT id FROM {$wpdb->prefix}psmsc_tickets WHERE id = " . get_post_meta( $ticket->ID, 'ticket_id', true ) ); |
| 3691 |
if ( $ticket_id ) { |
| 3692 |
wpsc_destroy_existing_ticket( $ticket_id ); |
| 3693 |
} |
| 3694 |
|
| 3695 |
$fields = get_terms( |
| 3696 |
array( |
| 3697 |
'taxonomy' => 'wpsc_ticket_custom_fields', |
| 3698 |
'hide_empty' => false, |
| 3699 |
'orderby' => 'term_id', |
| 3700 |
'order' => 'ASC', |
| 3701 |
) |
| 3702 |
); |
| 3703 |
|
| 3704 |
$cf_map = get_option( 'wpsc_upgrade_cf_term_id_map' ); |
| 3705 |
$data = array(); |
| 3706 |
|
| 3707 |
foreach ( $fields as $prev ) { |
| 3708 |
|
| 3709 |
$type = get_term_meta( $prev->term_id, 'wpsc_tf_type', true ); |
| 3710 |
|
| 3711 |
if ( ! isset( $cf_map[ $prev->term_id ] ) || $prev->slug == 'ticket_description' ) { |
| 3712 |
continue; |
| 3713 |
} |
| 3714 |
|
| 3715 |
$cf = wpsc_get_cf_by( 'id', $cf_map[ $prev->term_id ] ); |
| 3716 |
|
| 3717 |
if ( intval( $type ) === 0 ) { |
| 3718 |
|
| 3719 |
switch ( $prev->slug ) { |
| 3720 |
|
| 3721 |
case 'ticket_id': |
| 3722 |
case 'customer_name': |
| 3723 |
case 'customer_email': |
| 3724 |
case 'ticket_subject': |
| 3725 |
case 'date_created': |
| 3726 |
case 'date_updated': |
| 3727 |
$data[ $cf->slug ] = get_post_meta( $ticket->ID, $prev->slug, true ); |
| 3728 |
break; |
| 3729 |
|
| 3730 |
case 'ticket_status': |
| 3731 |
$map = get_option( 'wpsc_upgrade_status_map' ); |
| 3732 |
$val = get_post_meta( $ticket->ID, $prev->slug, true ); |
| 3733 |
$data[ $cf->slug ] = $map[ $val ]; |
| 3734 |
break; |
| 3735 |
|
| 3736 |
case 'ticket_category': |
| 3737 |
$map = get_option( 'wpsc_upgrade_category_map' ); |
| 3738 |
$val = get_post_meta( $ticket->ID, $prev->slug, true ); |
| 3739 |
$data[ $cf->slug ] = $map[ $val ]; |
| 3740 |
break; |
| 3741 |
|
| 3742 |
case 'ticket_priority': |
| 3743 |
$map = get_option( 'wpsc_upgrade_priority_map' ); |
| 3744 |
$val = get_post_meta( $ticket->ID, $prev->slug, true ); |
| 3745 |
$data[ $cf->slug ] = $map[ $val ]; |
| 3746 |
break; |
| 3747 |
|
| 3748 |
case 'agent_created': |
| 3749 |
$map = get_option( 'wpsc_upgrade_agent_map' ); |
| 3750 |
$val = get_post_meta( $ticket->ID, $prev->slug, true ); |
| 3751 |
$data[ $cf->slug ] = $val ? $map[ $val ] : 0; |
| 3752 |
break; |
| 3753 |
|
| 3754 |
case 'assigned_agent': |
| 3755 |
$map = get_option( 'wpsc_upgrade_agent_map' ); |
| 3756 |
$val = array_filter( |
| 3757 |
array_map( |
| 3758 |
function ( $agent_id ) use ( $map ) { |
| 3759 |
return $agent_id ? $map[ $agent_id ] : ''; |
| 3760 |
}, |
| 3761 |
get_post_meta( $ticket->ID, $prev->slug, false ) |
| 3762 |
) |
| 3763 |
); |
| 3764 |
$data[ $cf->slug ] = implode( '|', $val ); |
| 3765 |
break; |
| 3766 |
|
| 3767 |
case 'sf_rating': |
| 3768 |
$map = get_option( 'wpsc_upgrade_sf_rating_map' ); |
| 3769 |
$val = get_post_meta( $ticket->ID, $prev->slug, true ); |
| 3770 |
if ( is_numeric( $val ) ) { |
| 3771 |
$data[ $cf->slug ] = $map[ $val ]; |
| 3772 |
} |
| 3773 |
break; |
| 3774 |
|
| 3775 |
case 'sla': |
| 3776 |
$val = get_post_meta( $ticket->ID, $prev->slug, true ); |
| 3777 |
if ( $val && $val != '3099-01-01 00:00:00' ) { |
| 3778 |
$policy_map = get_option( 'wpsc_upgrade_sla_policy_map' ); |
| 3779 |
$data[ $cf->slug ] = $val; |
| 3780 |
$data['sla_policy'] = $policy_map[ get_post_meta( $ticket->ID, 'sla_term', true ) ]; |
| 3781 |
$data['od_email'] = get_post_meta( $ticket->ID, 'wpsp_out_of_sla_email_send', true ); |
| 3782 |
} |
| 3783 |
break; |
| 3784 |
} |
| 3785 |
} else { |
| 3786 |
|
| 3787 |
switch ( intval( $type ) ) { |
| 3788 |
|
| 3789 |
case 1: |
| 3790 |
case 5: |
| 3791 |
case 6: |
| 3792 |
case 7: |
| 3793 |
case 8: |
| 3794 |
case 9: |
| 3795 |
case 11: |
| 3796 |
case 12: |
| 3797 |
$data[ $cf->slug ] = get_post_meta( $ticket->ID, $prev->slug, true ); |
| 3798 |
break; |
| 3799 |
|
| 3800 |
case 2: |
| 3801 |
case 4: |
| 3802 |
$options = wpsc_get_cf_options( $cf->id ); |
| 3803 |
$val = get_post_meta( $ticket->ID, $prev->slug, true ); |
| 3804 |
foreach ( $options as $option ) { |
| 3805 |
if ( $option->name == $val ) { |
| 3806 |
$data[ $cf->slug ] = $option->id; |
| 3807 |
break; |
| 3808 |
} |
| 3809 |
} |
| 3810 |
break; |
| 3811 |
|
| 3812 |
case 3: |
| 3813 |
$options = wpsc_get_cf_options( $cf->id ); |
| 3814 |
$prev_val = get_post_meta( $ticket->ID, $prev->slug, false ); |
| 3815 |
$new_val = array(); |
| 3816 |
foreach ( $options as $option ) { |
| 3817 |
if ( in_array( $option->name, $prev_val ) ) { |
| 3818 |
$new_val[] = $option->id; |
| 3819 |
} |
| 3820 |
} |
| 3821 |
$data[ $cf->slug ] = implode( '|', $new_val ); |
| 3822 |
break; |
| 3823 |
|
| 3824 |
case 10: |
| 3825 |
$prev_val = array_filter( get_post_meta( $ticket->ID, $prev->slug, false ) ); |
| 3826 |
$new_val = array(); |
| 3827 |
$upload_dir = wp_upload_dir(); |
| 3828 |
foreach ( $prev_val as $item ) { |
| 3829 |
$term_meta = get_term_meta( $item ); |
| 3830 |
if ( ! $term_meta ) { |
| 3831 |
continue; |
| 3832 |
} |
| 3833 |
$wpdb->insert( |
| 3834 |
$wpdb->prefix . 'psmsc_attachments', |
| 3835 |
array( |
| 3836 |
'name' => $term_meta['filename'][0], |
| 3837 |
'file_path' => '/wpsc/' . $term_meta['save_file_name'][0], |
| 3838 |
'is_image' => $term_meta['is_image'][0], |
| 3839 |
'is_active' => 1, |
| 3840 |
'date_created' => $term_meta['time_uploaded'][0], |
| 3841 |
'source' => 'cf', |
| 3842 |
'source_id' => $cf->id, |
| 3843 |
'ticket_id' => $data['id'], |
| 3844 |
) |
| 3845 |
); |
| 3846 |
$new_val[] = $wpdb->insert_id; |
| 3847 |
} |
| 3848 |
$data[ $cf->slug ] = implode( '|', $new_val ); |
| 3849 |
break; |
| 3850 |
} |
| 3851 |
} |
| 3852 |
} |
| 3853 |
|
| 3854 |
// customer record if not exists. |
| 3855 |
$customer = wpsc_import_customer( $data['name'], $data['email'] ); |
| 3856 |
$data['customer'] = $customer->id; |
| 3857 |
unset( $data['name'] ); |
| 3858 |
unset( $data['email'] ); |
| 3859 |
|
| 3860 |
// user type. |
| 3861 |
$data['user_type'] = $customer->user ? 'registered' : 'guest'; |
| 3862 |
|
| 3863 |
// deleted. |
| 3864 |
$data['is_active'] = $ticket->post_status == 'publish' ? 1 : 0; |
| 3865 |
|
| 3866 |
// Auth code. |
| 3867 |
$data['auth_code'] = get_post_meta( $ticket->ID, 'ticket_auth_code', true ); |
| 3868 |
|
| 3869 |
// create ticket record. |
| 3870 |
$wpdb->insert( |
| 3871 |
$wpdb->prefix . 'psmsc_tickets', |
| 3872 |
$data |
| 3873 |
); |
| 3874 |
|
| 3875 |
$ticket = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}psmsc_tickets WHERE id = " . $wpdb->insert_id ); |
| 3876 |
|
| 3877 |
// import ticket threads. |
| 3878 |
self::import_ticket_threads( $ticket ); |
| 3879 |
} |
| 3880 |
|
| 3881 |
/** |
| 3882 |
* Import ticket threads |
| 3883 |
* |
| 3884 |
* @param stdClass $ticket - ticket object. |
| 3885 |
* @return void |
| 3886 |
*/ |
| 3887 |
public static function import_ticket_threads( $ticket ) { |
| 3888 |
|
| 3889 |
global $wpdb; |
| 3890 |
$gs = get_option( 'wpsc-gs-general' ); |
| 3891 |
$tl_advanced = get_option( 'wpsc-tl-ms-advanced' ); |
| 3892 |
$installed_addons = get_option( 'wpsc_upgrade_installed_addons' ); |
| 3893 |
|
| 3894 |
$threads = get_posts( |
| 3895 |
array( |
| 3896 |
'post_type' => 'wpsc_ticket_thread', |
| 3897 |
'post_status' => 'publish', |
| 3898 |
'orderby' => 'date', |
| 3899 |
'order' => 'ASC', |
| 3900 |
'posts_per_page' => -1, |
| 3901 |
'meta_query' => array( |
| 3902 |
'relation' => 'AND', |
| 3903 |
array( |
| 3904 |
'key' => 'ticket_id', |
| 3905 |
'value' => $ticket->id, |
| 3906 |
'compare' => '=', |
| 3907 |
), |
| 3908 |
), |
| 3909 |
) |
| 3910 |
); |
| 3911 |
|
| 3912 |
// ticket update data. |
| 3913 |
$ticket_data = array(); |
| 3914 |
|
| 3915 |
// last reply thread. |
| 3916 |
$last_thread = null; |
| 3917 |
|
| 3918 |
// first response delay. |
| 3919 |
$frd = 0; |
| 3920 |
|
| 3921 |
// average response delay. |
| 3922 |
$ard = 0; |
| 3923 |
|
| 3924 |
// communication gap. |
| 3925 |
$cg = 1; |
| 3926 |
|
| 3927 |
// report temp variables. |
| 3928 |
$count = 0; |
| 3929 |
$last_reply_by = 'customer'; |
| 3930 |
$last_reply_time = new DateTime( $ticket->date_created ); |
| 3931 |
$delay = 0; |
| 3932 |
|
| 3933 |
foreach ( $threads as $thread ) { |
| 3934 |
|
| 3935 |
$thread_type = get_post_meta( $thread->ID, 'thread_type', true ); |
| 3936 |
|
| 3937 |
if ( in_array( $thread_type, array( 'report', 'reply', 'note' ) ) ) { |
| 3938 |
|
| 3939 |
// thread_customer import. |
| 3940 |
$customer_name = get_post_meta( $thread->ID, 'customer_name', true ); |
| 3941 |
$customer_email = get_post_meta( $thread->ID, 'customer_email', true ); |
| 3942 |
$customer = wpsc_import_customer( $customer_name, $customer_email ); |
| 3943 |
|
| 3944 |
// create thread record. |
| 3945 |
$wpdb->insert( |
| 3946 |
$wpdb->prefix . 'psmsc_threads', |
| 3947 |
array( |
| 3948 |
'ticket' => $ticket->id, |
| 3949 |
'customer' => $customer->id, |
| 3950 |
'type' => $thread_type, |
| 3951 |
'body' => $thread->post_content, |
| 3952 |
'date_created' => $thread->post_date, |
| 3953 |
'date_updated' => $thread->post_date, |
| 3954 |
) |
| 3955 |
); |
| 3956 |
$new_thread = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}psmsc_threads WHERE id = " . $wpdb->insert_id ); |
| 3957 |
|
| 3958 |
// Calculate response delays. |
| 3959 |
if ( $new_thread->type == 'reply' ) { |
| 3960 |
++$cg; |
| 3961 |
$current_reply_by = 'customer'; |
| 3962 |
if ( $ticket->customer != $new_thread->customer && wpsc_is_agent( $new_thread->customer ) ) { |
| 3963 |
$current_reply_by = 'agent'; |
| 3964 |
} |
| 3965 |
if ( $last_reply_by == 'customer' && $current_reply_by == 'agent' ) { |
| 3966 |
++$count; |
| 3967 |
$diff = ceil( abs( $last_reply_time->getTimestamp() - ( new DateTime( $new_thread->date_created ) )->getTimestamp() ) / 60 ); |
| 3968 |
if ( $count == 1 ) { |
| 3969 |
$frd = $diff; |
| 3970 |
} |
| 3971 |
$delay += $diff; |
| 3972 |
} |
| 3973 |
if ( $last_reply_by == 'agent' && $current_reply_by == 'customer' ) { |
| 3974 |
$last_reply_time = new DateTime( $new_thread->date_created ); |
| 3975 |
} |
| 3976 |
$last_reply_by = $current_reply_by; |
| 3977 |
} |
| 3978 |
|
| 3979 |
if ( $new_thread->type == 'report' || $new_thread->type == 'reply' ) { |
| 3980 |
$last_thread = $new_thread; |
| 3981 |
} |
| 3982 |
|
| 3983 |
// Handle attachments. |
| 3984 |
$prev = get_post_meta( $thread->ID, 'attachments', true ); |
| 3985 |
$new = array(); |
| 3986 |
$upload_dir = wp_upload_dir(); |
| 3987 |
foreach ( $prev as $item ) { |
| 3988 |
|
| 3989 |
$term_meta = get_term_meta( $item ); |
| 3990 |
if ( ! $term_meta ) { |
| 3991 |
continue; |
| 3992 |
} |
| 3993 |
|
| 3994 |
$wpdb->insert( |
| 3995 |
$wpdb->prefix . 'psmsc_attachments', |
| 3996 |
array( |
| 3997 |
'name' => $term_meta['filename'][0], |
| 3998 |
'file_path' => '/wpsc/' . $term_meta['save_file_name'][0], |
| 3999 |
'is_image' => $term_meta['is_image'][0], |
| 4000 |
'is_active' => 1, |
| 4001 |
'date_created' => $term_meta['time_uploaded'][0], |
| 4002 |
'source' => $thread_type, |
| 4003 |
'source_id' => $new_thread->id, |
| 4004 |
'ticket_id' => $ticket->id, |
| 4005 |
) |
| 4006 |
); |
| 4007 |
$new[] = $wpdb->insert_id; |
| 4008 |
} |
| 4009 |
// update attachments to db. |
| 4010 |
$wpdb->update( |
| 4011 |
$wpdb->prefix . 'psmsc_threads', |
| 4012 |
array( |
| 4013 |
'attachments' => implode( '|', $new ), |
| 4014 |
'body' => self::import_uploaded_thread_images( $new_thread->body, $new_thread, $ticket ), |
| 4015 |
), |
| 4016 |
array( 'id' => $new_thread->id ) |
| 4017 |
); |
| 4018 |
|
| 4019 |
} elseif ( $thread_type == 'log' ) { |
| 4020 |
|
| 4021 |
$wpdb->insert( |
| 4022 |
$wpdb->prefix . 'psmsc_threads', |
| 4023 |
array( |
| 4024 |
'ticket' => $ticket->id, |
| 4025 |
'customer' => 0, |
| 4026 |
'type' => 'log', |
| 4027 |
'body' => $thread->post_content, |
| 4028 |
'date_created' => $thread->post_date, |
| 4029 |
'date_updated' => $thread->post_date, |
| 4030 |
) |
| 4031 |
); |
| 4032 |
|
| 4033 |
} elseif ( $installed_addons[15]['is_installed'] && $thread_type == 'feedback' ) { |
| 4034 |
// Add ticket feedback (satisfaction survey). |
| 4035 |
$ticket_data['sf_feedback'] = $thread->post_content; |
| 4036 |
$ticket_data['sf_date'] = $thread->post_date; |
| 4037 |
} |
| 4038 |
} |
| 4039 |
|
| 4040 |
// date_closed was not available in v1 so date_updated is considered as date closed for closed tickets. |
| 4041 |
if ( $ticket->status == $gs['close-ticket-status'] || in_array( $ticket->status, $tl_advanced['closed-ticket-statuses'] ) ) { |
| 4042 |
$ticket_data['date_closed'] = $ticket->date_updated; |
| 4043 |
} |
| 4044 |
|
| 4045 |
// last reply by and last reply on. |
| 4046 |
if ( $last_thread ) { |
| 4047 |
$ticket_data['last_reply_by'] = $last_thread->customer; |
| 4048 |
$ticket_data['last_reply_on'] = $last_thread->date_created; |
| 4049 |
} |
| 4050 |
|
| 4051 |
// report add-on. |
| 4052 |
if ( $installed_addons[6]['is_installed'] ) { |
| 4053 |
$ticket_data['frd'] = $frd; |
| 4054 |
if ( $count ) { |
| 4055 |
$ticket_data['ard'] = ceil( $delay / $count ); |
| 4056 |
} |
| 4057 |
$ticket_data['cg'] = $cg; |
| 4058 |
if ( $ticket->status == $gs['close-ticket-status'] || in_array( $ticket->status, $tl_advanced['closed-ticket-statuses'] ) ) { |
| 4059 |
$ticket_data['cd'] = ceil( abs( ( new DateTime( $ticket->date_created ) )->getTimestamp() - ( new DateTime( $ticket->date_closed ) )->getTimestamp() ) / 60 ); |
| 4060 |
} |
| 4061 |
} |
| 4062 |
|
| 4063 |
// insert sf_date if only rating is available. |
| 4064 |
if ( $ticket->rating && ! isset( $ticket_data['sf_date'] ) ) { |
| 4065 |
$date_closed = isset( $ticket->date_closed ) ? $ticket->date_closed : ''; |
| 4066 |
$date_closed = ! $date_closed && isset( $ticket_data['date_closed'] ) ? $ticket_data['date_closed'] : $date_closed; |
| 4067 |
if ( $date_closed ) { |
| 4068 |
$ticket_data['sf_date'] = $date_closed; |
| 4069 |
} |
| 4070 |
} |
| 4071 |
|
| 4072 |
// update ticket data. |
| 4073 |
$wpdb->update( |
| 4074 |
$wpdb->prefix . 'psmsc_tickets', |
| 4075 |
$ticket_data, |
| 4076 |
array( 'id' => $ticket->id ) |
| 4077 |
); |
| 4078 |
} |
| 4079 |
|
| 4080 |
/** |
| 4081 |
* Import uploaded thread images |
| 4082 |
* |
| 4083 |
* @param string $thread_content - thread html. |
| 4084 |
* @param stdClass $thread - thread object. |
| 4085 |
* @param stdClass $ticket - ticket object. |
| 4086 |
* @return string |
| 4087 |
*/ |
| 4088 |
public static function import_uploaded_thread_images( $thread_content, $thread, $ticket ) { |
| 4089 |
|
| 4090 |
global $wpdb; |
| 4091 |
$upload_dir = wp_upload_dir(); |
| 4092 |
$regex = 'src="' . preg_quote( $upload_dir['baseurl'], '/' ) . '\/wpsc\/(.*?)"'; |
| 4093 |
preg_match_all( '/' . $regex . '/', $thread_content, $matches ); |
| 4094 |
if ( $matches[1] ) { |
| 4095 |
$count = count( $matches[1] ); |
| 4096 |
for ( $i = 0; $i < $count; $i++ ) { |
| 4097 |
|
| 4098 |
$file_path = $upload_dir['basedir'] . '/wpsc/' . $matches[1][ $i ]; |
| 4099 |
if ( ! file_exists( $file_path ) ) { |
| 4100 |
continue; |
| 4101 |
} |
| 4102 |
|
| 4103 |
$file_path = str_replace( $upload_dir['basedir'], '', $file_path ); |
| 4104 |
$file_name = basename( $file_path ); |
| 4105 |
$file_url = $upload_dir['baseurl'] . '/wpsc/' . $matches[1][ $i ]; |
| 4106 |
|
| 4107 |
$wpdb->insert( |
| 4108 |
$wpdb->prefix . 'psmsc_attachments', |
| 4109 |
array( |
| 4110 |
'name' => $file_name, |
| 4111 |
'file_path' => $file_path, |
| 4112 |
'is_image' => 1, |
| 4113 |
'is_active' => 1, |
| 4114 |
'date_created' => ( new DateTime() )->format( 'Y-m-d H:i:s' ), |
| 4115 |
'source' => 'img_editor', |
| 4116 |
'source_id' => $thread->id, |
| 4117 |
'ticket_id' => $ticket->id, |
| 4118 |
) |
| 4119 |
); |
| 4120 |
|
| 4121 |
$thread_content = str_replace( |
| 4122 |
$file_url, |
| 4123 |
home_url( '/' ) . '?wpsc_attachment=' . $wpdb->insert_id, |
| 4124 |
$thread_content |
| 4125 |
); |
| 4126 |
} |
| 4127 |
} |
| 4128 |
return $thread_content; |
| 4129 |
} |
| 4130 |
} |
| 4131 |
|
| 4132 |
endif; |
| 4133 |
|
| 4134 |
WPSC_Upgrade_DB_V1::init(); |
| 4135 |
|
| 4136 |
require_once __DIR__ . '/functions.php'; |
| 4137 |
|