@@ -7,7 +7,7 @@ class dsEventCalendarPackage extends Package
7
7
8
8
protected $ pkgHandle = 'dsEventCalendar ' ;
9
9
protected $ appVersionRequired = '5.5.0 ' ;
10
- protected $ pkgVersion = '3.0.3 ' ;
10
+ protected $ pkgVersion = '3.1.0 ' ;
11
11
12
12
public function getPackageDescription ()
13
13
{
@@ -30,13 +30,18 @@ public function install()
30
30
public function upgrade ()
31
31
{
32
32
$ currentVersion = $ this ->getPackageVersion ();
33
+ $ majorVersion = explode (". " , $ currentVersion );
34
+ $ majorVersion = $ majorVersion [0 ];
33
35
parent ::upgrade ();
34
- $ this ->update2to3 ();
36
+ if ($ majorVersion == 2 ) {
37
+ $ this ->update2to3 ();
38
+ }
35
39
$ this ->installSP ($ this , $ currentVersion );
36
40
$ this ->installSettings ();
37
41
}
38
42
39
- private function update2to3 (){
43
+ private function update2to3 ()
44
+ {
40
45
$ p4 = SinglePage::getByPath ('/dashboard/event_calendar/list_event ' );
41
46
42
47
if (is_object ($ p4 )) {
@@ -66,16 +71,16 @@ private function installSP($pkg)
66
71
$ p2 ->update (array ('cName ' => t ('Calendars list ' ), 'cDescription ' => '' ));
67
72
}
68
73
69
- $ p3 = SinglePage::add ('/dashboard/event_calendar/calendar ' , $ pkg );
70
- if (is_object ($ p3 )) {
71
- $ p3 ->update (array ('cName ' => t ('Add / edit calendar ' ), 'cDescription ' => '' ));
72
- }
73
-
74
74
$ p4 = SinglePage::add ('/dashboard/event_calendar/list_event ' , $ pkg );
75
75
if (is_object ($ p4 )) {
76
76
$ p4 ->update (array ('cName ' => t ('Events list ' ), 'cDescription ' => '' ));
77
77
}
78
78
79
+ $ p3 = SinglePage::add ('/dashboard/event_calendar/calendar ' , $ pkg );
80
+ if (is_object ($ p3 )) {
81
+ $ p3 ->update (array ('cName ' => t ('Add / edit calendar ' ), 'cDescription ' => '' ));
82
+ }
83
+
79
84
$ p5 = SinglePage::add ('/dashboard/event_calendar/event ' , $ pkg );
80
85
if (is_object ($ p5 )) {
81
86
$ p5 ->update (array ('cName ' => t ('Add / edit event ' ), 'cDescription ' => '' ));
@@ -90,32 +95,127 @@ private function installSP($pkg)
90
95
if (is_object ($ p7 )) {
91
96
$ p7 ->update (array ('cName ' => t ('Settings ' ), 'cDescription ' => '' ));
92
97
}
98
+
99
+ // $p8 = SinglePage::add('/dashboard/event_calendar/help', $pkg);
100
+ // if (is_object($p8)) {
101
+ // $p8->update(array('cName' => t('Help'), 'cDescription' => ''));
102
+ // }
93
103
}
94
104
95
105
private function installSettings ()
96
106
{
97
107
$ db = Loader::db ();
98
108
99
- $ sql = " INSERT IGNORE INTO dsEventCalendarSettings SET opt= 'lang' , value='en-gb' " ;
100
- $ db -> Execute ( $ sql ) ;
109
+ //if add new setting - increment this number
110
+ $ howManySettings = 6 ;
101
111
102
- // $sql = "INSERT IGNORE INTO dsEventCalendarSettings SET opt= 'formatTitle' , value='MMMM YYYY'";
103
- // $db->Execute($sql);
112
+ //check is settings are duplicate
113
+ $ sql = "select count(*) as count from dsEventCalendarSettings " ;
114
+ $ row = $ db ->GetRow ($ sql );
104
115
105
- $ sql = "INSERT IGNORE INTO dsEventCalendarSettings SET opt= 'formatEvent' , value='DD MMMM YYYY' " ;
106
- $ db ->Execute ($ sql );
116
+ if ($ row ['count ' ] > $ howManySettings ) {
117
+ $ this ->removeDuplicateSettings ();
118
+ }
107
119
108
- $ sql = "INSERT IGNORE INTO dsEventCalendarSettings SET opt= 'startFrom' , value='1' " ;
109
- $ db ->Execute ($ sql );
110
120
111
- $ sql = "INSERT IGNORE INTO dsEventCalendarSettings SET opt= 'eventsInDay' , value='3' " ;
121
+ // check is settings exits
122
+ $ sql = "select count(*) as count from dsEventCalendarSettings where opt = 'lang' " ;
123
+ $ row = $ db ->GetRow ($ sql );
124
+ if ($ row ['count ' ] == 0 ) {
125
+ $ sql = "INSERT IGNORE INTO dsEventCalendarSettings SET opt= 'lang' , value='en-gb' " ;
126
+ $ db ->Execute ($ sql );
127
+ }
128
+ $ sql = "select count(*) as count from dsEventCalendarSettings where opt= 'formatEvent' " ;
129
+ $ row = $ db ->GetRow ($ sql );
130
+ if ($ row ['count ' ] == 0 ) {
131
+ $ sql = "INSERT IGNORE INTO dsEventCalendarSettings SET opt= 'formatEvent' , value='DD MMMM YYYY' " ;
132
+ $ db ->Execute ($ sql );
133
+ }
134
+ $ sql = "select count(*) as count from dsEventCalendarSettings where opt= 'startFrom' " ;
135
+ $ row = $ db ->GetRow ($ sql );
136
+ if ($ row ['count ' ] == 0 ) {
137
+ $ sql = "INSERT IGNORE INTO dsEventCalendarSettings SET opt= 'startFrom' , value='1' " ;
138
+ $ db ->Execute ($ sql );
139
+ }
140
+ $ sql = "select count(*) as count from dsEventCalendarSettings where opt= 'eventsInDay' " ;
141
+ $ row = $ db ->GetRow ($ sql );
142
+ if ($ row ['count ' ] == 0 ) {
143
+ $ sql = "INSERT IGNORE INTO dsEventCalendarSettings SET opt= 'eventsInDay' , value='3' " ;
144
+ $ db ->Execute ($ sql );
145
+ }
146
+ $ sql = "select count(*) as count from dsEventCalendarSettings where opt= 'default_color' " ;
147
+ $ row = $ db ->GetRow ($ sql );
148
+ if ($ row ['count ' ] == 0 ) {
149
+ $ sql = "INSERT IGNORE INTO dsEventCalendarSettings SET opt= 'default_color' , value='#808080' " ;
150
+ $ db ->Execute ($ sql );
151
+ }
152
+ $ sql = "select count(*) as count from dsEventCalendarSettings where opt= 'timeFormat' " ;
153
+ $ row = $ db ->GetRow ($ sql );
154
+ if ($ row ['count ' ] == 0 ) {
155
+ $ sql = "INSERT IGNORE INTO dsEventCalendarSettings SET opt= 'timeFormat' , value='HH:mm' " ;
156
+ $ db ->Execute ($ sql );
157
+ }
158
+ }
159
+
160
+ private function removeDuplicateSettings ()
161
+ {
162
+ $ db = Loader::db ();
163
+ $ settings = array ();
164
+
165
+ $ sql = "select * from dsEventCalendarSettings where opt = 'lang' " ;
166
+ $ row = $ db ->GetRow ($ sql );
167
+ array_push ($ settings , array (
168
+ 'opt ' => $ row ['opt ' ],
169
+ 'value ' => $ row ['value ' ]
170
+ ));
171
+
172
+ $ sql = "select * from dsEventCalendarSettings where opt= 'formatEvent' " ;
173
+ $ row = $ db ->GetRow ($ sql );
174
+ array_push ($ settings , array (
175
+ 'opt ' => $ row ['opt ' ],
176
+ 'value ' => $ row ['value ' ]
177
+ ));
178
+ $ sql = "select * from dsEventCalendarSettings where opt= 'startFrom' " ;
179
+ $ row = $ db ->GetRow ($ sql );
180
+ array_push ($ settings , array (
181
+ 'opt ' => $ row ['opt ' ],
182
+ 'value ' => $ row ['value ' ]
183
+ ));
184
+
185
+ $ sql = "select * from dsEventCalendarSettings where opt= 'eventsInDay' " ;
186
+ $ row = $ db ->GetRow ($ sql );
187
+ array_push ($ settings , array (
188
+ 'opt ' => $ row ['opt ' ],
189
+ 'value ' => $ row ['value ' ]
190
+ ));
191
+ $ sql = "select * from dsEventCalendarSettings where opt= 'default_color' " ;
192
+ $ row = $ db ->GetRow ($ sql );
193
+ array_push ($ settings , array (
194
+ 'opt ' => $ row ['opt ' ],
195
+ 'value ' => $ row ['value ' ]
196
+ ));
197
+
198
+ $ sql = "select * from dsEventCalendarSettings where opt= 'timeFormat' " ;
199
+ $ row = $ db ->GetRow ($ sql );
200
+ array_push ($ settings , array (
201
+ 'opt ' => $ row ['opt ' ],
202
+ 'value ' => $ row ['value ' ]
203
+ ));
204
+
205
+ //clear table
206
+ $ sql = "TRUNCATE dsEventCalendarSettings " ;
112
207
$ db ->Execute ($ sql );
113
208
114
- $ sql = "INSERT IGNORE INTO dsEventCalendarSettings SET opt= 'default_color' , value='#808080' " ;
209
+
210
+ //add unique index
211
+ $ sql = "ALTER TABLE dsEventCalendarSettings ADD UNIQUE INDEX dsOptUnique (opt); " ;
115
212
$ db ->Execute ($ sql );
116
213
117
- // $sql = "INSERT IGNORE INTO dsEventCalendarSettings SET opt= 'default_name' , value='Default'";
118
- // $db->Execute($sql);
214
+ foreach ($ settings as $ s )
215
+ {
216
+ $ sql = "INSERT IGNORE INTO dsEventCalendarSettings SET opt= ' " .$ s ['opt ' ]."' , value=' " .$ s ['value ' ]."' " ;
217
+ $ db ->Execute ($ sql );
218
+ }
119
219
}
120
220
}
121
221
0 commit comments