/** * @copydoc GridHandler::loadData() */ protected function loadData($request, $filter) { $dbconn = DBConnection::getConn(); $dbServerInfo = $dbconn->ServerInfo(); $serverInfo = array('admin.server.platform' => Core::serverPHPOS(), 'admin.server.phpVersion' => Core::serverPHPVersion(), 'admin.server.apacheVersion' => function_exists('apache_get_version') ? apache_get_version() : __('common.notAvailable'), 'admin.server.dbDriver' => Config::getVar('database', 'driver'), 'admin.server.dbVersion' => empty($dbServerInfo['description']) ? $dbServerInfo['version'] : $dbServerInfo['description']); return $serverInfo; }
/** * Execute the command */ function execute() { $stderr = fopen('php://stdout', 'w'); $locales = AppLocale::getAllLocales(); $dbConn = DBConnection::getConn(); foreach ($locales as $locale => $localeName) { fprintf($stderr, "Checking {$localeName}...\n"); $oldTemplatesText = $this->fetchFileVersion('ojs', "locale/{$locale}/emailTemplates.xml", $this->oldTag); $newTemplatesText = $this->fetchFileVersion('ojs', "locale/{$locale}/emailTemplates.xml", $this->newTag); if ($oldTemplatesText === false || $newTemplatesText === false) { fprintf($stderr, "Skipping {$localeName}; could not fetch.\n"); continue; } $oldEmails = $this->parseEmails($oldTemplatesText); $newEmails = $this->parseEmails($newTemplatesText); foreach ($oldEmails['email_text'] as $oi => $junk) { $key = $junk['attributes']['key']; $ni = null; foreach ($newEmails['email_text'] as $ni => $junk) { if ($key == $junk['attributes']['key']) { break; } } if ($oldEmails['subject'][$oi]['value'] != $newEmails['subject'][$ni]['value']) { echo "UPDATE email_templates_default_data SET subject='" . $dbConn->escape($newEmails['subject'][$ni]['value']) . "' WHERE key='" . $dbConn->escape($key) . "' AND locale='" . $dbConn->escape($locale) . "' AND subject='" . $dbConn->escape($oldEmails['subject'][$oi]['value']) . "';\n"; } if ($oldEmails['body'][$oi]['value'] != $newEmails['body'][$ni]['value']) { echo "UPDATE email_templates_default_data SET body='" . $dbConn->escape($newEmails['body'][$ni]['value']) . "' WHERE key='" . $dbConn->escape($key) . "' AND locale='" . $dbConn->escape($locale) . "' AND body='" . $dbConn->escape($oldEmails['body'][$oi]['value']) . "';\n"; } } } fclose($stderr); }
/** * @copydoc GridHandler::loadData() */ protected function loadData($request, $filter) { $dbconn = DBConnection::getConn(); $dbServerInfo = $dbconn->ServerInfo(); $serverInfo = array('admin.server.platform' => PHP_OS, 'admin.server.phpVersion' => phpversion(), 'admin.server.apacheVersion' => $_SERVER['SERVER_SOFTWARE'], 'admin.server.dbDriver' => Config::getVar('database', 'driver'), 'admin.server.dbVersion' => empty($dbServerInfo['description']) ? $dbServerInfo['version'] : $dbServerInfo['description']); return $serverInfo; }
/** * Parse an XML database file and output the corresponding SQL statements. * See lib/pkp/dtd/xmlSchema.dtd for the format of the XML files. */ function execute() { require_once './lib/pkp/lib/adodb/adodb-xmlschema.inc.php'; if (in_array($this->command, array('print', 'save'))) { // Don't connect to actual database (so parser won't build upgrade XML) $conn = new DBConnection(Config::getVar('database', 'driver'), null, null, null, null, true, Config::getVar('i18n', 'connection_charset')); $dbconn = $conn->getDBConn(); } else { // Create or upgrade existing database $dbconn =& DBConnection::getConn(); } $schema = new adoSchema($dbconn); $dict =& $schema->dict; $dict->SetCharSet(Config::getVar('i18n', 'database_charset')); if ($this->type == 'schema') { // Parse XML schema files $sql = $schema->parseSchema($this->inputFile); switch ($this->command) { case 'execute': $schema->ExecuteSchema(); break; case 'save': case 'save_upgrade': $schema->SaveSQL($this->outputFile); break; case 'print': case 'print_upgrade': default: echo @$schema->PrintSQL('TEXT') . "\n"; break; } } else { if ($this->type == 'data') { // Parse XML data files $dataXMLParser = new DBDataXMLParser(); $dataXMLParser->setDBConn($dbconn); $sql = $dataXMLParser->parseData($this->inputFile); switch ($this->command) { case 'execute': $schema->addSQL($sql); $schema->ExecuteSchema(); break; case 'save': case 'save_upgrade': $schema->addSQL($sql); $schema->SaveSQL($this->outputFile); break; case 'print': case 'print_upgrade': default: $schema->addSQL($sql); echo @$schema->PrintSQL('TEXT') . "\n"; break; } $schema->destroy(); $dataXMLParser->destroy(); } } }
/** * (Un-)install the test schema (if it exists) * @param $testPhase string */ private function installTestSchema($testPhase) { if (is_readable($this->getTestSchemaFile($testPhase))) { if (is_null($this->_testSchema)) { import('classes.db.compat.AdodbXmlschemaCompat'); $this->_testSchema =& new AdodbXmlschemaCompat(DBConnection::getConn(), Config::getVar('i18n', 'database_charset')); } $this->_testSchema->ParseSchema($this->getTestSchemaFile($testPhase)); $this->_testSchema->ExecuteSchema(); } }
/** * Constructor. * Initialize the database connection. */ function DAO($dataSource = null, $callHooks = true) { if ($callHooks === true) { // Call hooks based on the object name. Results // in hook calls named e.g. "sessiondao::_Constructor" if (HookRegistry::call(strtolower_codesafe(get_class($this)) . '::_Constructor', array($this, &$dataSource))) { return; } } if (!isset($dataSource)) { $this->setDataSource(DBConnection::getConn()); } else { $this->setDataSource($dataSource); } }
/** * Constructor. * Initialize the database connection. */ function DAO($dataSource = null, $callHooks = true) { if ($callHooks === true && checkPhpVersion('4.3.0')) { // Call hooks based on the object name. Results // in hook calls named e.g. "sessiondao::_Constructor" if (HookRegistry::call(strtolower(get_class($this)) . '::_Constructor', array(&$this, &$dataSource))) { return; } } if (!isset($dataSource)) { $this->_dataSource =& DBConnection::getConn(); } else { $this->_dataSource = $dataSource; } }
/** * Test SQL DDL changes embedded in XML data descriptor. * @covers DBDataXMLParser::parseData */ public function testParseSQLDDL() { $dataXMLParser = new DBDataXMLParser(); $dataXMLParser->setDBConn(DBConnection::getConn()); switch (Config::getVar('database', 'driver')) { case 'mysql': $this->assertEquals(array(array('DROP TABLE IF EXISTS myDropTable'), array('ALTER TABLE myModTable DROP COLUMN myDropColumn'), array('RENAME TABLE sessions TO myNewTableName')), $dataXMLParser->parseData(dirname(__FILE__) . '/data-ddl.xml')); break; case 'postgres': $this->markTestSkipped('PostgreSQL/ADODB weirdness prevents this test.'); break; default: $this->fail('Unknown DB driver.'); } }
/** * Constructor. * Initialize the database connection. */ function DAO($dataSource = null, $callHooks = true) { if ($callHooks === true && checkPhpVersion('4.3.0')) { $trace = debug_backtrace(); // Call hooks based on the calling entity, assuming // this method is only called by a subclass. Results // in hook calls named e.g. "SessionDAO::Constructor" if (HookRegistry::call($trace[1]['class'] . '::Constructor', array(&$this, &$dataSource))) { return; } } if (!isset($dataSource)) { $this->_dataSource =& DBConnection::getConn(); } else { $this->_dataSource = $dataSource; } }
/** * Show system information summary. */ function systemInfo() { $this->validate(); $this->setupTemplate(true); $configData =& Config::getData(); $dbconn =& DBConnection::getConn(); $dbServerInfo = $dbconn->ServerInfo(); $versionDao =& DAORegistry::getDAO('VersionDAO'); $currentVersion =& $versionDao->getCurrentVersion(); $versionHistory =& $versionDao->getVersionHistory(); $serverInfo = array('admin.server.platform' => Core::serverPHPOS(), 'admin.server.phpVersion' => Core::serverPHPVersion(), 'admin.server.apacheVersion' => function_exists('apache_get_version') ? apache_get_version() : Locale::translate('common.notAvailable'), 'admin.server.dbDriver' => Config::getVar('database', 'driver'), 'admin.server.dbVersion' => empty($dbServerInfo['description']) ? $dbServerInfo['version'] : $dbServerInfo['description']); $templateMgr =& TemplateManager::getManager(); $templateMgr->assign_by_ref('currentVersion', $currentVersion); $templateMgr->assign_by_ref('versionHistory', $versionHistory); $templateMgr->assign_by_ref('configData', $configData); $templateMgr->assign_by_ref('serverInfo', $serverInfo); if (Request::getUserVar('versionCheck')) { $latestVersionInfo =& VersionCheck::getLatestVersion(); $latestVersionInfo['patch'] = VersionCheck::getPatch($latestVersionInfo); $templateMgr->assign_by_ref('latestVersionInfo', $latestVersionInfo); } $templateMgr->display('admin/systemInfo.tpl'); }
/** * Auxiliary function to errorHandler that returns a formatted error message. * Error type formatting code adapted from ash, http://ca3.php.net/manual/en/function.set-error-handler.php * @param $errorno string * @param $errstr string * @param $errfile string * @param $errline string * @return $message string */ function buildErrorMessage($errorno, $errstr, $errfile, $errline) { $message = array(); $errorType = array(E_ERROR => 'ERROR', E_WARNING => 'WARNING', E_PARSE => 'PARSING ERROR', E_NOTICE => 'NOTICE', E_CORE_ERROR => 'CORE ERROR', E_CORE_WARNING => 'CORE WARNING', E_COMPILE_ERROR => 'COMPILE ERROR', E_COMPILE_WARNING => 'COMPILE WARNING', E_USER_ERROR => 'USER ERROR', E_USER_WARNING => 'USER WARNING', E_USER_NOTICE => 'USER NOTICE'); if (array_key_exists($errorno, $errorType)) { $type = $errorType[$errorno]; } else { $type = 'CAUGHT EXCEPTION'; } // Return abridged message if strict error or notice (since they are more common) // This also avoids infinite loops when E_STRICT (=deprecation level) error // reporting is switched on. $shortErrors = E_NOTICE; if (defined('E_STRICT')) { $shortErrors |= E_STRICT; } if (defined('E_DEPRECATED')) { $shortErrors |= E_DEPRECATED; } if ($errorno & $shortErrors) { return $type . ': ' . $errstr . ' (' . $errfile . ':' . $errline . ')'; } $message[] = $this->getName() . ' has produced an error'; $message[] = ' Message: ' . $type . ': ' . $errstr; $message[] = ' In file: ' . $errfile; $message[] = ' At line: ' . $errline; $message[] = ' Stacktrace: '; if (Config::getVar('debug', 'show_stacktrace')) { $trace = debug_backtrace(); // Remove the call to fatalError from the call trace. array_shift($trace); // Back-trace pretty-printer adapted from the following URL: // http://ca3.php.net/manual/en/function.debug-backtrace.php // Thanks to diz at ysagoon dot com foreach ($trace as $bt) { $args = ''; if (isset($bt['args'])) { foreach ($bt['args'] as $a) { if (!empty($args)) { $args .= ', '; } switch (gettype($a)) { case 'integer': case 'double': $args .= $a; break; case 'string': $a = htmlspecialchars($a); $args .= "\"{$a}\""; break; case 'array': $args .= 'Array(' . count($a) . ')'; break; case 'object': $args .= 'Object(' . get_class($a) . ')'; break; case 'resource': $args .= 'Resource(' . strstr($a, '#') . ')'; break; case 'boolean': $args .= $a ? 'True' : 'False'; break; case 'NULL': $args .= 'Null'; break; default: $args .= 'Unknown'; } } } $class = isset($bt['class']) ? $bt['class'] : ''; $type = isset($bt['type']) ? $bt['type'] : ''; $function = isset($bt['function']) ? $bt['function'] : ''; $file = isset($bt['file']) ? $bt['file'] : '(unknown)'; $line = isset($bt['line']) ? $bt['line'] : '(unknown)'; $message[] = " File: {$file} line {$line}"; $message[] = " Function: {$class}{$type}{$function}({$args})"; } } static $dbServerInfo; if (!isset($dbServerInfo) && Config::getVar('general', 'installed')) { $dbconn =& DBConnection::getConn(); $dbServerInfo = $dbconn->ServerInfo(); } $message[] = " Server info:"; $message[] = " OS: " . Core::serverPHPOS(); $message[] = " PHP Version: " . Core::serverPHPVersion(); $message[] = " Apache Version: " . (function_exists('apache_get_version') ? apache_get_version() : 'N/A'); $message[] = " DB Driver: " . Config::getVar('database', 'driver'); if (isset($dbServerInfo)) { $message[] = " DB server version: " . (empty($dbServerInfo['description']) ? $dbServerInfo['version'] : $dbServerInfo['description']); } return implode("\n", $message); }
/** * Execute the parsed SQL statements. * @param $continueOnError boolean continue to execute remaining statements if a failure occurs * @return boolean success */ function executeData($continueOnError = false) { $this->errorMsg = null; $dbconn = $this->dbconn == null ? DBConnection::getConn() : $this->dbconn; foreach ($this->sql as $stmt) { $dbconn->execute($stmt); if (!$continueOnError && $dbconn->errorNo() != 0) { return false; } } return true; }