本文整理汇总了PHP中Zotero_DB::readOnly方法的典型用法代码示例。如果您正苦于以下问题:PHP Zotero_DB::readOnly方法的具体用法?PHP Zotero_DB::readOnly怎么用?PHP Zotero_DB::readOnly使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zotero_DB
的用法示例。
在下文中一共展示了Zotero_DB::readOnly方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: init
//.........这里部分代码省略.........
Zotero_Users::addFromWWW($this->objectUserID);
} catch (Exception $e) {
if ($e->getCode() == Z_ERROR_USER_NOT_FOUND) {
$this->e404("User {$this->objectUserID} not found");
}
throw $e;
}
$this->objectLibraryID = Zotero_Users::getLibraryIDFromUserID($this->objectUserID);
} else {
throw $e;
}
}
// Make sure user isn't banned
if (!Zotero_Users::isValidUser($this->objectUserID)) {
$this->e404();
}
} else {
if (isset($this->objectGroupID)) {
if (!$this->objectGroupID) {
$this->e400("Invalid group ID", Z_ERROR_INVALID_INPUT);
}
// Make sure group exists
$group = Zotero_Groups::get($this->objectGroupID);
if (!$group) {
$this->e404();
}
// Don't show groups owned by banned users
if (!Zotero_Users::isValidUser($group->ownerUserID)) {
$this->e404();
}
$this->objectLibraryID = Zotero_Groups::getLibraryIDFromGroupID($this->objectGroupID);
}
}
$apiVersion = !empty($_SERVER['HTTP_ZOTERO_API_VERSION']) ? (int) $_SERVER['HTTP_ZOTERO_API_VERSION'] : false;
// Serve v1 to ZotPad 1.x, at Mikko's request
if (!$apiVersion && !empty($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], 'ZotPad 1') === 0) {
$apiVersion = 1;
}
// For publications URLs (e.g., /users/:userID/publications/items), swap in
// objectLibraryID of user's publications library
if (!empty($extra['publications'])) {
// Query parameters not yet parsed, so check version parameter
if ($apiVersion && $apiVersion < 3 || !empty($_REQUEST['v']) && $_REQUEST['v'] < 3 || !empty($_REQUEST['version']) && $_REQUEST['version'] == 1) {
$this->e404();
}
$userLibraryID = $this->objectLibraryID;
$this->objectLibraryID = Zotero_Users::getLibraryIDFromUserID($this->objectUserID, 'publications');
// If one doesn't exist, for write requests create a library if the key
// has write permission to the user library. For read requests, just
// return a 404.
if (!$this->objectLibraryID) {
if ($this->isWriteMethod()) {
if (!$this->permissions->canAccess($userLibraryID) || !$this->permissions->canWrite($userLibraryID)) {
$this->e403();
}
$this->objectLibraryID = Zotero_Publications::add($this->objectUserID);
} else {
$this->objectLibraryID = 0;
}
}
}
// Return 409 if target library is locked
switch ($this->method) {
case 'POST':
case 'PUT':
case 'DELETE':
switch ($this->action) {
// Library lock doesn't matter for some admin requests
case 'keys':
case 'storageadmin':
break;
default:
if ($this->objectLibraryID && Zotero_Libraries::isLocked($this->objectLibraryID)) {
$this->e409("Target library is locked");
}
break;
}
}
$this->scopeObject = !empty($extra['scopeObject']) ? $extra['scopeObject'] : $this->scopeObject;
$this->subset = !empty($extra['subset']) ? $extra['subset'] : $this->subset;
$this->fileMode = !empty($extra['file']) ? !empty($_GET['info']) ? 'info' : 'download' : false;
$this->fileView = !empty($extra['view']);
$this->singleObject = $this->objectKey && !$this->subset;
$this->checkLibraryIfModifiedSinceVersion($this->action);
// If Accept header includes application/atom+xml, send Atom, as long as there's no 'format'
$atomAccepted = false;
if (!empty($_SERVER['HTTP_ACCEPT'])) {
$accept = preg_split('/\\s*,\\s*/', $_SERVER['HTTP_ACCEPT']);
$atomAccepted = in_array('application/atom+xml', $accept);
}
$this->queryParams = Zotero_API::parseQueryParams($_SERVER['QUERY_STRING'], $this->action, $this->singleObject, $apiVersion, $atomAccepted);
// Sorting by Item Type or Added By currently require writing to shard tables, so don't
// send those to the read replicas
if ($this->queryParams['sort'] == 'itemType' || $this->queryParams['sort'] == 'addedBy') {
Zotero_DB::readOnly(false);
}
$this->apiVersion = $version = $this->queryParams['v'];
header("Zotero-API-Version: " . $version);
StatsD::increment("api.request.version.v" . $version, 0.25);
}
示例2: preg_match
if ($_SERVER['REQUEST_URI'] == '*') {
//error_log("Ignoring OPTIONS request");
exit;
}
// Get canonical URL without extension and query string
preg_match("/[^?]+/", $_SERVER['REQUEST_URI'], $matches);
define('Z_ENV_SELF', $matches[0]);
// Load in core functions
require 'DB.inc.php';
require 'IPAddress.inc.php';
require 'Shards.inc.php';
require 'config/dbconnect.inc.php';
require 'StatsD.inc.php';
// Use DB read replicas for GET requests
if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'GET') {
Zotero_DB::readOnly(true);
}
// Database callbacks
Zotero_DB::addCallback("begin", array("Zotero_Notifier", "begin"));
Zotero_DB::addCallback("commit", array("Zotero_Notifier", "commit"));
Zotero_DB::addCallback("callback", array("Zotero_Notifier", "reset"));
Zotero_NotifierObserver::init();
// Memcached
require 'Memcached.inc.php';
Z_Core::$MC = new Z_MemcachedClientLocal(Z_CONFIG::$SYNC_DOMAIN, array('disabled' => !Z_CONFIG::$MEMCACHED_ENABLED, 'servers' => Z_CONFIG::$MEMCACHED_SERVERS));
Zotero_DB::addCallback("begin", array(Z_Core::$MC, "begin"));
Zotero_DB::addCallback("commit", array(Z_Core::$MC, "commit"));
Zotero_DB::addCallback("reset", array(Z_Core::$MC, "reset"));
//
// Set up AWS service factory
//
示例3: updated
public function updated()
{
// Shards can use read-only mode
Zotero_DB::readOnly(true);
// Master remains writable for session/queue data
Zotero_DB::readOnly(false, 0);
if (empty($_REQUEST['lastsync'])) {
$this->error(400, 'NO_LAST_SYNC_TIME', 'Last sync time not provided');
}
$lastsync = false;
if (is_numeric($_REQUEST['lastsync'])) {
$lastsync = (int) $_REQUEST['lastsync'];
} else {
$this->error(400, 'INVALID_LAST_SYNC_TIME', 'Last sync time is invalid');
}
$this->sessionCheck();
if (isset($_SERVER['HTTP_X_ZOTERO_VERSION'])) {
require_once '../model/ToolkitVersionComparator.inc.php';
if (ToolkitVersionComparator::compare($_SERVER['HTTP_X_ZOTERO_VERSION'], "2.0.4") < 0) {
$futureUsers = Z_Core::$MC->get('futureUsers');
if (!$futureUsers) {
$futureUsers = Zotero_DB::columnQuery("SELECT userID FROM futureUsers");
Z_Core::$MC->set('futureUsers', $futureUsers, 1800);
}
if (in_array($this->userID, $futureUsers)) {
Z_Core::logError("Blocking sync for future user " . $this->userID . " with version " . $_SERVER['HTTP_X_ZOTERO_VERSION']);
$upgradeMessage = "Due to improvements made to sync functionality, you must upgrade to Zotero 2.0.6 or later (via Firefox's Tools menu -> Add-ons -> Extensions -> Find Updates or from zotero.org) to continue syncing your Zotero library.";
$this->error(400, 'UPGRADE_REQUIRED', $upgradeMessage);
}
}
}
$doc = new DOMDocument();
$domResponse = dom_import_simplexml($this->responseXML);
$domResponse = $doc->importNode($domResponse, true);
$doc->appendChild($domResponse);
try {
$result = Zotero_Sync::getSessionDownloadResult($this->sessionID);
} catch (Exception $e) {
$this->handleUpdatedError($e);
}
// XML response
if (is_string($result)) {
$this->clearWaitTime($this->sessionID);
$this->responseXML = new SimpleXMLElement($result);
$this->end();
}
// Queued
if ($result === false) {
$queued = $this->responseXML->addChild('locked');
$queued['wait'] = $this->getWaitTime($this->sessionID);
$this->end();
}
// Not queued
if ($result == -1) {
// See if we're locked
Zotero_DB::beginTransaction();
if (Zotero_Sync::userIsWriteLocked($this->userID) || !empty($_REQUEST['upload']) && Zotero_Sync::userIsReadLocked($this->userID)) {
Zotero_DB::commit();
$locked = $this->responseXML->addChild('locked');
$locked['wait'] = $this->getWaitTime($this->sessionID);
$this->end();
}
Zotero_DB::commit();
$queue = true;
if (Z_ENV_TESTING_SITE && !empty($_GET['noqueue'])) {
$queue = false;
}
// TEMP
$cacheKeyExtra = (!empty($_POST['ft']) ? json_encode($_POST['ft']) : "") . (!empty($_POST['ftkeys']) ? json_encode($_POST['ftkeys']) : "");
// If we have a cached response, return that
try {
$startedTimestamp = microtime(true);
$cached = Zotero_Sync::getCachedDownload($this->userID, $lastsync, $this->apiVersion, $cacheKeyExtra);
// Not locked, so clear wait index
$this->clearWaitTime($this->sessionID);
if ($cached) {
$this->responseXML = simplexml_load_string($cached, "SimpleXMLElement", LIBXML_COMPACT | LIBXML_PARSEHUGE);
// TEMP
if (!$this->responseXML) {
error_log("Invalid cached XML data -- stripping control characters");
// Strip control characters in XML data
$cached = preg_replace('/[\\x00-\\x08\\x0B\\x0C\\x0E-\\x1F\\x7F]/', '', $cached);
$this->responseXML = simplexml_load_string($cached, "SimpleXMLElement", LIBXML_COMPACT | LIBXML_PARSEHUGE);
}
$duration = round((double) microtime(true) - $startedTimestamp, 2);
Zotero_Sync::logDownload($this->userID, round($lastsync), strlen($cached), $this->ipAddress ? $this->ipAddress : 0, 0, $duration, $duration, (int) (!$this->responseXML));
StatsD::increment("sync.process.download.cache.hit");
if (!$this->responseXML) {
$msg = "Error parsing cached XML for user " . $this->userID;
error_log($msg);
$this->handleUpdatedError(new Exception($msg));
}
$this->end();
}
} catch (Exception $e) {
$msg = $e->getMessage();
if (strpos($msg, "Too many connections") !== false) {
$msg = "'Too many connections' from MySQL";
} else {
$msg = "'{$msg}'";
//.........这里部分代码省略.........