public function testRemovesReminders()
 {
     $seriesId = 99;
     $builder = new ExistingReservationSeriesBuilder();
     $series = $builder->WithId($seriesId)->Build();
     $series->WithStartReminder(new ReservationReminder(100, ReservationReminderInterval::Days));
     $series->WithEndReminder(new ReservationReminder(15, ReservationReminderInterval::Minutes));
     $series->RemoveStartReminder();
     $series->RemoveEndReminder();
     $this->repository->Update($series);
     $command1 = new RemoveReservationReminderCommand($seriesId, ReservationReminderType::Start);
     $command2 = new RemoveReservationReminderCommand($seriesId, ReservationReminderType::End);
     $this->assertTrue($this->db->ContainsCommand($command1));
     $this->assertTrue($this->db->ContainsCommand($command2));
 }
Пример #2
0
    private function MigrateReservations(Database $legacyDatabase, Database $currentDatabase)
    {
        $reservationsMigrated = MigrationSession::GetLastReservationRow();
        $getMigratedCount = new AdHocCommand('SELECT
				(select count(*) from reservation_series where legacyid is not null) +
				(select count(*) from blackout_series where legacyid is not null )
				as count');
        $reader = ServiceLocator::GetDatabase()->Query($getMigratedCount);
        if ($row = $reader->GetRow()) {
            $reservationsMigrated = $row['count'];
        }
        Log::Debug('Start migrating reservations. Starting at row %s', $reservationsMigrated);
        $reservationRepository = new ReservationRepository();
        $blackoutRepository = new BlackoutRepository();
        $getLegacyReservations = new AdHocCommand("select r.resid, machid, scheduleid, start_date, end_date,\n            starttime, endtime, created, modified, parentid, is_blackout, is_pending, summary, allow_participation, allow_anon_participation,\n            ru.memberid\n            FROM reservations r INNER JOIN reservation_users ru ON r.resid = ru.resid AND owner = 1\n            ORDER BY r.resid LIMIT {$reservationsMigrated}, 100");
        $getExisting = new AdHocCommand('select legacyid from reservation_series');
        $reader = $currentDatabase->Query($getExisting);
        $knownIds = array();
        while ($row = $reader->GetRow()) {
            $knownIds[] = $row['legacyid'];
        }
        $getLegacyReservationAccessories = new AdHocCommand('SELECT resid, resourceid from reservation_resources');
        $getLegacyReservationParticipants = new AdHocCommand('SELECT resid, memberid, owner, invited  FROM reservation_users WHERE (owner is null or owner = 0)');
        $getAccessoryMapping = new AdHocCommand('select accessory_id, legacyid from accessories');
        $getUserMapping = new AdHocCommand('select user_id, legacyid from users');
        $getResourceMapping = new AdHocCommand('select resource_id, legacyid from resources');
        $accessoryMapping = array();
        $accessoryMappingReader = $currentDatabase->Query($getAccessoryMapping);
        while ($row = $accessoryMappingReader->GetRow()) {
            $legacyId = $row['legacyid'];
            $accessoryMapping[$legacyId] = $row['accessory_id'];
        }
        $userMapping = array();
        $userMappingReader = $currentDatabase->Query($getUserMapping);
        while ($row = $userMappingReader->GetRow()) {
            $legacyId = $row['legacyid'];
            $userMapping[$legacyId] = $row['user_id'];
        }
        $resourceMapping = array();
        $resourceMappingReader = $currentDatabase->Query($getResourceMapping);
        while ($row = $resourceMappingReader->GetRow()) {
            $legacyId = $row['legacyid'];
            $resourceMapping[$legacyId] = $row['resource_id'];
        }
        $reservationAccessories = array();
        $legacyAccessoryReader = $legacyDatabase->Query($getLegacyReservationAccessories);
        while ($row = $legacyAccessoryReader->GetRow()) {
            $resId = $row['resid'];
            if (!array_key_exists($resId, $reservationAccessories)) {
                $reservationAccessories[$resId] = array();
            }
            $reservationAccessories[$resId][] = $row['resourceid'];
        }
        $reservationParticipants = array();
        $legacyParticipantReader = $legacyDatabase->Query($getLegacyReservationParticipants);
        while ($row = $legacyParticipantReader->GetRow()) {
            $resId = $row['resid'];
            if (!array_key_exists($resId, $reservationParticipants)) {
                $reservationParticipants[$resId] = array();
            }
            $reservationParticipants[$resId][] = array('id' => $row['memberid'], 'invited' => $row['invited']);
        }
        $legacyReservationReader = $legacyDatabase->Query($getLegacyReservations);
        while ($row = $legacyReservationReader->GetRow()) {
            $legacyId = $row['resid'];
            if (in_array($legacyId, $knownIds)) {
                continue;
            }
            $date = $this->BuildDateRange($row['start_date'], $row['starttime'], $row['end_date'], $row['endtime']);
            $mappedUserId = $userMapping[$row['memberid']];
            $mappedResourceId = $resourceMapping[$row['machid']];
            if ($row['is_blackout'] == 1) {
                // handle blackout
                $blackout = BlackoutSeries::Create($mappedUserId, '', $date);
                $blackout->AddResourceId($mappedResourceId);
                $newId = $blackoutRepository->Add($blackout);
                $currentDatabase->Execute(new AdHocCommand("update blackout_series set legacyid = \"{$legacyId}\" where blackout_series_id = {$newId}"));
            } else {
                // handle reservation
                $mappedParticipantIds = array();
                $mappedInviteeIds = array();
                if (array_key_exists($legacyId, $reservationParticipants)) {
                    $legacyParticipants = $reservationParticipants[$legacyId];
                    foreach ($legacyParticipants as $legacyParticipantId) {
                        $userId = $userMapping[$legacyParticipantId['id']];
                        if (empty($legacyParticipantId['invited'])) {
                            $mappedParticipantIds[] = $userId;
                        } else {
                            $mappedInviteeIds[] = $userId;
                        }
                    }
                }
                $mappedAccessoryList = array();
                if (array_key_exists($legacyId, $reservationAccessories)) {
                    $legacyAccessories = $reservationAccessories[$legacyId];
                    foreach ($legacyAccessories as $legacyAccessoryId) {
                        if (array_key_exists($legacyAccessoryId, $accessoryMapping)) {
                            $mappedAccessoryId = $accessoryMapping[$legacyAccessoryId];
                            $mappedAccessoryList[] = new ReservationAccessory($mappedAccessoryId, 1);
                        }
                    }
                }
                $currentUser = new UserSession($row['memberid']);
                $currentUser->Timezone = Configuration::Instance()->GetDefaultTimezone();
                $mappedResource = new MigrateBookableResource($mappedResourceId);
                $reservation = ReservationSeries::Create($mappedUserId, $mappedResource, '', $row['summary'], $date, new RepeatNone(), $currentUser);
                foreach ($mappedAccessoryList as $accessory) {
                    $reservation->AddAccessory($accessory);
                }
                $reservation->ChangeParticipants($mappedParticipantIds);
                $reservation->ChangeInvitees($mappedInviteeIds);
                try {
                    $reservationRepository->Add($reservation);
                    $newId = $reservation->SeriesId();
                    $currentDatabase->Execute(new AdHocCommand("update reservation_series set legacyid = \"{$legacyId}\" where series_id = {$newId}"));
                } catch (Exception $ex) {
                    Log::Error('Error migrating reservation %s. Exception: %s', $legacyId, $ex);
                }
            }
            $reservationsMigrated++;
            MigrationSession::SetLastReservationRow($reservationsMigrated);
        }
        Log::Debug('Done migrating reservations (%s reservations)', $reservationsMigrated);
        $getLegacyCount = new AdHocCommand('select count(*) as count from reservations');
        //		$getMigratedCount = new AdHocCommand('SELECT
        //		(select count(*) from reservation_series where legacyid is not null) +
        //		(select count(*) from blackout_series where legacyid is not null )
        //		as count');
        $progressCounts = $this->GetProgressCounts($getLegacyCount, $getMigratedCount);
        $this->page->SetProgress($progressCounts);
        Log::Debug('There are %s total legacy reservations and %s already migrated. Progress is %s', $progressCounts->LegacyCount, $progressCounts->MigratedCount, $progressCounts->PercentComplete);
        $this->page->SetReservationsMigrated($progressCounts->MigratedCount);
        MigrationSession::SetLastReservationRow($progressCounts->MigratedCount);
    }
 public function SetParticipants($reservationRefNum)
 {
     $reservationRepository = new ReservationRepository();
     $series = $reservationRepository->LoadByReferenceNumber($reservationRefNum);
     $userrepo = new UserRepository();
     $participantIDs = $series->CurrentInstance()->Participants();
     foreach ($participantIDs as $value) {
         $user = $userrepo->LoadById($value);
         $participantnames[] = $user->FullName();
     }
     return $participantnames;
 }
Пример #4
0
$rid = trim($_REQUEST['rid']);
if ($contact_info && $rid) {
    header('HTTP/1.1 406 Not Acceptable', true, 406);
    print json_encode(array('message' => "You must not set both contact_info and rid"));
    return;
}
if ($contact_info) {
    $resource = $resourceRepository->LoadByContactInfo($contact_info);
} elseif ($rid) {
    $resource = $resourceRepository->LoadByPublicId($rid);
}
$updateAction = ReservationAction::Update;
$persistenceFactory = new ReservationPersistenceFactory();
$persistenceService = $persistenceFactory->Create($updateAction);
$handler = ReservationHandler::Create($updateAction, $persistenceService, ServiceLocator::GetServer()->GetUserSession());
$reservationRepository = new ReservationRepository();
$series = $reservationRepository->LoadByReferenceNumber($params['rn']);
if (!$series) {
    header('HTTP/1.1 404 Not Found', true, 404);
    $response = array('reference_number' => $rn, 'message' => 'Reservation could not be found');
    print json_encode($response);
    return;
}
$series->ApplyChangesTo(SeriesUpdateScope::FullSeries);
if ($params['starts_at'] || $params['ends_at']) {
    if (!$params['starts_at']) {
        $params['starts_at'] = $series->CurrentInstance()->Duration()->GetBegin();
    }
    if (!$params['ends_at']) {
        $params['ends_at'] = $series->CurrentInstance()->Duration()->GetEnd();
    }
Пример #5
0
    $resources[] = $resource;
}
echo "Loaded {$numberOfResources} resources<br/>";
// ACCESSORIES
$db->Execute(new AdHocCommand("delete from accessories where accessory_name like 'load%'"));
$accessoryRepo = new AccessoryRepository();
for ($i = 0; $i < $numberOfAccessories; $i++) {
    $accessory = new Accessory(0, "Load {$i}", 10);
    $id = $accessoryRepo->Add($accessory);
}
echo "Loaded {$numberOfAccessories} accessories<br/>";
// RESERVATIONS
$db->Execute(new AdHocCommand("delete from reservation_series where title like 'load%'"));
$scheduleRepo = new ScheduleRepository();
$layout = $scheduleRepo->GetLayout(1, new ScheduleLayoutFactory('America/Chicago'));
$reservationRepo = new ReservationRepository();
$bookedBy = new UserSession(1);
$bookedBy->Timezone = 'America/Chicago';
$currentDate = Date::Now();
$i = 0;
while ($i < $numberOfReservations) {
    $periods = $layout->GetLayout($currentDate);
    foreach ($periods as $period) {
        $howManyResources = rand(1, count($resources));
        $startResource = rand(0, $howManyResources);
        if ($period->IsReservable()) {
            for ($resourceNum = $startResource; $resourceNum < $howManyResources; $resourceNum++) {
                $userId = getRandomUserId($users)->Id();
                $resource = $resources[$resourceNum];
                $date = new DateRange($period->BeginDate(), $period->EndDate(), 'America/Chicago');
                $reservation = ReservationSeries::Create($userId, $resource, "load{$i}", null, $date, new RepeatNone(), $bookedBy);