public function testCanAddResourceWithMinimumAttributes()
 {
     $name = "name";
     $scheduleId = 828;
     $resourceId = 8888;
     $autoAssign = true;
     $groupId = 111;
     $resource = BookableResource::CreateNew($name, $scheduleId, $autoAssign);
     $resource->SetAdminGroupId($groupId);
     $this->db->_ExpectedInsertId = $resourceId;
     $this->repository->Add($resource);
     $expectedAddCommand = new AddResourceCommand($name, $scheduleId, $autoAssign, $groupId);
     $assignResourcePermissions = new AutoAssignResourcePermissionsCommand($resourceId);
     $actualAddResourceCommand = $this->db->_Commands[0];
     $actualAssignResourcePermissions = $this->db->_Commands[1];
     $this->assertEquals($expectedAddCommand, $actualAddResourceCommand);
     $this->assertEquals($assignResourcePermissions, $actualAssignResourcePermissions);
 }
示例#2
0
 private function MigrateResources(Database $legacyDatabase, Database $currentDatabase)
 {
     $resourcesMigrated = MigrationSession::GetLastResourceRow();
     Log::Debug('Start migrating resources. Starting at row %s', $resourcesMigrated);
     $resourceRepo = new ResourceRepository();
     $getExisting = new AdHocCommand('select legacyid from resources');
     $reader = $currentDatabase->Query($getExisting);
     $knownIds = array();
     while ($row = $reader->GetRow()) {
         $knownIds[] = $row['legacyid'];
     }
     $getResources = new AdHocCommand("select machid, scheduleid, name, location, rphone, notes, status, minres, maxres, autoassign, approval,\n                        allow_multi, max_participants, min_notice_time, max_notice_time\n                        from resources order by machid limit {$resourcesMigrated}, 500");
     $reader = $legacyDatabase->Query($getResources);
     while ($row = $reader->GetRow()) {
         $legacyResourceId = $row['machid'];
         if (in_array($legacyResourceId, $knownIds)) {
             continue;
         }
         $newScheduleReader = $currentDatabase->Query(new AdHocCommand("select schedule_id from schedules where legacyId = \"{$row['scheduleid']}\""));
         if ($srow = $newScheduleReader->GetRow()) {
             $newScheduleId = $srow['schedule_id'];
         }
         $minTimeSeconds = $row['minres'] * 60;
         $maxTimeSeconds = $row['maxres'] * 60;
         $min_notice_time = $row['min_notice_time'] * 60;
         $max_notice_time = $row['max_notice_time'] * 60;
         $newId = $resourceRepo->Add(new BookableResource(null, $row['name'], $row['location'], $row['rphone'], $row['notes'], $minTimeSeconds, $maxTimeSeconds, $row['autoassign'], $row['approval'], $row['allow_multi'], $row['max_participants'], $min_notice_time, $max_notice_time, null, $newScheduleId));
         $currentDatabase->Execute(new AdHocCommand("update resources set legacyid = \"{$row['machid']}\" where resource_id = {$newId}"));
         $resourcesMigrated++;
         MigrationSession::SetLastResourceRow($resourcesMigrated);
     }
     Log::Debug('Done migrating resources (%s resources)', $resourcesMigrated);
     $getLegacyCount = new AdHocCommand('select count(*) as count from resources');
     $getMigratedCount = new AdHocCommand('select count(*) as count from resources where legacyid is not null');
     $progressCounts = $this->GetProgressCounts($getLegacyCount, $getMigratedCount);
     $this->page->SetProgress($progressCounts);
     $this->page->SetResourcesMigrated($progressCounts->MigratedCount);
     MigrationSession::SetLastResourceRow($progressCounts->MigratedCount);
 }
示例#3
0
$db = ServiceLocator::GetDatabase();
// USERS
$db->Execute(new AdHocCommand("delete from users where fname ='load' and lname = 'test'"));
$userRepo = new UserRepository();
for ($i = 0; $i < $numberOfUsers; $i++) {
    $user = User::Create("load{$i}", "test{$i}", "email {$i}", "username {$i}", "en_us", "America/Chicago", "7b6aec38ff9b7650d64d0374194307bdde711425", "3b3dbb9b");
    $userId = $userRepo->Add($user);
    $users[] = $user;
}
echo "Loaded {$numberOfUsers} users<br/>";
// RESOURCES
$db->Execute(new AdHocCommand("delete from resources where name like 'load%'"));
$resourceRepo = new ResourceRepository();
for ($i = 0; $i < $numberOfResources; $i++) {
    $resource = BookableResource::CreateNew("load{$i}", 1);
    $resourceId = $resourceRepo->Add($resource);
    $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'));