Skip to content

Commit a7173dc

Browse files
committed
[smarcet] - #13793
* moved default event types to flag on DB
1 parent 34004a1 commit a7173dc

4 files changed

Lines changed: 74 additions & 35 deletions

File tree

migrations/migrations.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,5 @@ migrations:
9898
- RepublishElectionPagesMigration
9999
- AddOnDeleteCascadeForEventsAndPresentationMaterials
100100
- AddSummitCalendarSyncErrorEmailMigration
101+
- RefactorDefaultEventTypesMigration
101102

summit/code/infrastructure/active_records/Summit.php

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,6 +1072,7 @@ public static function seedBasicEventTypes($summit_id)
10721072
$presentation->AreSpeakersMandatory = false;
10731073
$presentation->UseModerator = false;
10741074
$presentation->IsModeratorMandatory = false;
1075+
$presentation->IsDefault = true;
10751076
$presentation->write();
10761077

10771078
$key_note = SummitEventType::get()->filter(['Type' => IPresentationType::Keynotes, 'SummitID' => $summit_id])->first();
@@ -1090,6 +1091,7 @@ public static function seedBasicEventTypes($summit_id)
10901091
$key_note->AreSpeakersMandatory = false;
10911092
$key_note->UseModerator = true;
10921093
$key_note->IsModeratorMandatory = false;
1094+
$key_note->IsDefault = true;
10931095
$key_note->write();
10941096

10951097
$panel = SummitEventType::get()->filter(['Type' => IPresentationType::Panel, 'SummitID' => $summit_id])->first();
@@ -1108,6 +1110,7 @@ public static function seedBasicEventTypes($summit_id)
11081110
$panel->AreSpeakersMandatory = false;
11091111
$panel->UseModerator = true;
11101112
$panel->IsModeratorMandatory = false;
1113+
$panel->IsDefault = true;
11111114
$panel->write();
11121115

11131116
$lighting_talks = SummitEventType::get()->filter(['Type' => IPresentationType::LightingTalks, 'SummitID' => $summit_id])->first();
@@ -1126,6 +1129,7 @@ public static function seedBasicEventTypes($summit_id)
11261129
$lighting_talks->AreSpeakersMandatory = false;
11271130
$lighting_talks->UseModerator = false;
11281131
$lighting_talks->IsModeratorMandatory = false;
1132+
$lighting_talks->IsDefault = true;
11291133
$lighting_talks->write();
11301134

11311135
$hand_on_labs = SummitEventType::get()->filter(['Type' => ISummitEventType::HandonLabs, 'SummitID' => $summit_id])->first();
@@ -1136,6 +1140,7 @@ public static function seedBasicEventTypes($summit_id)
11361140

11371141
$hand_on_labs->Type = ISummitEventType::HandonLabs;
11381142
$hand_on_labs->SummitID = $summit_id;
1143+
$hand_on_labs->IsDefault = true;
11391144
$hand_on_labs->write();
11401145

11411146
$lunch = SummitEventType::get()->filter(['Type' => ISummitEventType::Lunch, 'SummitID' => $summit_id])->first();
@@ -1145,6 +1150,7 @@ public static function seedBasicEventTypes($summit_id)
11451150

11461151
$lunch->Type = ISummitEventType::Lunch;
11471152
$lunch->SummitID = $summit_id;
1153+
$lunch->IsDefault = true;
11481154
$lunch->write();
11491155

11501156
$breaks = SummitEventType::get()->filter(['Type' => ISummitEventType::Breaks, 'SummitID' => $summit_id])->first();
@@ -1154,16 +1160,17 @@ public static function seedBasicEventTypes($summit_id)
11541160

11551161
$breaks->Type = ISummitEventType::Breaks;
11561162
$breaks->SummitID = $summit_id;
1163+
$breaks->IsDefault = true;
11571164
$breaks->write();
11581165

1159-
11601166
$evening_events = SummitEventType::get()->filter(['Type' => ISummitEventType::EveningEvents, 'SummitID' => $summit_id])->first();
11611167
if (is_null($evening_events)) {
11621168
$evening_events = new SummitEventType();
11631169
}
11641170

11651171
$evening_events->Type = ISummitEventType::EveningEvents;
11661172
$evening_events->SummitID = $summit_id;
1173+
$breaks->IsDefault = true;
11671174
$evening_events->write();
11681175

