protected function load()
 {
     $this->rows = array();
     $this->db = Loader::db();
     if (!$this->db) {
         return;
     }
     $r = $this->db->Execute('select * from ConfigStore where uID = 0 order by cfKey asc');
     while ($row = $r->FetchRow()) {
         if (!$row['pkgID']) {
             $row['pkgID'] = 0;
         }
         $this->rows["{$row['cfKey']}.{$row['pkgID']}"] = $row;
     }
     $r->Close();
 }
Example #2
0
 public function Execute(Database $database)
 {
     $database->Execute(new RemoveReservationReminderCommand($this->event->SeriesId(), $this->event->ReminderType()));
     $database->Execute(new AddReservationReminderCommand($this->event->SeriesId(), $this->event->MinutesPrior(), $this->event->ReminderType()));
 }
Example #3
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);
    }
 }
 // Create account --------------
 if (empty($GLOBALS['script_error_log'])) {
     $_POST['user_name'] = trim($_POST['user_name']);
     $_POST['user_location'] = trim($_POST['user_location']);
     $_POST['user_email'] = trim($_POST['user_email']);
     if (empty($_POST['user_name'])) {
         $GLOBALS['script_error_log'][] = _("You must provide a name.");
     }
     if (empty($openid_name)) {
         $GLOBALS['script_error_log'][] = _("You must provide an openid name.");
     } else {
         require_once '../class/Db.class.php';
         $db = new Database($core_config['db']);
         $query = "\n\t\t\t\tSELECT user_id\n\t\t\t\tFROM " . $db->prefix . "_user\n\t\t\t\tWHERE openid_name=" . $db->qstr($openid_name);
         $result = $db->Execute($query);
         if (!empty($result[0])) {
             $user_id = $result[0]['user_id'];
         }
     }
     if (!checkEmail($_POST['user_email'])) {
         $GLOBALS['script_error_log'][] = _("Your email address does not like a valid email address.");
     }
     if (empty($_POST['user_location'])) {
         $GLOBALS['script_error_log'][] = _("You must provide a location.");
     }
     if ($_POST['user_password1'] != $_POST['user_password2']) {
         $GLOBALS['script_error_log'][] = _("Your new passwords did not match.");
     }
     if (strlen($_POST['user_password1']) < 2) {
         $GLOBALS['script_error_log'][] = _("Your password must be longer than 2 characters.");
Example #5
0
 function testConnectAndDisconnectAreCalledForEachExecute()
 {
     $SqlCommand = new SqlCommand('query');
     $cn = new FakeDBConnection();
     $db = new Database($cn);
     $db->Execute($SqlCommand);
     $this->assertTrue($cn->_ConnectWasCalled, 'Connect should be called for every query');
     $this->assertEquals($SqlCommand, $cn->_LastExecuteCommand);
     $this->assertTrue($cn->_DisconnectWasCalled, 'Disonnect should be called for every query');
 }
Example #6
0
	private function load() {
		if (defined('ENABLE_CACHE') && (!ENABLE_CACHE)) {
			// if cache has been explicitly disabled, we re-enable it anyway.
			Cache::enableCache();
		}
		$val = Cache::get('config_options', 'all');
		if ($val) {
			$this->rows = $val;
		} else {
			$this->rows = array();
			$r = $this->db->Execute('select * from Config where uID = 0 order by cfKey asc');
			while ($row = $r->FetchRow()) {
				if (!$row['pkgID']) {
					$row['pkgID'] = 0;
				}
				$this->rows["{$row['cfKey']}.{$row['pkgID']}"] = $row;
			}
			$r->Close();
			Cache::set('config_options', 'all', $this->rows);
		}
		if (defined('ENABLE_CACHE') && (!ENABLE_CACHE)) {
			Cache::disableCache();
		}
	}
Example #7
0
// inner template
// SETUP WEBSPACE ---------------------------------------------------
if (!empty($core_config['script']['single_webspace'])) {
    // single comain name
    $user_webspace = $core_config['script']['single_webspace'];
} elseif (!empty($core_config['script']['multiple_webspace_pattern'])) {
    // using sub-domains
    preg_match($core_config['script']['multiple_webspace_pattern'], $_SERVER['HTTP_HOST'], $matches);
    if (!empty($matches[1])) {
        $user_webspace = $matches[1];
    }
}
if (isset($user_webspace)) {
    // SELECT WEBSPACE -------------------------------------------
    $query = "\n\t\tSELECT ws.webspace_css, ws.webspace_html, u.openid_name, \n\t\tu.user_name, u.user_email, u.user_location, u.user_id, \n\t\tws.webspace_title, ws.webspace_theme, u.user_live \n\t\tFROM " . $db->prefix . "_user u \n\t\tLEFT JOIN " . $db->prefix . "_webspace ws ON u.user_id=ws.user_id \n\t\tWHERE \n\t\tu.openid_name=" . $db->qstr($user_webspace);
    $result = $db->Execute($query, 1);
    if (!empty($result[0]) && $result[0]['user_live'] == 1) {
        $webspace = $result[0];
        define("WEBSPACE_OPENID", $webspace['openid_name']);
        define("WEBSPACE_USERID", $webspace['user_id']);
        define("WEBSPACE_USERNAME", $webspace['user_name']);
        if (!empty($webspace['webspace_title'])) {
            $tpl->set('webspace_title', $webspace['webspace_title']);
        }
        $body->set('webspace', $webspace);
        $maintainer_openids = array();
        if (!empty($core_config['security']['maintainer_openids'])) {
            $maintainer_openids = explode(",", $core_config['security']['maintainer_openids']);
            foreach ($maintainer_openids as $key => $i) {
                $maintainer_openids[$key] = trim($i);
            }
 /**
  * Save the current values as the new config table.
  *
  * @param null|string $name
  * @return mixed|void
  */
 public function save($name = null)
 {
     if (is_null($name)) {
         reset($this->values);
         // rewind the array to the first element
         foreach ($this->values as $name => $value) {
             $this->save($name);
         }
     } else {
         $this->database->Execute("DELETE FROM config WHERE name = :name", array("name" => $name));
         $this->database->Execute("INSERT INTO config VALUES (:name, :value)", array("name" => $name, "value" => $this->values[$name]));
     }
     // rather than deleting and having some other request(s) do a thundering
     // herd of race-conditioned updates, just save the updated version once here
     $this->database->cache->set("config", $this->values);
 }