| 1 |
<?php if (! defined('ABSPATH')) exit; // Exit if accessed directly |
| 2 |
class SH4_Upgrade3_Query |
| 3 |
{ |
| 4 |
protected $prfxStandalone = 'shf2_v3_'; |
| 5 |
protected $prfxWp = 'shiftcontroller_v3_'; |
| 6 |
public $dic; |
| 7 |
|
| 8 |
public function __construct( |
| 9 |
HC3_Dic $dic |
| 10 |
) |
| 11 |
{ |
| 12 |
$this->dic = $dic; |
| 13 |
} |
| 14 |
|
| 15 |
public function hasVersion3() |
| 16 |
{ |
| 17 |
$return = FALSE; |
| 18 |
|
| 19 |
if( defined('WPINC') ){ |
| 20 |
global $wpdb; |
| 21 |
|
| 22 |
$prfx = $wpdb->prefix . $this->prfxWp; |
| 23 |
$testTable = $prfx . 'locations'; |
| 24 |
|
| 25 |
if( $wpdb->get_var("SHOW TABLES LIKE '$testTable'") != $testTable ){ |
| 26 |
$return = FALSE; |
| 27 |
} |
| 28 |
else { |
| 29 |
$return = TRUE; |
| 30 |
} |
| 31 |
} |
| 32 |
else { |
| 33 |
$db = $this->dic->make('HC3_Database'); |
| 34 |
$prfx = $this->prfxStandalone; |
| 35 |
|
| 36 |
$sql = "SELECT * FROM {$prfx}locations"; |
| 37 |
$oldLocations = $db->query( $sql ); |
| 38 |
if( $oldLocations ){ |
| 39 |
$return = TRUE; |
| 40 |
} |
| 41 |
else { |
| 42 |
$return = FALSE; |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
return $return; |
| 47 |
} |
| 48 |
|
| 49 |
public function findOldData() |
| 50 |
{ |
| 51 |
$oldLocations = $oldEmployees = $oldShifts = $oldUsers = array(); |
| 52 |
|
| 53 |
if( defined('WPINC') ){ |
| 54 |
global $wpdb; |
| 55 |
$prfx = $wpdb->prefix . $this->prfxWp; |
| 56 |
|
| 57 |
$sql = "SELECT * FROM {$prfx}locations"; |
| 58 |
$oldLocations = $wpdb->get_results( $sql, ARRAY_A ); |
| 59 |
|
| 60 |
$level = 1; |
| 61 |
$sql = "SELECT * FROM {$prfx}users WHERE level & $level"; |
| 62 |
$oldEmployees = $wpdb->get_results( $sql, ARRAY_A ); |
| 63 |
|
| 64 |
$sql = "SELECT * FROM {$prfx}shifts"; |
| 65 |
$oldShifts = $wpdb->get_results( $sql, ARRAY_A ); |
| 66 |
|
| 67 |
$importUsers = FALSE; |
| 68 |
} |
| 69 |
else { |
| 70 |
$db = $this->dic->make('HC3_Database'); |
| 71 |
$prfx = $this->prfxStandalone; |
| 72 |
|
| 73 |
$sql = "SELECT * FROM {$prfx}locations"; |
| 74 |
$oldLocations = $db->query( $sql ); |
| 75 |
|
| 76 |
$level = 1; |
| 77 |
$sql = "SELECT * FROM {$prfx}users WHERE level & $level"; |
| 78 |
$oldEmployees = $db->query( $sql ); |
| 79 |
|
| 80 |
$sql = "SELECT * FROM {$prfx}shifts"; |
| 81 |
$oldShifts = $db->query( $sql ); |
| 82 |
|
| 83 |
$importUsers = TRUE; |
| 84 |
} |
| 85 |
|
| 86 |
$return = array( $oldLocations, $oldEmployees, $oldShifts, $importUsers ); |
| 87 |
return $return; |
| 88 |
} |
| 89 |
} |