/
updatedb_helper.php
961 lines (874 loc) · 62.6 KB
/
updatedb_helper.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
<?PHP
/*
* LimeSurvey
* Copyright (C) 2007-2011 The LimeSurvey Project Team / Carsten Schmitz
* All rights reserved.
* License: GNU/GPL License v2 or later, see LICENSE.php
* LimeSurvey is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*
*/
// There will be a file for each database (accordingly named to the dbADO scheme)
// where based on the current database version the database is upgraded
// For this there will be a settings table which holds the last time the database was upgraded
/**
* @param integer $iOldDBVersion The previous database version
* @param boolean $bSilent Run update silently with no output - this checks if the update can be run silently at all. If not it will not run any updates at all.
*/
function db_upgrade_all($iOldDBVersion, $bSilent=false) {
/**
* If you add a new database version add any critical database version numbers to this array. See link
* @link https://manual.limesurvey.org/Database_versioning for explanations
* @var array $aCriticalDBVersions An array of cricital database version.
*/
$aCriticalDBVersions = array();
$aAllUpdates = range($iOldDBVersion+1,Yii::app()->getConfig('dbversionnumber'));
// If trying to update silenty check if it is really possible
if ($bSilent && (count(array_intersect($aCriticalDBVersions,$aAllUpdates))>0)){
return false;
}
/// This function does anything necessary to upgrade
/// older versions to match current functionality
global $modifyoutput;
Yii::app()->loadHelper('database');
$sUserTemplateRootDir = Yii::app()->getConfig('usertemplaterootdir');
$sStandardTemplateRootDir = Yii::app()->getConfig('standardtemplaterootdir');
$oDB = Yii::app()->getDb();
$oDB->schemaCachingDuration = 0; // Deactivate schema caching
Yii::app()->setConfig('Updating',true);
try{
/**
* Add table for notifications
* @since 2016-08-04
* @author Olle Haerstedt
*/
if ($iOldDBVersion < 259) {
$oTransaction = $oDB->beginTransaction();
$oDB->createCommand()->createTable('{{notifications}}', array(
'id' => 'pk',
'entity' => 'string(15) not null',
'entity_id' => 'integer not null',
'title' => 'string not null', // varchar(255) in postgres
'message' => 'text not null',
'status' => "string(15) not null default 'new' ",
'importance' => 'integer default 1',
'display_class' => "string(31) default 'default'",
'created' => 'datetime not null',
'first_read' => 'datetime null'
));
$oDB->createCommand()->createIndex('notif_index', '{{notifications}}', 'entity, entity_id, status', false);
$oDB->createCommand()->update('{{settings_global}}',array('stg_value'=>259),"stg_name='DBVersion'");
$oTransaction->commit();
}
if ($iOldDBVersion < 260) {
$oTransaction = $oDB->beginTransaction();
alterColumn('{{participant_attribute_names}}','defaultname',"string(255)",false);
alterColumn('{{participant_attribute_names_lang}}','attribute_name',"string(255)",false);
$oDB->createCommand()->update('{{settings_global}}',array('stg_value'=>260),"stg_name='DBVersion'");
$oTransaction->commit();
}
if ($iOldDBVersion < 261) {
$oTransaction = $oDB->beginTransaction();
/*
* The hash value of a notification is used to calculate uniqueness.
* @since 2016-08-10
* @author Olle Haerstedt
*/
addColumn('{{notifications}}', 'hash', 'string(64)');
$oDB->createCommand()->createIndex('notif_hash_index', '{{notifications}}', 'hash', false);
$oDB->createCommand()->update('{{settings_global}}',array('stg_value'=>261),"stg_name='DBVersion'");
$oTransaction->commit();
}
if ($iOldDBVersion < 262) {
$oTransaction = $oDB->beginTransaction();
alterColumn('{{settings_global}}','stg_value',"text",false);
$oDB->createCommand()->update('{{settings_global}}',array('stg_value'=>262),"stg_name='DBVersion'");
$oTransaction->commit();
}
if ($iOldDBVersion < 263) {
$oTransaction = $oDB->beginTransaction();
// Dummy version update for hash column in installation SQL.
$oDB->createCommand()->update('{{settings_global}}',array('stg_value'=>263),"stg_name='DBVersion'");
$oTransaction->commit();
}
/**
* Add seed column in all active survey tables
* Might take time to execute
* @since 2016-09-01
*/
if ($iOldDBVersion < 290) {
$oTransaction = $oDB->beginTransaction();
// Loop all surveys
$surveys = Survey::model()->findAll();
foreach ($surveys as $survey)
{
$prefix = Yii::app()->getDb()->tablePrefix;
$tableName = $prefix . 'survey_' . $survey->sid;
// If survey has active table, create seed column
$table = Yii::app()->db->schema->getTable($tableName);
if ($table)
{
if (!isset($table->columns['seed']))
{
Yii::app()->db->createCommand()->addColumn($tableName, 'seed', 'string(31)');
}
else
{
continue;
}
// RAND is RANDOM in Postgres
switch (Yii::app()->db->driverName)
{
case 'pgsql':
Yii::app()->db->createCommand("UPDATE $tableName SET seed = ROUND(RANDOM() * 10000000)")->execute();
break;
default:
Yii::app()->db->createCommand("UPDATE $tableName SET seed = ROUND(RAND() * 10000000, 0)")->execute();
break;
}
}
}
$oDB->createCommand()->update('{{settings_global}}',array('stg_value'=>290),"stg_name='DBVersion'");
$oTransaction->commit();
}
/**
* Plugin JSON config file
* @since 2016-08-22
*/
if ($iOldDBVersion < 291)
{
$oTransaction = $oDB->beginTransaction();
addColumn('{{plugins}}', 'version', 'string(32)');
$oDB->createCommand()->update('{{settings_global}}',array('stg_value'=>291),"stg_name='DBVersion'");
$oTransaction->commit();
}
/**
* Survey menue table
* @since 2017-07-03
*/
if ($iOldDBVersion < 293) {
$oTransaction = $oDB->beginTransaction();
createSurveyMenuTable293($oDB);
$oDB->createCommand()->update('{{settings_global}}',array('stg_value'=>293),"stg_name='DBVersion'");
$oTransaction->commit();
}
/**
* Survey menue table update
* @since 2017-07-03
*/
if ($iOldDBVersion < 294) {
$oTransaction = $oDB->beginTransaction();
$oDB->createCommand()->addColumn('{{surveymenu}}', 'position', "string(255) DEFAULT 'side'");
$oDB->createCommand()->truncateTable('{{surveymenu_entries}}');
$colsToAdd = array("id","menu_id","order","name","title","menu_title","menu_description","menu_icon","menu_icon_type","menu_class","menu_link","action","template","partial","classes","permission","permission_grade","data","getdatamethod","language","changed_at","changed_by","created_at","created_by");
$rowsToAdd = array(
array(1,1,1,'overview','Survey overview','Overview','Open general survey overview and quick action','list','fontawesome','','admin/survey/sa/view','','','','','','',NULL,'','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0),
array(2,1,2,'generalsettings','Edit survey general settings','General settings','Open general survey settings','gears','fontawesome','','','updatesurveylocalesettings','editLocalSettings_main_view','/admin/survey/subview/accordion/_generaloptions_panel','','surveysettings','read',NULL,'_generalTabEditSurvey','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0),
array(3,1,3,'surveytexts','Edit survey text elements','Survey texts','Edit survey text elements','file-text-o','fontawesome','','','updatesurveylocalesettings','editLocalSettings_main_view','/admin/survey/subview/tab_edit_view','','surveylocale','read',NULL,'_getTextEditData','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0),
array(4,1,4,'participants','Survey participants','Survey participants','Go to survey participant and token settings','user','fontawesome','','admin/tokens/sa/index/','','','','','surveysettings','update',NULL,'','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0),
array(5,1,4,'presentation','Presentation & navigation settings','Presentation','Edit presentation and navigation settings','eye-slash','fontawesome','','','updatesurveylocalesettings','editLocalSettings_main_view','/admin/survey/subview/accordion/_presentation_panel','','surveylocale','read',NULL,'_tabPresentationNavigation','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0),
array(6,1,5,'publication','Publication and access control settings','Publication & access','Edit settings for publicationa and access control','key','fontawesome','','','updatesurveylocalesettings','editLocalSettings_main_view','/admin/survey/subview/accordion/_publication_panel','','surveylocale','read',NULL,'_tabPublicationAccess','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0),
array(7,1,6,'surveypermissions','Edit surveypermissions','Survey permissions','Edit permissions for this survey','lock','fontawesome','','admin/surveypermission/sa/view/','','','','','surveysecurity','read',NULL,'','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0),
array(8,1,7,'tokens','Token handling','Participant tokens','Define how tokens should be treated or generated','users','fontawesome','','','updatesurveylocalesettings','editLocalSettings_main_view','/admin/survey/subview/accordion/_tokens_panel','','surveylocale','read',NULL,'_tabTokens','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0),
array(9,1,8,'quotas','Edit quotas','Survey quotas','Edit quotas for this survey.','tasks','fontawesome','','admin/quotas/sa/index/','','','','','quotas','read',NULL,'','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0),
array(10,1,9,'assessments','Edit assessments','Assessments','Edit and look at the asessements for this survey.','comment-o','fontawesome','','admin/assessments/sa/index/','','','','','assessments','read',NULL,'','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0),
array(11,1,10,'notification','Notification and data management settings','Data management','Edit settings for notification and data management','feed','fontawesome','','','updatesurveylocalesettings','editLocalSettings_main_view','/admin/survey/subview/accordion/_notification_panel','','surveylocale','read',NULL,'_tabNotificationDataManagement','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0),
array(12,1,11,'emailtemplates','Email templates','Email templates','Edit the templates for invitation, reminder and registration emails','envelope-square','fontawesome','','admin/emailtemplates/sa/index/','','','','','assessments','read',NULL,'','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0),
array(13,1,12,'panelintegration','Edit survey panel integration','Panel integration','Define panel integrations for your survey','link','fontawesome','','','updatesurveylocalesettings','editLocalSettings_main_view','/admin/survey/subview/accordion/_integration_panel','','surveylocale','read',NULL,'_tabPanelIntegration','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0),
array(14,1,13,'ressources','Add/Edit ressources to the survey','Ressources','Add/Edit ressources to the survey','file','fontawesome','','','updatesurveylocalesettings','editLocalSettings_main_view','/admin/survey/subview/accordion/_resources_panel','','surveylocale','read',NULL,'_tabResourceManagement','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0)
);
foreach($rowsToAdd as $row){
$oDB->createCommand()->insert('{{surveymenu_entries}}', array_combine($colsToAdd,$row));
}
$oDB->createCommand()->update('{{settings_global}}',array('stg_value'=>294),"stg_name='DBVersion'");
$oTransaction->commit();
}
/**
* Survey menue table update
* @since 2017-07-12
*/
if ($iOldDBVersion < 296) {
$oTransaction = $oDB->beginTransaction();
addColumn('{{surveymenu}}', 'user_id', "int DEFAULT NULL");
addColumn('{{surveymenu_entries}}', 'user_id', "int DEFAULT NULL");
$oDB->createCommand()->insert('{{surveymenu}}', array('id' => 2,'parent_id' => NULL,'survey_id' => NULL,'order' => 1,'level' => 0,'title' => 'quickmenu','description' => 'Quickmenu', 'position'=>'collapsed', 'changed_at' => date('Y-m-d H:i:s'),'changed_by' => 0,'created_at' => date('Y-m-d H:i:s'),'created_by' => 0));
$colsToAdd = array("id","menu_id","user_id","order","name","title","menu_title","menu_description","menu_icon","menu_icon_type","menu_class","menu_link","action","template","partial","classes","permission","permission_grade","data","getdatamethod","language","changed_at","changed_by","created_at","created_by");
$rowsToAdd = array(
array(15,2,NULL,1,'activateSurvey','Activate survey','Activate survey','Activate survey','play','fontawesome','','admin/survey/sa/activate','','','','','surveyactivation','update','{\"render\": {\"isActive\": false}}','','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0),
array(16,2,NULL,2,'deactivateSurvey','Stop this survey','Stop this survey','Stop this survey','stop','fontawesome','','admin/survey/sa/deactivate','','','','','surveyactivation','update','{\"render\": {\"isActive\": true}}','','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0),
array(17,2,NULL,3,'testSurvey','Go to survey','Go to survey','Go to survey','cog','fontawesome','','survey/index','','','','','','','{\"render\": {\"link\": {\"external\": true, \"data\": {\"sid\": [\"this\",\"sid\"], \"newtest\": \"Y\", \"lang\": [\"this\",\"language\"]}}}}','','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0),
array(18,2,NULL,4,'listQuestions','List questions','List questions','List questions','list','fontawesome','','admin/survey/sa/listquestions','','','','','surveycontent','read',NULL,'','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0),
array(19,2,NULL,5,'listQuestionGroups','List question groups','List question groups','List question groups','th-list','fontawesome','','admin/survey/sa/listquestiongroups','','','','','surveycontent','read',NULL,'','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0),
array(20,2,NULL,6,'generalsettings','Edit survey general settings','General settings','Open general survey settings','gears','fontawesome','','','updatesurveylocalesettings','editLocalSettings_main_view','/admin/survey/subview/accordion/_generaloptions_panel','','surveysettings','read',NULL,'_generalTabEditSurvey','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0),
array(21,2,NULL,7,'surveypermissions','Edit surveypermissions','Survey permissions','Edit permissions for this survey','lock','fontawesome','','admin/surveypermission/sa/view/','','','','','surveysecurity','read',NULL,'','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0),
array(22,2,NULL,8,'quotas','Edit quotas','Survey quotas','Edit quotas for this survey.','tasks','fontawesome','','admin/quotas/sa/index/','','','','','quotas','read',NULL,'','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0),
array(23,2,NULL,9,'assessments','Edit assessments','Assessments','Edit and look at the asessements for this survey.','comment-o','fontawesome','','admin/assessments/sa/index/','','','','','assessments','read',NULL,'','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0),
array(24,2,NULL,10,'emailtemplates','Email templates','Email templates','Edit the templates for invitation, reminder and registration emails','envelope-square','fontawesome','','admin/emailtemplates/sa/index/','','','','','surveylocale','read',NULL,'','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0),
array(25,2,NULL,11,'surveyLogicFile','Survey logic file','Survey logic file','Survey logic file','sitemap','fontawesome','','admin/expressions/sa/survey_logic_file/','','','','','surveycontent','read',NULL,'','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0),
array(26,2,NULL,12,'tokens','Token handling','Participant tokens','Define how tokens should be treated or generated','user','fontawesome','','','updatesurveylocalesettings','editLocalSettings_main_view','/admin/survey/subview/accordion/_tokens_panel','','surveylocale','read',NULL,'_tabTokens','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0),
array(27,2,NULL,13,'cpdb','Central participant database','Central participant database','Central participant database','users','fontawesome','','admin/participants/sa/displayParticipants','','','','','tokens','read','{render: {\"link\": {}}','','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0),
array(28,2,NULL,14,'responses','Responses','Responses','Responses','icon-browse','iconclass','','admin/responses/sa/browse/','','','','','responses','read','{\"render\": {\"isActive\": true}}','','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0),
array(29,2,NULL,15,'statistics','Statistics','Statistics','Statistics','bar-chart','fontawesome','','admin/statistics/sa/index/','','','','','statistics','read','{\"render\": {\"isActive\": true}}','','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0),
array(30,2,NULL,16,'reorder','Reorder questions/question groups','Reorder questions/question groups','Reorder questions/question groups','icon-organize','iconclass','','admin/survey/sa/organize/','','','','','surveycontent','update','{\"render\": {\"isActive\": false}}','','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0),
);
foreach($rowsToAdd as $row){
$combined = array_combine($colsToAdd,$row);
$oDB->createCommand()->insert('{{surveymenu_entries}}', $combined);
}
$oTransaction->commit();
}
/**
* Template tables
* @since 2017-07-12
*/
if ($iOldDBVersion < 298) {
$oTransaction = $oDB->beginTransaction();
upgradeTemplateTables298($oDB);
$oTransaction->commit();
$oDB->createCommand()->update('{{settings_global}}',array('stg_value'=>298),"stg_name='DBVersion'");
}
/**
* Template tables
* @since 2017-07-12
*/
if ($iOldDBVersion < 304) {
$oTransaction = $oDB->beginTransaction();
upgradeTemplateTables304($oDB);
$oTransaction->commit();
$oDB->createCommand()->update('{{settings_global}}',array('stg_value'=>304),"stg_name='DBVersion'");
}
/**
* Update to sidemenu rendering
*/
if ($iOldDBVersion < 305) {
$oTransaction = $oDB->beginTransaction();
$oDB->createCommand()->update('{{surveymenu_entries}}',
array('data'=> "{\"render\": {\"link\": {\"external\": true, \"data\": {\"sid\": [\"survey\",\"sid\"], \"newtest\": \"Y\", \"lang\": [\"survey\",\"language\"]}}}}"),
"id=17"
);
$oDB->createCommand()->update('{{surveymenu_entries}}',
array('data'=> "{\"render\": { \"link\": {\"data\": {\"surveyid\": [\"survey\",\"sid\"]}} } }"),
"id IN (1,4,7,9,10,12,18,19,21,22,23,24,25)"
);
$oDB->createCommand()->update('{{surveymenu_entries}}',
array('data'=> "{\"render\": {\"isActive\": false, \"link\": {\"data\": {\"surveyid\": [\"survey\",\"sid\"]}}}}"),
"id IN (15,30)"
);
$oDB->createCommand()->update('{{surveymenu_entries}}',
array('data'=> "{\"render\": {\"isActive\": true, \"link\": {\"data\": {\"surveyid\": [\"survey\",\"sid\"]}}}}"),
"id=16"
);
$oTransaction->commit();
$oDB->createCommand()->update('{{settings_global}}',array('stg_value'=>305),"stg_name='DBVersion'");
}
/**
* Template tables
* @since 2017-07-12
*/
if ($iOldDBVersion < 306) {
$oTransaction = $oDB->beginTransaction();
createSurveyGroupTables306($oDB);
$oTransaction->commit();
$oDB->createCommand()->update('{{settings_global}}',array('stg_value'=>306),"stg_name='DBVersion'");
}
/**
* User settings table
* @since 2016-08-29
*/
if ($iOldDBVersion < 307) {
$oTransaction = $oDB->beginTransaction();
if (tableExists('{settings_user}')) {
$oDB->createCommand()->dropTable('{{settings_user}}');
}
$oDB->createCommand()->createTable('{{settings_user}}', array(
'id' => 'int NOT NULL AUTO_INCREMENT',
'uid' => 'integer NOT NULL',
'entity' => 'string(15)',
'entity_id' => 'string(31)',
'stg_name' => 'string(63) not null',
'stg_value' => 'text',
'PRIMARY KEY (id)'
));
$oDB->createCommand()->update('{{settings_global}}',array('stg_value'=>307),"stg_name='DBVersion'");
$oTransaction->commit();
}
/*
* Change dbfieldnames to be more functional
*/
if ($iOldDBVersion < 308) {
$oTransaction = $oDB->beginTransaction();
$oDB->createCommand()->renameColumn('{{surveymenu_entries}}','order','ordering');
$oDB->createCommand()->renameColumn('{{surveymenu}}','order','ordering');
$oDB->createCommand()->update('{{settings_global}}',array('stg_value'=>308),"stg_name='DBVersion'");
$oTransaction->commit();
}
/*
* Add survey template editing to menu
*/
if ($iOldDBVersion < 309) {
$oTransaction = $oDB->beginTransaction();
$oDB->createCommand()->insert('{{surveymenu_entries}}',array_combine(
array(
"menu_id","ordering","name","title","menu_title","menu_description","menu_icon","menu_icon_type",
"menu_link","permission","permission_grade",
"data",
"language","changed_at","changed_by","created_at","created_by"),
array(
1,3,"template_options","Template options","Template options","Edit Template options for this survey","paint-brush","fontawesome",
"admin/templateoptions/sa/updatesurvey","surveysettings","read",
'{"render": {"link": { "pjaxed": false, "data": {"surveyid": ["survey","sid"], "gsid":["survey","gsid"]}}}}',
"en-GB",date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0
)
)
);
$oDB->createCommand()->update('{{settings_global}}',array('stg_value'=>309),"stg_name='DBVersion'");
$oTransaction->commit();
SurveymenuEntries::reorderMenu(1);
}
/*
* Reset all surveymenu tables, because there were too many errors
*/
if ($iOldDBVersion < 310) {
$oTransaction = $oDB->beginTransaction();
reCreateSurveyMenuTable310($oDB);
$oDB->createCommand()->update('{{settings_global}}',array('stg_value'=>310),"stg_name='DBVersion'");
$oTransaction->commit();
}
/*
* Add template settings to survey groups
*/
if ($iOldDBVersion < 311) {
$oTransaction = $oDB->beginTransaction();
addColumn('{{surveys_groups}}','template', "string(128) DEFAULT 'default'");
$oDB->createCommand()->update('{{settings_global}}',array('stg_value'=>311),"stg_name='DBVersion'");
$oTransaction->commit();
}
}
catch(Exception $e)
{
Yii::app()->setConfig('Updating',false);
$oTransaction->rollback();
// Activate schema caching
$oDB->schemaCachingDuration=3600;
// Load all tables of the application in the schema
$oDB->schema->getTables();
// clear the cache of all loaded tables
$oDB->schema->refresh();
//echo '<br /><br />'.gT('An non-recoverable error happened during the update. Error details:')."<p>".htmlspecialchars($e->getMessage()).'</p><br />';
Yii::app()->user->setFlash('error', gT('An non-recoverable error happened during the update. Error details:')."<p>".htmlspecialchars($e->getMessage()).'</p><br />');
return false;
}
// Load all tables of the application in the schema
$oDB->schema->getTables();
// clear the cache of all loaded tables
$oDB->schema->refresh();
$oDB->active = false;
$oDB->active = true;
// Force User model to refresh meta data (for updates from very old versions)
User::model()->refreshMetaData();
// Inform superadmin about update
$superadmins = User::model()->getSuperAdmins();
$currentDbVersion = $oDB->createCommand()->select('stg_value')->from('{{settings_global}}')->where("stg_name=:stg_name", array('stg_name'=>'DBVersion'))->queryRow();
Notification::broadcast(array(
'title' => gT('Database update'),
'message' => sprintf(gT('The database has been updated from version %s to version %s.'), $iOldDBVersion, $currentDbVersion['stg_value'])
), $superadmins);
fixLanguageConsistencyAllSurveys();
Yii::app()->setConfig('Updating',false);
return true;
}
function createSurveyMenuTable293($oDB) {
// Drop the old survey rights table.
if (tableExists('{surveymenu}')) {
$oDB->createCommand()->dropTable('{{surveymenu}}');
}
if (tableExists('{surveymenu_entries}')) {
$oDB->createCommand()->dropTable('{{surveymenu_entries}}');
}
$oDB->createCommand()->createTable('{{surveymenu}}', array(
"id" => "int NOT NULL AUTO_INCREMENT",
"parent_id" => "int DEFAULT NULL",
"survey_id" => "int DEFAULT NULL",
"order" => "int DEFAULT '0'",
"level" => "int DEFAULT '0'",
"title" => "character varying(255) NOT NULL DEFAULT ''",
"description" => "text ",
"changed_at" => "timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP",
"changed_by" => "int NOT NULL DEFAULT '0'",
"created_at" => "datetime DEFAULT NULL",
"created_by" => "int NOT NULL DEFAULT '0'",
'PRIMARY KEY (id)'
));
$oDB->createCommand()->insert(
'{{surveymenu}}',
array(
'id' => 1,
'parent_id' => NULL,
'survey_id' => NULL,
'order' => 0,
'level' => 0,
'title' => 'surveymenu',
'description' => 'Main survey menu',
'changed_at' => date('Y-m-d H:i:s'),
'changed_by' => 0,
'created_at' => date('Y-m-d H:i:s'),
'created_by' => 0
)
);
$oDB->createCommand()->createTable('{{surveymenu_entries}}', array(
"id" => "int NOT NULL AUTO_INCREMENT",
"menu_id" => "int DEFAULT NULL",
"order" => "int DEFAULT '0'",
"name" => "character varying(255) NOT NULL DEFAULT ''",
"title" => "character varying(255) NOT NULL DEFAULT ''",
"menu_title" => "character varying(255) NOT NULL DEFAULT ''",
"menu_description" => "text ",
"menu_icon" => "character varying(255) NOT NULL DEFAULT ''",
"menu_icon_type" => "character varying(255) NOT NULL DEFAULT ''",
"menu_class" => "character varying(255) NOT NULL DEFAULT ''",
"menu_link" => "character varying(255) NOT NULL DEFAULT ''",
"action" => "character varying(255) NOT NULL DEFAULT ''",
"template" => "character varying(255) NOT NULL DEFAULT ''",
"partial" => "character varying(255) NOT NULL DEFAULT ''",
"classes" => "character varying(255) NOT NULL DEFAULT ''",
"permission" => "character varying(255) NOT NULL DEFAULT ''",
"permission_grade" => "character varying(255) DEFAULT NULL",
"data" => "text ",
"getdatamethod" => "character varying(255) NOT NULL DEFAULT ''",
"language" => "character varying(255) NOT NULL DEFAULT 'en-GB'",
"changed_at" => "timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP",
"changed_by" => "int NOT NULL DEFAULT '0'",
"created_at" => "datetime DEFAULT NULL",
"created_by" => "int NOT NULL DEFAULT '0'",
"PRIMARY KEY (id)",
"FOREIGN KEY (menu_id) REFERENCES {{surveymenu}} (id) ON DELETE CASCADE"
));
$colsToAdd = array("id","menu_id","order","name","title","menu_title","menu_description","menu_icon","menu_icon_type","menu_class","menu_link","action","template","partial","classes","permission","permission_grade","data","getdatamethod","language","changed_at","changed_by","created_at","created_by");
$rowsToAdd = array(
array(1,1,1,'overview','Survey overview','Overview','Open general survey overview and quick action','list','fontawesome','','admin/survey/sa/view','','','','','','',NULL,'','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0),
array(2,1,2,'generalsettings','Edit survey general settings','General settings','Open general survey settings','gears','fontawesome','','','updatesurveylocalesettings','editLocalSettings_main_view','/admin/survey/subview/accordion/_generaloptions_panel','','surveysettings','read',NULL,'_generalTabEditSurvey','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0),
array(3,1,3,'surveytexts','Edit survey text elements','Survey texts','Edit survey text elements','file-text-o','fontawesome','','','updatesurveylocalesettings','editLocalSettings_main_view','/admin/survey/subview/tab_edit_view','','surveylocale','read',NULL,'_getTextEditData','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0),
array(4,1,4,'presentation','Presentation & navigation settings','Presentation','Edit presentation and navigation settings','eye-slash','fontawesome','','','updatesurveylocalesettings','editLocalSettings_main_view','/admin/survey/subview/accordion/_presentation_panel','','surveylocale','read',NULL,'_tabPresentationNavigation','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0),
array(5,1,5,'publication','Publication and access control settings','Publication & access','Edit settings for publicationa and access control','key','fontawesome','','','updatesurveylocalesettings','editLocalSettings_main_view','/admin/survey/subview/accordion/_publication_panel','','surveylocale','read',NULL,'_tabPublicationAccess','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0),
array(6,1,6,'surveypermissions','Edit surveypermissions','Survey permissions','Edit permissions for this survey','lock','fontawesome','','admin/surveypermission/sa/view/','','','','','surveysecurity','read',NULL,'','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0),
array(7,1,7,'tokens','Token handling','Participant tokens','Define how tokens should be treated or generated','users','fontawesome','','','updatesurveylocalesettings','editLocalSettings_main_view','/admin/survey/subview/accordion/_tokens_panel','','surveylocale','read',NULL,'_tabTokens','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0),
array(8,1,8,'quotas','Edit quotas','Survey quotas','Edit quotas for this survey.','tasks','fontawesome','','admin/quotas/sa/index/','','','','','quotas','read',NULL,'','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0),
array(9,1,9,'assessments','Edit assessments','Assessments','Edit and look at the asessements for this survey.','comment-o','fontawesome','','admin/assessments/sa/index/','','','','','assessments','read',NULL,'','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0),
array(10,1,10,'notification','Notification and data management settings','Data management','Edit settings for notification and data management','feed','fontawesome','','','updatesurveylocalesettings','editLocalSettings_main_view','/admin/survey/subview/accordion/_notification_panel','','surveylocale','read',NULL,'_tabNotificationDataManagement','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0),
array(11,1,11,'emailtemplates','Email templates','Email templates','Edit the templates for invitation, reminder and registration emails','envelope-square','fontawesome','','admin/emailtemplates/sa/index/','','','','','assessments','read',NULL,'','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0),
array(12,1,12,'panelintegration','Edit survey panel integration','Panel integration','Define panel integrations for your survey','link','fontawesome','','','updatesurveylocalesettings','editLocalSettings_main_view','/admin/survey/subview/accordion/_integration_panel','','surveylocale','read',NULL,'_tabPanelIntegration','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0),
array(13,1,13,'ressources','Add/Edit ressources to the survey','Ressources','Add/Edit ressources to the survey','file','fontawesome','','','updatesurveylocalesettings','editLocalSettings_main_view','/admin/survey/subview/accordion/_resources_panel','','surveylocale','read',NULL,'_tabResourceManagement','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0)
);
foreach($rowsToAdd as $row){
$oDB->createCommand()->insert('{{surveymenu_entries}}', array_combine($colsToAdd,$row));
}
}
function reCreateSurveyMenuTable310(&$oDB)
{
// Drop the old surveymenu table.
if (tableExists('{surveymenu}')) {
$oDB->createCommand()->dropTable('{{surveymenu}}');
}
// Drop the old surveymenu_entries table.
if (tableExists('{surveymenu_entries}')) {
$oDB->createCommand()->dropTable('{{surveymenu_entries}}');
}
$oDB->createCommand()->createTable('{{surveymenu}}', array(
"id" => "int(11) NOT NULL AUTO_INCREMENT",
"parent_id" => "int(11) DEFAULT NULL",
"survey_id" => "int(11) DEFAULT NULL",
"user_id" => "int(11) DEFAULT NULL",
"ordering" => "int(11) DEFAULT '0'",
"level" => "int(11) DEFAULT '0'",
"title" => "varchar(255) NOT NULL DEFAULT ''",
"position" => "varchar(255) NOT NULL DEFAULT 'side'",
"description" => "text ",
"changed_at" => "timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP",
"changed_by" => "int(11) NOT NULL DEFAULT '0'",
"created_at" => "datetime DEFAULT NULL",
"created_by" => "int(11) NOT NULL DEFAULT '0'",
"PRIMARY KEY (`id`)",
"KEY `ordering` (`ordering`)",
"KEY `title` (`title`(250))"
));
$oDB->createCommand()->insert(
'{{surveymenu}}',
array(
"id" =>1,
"parent_id" =>NULL,
"survey_id" =>NULL,
"user_id" =>NULL,
"ordering" =>1,
"level" =>0,
"title" =>'surveymenu',
"position" =>'side',
"description" =>'Main survey menu',
"changed_at" => date('Y-m-d H:i:s'),
"changed_by" =>0,
"created_at" =>date('Y-m-d H:i:s'),
"created_by" => 0
));
$oDB->createCommand()->insert(
'{{surveymenu}}',
array(
"id" =>2,
"parent_id" =>NULL,
"survey_id" =>NULL,
"user_id" =>NULL,
"ordering" =>1,
"level" =>0,
"title" =>'quickmenue',
"position" =>'collapsed',
"description" =>'Quickmenu',
"changed_at" => date('Y-m-d H:i:s'),
"changed_by" =>0,
"created_at" =>date('Y-m-d H:i:s'),
"created_by" => 0
));
$oDB->createCommand()->createTable('{{surveymenu_entries}}', array(
"id" => "int(11) NOT NULL AUTO_INCREMENT",
"menu_id" => "int(11) DEFAULT NULL",
"user_id" => "int(11) DEFAULT NULL",
"ordering" => "int(11) DEFAULT '0'",
"name" => "varchar(255) NOT NULL DEFAULT ''",
"title" => "varchar(255) NOT NULL DEFAULT ''",
"menu_title" => "varchar(255) NOT NULL DEFAULT ''",
"menu_description" => "text ",
"menu_icon" => "varchar(255) NOT NULL DEFAULT ''",
"menu_icon_type" => "varchar(255) NOT NULL DEFAULT ''",
"menu_class" => "varchar(255) NOT NULL DEFAULT ''",
"menu_link" => "varchar(255) NOT NULL DEFAULT ''",
"action" => "varchar(255) NOT NULL DEFAULT ''",
"template" => "varchar(255) NOT NULL DEFAULT ''",
"partial" => "varchar(255) NOT NULL DEFAULT ''",
"classes" => "varchar(255) NOT NULL DEFAULT ''",
"permission" => "varchar(255) NOT NULL DEFAULT ''",
"permission_grade" => "varchar(255) DEFAULT NULL",
"data" => "text ",
"getdatamethod" => "varchar(255) NOT NULL DEFAULT ''",
"language" => "varchar(255) NOT NULL DEFAULT 'en-GB'",
"changed_at" => "timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP",
"changed_by" => "int(11) NOT NULL DEFAULT '0'",
"created_at" => "datetime DEFAULT NULL",
"created_by" => "int(11) NOT NULL DEFAULT '0'",
"PRIMARY KEY (`id`)",
"KEY `menu_id` (`menu_id`)",
"KEY `ordering` (`ordering`)",
"KEY `title` (`title`(191))",
"KEY `menu_title` (`menu_title`(191))"
));
$colsToAdd = array("id","menu_id","user_id","ordering","name","title","menu_title","menu_description","menu_icon","menu_icon_type","menu_class","menu_link","action","template","partial","classes","permission","permission_grade","data","getdatamethod","language","changed_at","changed_by","created_at","created_by");
$rowsToAdd = array(
array(1,1,NULL,1,'overview','Survey overview','Overview','Open general survey overview and quick action','list','fontawesome','','admin/survey/sa/view','','','','','','','{\"render\": { \"link\": {\"data\": {\"surveyid\": [\"survey\",\"sid\"]}}}}','','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0),
array(2,1,NULL,2,'generalsettings','Edit survey general settings','General settings','Open general survey settings','gears','fontawesome','','','updatesurveylocalesettings','editLocalSettings_main_view','/admin/survey/subview/accordion/_generaloptions_panel','','surveysettings','read',NULL,'_generalTabEditSurvey','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0),
array(3,1,NULL,3,'surveytexts','Edit survey text elements','Survey texts','Edit survey text elements','file-text-o','fontawesome','','','updatesurveylocalesettings','editLocalSettings_main_view','/admin/survey/subview/tab_edit_view','','surveylocale','read',NULL,'_getTextEditData','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0),
array(4,1,NULL,4,'template_options','Template options','Template options','Edit Template options for this survey','paint-brush','fontawesome','','admin/templateoptions/sa/updatesurvey','','','','','templates','read','{"render": {"link": { "pjaxed": false, "data": {"surveyid": ["survey","sid"], "gsid":["survey","gsid"]}}}}','','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0),
array(5,1,NULL,5,'participants','Survey participants','Survey participants','Go to survey participant and token settings','user','fontawesome','','admin/tokens/sa/index/','','','','','surveysettings','update','{\"render\": { \"link\": {\"data\": {\"surveyid\": [\"survey\",\"sid\"]}}}}','','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0),
array(6,1,NULL,6,'presentation','Presentation & navigation settings','Presentation','Edit presentation and navigation settings','eye-slash','fontawesome','','','updatesurveylocalesettings','editLocalSettings_main_view','/admin/survey/subview/accordion/_presentation_panel','','surveylocale','read',NULL,'_tabPresentationNavigation','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0),
array(7,1,NULL,7,'publication','Publication and access control settings','Publication & access','Edit settings for publicationa and access control','key','fontawesome','','','updatesurveylocalesettings','editLocalSettings_main_view','/admin/survey/subview/accordion/_publication_panel','','surveylocale','read',NULL,'_tabPublicationAccess','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0),
array(8,1,NULL,8,'surveypermissions','Edit surveypermissions','Survey permissions','Edit permissions for this survey','lock','fontawesome','','admin/surveypermission/sa/view/','','','','','surveysecurity','read','{\"render\": { \"link\": {\"data\": {\"surveyid\": [\"survey\",\"sid\"]}}}}','','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0),
array(9,1,NULL,9,'tokens','Token handling','Participant tokens','Define how tokens should be treated or generated','users','fontawesome','','','updatesurveylocalesettings','editLocalSettings_main_view','/admin/survey/subview/accordion/_tokens_panel','','surveylocale','read',NULL,'_tabTokens','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0),
array(10,1,NULL,10,'quotas','Edit quotas','Survey quotas','Edit quotas for this survey.','tasks','fontawesome','','admin/quotas/sa/index/','','','','','quotas','read','{\"render\": { \"link\": {\"data\": {\"surveyid\": [\"survey\",\"sid\"]}}}}','','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0),
array(11,1,NULL,11,'assessments','Edit assessments','Assessments','Edit and look at the asessements for this survey.','comment-o','fontawesome','','admin/assessments/sa/index/','','','','','assessments','read','{\"render\": { \"link\": {\"data\": {\"surveyid\": [\"survey\",\"sid\"]}}}}','','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0),
array(12,1,NULL,12,'notification','Notification and data management settings','Data management','Edit settings for notification and data management','feed','fontawesome','','','updatesurveylocalesettings','editLocalSettings_main_view','/admin/survey/subview/accordion/_notification_panel','','surveylocale','read',NULL,'_tabNotificationDataManagement','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0),
array(13,1,NULL,13,'emailtemplates','Email templates','Email templates','Edit the templates for invitation, reminder and registration emails','envelope-square','fontawesome','','admin/emailtemplates/sa/index/','','','','','assessments','read','{\"render\": { \"link\": {\"data\": {\"surveyid\": [\"survey\",\"sid\"]}}}}','','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0),
array(14,1,NULL,14,'panelintegration','Edit survey panel integration','Panel integration','Define panel integrations for your survey','link','fontawesome','','','updatesurveylocalesettings','editLocalSettings_main_view','/admin/survey/subview/accordion/_integration_panel','','surveylocale','read',NULL,'_tabPanelIntegration','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0),
array(15,1,NULL,15,'ressources','Add/Edit ressources to the survey','Ressources','Add/Edit ressources to the survey','file','fontawesome','','','updatesurveylocalesettings','editLocalSettings_main_view','/admin/survey/subview/accordion/_resources_panel','','surveylocale','read',NULL,'_tabResourceManagement','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0),
array(16,2,NULL,1,'activateSurvey','Activate survey','Activate survey','Activate survey','play','fontawesome','','admin/survey/sa/activate','','','','','surveyactivation','update','{\"render\": {\"isActive\": false, \"link\": {\"data\": {\"surveyid\": [\"survey\",\"sid\"]}}}}','','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0),
array(17,2,NULL,2,'deactivateSurvey','Stop this survey','Stop this survey','Stop this survey','stop','fontawesome','','admin/survey/sa/deactivate','','','','','surveyactivation','update','{\"render\": {\"isActive\": true, \"link\": {\"data\": {\"surveyid\": [\"survey\",\"sid\"]}}}}','','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0),
array(18,2,NULL,3,'testSurvey','Go to survey','Go to survey','Go to survey','cog','fontawesome','','survey/index/','','','','','','','{\"render\"\: {\"link\"\: {\"external\"\: true, \"data\"\: {\"sid\"\: [\"survey\",\"sid\"], \"newtest\"\: \"Y\", \"lang\"\: [\"survey\",\"language\"]}}}}','','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0),
array(19,2,NULL,4,'listQuestions','List questions','List questions','List questions','list','fontawesome','','admin/survey/sa/listquestions','','','','','surveycontent','read','{\"render\": { \"link\": {\"data\": {\"surveyid\": [\"survey\",\"sid\"]}}}}','','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0),
array(20,2,NULL,5,'listQuestionGroups','List question groups','List question groups','List question groups','th-list','fontawesome','','admin/survey/sa/listquestiongroups','','','','','surveycontent','read','{\"render\": { \"link\": {\"data\": {\"surveyid\": [\"survey\",\"sid\"]}}}}','','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0),
array(21,2,NULL,6,'generalsettings','Edit survey general settings','General settings','Open general survey settings','gears','fontawesome','','','updatesurveylocalesettings','editLocalSettings_main_view','/admin/survey/subview/accordion/_generaloptions_panel','','surveysettings','read',NULL,'_generalTabEditSurvey','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0),
array(22,2,NULL,7,'surveypermissions','Edit surveypermissions','Survey permissions','Edit permissions for this survey','lock','fontawesome','','admin/surveypermission/sa/view/','','','','','surveysecurity','read','{\"render\": { \"link\": {\"data\": {\"surveyid\": [\"survey\",\"sid\"]}}}}','','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0),
array(23,2,NULL,8,'quotas','Edit quotas','Survey quotas','Edit quotas for this survey.','tasks','fontawesome','','admin/quotas/sa/index/','','','','','quotas','read','{\"render\": { \"link\": {\"data\": {\"surveyid\": [\"survey\",\"sid\"]}}}}','','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0),
array(24,2,NULL,9,'assessments','Edit assessments','Assessments','Edit and look at the asessements for this survey.','comment-o','fontawesome','','admin/assessments/sa/index/','','','','','assessments','read','{\"render\": { \"link\": {\"data\": {\"surveyid\": [\"survey\",\"sid\"]}}}}','','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0),
array(25,2,NULL,10,'emailtemplates','Email templates','Email templates','Edit the templates for invitation, reminder and registration emails','envelope-square','fontawesome','','admin/emailtemplates/sa/index/','','','','','surveylocale','read','{\"render\": { \"link\": {\"data\": {\"surveyid\": [\"survey\",\"sid\"]}}}}','','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0),
array(26,2,NULL,11,'surveyLogicFile','Survey logic file','Survey logic file','Survey logic file','sitemap','fontawesome','','admin/expressions/sa/survey_logic_file/','','','','','surveycontent','read','{\"render\": { \"link\": {\"data\": {\"surveyid\": [\"survey\",\"sid\"]}}}}','','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0),
array(27,2,NULL,12,'tokens','Token handling','Participant tokens','Define how tokens should be treated or generated','user','fontawesome','','','updatesurveylocalesettings','editLocalSettings_main_view','/admin/survey/subview/accordion/_tokens_panel','','surveylocale','read','{\"render\": { \"link\": {\"data\": {\"surveyid\": [\"survey\",\"sid\"]}}}}','_tabTokens','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0),
array(28,2,NULL,13,'cpdb','Central participant database','Central participant database','Central participant database','users','fontawesome','','admin/participants/sa/displayParticipants','','','','','tokens','read','{render\: {\"link\"\: {}}','','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0),
array(29,2,NULL,14,'responses','Responses','Responses','Responses','icon-browse','iconclass','','admin/responses/sa/browse/','','','','','responses','read','{\"render\"\: {\"isActive\"\: true}}','','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0),
array(30,2,NULL,15,'statistics','Statistics','Statistics','Statistics','bar-chart','fontawesome','','admin/statistics/sa/index/','','','','','statistics','read','{\"render\"\: {\"isActive\"\: true}}','','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0),
array(31,2,NULL,16,'reorder','Reorder questions/question groups','Reorder questions/question groups','Reorder questions/question groups','icon-organize','iconclass','','admin/survey/sa/organize/','','','','','surveycontent','update','{\"render\": {\"isActive\": false, \"link\": {\"data\": {\"surveyid\": [\"survey\",\"sid\"]}}}}','','en-GB',date('Y-m-d H:i:s'),0,date('Y-m-d H:i:s'),0)
);
foreach($rowsToAdd as $row){
$oDB->createCommand()->insert('{{surveymenu_entries}}', array_combine($colsToAdd,$row));
}
}
/**
* @param $oDB
* @return void
*/
function createSurveyGroupTables306($oDB)
{
// Drop the old survey rights table.
if (tableExists('{surveys_groups}')) {
$oDB->createCommand()->dropTable('{{surveys_groups}}');
}
// Create templates table
$oDB->createCommand()->createTable('{{surveys_groups}}', array(
'gsid' => 'pk',
'name' => 'string(45) NOT NULL',
'title' => 'string(100) DEFAULT NULL',
'description' => 'text DEFAULT NULL',
'order' => 'int(11) NOT NULL',
'owner_uid' => 'int(11) DEFAULT NULL',
'parent_id' => 'int(11) DEFAULT NULL',
'created' => 'DATETIME',
'modified' => 'DATETIME',
'created_by' => 'int(11) NOT NULL'
));
// Add default template
$date = date("Y-m-d H:i:s");
$oDB->createCommand()->insert('{{surveys_groups}}', array(
'name' => 'default',
'title' => 'Default Survey Group',
'description' => 'LimeSurvey core default survey group',
'order' => '0',
'owner_uid' => '1',
'created' => $date,
'modified' => $date,
'created_by' => '1'
));
$oDB->createCommand()->addColumn('{{surveys}}','gsid',"int(11) DEFAULT 1");
}
/**
* @param $oDB
* @return void
*/
function upgradeTemplateTables304($oDB)
{
// Drop the old survey rights table.
if (tableExists('{templates}')) {
$oDB->createCommand()->dropTable('{{templates}}');
}
if (tableExists('{template_configuration}')) {
$oDB->createCommand()->dropTable('{{template_configuration}}');
}
// Create templates table
$oDB->createCommand()->createTable('{{templates}}', array(
'name' => 'string(150) NOT NULL',
'folder' => 'string(45) DEFAULT NULL',
'title' => 'string(100) NOT NULL',
'creation_date' => 'TIMESTAMP DEFAULT CURRENT_TIMESTAMP',
'author' => 'string(150) DEFAULT NULL',
'author_email' => 'string DEFAULT NULL',
'author_url' => 'string DEFAULT NULL',
'copyright' => 'MEDIUMTEXT',
'license' => 'MEDIUMTEXT',
'version' => 'string(45) DEFAULT NULL',
'api_version' => 'string(45) NOT NULL',
'view_folder' => 'string(45) NOT NULL',
'files_folder' => 'string(45) NOT NULL',
'description' => 'TEXT',
'last_update' => 'DATETIME DEFAULT NULL',
'owner_id' => 'INT(11) DEFAULT NULL',
'extends_templates_name' => 'string(150) DEFAULT NULL',
'PRIMARY KEY (name)'
));
// Add default template
$oDB->createCommand()->insert('{{templates}}', array(
'name' => 'default',
'folder' => 'default',
'title' => 'Advanced Template',
'creation_date' => '2017-07-12 12:00:00',
'author' => 'Louis Gac',
'author_email' => 'louis.gac@limesurvey.org',
'author_url' => 'https://www.limesurvey.org/',
'copyright' => 'Copyright (C) 2007-2017 The LimeSurvey Project Team\r\nAll rights reserved.',
'license' => 'License: GNU/GPL License v2 or later, see LICENSE.php\r\n\r\nLimeSurvey is free software. This version may have been modified pursuant to the GNU General Public License, and as distributed it includes or is derivative of works licensed under the GNU General Public License or other free or open source software licenses. See COPYRIGHT.php for copyright notices and details.',
'version' => '1.0',
'api_version' => '3.0',
'view_folder' => 'views',
'files_folder' => 'files',
'description' => "<strong>LimeSurvey Advanced Template</strong><br>A template with custom options to show what it's possible to do with the new engines. Each template provider will be able to offer its own option page (loaded from template)",
'owner_id' => '1',
'extends_templates_name' => '',
));
// Add minimal template
$oDB->createCommand()->insert('{{templates}}', array(
'name' => 'minimal',
'folder' => 'minimal',
'title' => 'Minimal Template',
'creation_date' => '2017-07-12 12:00:00',
'author' => 'Louis Gac',
'author_email' => 'louis.gac@limesurvey.org',
'author_url' => 'https://www.limesurvey.org/',
'copyright' => 'Copyright (C) 2007-2017 The LimeSurvey Project Team\r\nAll rights reserved.',
'license' => 'License: GNU/GPL License v2 or later, see LICENSE.php\r\n\r\nLimeSurvey is free software. This version may have been modified pursuant to the GNU General Public License, and as distributed it includes or is derivative of works licensed under the GNU General Public License or other free or open source software licenses. See COPYRIGHT.php for copyright notices and details.',
'version' => '1.0',
'api_version' => '3.0',
'view_folder' => 'views',
'files_folder' => 'files',
'description' => '<strong>LimeSurvey Minimal Template</strong><br>A clean and simple base that can be used by developers to create their own solution.',
'owner_id' => '1',
'extends_templates_name' => '',
));
// Add material template
$oDB->createCommand()->insert('{{templates}}', array(
'name' => 'material',
'folder' => 'material',
'title' => 'Material Template',
'creation_date' => '2017-07-12 12:00:00',
'author' => 'Louis Gac',
'author_email' => 'louis.gac@limesurvey.org',
'author_url' => 'https://www.limesurvey.org/',
'copyright' => 'Copyright (C) 2007-2017 The LimeSurvey Project Team\r\nAll rights reserved.',
'license' => 'License: GNU/GPL License v2 or later, see LICENSE.php\r\n\r\nLimeSurvey is free software. This version may have been modified pursuant to the GNU General Public License, and as distributed it includes or is derivative of works licensed under the GNU General Public License or other free or open source software licenses. See COPYRIGHT.php for copyright notices and details.',
'version' => '1.0',
'api_version' => '3.0',
'view_folder' => 'views',
'files_folder' => 'files',
'description' => "<strong>LimeSurvey Advanced Template</strong><br> A template extending default, to show the inheritance concept. Notice the options, differents from Default.<br><small>uses FezVrasta's Material design theme for Bootstrap 3</small>",
'owner_id' => '1',
'extends_templates_name' => 'default',
));
// Add template configuration table
$oDB->createCommand()->createTable('{{template_configuration}}', array(
'id' => 'pk',
'templates_name' => 'string(150) NOT NULL',
'sid' => 'int(11) DEFAULT NULL',
'gsid' => 'int(11) DEFAULT NULL',
'uid' => 'int(11) DEFAULT NULL',
'files_css' => 'MEDIUMTEXT',
'files_js' => 'MEDIUMTEXT',
'files_print_css' => 'MEDIUMTEXT',
'options' => 'MEDIUMTEXT',
'cssframework_name' => 'string(45) DEFAULT NULL',
'cssframework_css' => 'MEDIUMTEXT',
'cssframework_js' => 'MEDIUMTEXT',
'packages_to_load' => 'MEDIUMTEXT',
));
// Add global configuration for Advanced Template
$oDB->createCommand()->insert('{{template_configuration}}', array(
'id' => '1',
'templates_name' => 'default',
'files_css' => '{"add": ["css/template.css", "css/animate.css"]}',
'files_js' => '{"add": ["scripts/template.js"]}',
'files_print_css' => '{"add":"css/print_template.css",}',
'options' => '{"ajaxmode":"on","brandlogo":"on", "boxcontainer":"on", "backgroundimage":"on","animatebody":"on","bodyanimation":"fadeInRight","animatequestion":"off","questionanimation":"flipInX","animatealert":"off","alertanimation":"shake"}',
'cssframework_name' => 'bootstrap',
'cssframework_css' => '{"replace": [["css/bootstrap.css","css/flatly.css"]]}',
'cssframework_js' => '',
'packages_to_load' => 'template-core,',
));
// Add global configuration for Minimal Template
$oDB->createCommand()->insert('{{template_configuration}}', array(
'id' => '2',
'templates_name' => 'minimal',
'files_css' => '{"add": ["css/template.css"]}',
'files_js' => '{"add": ["scripts/template.js"]}',
'files_print_css' => '{"add":"css/print_template.css",}',
'options' => '{}',
'cssframework_name' => 'bootstrap',
'cssframework_css' => '{}',
'cssframework_js' => '',
'packages_to_load' => 'template-core,',
));
// Add global configuration for Material Template
$oDB->createCommand()->insert('{{template_configuration}}', array(
'id' => '3',
'templates_name' => 'material',
'files_css' => '{"add": ["css/template.css", "css/bootstrap-material-design.css", "css/ripples.min.css"]}',
'files_js' => '{"add": ["scripts/template.js", "scripts/material.js", "scripts/ripples.min.js"]}',
'files_print_css' => '{"add":"css/print_template.css",}',
'options' => '{"ajaxmode":"on","brandlogo":"on", "animatebody":"on","bodyanimation":"fadeInRight","animatequestion":"off","questionanimation":"flipInX","animatealert":"off","alertanimation":"shake"}',
'cssframework_name' => 'bootstrap',
'cssframework_css' => '{"replace": [["css/bootstrap.css","css/bootstrap.css"]]}',
'cssframework_js' => '',
'packages_to_load' => 'template-core,',
));
}
/**
* @param $oDB
* @return void
*/
function upgradeTemplateTables298($oDB)
{
// Add global configuration for Advanced Template
$oDB->createCommand()->update('{{boxes}}',array(
'url'=>'admin/templateoptions',
'title'=>'Templates',
'desc'=>'View templates list',
) ,"id=6");
}
function fixLanguageConsistencyAllSurveys()
{
$surveyidquery = "SELECT sid,additional_languages FROM ".dbQuoteID('{{surveys}}');
$surveyidresult = Yii::app()->db->createCommand($surveyidquery)->queryAll();
foreach ( $surveyidresult as $sv )
{
fixLanguageConsistency($sv['sid'],$sv['additional_languages']);
}
}
/**
* @param string $sFieldType
*/
function alterColumn($sTable, $sColumn, $sFieldType, $bAllowNull=true, $sDefault='NULL')
{
$oDB = Yii::app()->db;
switch (Yii::app()->db->driverName){
case 'mysql':
case 'mysqli':
$sType=$sFieldType;
if ($bAllowNull!==true)
{
$sType.=' NOT NULL';
}
if ($sDefault!='NULL')
{
$sType.=" DEFAULT '{$sDefault}'";
}
$oDB->createCommand()->alterColumn($sTable,$sColumn,$sType);
break;
case 'dblib':
case 'sqlsrv':
case 'mssql':
dropDefaultValueMSSQL($sColumn,$sTable);
$sType=$sFieldType;
if ($bAllowNull!=true && $sDefault!='NULL')
{
$oDB->createCommand("UPDATE {$sTable} SET [{$sColumn}]='{$sDefault}' where [{$sColumn}] is NULL;")->execute();
}
if ($bAllowNull!=true)
{
$sType.=' NOT NULL';
}
else
{
$sType.=' NULL';
}
$oDB->createCommand()->alterColumn($sTable,$sColumn,$sType);
if ($sDefault!='NULL')
{
$oDB->createCommand("ALTER TABLE {$sTable} ADD default '{$sDefault}' FOR [{$sColumn}];")->execute();
}
break;
case 'pgsql':
$sType=$sFieldType;
$oDB->createCommand()->alterColumn($sTable,$sColumn,$sType);
try{ $oDB->createCommand("ALTER TABLE {$sTable} ALTER COLUMN {$sColumn} DROP DEFAULT")->execute();} catch(Exception $e) {};
try{ $oDB->createCommand("ALTER TABLE {$sTable} ALTER COLUMN {$sColumn} DROP NOT NULL")->execute();} catch(Exception $e) {};
if ($bAllowNull!=true)
{
$oDB->createCommand("ALTER TABLE {$sTable} ALTER COLUMN {$sColumn} SET NOT NULL")->execute();
}
if ($sDefault!='NULL')
{
$oDB->createCommand("ALTER TABLE {$sTable} ALTER COLUMN {$sColumn} SET DEFAULT '{$sDefault}'")->execute();
}
$oDB->createCommand()->alterColumn($sTable,$sColumn,$sType);
break;
default: die('Unknown database type');
}
}
/**
* @param string $sType
*/
function addColumn($sTableName, $sColumn, $sType)
{
Yii::app()->db->createCommand()->addColumn($sTableName,$sColumn,$sType);
}