~xibo-maintainers/xibo/tempel

« back to all changes in this revision

Viewing changes to install/database/20.php

  • Committer: Dan Garner
  • Date: 2015-09-29 15:16:59 UTC
  • mto: (454.2.11) (471.2.2)
  • mto: This revision was merged to the branch mainline in revision 468.
  • Revision ID: git-v1:ae24387a7b1397750b6ec86d0f286373da05eb16
Fixed Display Version Information Form (not showing media name)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
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');
 
7
 
 
8
class Step20 extends UpgradeStep
 
9
{
 
10
        public function Boot()
 
11
        {
 
12
                $db = &$this->db;
 
13
 
 
14
                // Will need to add some upgrade PHP to create a DisplayGroup (+ link record) for every Currently existing display.
 
15
                $dg = new DisplayGroup($db);
 
16
 
 
17
                // Get all displays
 
18
                $SQL = "SELECT DisplayID, Display FROM display";
 
19
                
 
20
                if (!$result = $db->query($SQL))
 
21
                {
 
22
                        reportError('20.php', "Error creating display groups");
 
23
                }
 
24
                
 
25
                while ($row = $db->get_assoc_row($result))
 
26
                {
 
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']);
 
30
 
 
31
                    $displayGroupID     = $dg->Add($display, 1);
 
32
 
 
33
                    $dg->Link($displayGroupID, $displayID);
 
34
                }
 
35
 
 
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();
 
39
 
 
40
                // Create groups for all current users
 
41
                $this->UpdateUserGroups();
 
42
 
 
43
                return true;
 
44
        }
 
45
 
 
46
        /**
 
47
         * Updates all schedule records with the correct display group id
 
48
         */
 
49
        private function UpdateSchedules()
 
50
        {
 
51
 
 
52
 
 
53
            // Get all schedules
 
54
            $SQL = "SELECT EventID, DisplayGroupIDs FROM schedule WHERE DisplayGroupIDs <> ''";
 
55
 
 
56
            if (!$result = $db->query($SQL))
 
57
            {
 
58
                reportError('20.php', "Error getting Schedules" . $db->error());
 
59
            }
 
60
 
 
61
            while ($row = $db->get_assoc_row($result))
 
62
            {
 
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']);
 
66
 
 
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";
 
72
 
 
73
                if (!$dgResult = $db->query($SQL))
 
74
                {
 
75
                    reportError('20.php', "Error getting Display Groups" . $db->error());
 
76
                }
 
77
 
 
78
                $displayGroupIDs = array();
 
79
 
 
80
                while ($row = $db->get_assoc_row($dgResult))
 
81
                {
 
82
                    $displayGroupIDs[] = \Xibo\Helper\Sanitize::int($row['DisplayGroupID']);
 
83
                }
 
84
 
 
85
                $displayGroupIDs = implode(',', $displayGroupIDs);
 
86
 
 
87
                // Update the schedule with the new IDs
 
88
                $SQL = "UPDATE schedule SET DisplayGroupIDs = '%s' WHERE EventID = %d";
 
89
                $SQL = sprintf($SQL, $displayGroupIDs, $eventID);
 
90
 
 
91
                if (!$db->query($SQL))
 
92
                {
 
93
                    reportError('20.php', "Error updating schedules." . $db->error());
 
94
                }
 
95
            }
 
96
 
 
97
            // Get all schedule details
 
98
            $SQL = "SELECT Schedule_DetailID, DisplayGroupID FROM schedule_detail";
 
99
 
 
100
            if (!$result = $db->query($SQL))
 
101
            {
 
102
                reportError('20.php', "Error getting Schedule Details" . $db->error());
 
103
            }
 
104
 
 
105
            while ($row = $db->get_assoc_row($result))
 
106
            {
 
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']);
 
110
 
 
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";
 
116
 
 
117
                if (!$dgResult = $db->query($SQL))
 
118
                {
 
119
                    reportError('20.php', "Error getting Display Groups. " . $db->error());
 
120
                }
 
121
 
 
122
                $row = $db->get_assoc_row($dgResult);
 
123
 
 
124
                $displayGroupID = \Xibo\Helper\Sanitize::int($row['DisplayGroupID']);
 
125
 
 
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);
 
129
 
 
130
                if (!$db->query($SQL))
 
131
                {
 
132
                    reportError('20.php', "Error updating schedule_detail." . $db->error());
 
133
                }
 
134
            }
 
135
        }
 
136
 
 
137
        /**
 
138
         * We need to update the user groups
 
139
         */
 
140
        private function UpdateUserGroups()
 
141
        {
 
142
 
 
143
 
 
144
            // Get all the current users in the system
 
145
            $SQL = "SELECT UserID, groupID, UserName FROM `user`";
 
146
 
 
147
            if (!$result = $db->query($SQL))
 
148
            {
 
149
                reportError('20.php', "Error creating user groups" . $db->error());
 
150
            }
 
151
 
 
152
            while ($row = $db->get_assoc_row($result))
 
153
            {
 
154
                // For each display create a display group and link it to the display
 
155
                $ugid           = 0;
 
156
                $userID         = \Xibo\Helper\Sanitize::int($row['UserID']);
 
157
                $groupID        = \Xibo\Helper\Sanitize::int($row['groupID']);
 
158
                $username       = \Xibo\Helper\Sanitize::string($row['UserName']);
 
159
 
 
160
                $ug = new UserGroup($db);
 
161
 
 
162
                // For each one create a user specific group
 
163
                if (!$ugId = $ug->Add($username, 1))
 
164
                {
 
165
                    reportError('20.php', "Error creating user groups" . $db->error());
 
166
                }
 
167
 
 
168
                // Link to the users own userspecific group and also to the one they were already on
 
169
                $ug->Link($ugId, $userID);
 
170
 
 
171
                $ug->Link($groupID, $userID);
 
172
            }
 
173
        }
 
174
}
 
175
?>
 
 
b'\\ No newline at end of file'