fix #212: Duplicate entry for Room name

This commit is contained in:
msquare 2017-12-10 18:36:53 +01:00
parent dbf6e64a2c
commit aae8c77ed1
1 changed files with 14 additions and 7 deletions

View File

@ -310,26 +310,33 @@ function prepare_rooms($file)
$data = read_xml($file); $data = read_xml($file);
// Load rooms from db for compare with input // Load rooms from db for compare with input
$rooms = DB::select('SELECT `Name`, `RID` FROM `Room` WHERE `from_frab`=TRUE'); $rooms = Rooms();
// Contains rooms from db with from_frab==true
$rooms_db = []; $rooms_db = [];
// Contains all rooms from db
$rooms_db_all = [];
// Contains all rooms from db and frab
$rooms_import = []; $rooms_import = [];
foreach ($rooms as $room) { foreach ($rooms as $room) {
if($room['from_frab']) {
$rooms_db[] = $room['Name']; $rooms_db[] = $room['Name'];
}
$rooms_db_all[] = $room['Name'];
$rooms_import[$room['Name']] = $room['RID']; $rooms_import[$room['Name']] = $room['RID'];
} }
$events = $data->vcalendar->vevent; $events = $data->vcalendar->vevent;
$rooms_pb = []; $rooms_frab = [];
foreach ($events as $event) { foreach ($events as $event) {
$rooms_pb[] = (string)$event->location; $rooms_frab[] = (string)$event->location;
if (!isset($rooms_import[trim($event->location)])) { if (!isset($rooms_import[trim($event->location)])) {
$rooms_import[trim($event->location)] = trim($event->location); $rooms_import[trim($event->location)] = trim($event->location);
} }
} }
$rooms_pb = array_unique($rooms_pb); $rooms_frab = array_unique($rooms_frab);
$rooms_new = array_diff($rooms_pb, $rooms_db); $rooms_new = array_diff($rooms_frab, $rooms_db_all);
$rooms_deleted = array_diff($rooms_db, $rooms_pb); $rooms_deleted = array_diff($rooms_db, $rooms_frab);
return [ return [
$rooms_new, $rooms_new,