PluginProbe
ShiftController Employee Shift Scheduling / 4.9.26
ShiftController Employee Shift Scheduling v4.9.26
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.26, at sh4/app/migration.php

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