| 1 |
<?php if (! defined('ABSPATH')) exit; // Exit if accessed directly |
| 2 |
class SH4_Shifts_Migration |
| 3 |
{ |
| 4 |
public $dbForge, $migrationService; |
| 5 |
|
| 6 |
public function __construct( |
| 7 |
HC3_Hooks $hooks, |
| 8 |
HC3_MigrationService $migrationService, |
| 9 |
HC3_Database_DbForge $dbForge = NULL |
| 10 |
) |
| 11 |
{ |
| 12 |
$this->dbForge = $dbForge; |
| 13 |
$this->migrationService = $migrationService; |
| 14 |
} |
| 15 |
|
| 16 |
public function up() |
| 17 |
{ |
| 18 |
$currentVersion = $this->migrationService->getVersion( 'shifts' ); |
| 19 |
|
| 20 |
if( $currentVersion < 1 ){ |
| 21 |
$this->version1(); |
| 22 |
$this->migrationService->saveVersion( 'shifts', 1 ); |
| 23 |
} |
| 24 |
|
| 25 |
if( $currentVersion < 2 ){ |
| 26 |
$this->version2(); |
| 27 |
$this->migrationService->saveVersion( 'shifts', 2 ); |
| 28 |
} |
| 29 |
} |
| 30 |
|
| 31 |
public function version1() |
| 32 |
{ |
| 33 |
if( $this->dbForge ){ |
| 34 |
$this->dbForge->add_field( |
| 35 |
array( |
| 36 |
'id' => array( |
| 37 |
'type' => 'INT', |
| 38 |
'null' => FALSE, |
| 39 |
'unsigned' => TRUE, |
| 40 |
'auto_increment' => TRUE |
| 41 |
), |
| 42 |
|
| 43 |
'starts_at' => array( |
| 44 |
'type' => 'BIGINT', |
| 45 |
'null' => FALSE, |
| 46 |
), |
| 47 |
'ends_at' => array( |
| 48 |
'type' => 'BIGINT', |
| 49 |
'null' => FALSE, |
| 50 |
), |
| 51 |
|
| 52 |
'break_starts_at' => array( |
| 53 |
'type' => 'BIGINT', |
| 54 |
'null' => TRUE, |
| 55 |
), |
| 56 |
'break_ends_at' => array( |
| 57 |
'type' => 'BIGINT', |
| 58 |
'null' => TRUE, |
| 59 |
), |
| 60 |
|
| 61 |
'status' => array( |
| 62 |
'type' => 'VARCHAR(16)', |
| 63 |
'null' => FALSE, |
| 64 |
'default' => 'active', |
| 65 |
), |
| 66 |
'calendar_id' => array( |
| 67 |
'type' => 'INT', |
| 68 |
'null' => FALSE, |
| 69 |
), |
| 70 |
'employee_id' => array( |
| 71 |
'type' => 'INT', |
| 72 |
'null' => FALSE, |
| 73 |
), |
| 74 |
) |
| 75 |
); |
| 76 |
$this->dbForge->add_key('id', TRUE); |
| 77 |
$this->dbForge->create_table('shifts'); |
| 78 |
} |
| 79 |
} |
| 80 |
|
| 81 |
public function version2() |
| 82 |
{ |
| 83 |
if( $this->dbForge ){ |
| 84 |
$this->dbForge->add_field( |
| 85 |
array( |
| 86 |
'id' => array( |
| 87 |
'type' => 'INT', |
| 88 |
'null' => FALSE, |
| 89 |
'unsigned' => TRUE, |
| 90 |
'auto_increment' => TRUE |
| 91 |
), |
| 92 |
'parent_id' => array( |
| 93 |
'type' => 'INT', |
| 94 |
'null' => FALSE, |
| 95 |
), |
| 96 |
'meta_key' => array( |
| 97 |
'type' => 'VARCHAR(255)', |
| 98 |
'null' => FALSE, |
| 99 |
'default' => 'text' |
| 100 |
), |
| 101 |
'meta_value' => array( |
| 102 |
'type' => 'TEXT', |
| 103 |
'null' => TRUE, |
| 104 |
), |
| 105 |
) |
| 106 |
); |
| 107 |
$this->dbForge->add_key('id', TRUE); |
| 108 |
$this->dbForge->create_table('shifts_meta'); |
| 109 |
} |
| 110 |
} |
| 111 |
} |