| 1 |
<?php if (! defined('ABSPATH')) exit; // Exit if accessed directly |
| 2 |
class SH4_ShiftTypes_Migration |
| 3 |
{ |
| 4 |
public $dbForge; |
| 5 |
public $migrationService; |
| 6 |
|
| 7 |
public function __construct( |
| 8 |
HC3_Hooks $hooks, |
| 9 |
HC3_MigrationService $migrationService, |
| 10 |
|
| 11 |
HC3_Database_DbForge $dbForge = NULL |
| 12 |
) |
| 13 |
{ |
| 14 |
$this->dbForge = $dbForge; |
| 15 |
$this->migrationService = $migrationService; |
| 16 |
} |
| 17 |
|
| 18 |
public function up() |
| 19 |
{ |
| 20 |
$currentVersion = $this->migrationService->getVersion( 'shifttypes' ); |
| 21 |
|
| 22 |
if( $currentVersion < 1 ){ |
| 23 |
$this->version1(); |
| 24 |
$this->migrationService->saveVersion( 'shifttypes', 1 ); |
| 25 |
} |
| 26 |
} |
| 27 |
|
| 28 |
public function version1() |
| 29 |
{ |
| 30 |
if( $this->dbForge ){ |
| 31 |
$this->dbForge->add_field( |
| 32 |
array( |
| 33 |
'id' => array( |
| 34 |
'type' => 'INT', |
| 35 |
'null' => FALSE, |
| 36 |
'unsigned' => TRUE, |
| 37 |
'auto_increment' => TRUE |
| 38 |
), |
| 39 |
'title' => array( |
| 40 |
'type' => 'VARCHAR(255)', |
| 41 |
'null' => FALSE, |
| 42 |
), |
| 43 |
'starts_at' => array( |
| 44 |
'type' => 'INT', |
| 45 |
'null' => FALSE, |
| 46 |
), |
| 47 |
'ends_at' => array( |
| 48 |
'type' => 'INT', |
| 49 |
'null' => FALSE, |
| 50 |
), |
| 51 |
'break_starts_at' => array( |
| 52 |
'type' => 'INT', |
| 53 |
'null' => TRUE, |
| 54 |
), |
| 55 |
'break_ends_at' => array( |
| 56 |
'type' => 'INT', |
| 57 |
'null' => TRUE, |
| 58 |
), |
| 59 |
'range' => array( |
| 60 |
'type' => 'VARCHAR(16)', |
| 61 |
'null' => FALSE, |
| 62 |
'default' => SH4_ShiftTypes_Model::RANGE_HOURS, |
| 63 |
), |
| 64 |
) |
| 65 |
); |
| 66 |
$this->dbForge->add_key('id', TRUE); |
| 67 |
$this->dbForge->create_table('shifttypes'); |
| 68 |
} |
| 69 |
} |
| 70 |
} |