public function testCanChangeLayoutWithDailySlots()
 {
     $scheduleId = 89;
     $layoutId = 90;
     $timezone = 'America/New_York';
     $start1 = new Time(0, 0);
     $end1 = new Time(12, 0);
     $label1 = 'label 1';
     $start2 = new Time(12, 0);
     $end2 = new Time(0, 0);
     $slots = array(new LayoutPeriod($start1, $end1, PeriodTypes::RESERVABLE, $label1), new LayoutPeriod($start2, $end2, PeriodTypes::NONRESERVABLE));
     $layout = $this->getMock('ILayoutCreation');
     $layout->expects($this->once())->method('UsesDailyLayouts')->will($this->returnValue(true));
     $layout->expects($this->once())->method('Timezone')->will($this->returnValue($timezone));
     foreach (DayOfWeek::Days() as $day) {
         $layout->expects($this->at($day + 2))->method('GetSlots')->with($this->equalTo($day))->will($this->returnValue($slots));
     }
     $this->db->_ExpectedInsertId = $layoutId;
     $this->scheduleRepository->AddScheduleLayout($scheduleId, $layout);
     $expectedInsertBlockGroup = new AddLayoutCommand($timezone);
     $expectedUpdateScheduleLayout = new UpdateScheduleLayoutCommand($scheduleId, $layoutId);
     $this->assertTrue($this->db->ContainsCommand($expectedInsertBlockGroup));
     foreach (DayOfWeek::Days() as $day) {
         $this->assertTrue($this->db->ContainsCommand(new AddLayoutTimeCommand($layoutId, $start1, $end1, PeriodTypes::RESERVABLE, $label1, $day)));
         $this->assertTrue($this->db->ContainsCommand(new AddLayoutTimeCommand($layoutId, $start2, $end2, PeriodTypes::NONRESERVABLE, null, $day)));
     }
     $this->assertTrue($this->db->ContainsCommand($expectedUpdateScheduleLayout));
     $this->assertTrue($this->db->ContainsCommand(new DeleteOrphanLayoutsCommand()));
 }
Exemple #2
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);
 }