public function Add(Schedule $schedule, $copyLayoutFromScheduleId)
 {
     $user = $this->repo->LoadById($this->user->UserId);
     if (!$user->IsInRole(RoleLevel::SCHEDULE_ADMIN)) {
         throw new Exception(sprintf('Schedule Add Failed. User %s does not have admin access.', $this->user->UserId));
     }
     foreach ($user->Groups() as $group) {
         if ($group->IsScheduleAdmin) {
             $schedule->SetAdminGroupId($group->GroupId);
             break;
         }
     }
     parent::Add($schedule, $copyLayoutFromScheduleId);
 }
 public function testCanAddNewSchedule()
 {
     $layoutId = 87;
     $name = 'new dude';
     $isDefault = false;
     $weekdayStart = 2;
     $daysVisible = 5;
     $scheduleIdOfSourceLayout = 981;
     $schedule = new Schedule(null, $name, $isDefault, $weekdayStart, $daysVisible, null, $layoutId);
     $expectedGetScheduleById = new GetScheduleByIdCommand($scheduleIdOfSourceLayout);
     $fakeSchedules = new FakeScheduleRepository();
     $this->db->SetRows(array($fakeSchedules->GetRow(9, null, true, 0, 0, null, $layoutId)));
     $expectedInsertScheduleCommand = new AddScheduleCommand($name, $isDefault, $weekdayStart, $daysVisible, $layoutId);
     $this->scheduleRepository->Add($schedule, $scheduleIdOfSourceLayout);
     $this->assertTrue($this->db->ContainsCommand($expectedGetScheduleById));
     $this->assertTrue($this->db->ContainsCommand($expectedInsertScheduleCommand));
 }
Exemple #3
0
 private function MigrateSchedules(Database $legacyDatabase, Database $currentDatabase)
 {
     $schedulesMigrated = MigrationSession::GetLastScheduleRow();
     Log::Debug('Start migrating schedules. Starting at row %s', $schedulesMigrated);
     $scheduleRepo = new ScheduleRepository();
     $getLegacySchedules = new AdHocCommand("select scheduleid, scheduletitle, daystart, dayend, timespan,\n                timeformat, weekdaystart, viewdays, usepermissions, ishidden, showsummary, adminemail, isdefault\n                from schedules order by scheduleid limit {$schedulesMigrated}, 500");
     $getExistingSchedules = new AdHocCommand('select legacyid from schedules');
     $reader = $currentDatabase->Query($getExistingSchedules);
     $knownIds = array();
     while ($row = $reader->GetRow()) {
         $knownIds[] = $row['legacyid'];
     }
     $reader = $legacyDatabase->Query($getLegacySchedules);
     while ($row = $reader->GetRow()) {
         $legacyScheduleId = $row['scheduleid'];
         if (in_array($legacyScheduleId, $knownIds)) {
             continue;
         }
         $newId = $scheduleRepo->Add(new Schedule(null, $row['scheduletitle'], false, $row['weekdaystart'], $row['viewdays']), 1);
         $currentDatabase->Execute(new AdHocCommand("update schedules set legacyid = \"{$row['scheduleid']}\" where schedule_id = {$newId}"));
         $timezone = Configuration::Instance()->GetDefaultTimezone();
         $available = $this->CreateAvailableTimeSlots($row['daystart'], $row['dayend'], $row['timespan']);
         $unavailable = $this->CreateUnavailableTimeSlots($row['daystart'], $row['dayend'], $row['timespan']);
         $layout = ScheduleLayout::Parse($timezone, $available, $unavailable);
         $scheduleRepo->AddScheduleLayout($newId, $layout);
         $schedulesMigrated++;
         MigrationSession::SetLastScheduleRow($schedulesMigrated);
     }
     Log::Debug('Done migrating schedules (%s schedules)', $schedulesMigrated);
     $getLegacyCount = new AdHocCommand('select count(*) as count from schedules');
     $getMigratedCount = new AdHocCommand('select count(*) as count from schedules where legacyid is not null');
     $progressCounts = $this->GetProgressCounts($getLegacyCount, $getMigratedCount);
     $this->page->SetProgress($progressCounts);
     $this->page->SetSchedulesMigrated($progressCounts->MigratedCount);
     MigrationSession::SetLastScheduleRow($progressCounts->MigratedCount);
 }