PluginProbe
ShiftController Employee Shift Scheduling / 4.9.66
ShiftController Employee Shift Scheduling v4.9.66
4.9.97 4.9.96 4.9.95 4.9.74 4.9.75 4.9.76 4.9.77 4.9.78 4.9.84 4.9.85 4.9.87 4.9.91 4.9.92 trunk 2.1.0 2.1.1 2.1.2 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 3.2.4 All 38 releases
shiftcontroller / sh4 / app / migration.php

migration.php in ShiftController Employee Shift Scheduling 4.9.66, at sh4/app/migration.php

123 lines 4.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php if (! defined('ABSPATH')) exit; // Exit if accessed directly
2 class SH4_App_Migration
3 {
4 public $migrationService, $appCommand, $upgradeQuery, $upgradeCommand, $calendarsCommand, $calendarsQuery, $shiftTypesCommand, $shiftTypesQuery, $employeesCommand, $employeesQuery;
5
6 public function __construct(
7 HC3_Hooks $hooks,
8 HC3_MigrationService $migrationService,
9
10 SH4_App_Command $appCommand,
11
12 SH4_Upgrade3_Query $upgradeQuery,
13 SH4_Upgrade3_Command $upgradeCommand,
14
15 SH4_Calendars_Command $calendarsCommand,
16 SH4_Calendars_Query $calendarsQuery,
17
18 SH4_ShiftTypes_Command $shiftTypesCommand,
19 SH4_ShiftTypes_Query $shiftTypesQuery,
20
21 SH4_Employees_Command $employeesCommand,
22 SH4_Employees_Query $employeesQuery
23 )
24 {
25 $this->migrationService = $migrationService;
26
27 $this->appCommand = $hooks->wrap( $appCommand );
28
29 $this->upgradeQuery = $upgradeQuery;
30 $this->upgradeCommand = $upgradeCommand;
31
32 $this->calendarsCommand = $hooks->wrap( $calendarsCommand );
33 $this->calendarsQuery = $hooks->wrap( $calendarsQuery );
34
35 $this->shiftTypesCommand = $hooks->wrap( $shiftTypesCommand );
36 $this->shiftTypesQuery = $hooks->wrap( $shiftTypesQuery );
37
38 $this->employeesCommand = $hooks->wrap( $employeesCommand );
39 $this->employeesQuery = $hooks->wrap( $employeesQuery );
40 }
41
42 public function up()
43 {
44 $currentVersion = $this->migrationService->getVersion( 'app' );
45
46 if( $currentVersion < 1 ){
47 $this->version1();
48 $this->migrationService->saveVersion( 'app', 1 );
49 }
50 }
51
52 public function version1()
53 {
54 try {
55 $shiftTypesIds = array();
56 $shiftTypesIds[] = $this->shiftTypesCommand->createHours( 'Full time', 9*60*60, 18*60*60, 13*60*60, 14*60*60 );
57 $shiftTypesIds[] = $this->shiftTypesCommand->createHours( 'Morning', 9*60*60, 13*60*60 );
58 $shiftTypesIds[] = $this->shiftTypesCommand->createHours( 'Evening', 17*60*60, 21*60*60 );
59
60 $holidaysId = $this->shiftTypesCommand->createDays( 'Many days', 2, 30 );
61 $allDayId = $this->shiftTypesCommand->createHours( 'Full day', 0, 24*60*60 );
62
63 $calendarsIds = array();
64 $calendarsIds[] = $this->calendarsCommand->create( 'Barista', '#cbe86b' );
65 $calendarsIds[] = $this->calendarsCommand->create( 'Security', '#ffb3a7' );
66 $calendarsIds[] = $this->calendarsCommand->create( 'Waiter', '#89c4f4' );
67 $timeoffId = $this->calendarsCommand->create( 'Time off', '#a9a9a9', NULL, SH4_Calendars_Model::TYPE_TIMEOFF );
68
69 $employeesIds = array();
70 $employeesIds[] = $this->employeesCommand->create( 'George' );
71 $employeesIds[] = $this->employeesCommand->create( 'Karen' );
72 $employeesIds[] = $this->employeesCommand->create( 'Sarah' );
73
74 $holidaysShiftType = $this->shiftTypesQuery->findById( $holidaysId );
75 $allDayShiftType = $this->shiftTypesQuery->findById( $allDayId );
76
77 $timeoffCalendar = $this->calendarsQuery->findById( $timeoffId );
78 $this->appCommand->addShiftTypeToCalendar( $holidaysShiftType, $timeoffCalendar );
79 $this->appCommand->addShiftTypeToCalendar( $allDayShiftType, $timeoffCalendar );
80
81 $calendars = $this->calendarsQuery->findManyActiveById( $calendarsIds );
82 $employees = $this->employeesQuery->findManyActiveById( $employeesIds );
83 $shiftTypes = $this->shiftTypesQuery->findManyById( $shiftTypesIds );
84
85 $openShiftEmployee = $this->employeesQuery->findById( 0 );
86 $customTimeShiftType = $this->shiftTypesQuery->findById( 0 );
87
88 reset( $calendars );
89 foreach( $calendars as $calendar ){
90 reset( $shiftTypes );
91 foreach( $shiftTypes as $shiftType ){
92 $this->appCommand->addShiftTypeToCalendar( $shiftType, $calendar );
93 }
94 $this->appCommand->addShiftTypeToCalendar( $customTimeShiftType, $calendar );
95 }
96
97 reset( $calendars );
98 foreach( $calendars as $calendar ){
99 reset( $employees );
100 foreach( $employees as $employee ){
101 $this->appCommand->addEmployeeToCalendar( $employee, $calendar );
102 }
103 $this->appCommand->addEmployeeToCalendar( $openShiftEmployee, $calendar );
104 }
105
106 reset( $employees );
107 foreach( $employees as $employee ){
108 $this->appCommand->addEmployeeToCalendar( $employee, $timeoffCalendar );
109 }
110
111 $hasVersion3 = $this->upgradeQuery->hasVersion3();
112
113 if( $hasVersion3 ){
114 list( $oldLocations, $oldEmployees, $oldShifts, $importUsers ) = $this->upgradeQuery->findOldData();
115 $this->upgradeCommand->upgrade( $oldLocations, $oldEmployees, $oldShifts, $importUsers );
116 }
117 else {
118 }
119 }
120 catch( HC3_ExceptionArray $e ){
121 }
122 }
123 }