3
// Will need to include the Data classes.
4
require_once("lib/data/data.class.php");
5
require_once('lib/data/displaygroup.data.class.php');
6
require_once('lib/data/usergroup.data.class.php');
8
class Step20 extends UpgradeStep
10
public function Boot()
14
// Will need to add some upgrade PHP to create a DisplayGroup (+ link record) for every Currently existing display.
15
$dg = new DisplayGroup($db);
18
$SQL = "SELECT DisplayID, Display FROM display";
20
if (!$result = $db->query($SQL))
22
reportError('20.php', "Error creating display groups");
25
while ($row = $db->get_assoc_row($result))
27
// For each display create a display group and link it to the display
28
$displayID = \Xibo\Helper\Sanitize::int($row['DisplayID']);
29
$display = \Xibo\Helper\Sanitize::string($row['Display']);
31
$displayGroupID = $dg->Add($display, 1);
33
$dg->Link($displayGroupID, $displayID);
36
// We also need to do a number on the schedule records
37
// Each schedule record needs to be altered so that the displayID_list now reflects the displayGroupIDs
38
$this->UpdateSchedules();
40
// Create groups for all current users
41
$this->UpdateUserGroups();
47
* Updates all schedule records with the correct display group id
49
private function UpdateSchedules()
54
$SQL = "SELECT EventID, DisplayGroupIDs FROM schedule WHERE DisplayGroupIDs <> ''";
56
if (!$result = $db->query($SQL))
58
reportError('20.php', "Error getting Schedules" . $db->error());
61
while ($row = $db->get_assoc_row($result))
63
// For each display create a display group and link it to the display
64
$eventID = \Xibo\Helper\Sanitize::int($row['EventID']);
65
$displayGroupIDs = \Xibo\Helper\Sanitize::string($row['DisplayGroupIDs']);
67
// For the display ids in the list make us up a comma seperated list of display groups
68
$SQL = "SELECT displaygroup.DisplayGroupID FROM displaygroup ";
69
$SQL .= " INNER JOIN lkdisplaydg ON lkdisplaydg.DisplayGroupID = displaygroup.DisplayGroupID ";
70
$SQL .= sprintf("WHERE lkdisplaydg.DisplayID IN (%s)", $displayGroupIDs);
71
$SQL .= " AND IsDisplaySpecific = 1";
73
if (!$dgResult = $db->query($SQL))
75
reportError('20.php', "Error getting Display Groups" . $db->error());
78
$displayGroupIDs = array();
80
while ($row = $db->get_assoc_row($dgResult))
82
$displayGroupIDs[] = \Xibo\Helper\Sanitize::int($row['DisplayGroupID']);
85
$displayGroupIDs = implode(',', $displayGroupIDs);
87
// Update the schedule with the new IDs
88
$SQL = "UPDATE schedule SET DisplayGroupIDs = '%s' WHERE EventID = %d";
89
$SQL = sprintf($SQL, $displayGroupIDs, $eventID);
91
if (!$db->query($SQL))
93
reportError('20.php', "Error updating schedules." . $db->error());
97
// Get all schedule details
98
$SQL = "SELECT Schedule_DetailID, DisplayGroupID FROM schedule_detail";
100
if (!$result = $db->query($SQL))
102
reportError('20.php', "Error getting Schedule Details" . $db->error());
105
while ($row = $db->get_assoc_row($result))
107
// For each display create a display group and link it to the display
108
$eventID = \Xibo\Helper\Sanitize::int($row['Schedule_DetailID']);
109
$displayGroupID = \Xibo\Helper\Sanitize::int($row['DisplayGroupID']);
111
// For the display ids in the list make us up a comma seperated list of display groups
112
$SQL = "SELECT displaygroup.DisplayGroupID FROM displaygroup ";
113
$SQL .= " INNER JOIN lkdisplaydg ON lkdisplaydg.DisplayGroupID = displaygroup.DisplayGroupID ";
114
$SQL .= sprintf("WHERE lkdisplaydg.DisplayID = %d", $displayGroupID);
115
$SQL .= " AND IsDisplaySpecific = 1";
117
if (!$dgResult = $db->query($SQL))
119
reportError('20.php', "Error getting Display Groups. " . $db->error());
122
$row = $db->get_assoc_row($dgResult);
124
$displayGroupID = \Xibo\Helper\Sanitize::int($row['DisplayGroupID']);
126
// Update the schedule with the new IDs
127
$SQL = "UPDATE schedule_detail SET DisplayGroupID = %d WHERE schedule_detailID = %d";
128
$SQL = sprintf($SQL, $displayGroupID, $eventID);
130
if (!$db->query($SQL))
132
reportError('20.php', "Error updating schedule_detail." . $db->error());
138
* We need to update the user groups
140
private function UpdateUserGroups()
144
// Get all the current users in the system
145
$SQL = "SELECT UserID, groupID, UserName FROM `user`";
147
if (!$result = $db->query($SQL))
149
reportError('20.php', "Error creating user groups" . $db->error());
152
while ($row = $db->get_assoc_row($result))
154
// For each display create a display group and link it to the display
156
$userID = \Xibo\Helper\Sanitize::int($row['UserID']);
157
$groupID = \Xibo\Helper\Sanitize::int($row['groupID']);
158
$username = \Xibo\Helper\Sanitize::string($row['UserName']);
160
$ug = new UserGroup($db);
162
// For each one create a user specific group
163
if (!$ugId = $ug->Add($username, 1))
165
reportError('20.php', "Error creating user groups" . $db->error());
168
// Link to the users own userspecific group and also to the one they were already on
169
$ug->Link($ugId, $userID);
171
$ug->Link($groupID, $userID);
b'\\ No newline at end of file'