11691176

@@ -1172,26 +1179,12 @@ public static function seedBasicEventTypes($summit_id)
11721179
$groups_events = new SummitEventType();
11731180
}
11741181

1175-
$groups_events->Type = ISummitEventType::GroupsEvents;
1176-
$groups_events->SummitID = $summit_id;
1182+
$groups_events->Type = ISummitEventType::GroupsEvents;
1183+
$groups_events->SummitID = $summit_id;
1184+
$groups_events->IsDefault = true;
11771185
$groups_events->write();
11781186
}
11791187

1180-
public static function isDefaultEventType($event_type)
1181-
{
1182-
return in_array($event_type,
1183-
[
1184-
IPresentationType::Presentation,
1185-
IPresentationType::Keynotes,
1186-
IPresentationType::Panel,
1187-
IPresentationType::LightingTalks,
1188-
ISummitEventType::HandonLabs,
1189-
ISummitEventType::EveningEvents,
1190-
ISummitEventType::Lunch_Breaks,
1191-
ISummitEventType::GroupsEvents,
1192-
]);
1193-
}
1194-
11951188
/**
11961189
* @return bool
11971190
*/

summit/code/infrastructure/active_records/events/SummitEventType.php

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,30 +25,24 @@ class SummitEventType extends DataObject implements ISummitEventType
2525
'UseSponsors' => 'Boolean',
2626
'AreSponsorsMandatory' => 'Boolean',
2727
'AllowsAttachment' => 'Boolean',
28+
'IsDefault' => 'Boolean',
2829
);
2930

30-
private static $has_many = array
31-
(
32-
);
31+
private static $has_many = [];
3332

34-
private static $defaults = array
35-
(
36-
);
33+
private static $defaults = [];
3734

38-
private static $has_one = array
39-
(
35+
private static $has_one = [
4036
'Summit' => 'Summit'
41-
);
37+
];
4238

43-
private static $summary_fields = array
44-
(
39+
private static $summary_fields = [
4540
'Type'
46-
);
41+
];
4742

48-
private static $searchable_fields = array
49-
(
43+
private static $searchable_fields = [
5044
'Type'
51-
);
45+
];
5246
/**
5347
* @return int
5448
*/
@@ -74,7 +68,7 @@ public function getBlackoutTimes()
7468
}
7569

7670
public function canDelete($member=null) {
77-
if (Summit::isDefaultEventType($this->Type))
71+
if ($this->IsDefault)
7872
{
7973
return false;
8074
}
@@ -84,7 +78,7 @@ public function canDelete($member=null) {
8478
public function getCMSFields() {
8579
$fields = new FieldList();
8680
$fields->add($type_txt = new TextField('Type','Type'));
87-
if($this->ID > 0 && Summit::isDefaultEventType($this->Type))
81+
if($this->ID > 0 && $this->IsDefault)
8882
{
8983
$type_txt->setReadonly(true);
9084
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
/**
3+
* Copyright 2018 OpenStack Foundation
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
**/
14+
15+
/**
16+
* Class RefactorDefaultEventTypesMigration
17+
*/
18+
final class RefactorDefaultEventTypesMigration extends AbstractDBMigrationTask
19+
{
20+
protected $title = "RefactorDefaultEventTypesMigration";
21+
22+
protected $description = "RefactorDefaultEventTypesMigration";
23+
24+
function doUp()
25+
{
26+
$default_types = [
27+
IPresentationType::Presentation,
28+
IPresentationType::Keynotes,
29+
IPresentationType::Panel,
30+
IPresentationType::LightingTalks,
31+
ISummitEventType::HandonLabs,
32+
ISummitEventType::EveningEvents,
33+
ISummitEventType::Lunch_Breaks,
34+
ISummitEventType::GroupsEvents,
35+
];
36+
37+
$sql = <<<SQL
38+
UPDATE SummitEventType SET IsDefault = 1 WHERE Type IN (
39+
'%s'
40+
)
41+
SQL;
42+
43+
DB::query(sprintf($sql, implode("','",$default_types)));
44+
45+
}
46+
47+
function doDown()
48+
{
49+
// TODO: Implement doDown() method.
50+
}
51+
}

0 commit comments

Comments
 (0)