Passed
Push — master ( c3b9b9...2d5ec3 )
by Stiofan
12:21 queued 06:01
created

wpinv-upgrade-functions.php ➔ wpinv_v005_upgrades()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Upgrade related functions.
4
 *
5
 * @since 1.0.0
6
 */
7
8
/**
9
 * Perform automatic upgrades when necessary.
10
 *
11
 * @since 1.0.0
12
*/
13
function wpinv_automatic_upgrade() {
14
    $wpi_version = get_option( 'wpinv_version' );
15
    
16
    if ( $wpi_version == WPINV_VERSION ) {
17
        return;
18
    }
19
    
20
    if ( version_compare( $wpi_version, '0.0.5', '<' ) ) {
21
        wpinv_v005_upgrades();
22
    }
23
    
24
    update_option( 'wpinv_version', WPINV_VERSION );
25
}
26
add_action( 'admin_init', 'wpinv_automatic_upgrade' );
27
28
function wpinv_v005_upgrades() {
29
    global $wpdb;
30
    
31
    $wpdb->query( "UPDATE " . $wpdb->posts . " SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" );
32
}