本文整理汇总了PHP中ConnectionManager::connectToDatabase方法的典型用法代码示例。如果您正苦于以下问题:PHP ConnectionManager::connectToDatabase方法的具体用法?PHP ConnectionManager::connectToDatabase怎么用?PHP ConnectionManager::connectToDatabase使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConnectionManager
的用法示例。
在下文中一共展示了ConnectionManager::connectToDatabase方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: array_shift
}
break;
default:
echo "Unrecognized switch: {$argv[1]}\n\n";
$switchError = true;
break;
}
array_shift($argv);
}
// Display help message if parameters missing:
if (!isset($argv[2]) || $switchError) {
echo "Usage: {$progName} [--test-only] [--index <type>] XML_file " . "properties_file\n" . "\tXML_file - source file to index\n" . "\tproperties_file - import configuration file\n" . "If the optional --test-only flag is set, transformed XML will be " . "displayed\non screen for debugging purposes, but it will not be " . "indexed into VuFind.\n\n" . "If the optional --index parameter is set, it must be followed by " . "the name of\na class for accessing Solr; it defaults to the standard " . "Solr class, but could\nbe overridden with, for example, SolrAuth to " . "load authority records.\n\n" . "Note: See vudl.properties and ojs.properties for configuration " . "examples.\n";
exit(1);
}
// Setup Local Database Connection
ConnectionManager::connectToDatabase();
// Process the file (or die trying):
$xml = processXSLT($argv[1], $argv[2]);
if (!$xml) {
exit(1);
}
// Save the results (or just display them, if in test mode):
if (!$testMode) {
$solr = ConnectionManager::connectToIndex($index);
$result = $solr->saveRecord($xml);
if (!PEAR::isError($result)) {
echo "Successfully imported {$argv[1]}...\n";
exit(0);
} else {
echo "Fatal error: " . $result->getMessage() . "\n";
exit(1);
示例2: process
/**
* Process transactions. Try to register unregistered transactions
* and inform on expired transactions.
*
* @return void
* @access public
*/
public function process()
{
global $configArray;
global $interface;
ini_set('display_errors', true);
$configArray = $mainConfig = readConfig();
$datasourceConfig = getExtraConfigArray('datasources');
// Set up time zone. N.B. Don't use msg() or other
// functions requiring date before this.
date_default_timezone_set($configArray['Site']['timezone']);
$this->msg("OnlinePayment monitor started");
// Setup Local Database Connection
ConnectionManager::connectToDatabase();
// Initialize Mailer
$mailer = new VuFindMailer();
$now = new DateTime();
$expiredCnt = 0;
$failedCnt = 0;
$registeredCnt = 0;
$remindCnt = 0;
$user = false;
$report = array();
// Attempt to re-register paid transactions whose registration has failed.
$tr = new Transaction();
foreach ($tr->getFailedTransactions() as $t) {
$this->msg(" Registering transaction id {$t->id} / {$t->transaction_id}");
// check if the transaction has not been registered for too long
$paid_time = new DateTime($t->paid);
$diff = $now->diff($paid_time);
$diffHours = $diff->days * 24 + $diff->h;
if ($diffHours > $this->expireHours) {
if (!isset($report[$t->driver])) {
$report[$t->driver] = 0;
}
$report[$t->driver]++;
$expiredCnt++;
if (!$t->setTransactionReported($t->transaction_id)) {
$this->err(' Failed to update transaction ' . $t->transaction_id . 'as reported');
}
$transaction = clone $t;
$transaction->complete = Transaction::STATUS_REGISTRATION_EXPIRED;
if ($transaction->update($t) === false) {
$this->err(' Failed to update transaction ' . $t->transaction_id . 'as expired.');
} else {
$this->msg(' Transaction ' . $t->transaction_id . ' expired.');
}
} else {
if ($user === false || $t->user_id != $user->id) {
$user = User::staticGet($t->user_id);
}
$catalog = ConnectionManager::connectToCatalog();
if ($catalog && $catalog->status) {
$account = new User_account();
$account->user_id = $t->user_id;
$account->cat_username = $t->cat_username;
if ($account->find(true)) {
if (!($patron = $catalog->patronLogin($t->cat_username, $account->cat_password))) {
$this->err(' Could not perform patron login for transaction ' . $t->transaction_id);
$failedCnt++;
continue;
}
}
$res = $catalog->markFeesAsPaid($patron, $t->amount);
if ($res === true) {
if (!$t->setTransactionRegistered($t->transaction_id)) {
$this->err(' Failed to update transaction ' . $t->transaction_id . 'as registered');
}
$registeredCnt++;
} else {
$t->setTransactionRegistrationFailed($t->transaction_id, $res);
$failedCnt++;
$this->msg(' Registration of transaction ' . $t->transaction_id . ' failed');
$this->msg(" {$res}");
}
} else {
$this->err("Failed to connect to catalog ({$patronId})");
continue;
}
}
}
// Report paid and unregistered transactions whose registration
// can not be re-tried:
$tr = new Transaction();
foreach ($tr->getUnresolvedTransactions($this->reportIntervalHours) as $t) {
$this->msg(" Transaction id {$t->transaction_id} still unresolved.");
if (!$t->setTransactionReported($t->transaction_id)) {
$this->err(' Failed to update transaction ' . $t->transaction_id . ' as reported');
}
if (!isset($report[$t->driver])) {
$report[$t->driver] = 0;
}
$report[$t->driver]++;
$remindCnt++;
//.........这里部分代码省略.........
示例3: send
/**
* Send scheduled alerts
*
* @return void
*/
public function send()
{
global $configArray;
global $interface;
global $translator;
$iso8601 = 'Y-m-d\\TH:i:s\\Z';
ini_set('display_errors', true);
$configArray = $mainConfig = readConfig();
$datasourceConfig = getExtraConfigArray('datasources');
$siteLocal = $configArray['Site']['local'];
// Set up time zone. N.B. Don't use msg() or other functions requiring date before this.
date_default_timezone_set($configArray['Site']['timezone']);
$this->msg('Sending scheduled alerts');
// Setup Local Database Connection
ConnectionManager::connectToDatabase();
// Initialize Mailer
$mailer = new VuFindMailer();
// Find all scheduled alerts
$sql = 'SELECT * FROM "search" WHERE "schedule" > 0 ORDER BY user_id';
$s = new SearchEntry();
$s->query($sql);
$this->msg('Processing ' . $s->N . ' searches');
$user = false;
$interface = false;
$institution = false;
$todayTime = new DateTime();
while ($s->fetch()) {
$lastTime = new DateTime($s->last_executed);
if ($s->schedule == 1) {
// Daily
if ($todayTime->format('Y-m-d') == $lastTime->format('Y-m-d')) {
$this->msg('Bypassing search ' . $s->id . ': previous execution too recent (daily, ' . $lastTime->format($iso8601) . ')');
continue;
}
} elseif ($s->schedule == 2) {
// Weekly
$diff = $todayTime->diff($lastTime);
if ($diff->days < 6) {
$this->msg('Bypassing search ' . $s->id . ': previous execution too recent (weekly, ' . $lastTime->format($iso8601) . ')');
continue;
}
} else {
$this->msg('Search ' . $s->id . ': unknown schedule: ' . $s->schedule);
continue;
}
if ($user === false || $s->user_id != $user->id) {
$user = User::staticGet($s->user_id);
}
if (!$user->email || trim($user->email) == '') {
$this->msg('User ' . $user->username . ' does not have an email address, bypassing alert ' . $s->id);
continue;
}
$userInstitution = reset(explode(':', $user->username, 2));
if (!$institution || $institution != $userInstitution) {
$institution = $userInstitution;
if (!isset($datasourceConfig[$institution])) {
foreach ($datasourceConfig as $code => $values) {
if (isset($values['institution']) && strcasecmp($values['institution'], $institution) == 0) {
$institution = $code;
break;
}
}
}
if (!($configArray = $this->readInstitutionConfig($institution))) {
continue;
}
$configArray['Site']['url'] = $s->schedule_base_url;
// Start Interface
$interface = new UInterface($siteLocal);
$validLanguages = array_keys($configArray['Languages']);
$dateFormat = new VuFindDate();
}
$language = $user->language;
if (!in_array($user->language, $validLanguages)) {
$language = $configArray['Site']['language'];
}
$translator = new I18N_Translator(array($configArray['Site']['local'] . '/lang', $configArray['Site']['local'] . '/lang_local'), $language, $configArray['System']['debug']);
$interface->setLanguage($language);
$minSO = unserialize($s->search_object);
// Check minified search object type
$searchObject = SearchObjectFactory::deminify($minSO);
if (!$searchObject instanceof SearchObject_Solr) {
$this->msg('Search ' . $s->id . ': search object type not supported');
continue;
}
// Create a new search object to avoid cached defaults for e.g.
// hidden filters.
$searchObject = SearchObjectFactory::initSearchObject();
$searchObject->deminify($minSO);
$searchObject->setSort('first_indexed desc');
$searchTime = time();
$searchDate = gmdate($iso8601, time());
$searchObject->setLimit(50);
$searchObject->disableLogging();
$results = $searchObject->processSearch();
//.........这里部分代码省略.........
示例4: send
/**
* Send due date reminders
*
* @return void
*/
public function send()
{
global $configArray;
global $interface;
global $translator;
$iso8601 = 'Y-m-d\\TH:i:s\\Z';
ini_set('display_errors', true);
$configArray = $mainConfig = readConfig();
$datasourceConfig = getExtraConfigArray('datasources');
$siteLocal = $configArray['Site']['local'];
// Set up time zone. N.B. Don't use msg() or other functions requiring date before this.
date_default_timezone_set($configArray['Site']['timezone']);
$this->msg('Sending due date reminders');
// Setup Local Database Connection
ConnectionManager::connectToDatabase();
// And index
$db = ConnectionManager::connectToIndex();
// Initialize Mailer
$mailer = new VuFindMailer();
// Find all scheduled alerts
$sql = 'SELECT * FROM "user" WHERE "due_date_reminder" > 0 ORDER BY id';
$user = new User();
$user->query($sql);
$this->msg('Processing ' . $user->N . ' users');
$interface = false;
$institution = false;
$todayTime = new DateTime();
$catalog = ConnectionManager::connectToCatalog();
while ($user->fetch()) {
if (!$user->email || trim($user->email) == '') {
$this->msg('User ' . $user->username . ' does not have an email address, bypassing due date reminders');
continue;
}
// Initialize settings and interface
$userInstitution = reset(explode(':', $user->username, 2));
if (!$institution || $institution != $userInstitution) {
$institution = $userInstitution;
if (!isset($datasourceConfig[$institution])) {
foreach ($datasourceConfig as $code => $values) {
if (isset($values['institution']) && strcasecmp($values['institution'], $institution) == 0) {
$institution = $code;
break;
}
}
}
if (!($configArray = $this->readInstitutionConfig($institution))) {
continue;
}
// Start Interface
$interface = new UInterface($siteLocal);
$validLanguages = array_keys($configArray['Languages']);
$dateFormat = new VuFindDate();
}
$language = $user->language;
if (!in_array($user->language, $validLanguages)) {
$language = $configArray['Site']['language'];
}
$translator = new I18N_Translator(array($configArray['Site']['local'] . '/lang', $configArray['Site']['local'] . '/lang_local'), $language, $configArray['System']['debug']);
$interface->setLanguage($language);
// Go through accounts and check loans
$account = new User_account();
$account->user_id = $user->id;
if (!$account->find(false)) {
continue;
}
$remindLoans = array();
while ($account->fetch()) {
$patron = $catalog->patronLogin($account->cat_username, $account->cat_password);
if ($patron === null || PEAR::isError($patron)) {
$this->msg('Catalog login failed for user ' . $user->id . ', account ' . $account->id . ' (' . $account->cat_username . '): ' . ($patron ? $patron->getMessage() : 'patron not found'));
continue;
}
$loans = $catalog->getMyTransactions($patron);
if (PEAR::isError($loans)) {
$this->msg('Could not fetch loans for user ' . $user->id . ', account ' . $account->id . ' (' . $account->cat_username . ')');
continue;
}
foreach ($loans as $loan) {
$dueDate = new DateTime($loan['duedate']);
if ($todayTime >= $dueDate || $dueDate->diff($todayTime)->days <= $user->due_date_reminder) {
// Check that a reminder hasn't been sent already
$reminder = new Due_date_reminder();
$reminder->user_id = $user->id;
$reminder->loan_id = $loan['item_id'];
$reminder->due_date = $dueDate->format($iso8601);
if ($reminder->find(false)) {
// Reminder already sent
continue;
}
// Store also title for display in email
$title = isset($loan['title']) ? $loan['title'] : translate('Title not available');
if (isset($loan['id'])) {
$record = $db->getRecord($loan['id']);
if ($record && isset($record['title'])) {
$title = $record['title'];
//.........这里部分代码省略.........