PluginProbe
ShiftController Employee Shift Scheduling / 4.9.76
ShiftController Employee Shift Scheduling v4.9.76
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.76, at sh4/app/migration.php

135 lines 4.8 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
71 if( false && defined('HC3_DEV_INSTALL') ){
72 $numOfTestEmployees = 500;
73 for( $ii = 1; $ii <= $numOfTestEmployees; $ii++ ){
74 $employeesIds[] = $this->employeesCommand->create( 'Employee ' . $ii );
75 }
76 }
77 else {
78 $employeesIds[] = $this->employeesCommand->create( 'George' );
79 $employeesIds[] = $this->employeesCommand->create( 'Karen' );
80 $employeesIds[] = $this->employeesCommand->create( 'Sarah' );
81 }
82
83 $holidaysShiftType = $this->shiftTypesQuery->findById( $holidaysId );
84 $allDayShiftType = $this->shiftTypesQuery->findById( $allDayId );
85
86 $timeoffCalendar = $this->calendarsQuery->findById( $timeoffId );
87 $this->appCommand->addShiftTypeToCalendar( $holidaysShiftType, $timeoffCalendar );
88 $this->appCommand->addShiftTypeToCalendar( $allDayShiftType, $timeoffCalendar );
89
90 $calendars = $this->calendarsQuery->findManyActiveById( $calendarsIds );
91 $employees = $this->employeesQuery->findManyActiveById( $employeesIds );
92 $shiftTypes = $this->shiftTypesQuery->findManyById( $shiftTypesIds );
93
94 $openShiftEmployee = $this->employeesQuery->findById( 0 );
95 $customTimeShiftType = $this->shiftTypesQuery->findById( 0 );
96
97 reset( $calendars );
98 foreach( $calendars as $calendar ){
99 reset( $shiftTypes );
100 foreach( $shiftTypes as $shiftType ){
101 $this->appCommand->addShiftTypeToCalendar( $shiftType, $calendar );
102 }
103 $this->appCommand->addShiftTypeToCalendar( $customTimeShiftType, $calendar );
104 }
105
106 reset( $calendars );
107 foreach( $calendars as $calendar ){
108 reset( $employees );
109 foreach( $employees as $employee ){
110 $this->appCommand->addEmployeeToCalendar( $employee, $calendar );
111 }
112 $this->appCommand->addEmployeeToCalendar( $openShiftEmployee, $calendar );
113 }
114
115 reset( $employees );
116 foreach( $employees as $employee ){
117 $this->appCommand->addEmployeeToCalendar( $employee, $timeoffCalendar );
118 }
119
120 $hasVersion3 = $this->upgradeQuery->hasVersion3();
121 if( defined('HC3_DEV_INSTALL') ){
122 $hasVersion3 = false;
123 }
124
125 if( $hasVersion3 ){
126 list( $oldLocations, $oldEmployees, $oldShifts, $importUsers ) = $this->upgradeQuery->findOldData();
127 $this->upgradeCommand->upgrade( $oldLocations, $oldEmployees, $oldShifts, $importUsers );
128 }
129 else {
130 }
131 }
132 catch( HC3_ExceptionArray $e ){
133 }
134 }
135 }