本文整理汇总了PHP中Zotero_DB::profileStart方法的典型用法代码示例。如果您正苦于以下问题:PHP Zotero_DB::profileStart方法的具体用法?PHP Zotero_DB::profileStart怎么用?PHP Zotero_DB::profileStart使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zotero_DB
的用法示例。
在下文中一共展示了Zotero_DB::profileStart方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: init
public function init($extra)
{
require_once '../model/Error.inc.php';
if ($this->profile) {
Zotero_DB::profileStart($this->profileShard);
}
$this->startTime = microtime(true);
// Inflate gzipped data
if (!empty($_SERVER['HTTP_CONTENT_ENCODING']) && $_SERVER['HTTP_CONTENT_ENCODING'] == 'gzip') {
$gzdata = file_get_contents('php://input');
// Firefox 12 and above include the standard gzip header,
// which needs to be stripped
if (substr($gzdata, 0, 3) == chr(31) . chr(139) . chr(8)) {
// 1F 8B 08
$gzdata = substr($gzdata, 10);
}
$data = gzinflate($gzdata);
parse_str($data, $_POST);
foreach ($_POST as $key => $val) {
$_REQUEST[$key] = $val;
}
}
$this->responseXML = Zotero_Sync::getResponseXML();
//if (!Z_CONFIG::$SYNC_ENABLED && $_SERVER["REMOTE_ADDR"] != '') {
if (!Z_CONFIG::$SYNC_ENABLED) {
$this->error(503, 'SERVER_ERROR', Z_CONFIG::$MAINTENANCE_MESSAGE);
}
if (empty($_REQUEST['version'])) {
if ($this->action == 'index') {
echo "Nothing to see here.";
exit;
}
$this->error(400, 'NO_API_VERSION', "API version not specified");
}
$upgradeMessage = "Due to improvements made to sync functionality, you must upgrade to Zotero 3.0 or later from zotero.org to sync your Zotero library.";
if (isset($_SERVER['HTTP_X_ZOTERO_VERSION'])) {
require_once '../model/ToolkitVersionComparator.inc.php';
// Avoid infinite loop due to client bug
if ($_SERVER['HTTP_X_ZOTERO_VERSION'] == "2.0b6") {
die("Please upgrade to the latest version of Zotero from zotero.org.");
} else {
if (ToolkitVersionComparator::compare($_SERVER['HTTP_X_ZOTERO_VERSION'], "3.0") < 0) {
$this->error(400, 'UPGRADE_REQUIRED', $upgradeMessage);
} else {
if (isset($_SERVER['HTTP_USER_AGENT']) && (strpos($_SERVER['HTTP_USER_AGENT'], "Firefox/17") !== false || strpos($_SERVER['HTTP_USER_AGENT'], "Firefox/18") !== false || strpos($_SERVER['HTTP_USER_AGENT'], "Firefox/19") !== false || strpos($_SERVER['HTTP_USER_AGENT'], "Firefox/20") !== false || strpos($_SERVER['HTTP_USER_AGENT'], "Firefox/21") !== false || strpos($_SERVER['HTTP_USER_AGENT'], "Firefox/22") !== false) && ToolkitVersionComparator::compare($_SERVER['HTTP_X_ZOTERO_VERSION'], "3.0.9") < 0) {
$this->error(400, 'UPGRADE_REQUIRED', "Your version of Zotero is not compatible with Firefox 17 or later. Please upgrade to the latest version of Zotero from zotero.org.");
}
}
}
}
if (!in_array($_REQUEST['version'], $this->validAPIVersions)) {
if ($_REQUEST['version'] < 9) {
$this->error(400, 'UPGRADE_REQUIRED', $upgradeMessage);
}
$this->error(400, 'INVALID_API_VERSION', "Invalid request API version '{$_REQUEST['version']}'");
}
$this->apiVersion = (int) $_REQUEST['version'];
$this->responseXML['version'] = $this->apiVersion;
}
示例2: __construct
public function __construct($action, $settings, $extra)
{
require_once '../model/Error.inc.php';
if ($this->profile) {
Zotero_DB::profileStart($this->profileShard);
}
$this->startTime = microtime(true);
// Inflate gzipped data
if (!empty($_SERVER['HTTP_CONTENT_ENCODING']) && $_SERVER['HTTP_CONTENT_ENCODING'] == 'gzip') {
$gzdata = file_get_contents('php://input');
// Firefox 12 and above include the standard gzip header,
// which needs to be stripped
if (substr($gzdata, 0, 3) == chr(31) . chr(139) . chr(8)) {
// 1F 8B 08
$gzdata = substr($gzdata, 10);
}
$data = gzinflate($gzdata);
parse_str($data, $_POST);
foreach ($_POST as $key => $val) {
$_REQUEST[$key] = $val;
}
}
$this->responseXML = Zotero_Sync::getResponseXML();
//if (!Z_CONFIG::$SYNC_ENABLED && $_SERVER["REMOTE_ADDR"] != '') {
if (!Z_CONFIG::$SYNC_ENABLED) {
$this->error(503, 'SERVER_ERROR', Z_CONFIG::$MAINTENANCE_MESSAGE);
}
if (empty($_REQUEST['version'])) {
if ($action == 'index') {
echo "Nothing to see here.";
exit;
}
$this->error(400, 'NO_API_VERSION', "API version not specified");
}
$upgradeMessage = "Due to improvements made to sync functionality, you must upgrade to Zotero 2.0 or later (via Firefox's Tools menu -> Add-ons -> Extensions -> Find Updates or from zotero.org) to sync your Zotero library.";
if (isset($_SERVER['HTTP_X_ZOTERO_VERSION'])) {
require_once '../model/ToolkitVersionComparator.inc.php';
if ($_SERVER['HTTP_X_ZOTERO_VERSION'] == "2.0b6") {
die("Please upgrade to Zotero 2.0 via Tools -> Add-ons -> Extensions -> Find Updates or from zotero.org.");
} else {
if (preg_match("/2.0b[0-9].SVN/", $_SERVER['HTTP_X_ZOTERO_VERSION'])) {
// Can't use version for SVN builds
} else {
if (ToolkitVersionComparator::compare($_SERVER['HTTP_X_ZOTERO_VERSION'], "2.0rc.r5716") < 0) {
$this->error(400, 'UPGRADE_REQUIRED', $upgradeMessage);
}
}
}
}
if (!in_array($_REQUEST['version'], $this->validAPIVersions)) {
if ($_REQUEST['version'] < 8) {
$this->error(400, 'UPGRADE_REQUIRED', $upgradeMessage);
}
$this->error(400, 'INVALID_API_VERSION', "Invalid request API version '{$_REQUEST['version']}'");
}
$this->apiVersion = (int) $_REQUEST['version'];
$this->responseXML['version'] = $this->apiVersion;
}
示例3: init
public function init($extra)
{
$this->startTime = microtime(true);
if (!Z_CONFIG::$API_ENABLED) {
$this->e503(Z_CONFIG::$MAINTENANCE_MESSAGE);
}
set_exception_handler(array($this, 'handleException'));
// TODO: Throw error on some notices but allow DB/Memcached/etc. failures?
//set_error_handler(array($this, 'handleError'), E_ALL | E_USER_ERROR | E_RECOVERABLE_ERROR);
set_error_handler(array($this, 'handleError'), E_USER_ERROR | E_RECOVERABLE_ERROR);
require_once '../model/Error.inc.php';
// On testing sites, include notifications in headers
if (Z_CONFIG::$TESTING_SITE) {
Zotero_NotifierObserver::addMessageReceiver(function ($topic, $msg) {
$header = "Zotero-Debug-Notifications";
if (!empty($this->headers[$header])) {
$notifications = json_decode(base64_decode($this->headers[$header]));
} else {
$notifications = [];
}
$notifications[] = $msg;
$this->headers[$header] = base64_encode(json_encode($notifications));
});
}
register_shutdown_function(array($this, 'checkDBTransactionState'));
register_shutdown_function(array($this, 'logTotalRequestTime'));
register_shutdown_function(array($this, 'checkForFatalError'));
register_shutdown_function(array($this, 'addHeaders'));
$this->method = $_SERVER['REQUEST_METHOD'];
if (!in_array($this->method, array('HEAD', 'OPTIONS', 'GET', 'PUT', 'POST', 'DELETE', 'PATCH'))) {
$this->e501();
}
StatsD::increment("api.request.method." . strtolower($this->method), 0.25);
// There doesn't seem to be a way for PHP to start processing the request
// before the entire body is sent, so an Expect: 100 Continue will,
// depending on the client, either fail or cause a delay while the client
// waits for the 100 response. To make this explicit, we return an error.
if (!empty($_SERVER['HTTP_EXPECT'])) {
header("HTTP/1.1 417 Expectation Failed");
die("Expect header is not supported");
}
// CORS
if (isset($_SERVER['HTTP_ORIGIN'])) {
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods: HEAD, GET, POST, PUT, PATCH, DELETE");
header("Access-Control-Allow-Headers: Content-Type, If-Match, If-None-Match, If-Modified-Since-Version, If-Unmodified-Since-Version, Zotero-API-Version, Zotero-Write-Token");
header("Access-Control-Expose-Headers: Backoff, ETag, Last-Modified-Version, Link, Retry-After, Total-Results, Zotero-API-Version");
}
if ($this->method == 'OPTIONS') {
$this->end();
}
if (in_array($this->method, array('POST', 'PUT', 'PATCH'))) {
$this->ifUnmodifiedSince = isset($_SERVER['HTTP_IF_UNMODIFIED_SINCE']) ? strtotime($_SERVER['HTTP_IF_UNMODIFIED_SINCE']) : false;
$this->body = file_get_contents("php://input");
if ($this->body == "" && !in_array($this->action, array('clear', 'laststoragesync', 'removestoragefiles', 'itemContent'))) {
$this->e400("{$this->method} data not provided");
}
}
if ($this->profile) {
Zotero_DB::profileStart();
}
// If HTTP Basic Auth credentials provided, authenticate
if (isset($_SERVER['PHP_AUTH_USER'])) {
$username = $_SERVER['PHP_AUTH_USER'];
$password = $_SERVER['PHP_AUTH_PW'];
if ($username == Z_CONFIG::$API_SUPER_USERNAME && $password == Z_CONFIG::$API_SUPER_PASSWORD) {
$this->userID = 0;
$this->permissions = new Zotero_Permissions();
$this->permissions->setSuper();
} else {
if (!empty($extra['allowHTTP']) || !empty($extra['auth'])) {
$userID = Zotero_Users::authenticate('password', array('username' => $username, 'password' => $password));
if (!$userID) {
$this->e401('Invalid login');
}
$this->httpAuth = true;
$this->userID = $userID;
$this->grantUserPermissions($userID);
}
}
}
if (!isset($this->userID)) {
$key = false;
// Allow Zotero-API-Key header
if (!empty($_SERVER['HTTP_ZOTERO_API_KEY'])) {
$key = $_SERVER['HTTP_ZOTERO_API_KEY'];
}
// Allow ?key=<apikey>
if (isset($_GET['key'])) {
if (!$key) {
$key = $_GET['key'];
} else {
if ($_GET['key'] !== $key) {
$this->e400("Zotero-API-Key header and 'key' parameter differ");
}
}
}
// If neither of the above passed, allow "Authorization: Bearer <apikey>"
//
// Apache/mod_php doesn't seem to make Authorization available for auth schemes
//.........这里部分代码省略.........
示例4: __construct
public function __construct($action, $settings, $extra)
{
if (!Z_CONFIG::$API_ENABLED) {
$this->e503(Z_CONFIG::$MAINTENANCE_MESSAGE);
}
set_exception_handler(array($this, 'handleException'));
set_error_handler(array($this, 'handleError'), E_USER_ERROR);
require_once '../model/Error.inc.php';
$this->startTime = microtime(true);
$this->method = $_SERVER['REQUEST_METHOD'];
/*if (isset($_SERVER['REMOTE_ADDR'])
&& in_array($_SERVER['REMOTE_ADDR'], array(''))) {
header("HTTP/1.1 429 Rate Limited");
die("Too many requests");
}*/
if (!in_array($this->method, array('HEAD', 'GET', 'PUT', 'POST', 'DELETE', 'PATCH'))) {
header("HTTP/1.1 501 Not Implemented");
die("Method is not implemented");
}
// There doesn't seem to be a way for PHP to start processing the request
// before the entire body is sent, so an Expect: 100 Continue will,
// depending on the client, either fail or cause a delay while the client
// waits for the 100 response. To make this explicit, we return an error.
if (!empty($_SERVER['HTTP_EXPECT'])) {
header("HTTP/1.1 417 Expectation Failed");
die("Expect header is not supported");
}
if (in_array($this->method, array('POST', 'PUT', 'PATCH'))) {
$this->ifUnmodifiedSince = isset($_SERVER['HTTP_IF_UNMODIFIED_SINCE']) ? strtotime($_SERVER['HTTP_IF_UNMODIFIED_SINCE']) : false;
$this->body = file_get_contents("php://input");
}
if ($this->profile) {
Zotero_DB::profileStart($this->profileShard);
}
// If HTTP Basic Auth credentials provided, authenticate
if (isset($_SERVER['PHP_AUTH_USER'])) {
$username = $_SERVER['PHP_AUTH_USER'];
$password = $_SERVER['PHP_AUTH_PW'];
if ($username == Z_CONFIG::$API_SUPER_USERNAME && $password == Z_CONFIG::$API_SUPER_PASSWORD) {
$this->userID = 0;
$this->permissions = new Zotero_Permissions();
$this->permissions->setSuper();
} else {
if (!empty($extra['allowHTTP'])) {
$userID = Zotero_Users::authenticate('password', array('username' => $username, 'password' => $password));
if (!$userID) {
$this->e401('Invalid login');
}
$this->httpAuth = true;
$this->userID = $userID;
$this->grantUserPermissions($userID);
} else {
$this->e401('Invalid login');
}
}
} else {
if (isset($_GET['key'])) {
$keyObj = Zotero_Keys::authenticate($_GET['key']);
if (!$keyObj) {
$this->e403('Invalid key');
}
$this->apiKey = $_GET['key'];
$this->userID = $keyObj->userID;
$this->permissions = $keyObj->getPermissions();
// Check X-Zotero-Write-Token if it exists to make sure
if ($this->method == 'POST' || $this->method == 'PUT') {
if ($cacheKey = $this->getWriteTokenCacheKey()) {
if (Z_Core::$MC->get($cacheKey)) {
$this->e412("Write token already used");
}
}
}
} else {
if (!empty($_COOKIE) && !empty($_GET['session']) && ($this->userID = Zotero_Users::getUserIDFromSession($_COOKIE, $_GET['session']))) {
$this->grantUserPermissions($this->userID);
$this->cookieAuth = true;
} else {
if (!empty($_GET['auth'])) {
$this->e401();
}
// Always challenge a 'me' request
if (!empty($extra['userID']) && $extra['userID'] == 'me') {
$this->e403('You must specify a key when making a /me request.');
}
// Explicit auth request or not a GET request
if ($this->method != "GET") {
$this->e403('You must specify a key to access the Zotero API.');
}
// Anonymous request
$this->permissions = new Zotero_Permissions();
$this->permissions->setAnonymous();
}
}
}
// Get the API version
if (empty($_REQUEST['version'])) {
$this->apiVersion = $this->defaultAPIVersion;
} else {
if (!in_array($_REQUEST['version'], $this->validAPIVersions)) {
$this->e400("Invalid request API version '{$_REQUEST['version']}'");
//.........这里部分代码省略.........
示例5: processUploadInternal
private static function processUploadInternal($userID, SimpleXMLElement $xml, $syncQueueID = null, $syncProcessID = null)
{
$userLibraryID = Zotero_Users::getLibraryIDFromUserID($userID);
$affectedLibraries = self::parseAffectedLibraries($xml->asXML());
// Relations-only uploads don't have affected libraries
if (!$affectedLibraries) {
$affectedLibraries = array(Zotero_Users::getLibraryIDFromUserID($userID));
}
$processID = self::addUploadProcess($userID, $affectedLibraries, $syncQueueID, $syncProcessID);
set_time_limit(5400);
$profile = false;
if ($profile) {
$shardID = Zotero_Shards::getByUserID($userID);
Zotero_DB::profileStart($shardID);
}
try {
Zotero_DB::beginTransaction();
// Mark libraries as updated
foreach ($affectedLibraries as $libraryID) {
Zotero_Libraries::updateVersion($libraryID);
}
$timestamp = Zotero_Libraries::updateTimestamps($affectedLibraries);
Zotero_DB::registerTransactionTimestamp($timestamp);
// Make sure no other upload sessions use this same timestamp
// for any of these libraries, since we return >= 1 as the next
// last sync time
if (!Zotero_Libraries::setTimestampLock($affectedLibraries, $timestamp)) {
throw new Exception("Library timestamp already used", Z_ERROR_LIBRARY_TIMESTAMP_ALREADY_USED);
}
$modifiedItems = array();
// Add/update creators
if ($xml->creators) {
// DOM
$keys = array();
$xmlElements = dom_import_simplexml($xml->creators);
$xmlElements = $xmlElements->getElementsByTagName('creator');
Zotero_DB::query("SET foreign_key_checks = 0");
try {
$addedLibraryIDs = array();
$addedCreatorDataHashes = array();
foreach ($xmlElements as $xmlElement) {
$key = $xmlElement->getAttribute('key');
if (isset($keys[$key])) {
throw new Exception("Creator {$key} already processed");
}
$keys[$key] = true;
$creatorObj = Zotero_Creators::convertXMLToCreator($xmlElement);
if (Zotero_Utilities::unicodeTrim($creatorObj->firstName) === '' && Zotero_Utilities::unicodeTrim($creatorObj->lastName) === '') {
continue;
}
$addedLibraryIDs[] = $creatorObj->libraryID;
$changed = $creatorObj->save($userID);
// If the creator changed, we need to update all linked items
if ($changed) {
$modifiedItems = array_merge($modifiedItems, $creatorObj->getLinkedItems());
}
}
} catch (Exception $e) {
Zotero_DB::query("SET foreign_key_checks = 1");
throw $e;
}
Zotero_DB::query("SET foreign_key_checks = 1");
unset($keys);
unset($xml->creators);
//
// Manual foreign key checks
//
// libraryID
foreach (array_unique($addedLibraryIDs) as $addedLibraryID) {
$shardID = Zotero_Shards::getByLibraryID($addedLibraryID);
$sql = "SELECT COUNT(*) FROM shardLibraries WHERE libraryID=?";
if (!Zotero_DB::valueQuery($sql, $addedLibraryID, $shardID)) {
throw new Exception("libraryID inserted into `creators` not found in `shardLibraries` ({$addedLibraryID}, {$shardID})");
}
}
}
// Add/update items
$savedItems = array();
if ($xml->items) {
$childItems = array();
// DOM
$xmlElements = dom_import_simplexml($xml->items);
$xmlElements = $xmlElements->getElementsByTagName('item');
foreach ($xmlElements as $xmlElement) {
$libraryID = (int) $xmlElement->getAttribute('libraryID');
$key = $xmlElement->getAttribute('key');
if (isset($savedItems[$libraryID . "/" . $key])) {
throw new Exception("Item {$libraryID}/{$key} already processed");
}
$itemObj = Zotero_Items::convertXMLToItem($xmlElement);
if (!$itemObj->getSourceKey()) {
try {
$modified = $itemObj->save($userID);
if ($modified) {
$savedItems[$libraryID . "/" . $key] = true;
}
} catch (Exception $e) {
if (strpos($e->getMessage(), 'libraryIDs_do_not_match') !== false) {
throw new Exception($e->getMessage() . " ({$key})");
}
//.........这里部分代码省略.........
示例6: processUploadInternal
private static function processUploadInternal($userID, SimpleXMLElement $xml, $syncQueueID = null, $syncProcessID = null)
{
$userLibraryID = Zotero_Users::getLibraryIDFromUserID($userID);
$affectedLibraries = self::parseAffectedLibraries($xml->asXML());
// Relations-only uploads don't have affected libraries
if (!$affectedLibraries) {
$affectedLibraries = array(Zotero_Users::getLibraryIDFromUserID($userID));
}
$processID = self::addUploadProcess($userID, $affectedLibraries, $syncQueueID, $syncProcessID);
set_time_limit(5400);
$profile = false;
if ($profile) {
$shardID = Zotero_Shards::getByUserID($userID);
Zotero_DB::profileStart($shardID);
}
try {
Z_Core::$MC->begin();
Zotero_DB::beginTransaction();
// Mark libraries as updated
$timestamp = Zotero_Libraries::updateTimestamps($affectedLibraries);
Zotero_DB::registerTransactionTimestamp($timestamp);
// Make sure no other upload sessions use this same timestamp
// for any of these libraries, since we return >= 1 as the next
// last sync time
if (!Zotero_Libraries::setTimestampLock($affectedLibraries, $timestamp)) {
throw new Exception("Library timestamp already used", Z_ERROR_LIBRARY_TIMESTAMP_ALREADY_USED);
}
// Add/update creators
if ($xml->creators) {
// DOM
$keys = array();
$xmlElements = dom_import_simplexml($xml->creators);
$xmlElements = $xmlElements->getElementsByTagName('creator');
Zotero_DB::query("SET foreign_key_checks = 0");
try {
$addedLibraryIDs = array();
$addedCreatorDataHashes = array();
foreach ($xmlElements as $xmlElement) {
$key = $xmlElement->getAttribute('key');
if (isset($keys[$key])) {
throw new Exception("Creator {$key} already processed");
}
$keys[$key] = true;
$creatorObj = Zotero_Creators::convertXMLToCreator($xmlElement);
$addedLibraryIDs[] = $creatorObj->libraryID;
$creatorObj->save();
}
} catch (Exception $e) {
Zotero_DB::query("SET foreign_key_checks = 1");
throw $e;
}
Zotero_DB::query("SET foreign_key_checks = 1");
unset($keys);
unset($xml->creators);
//
// Manual foreign key checks
//
// libraryID
foreach ($addedLibraryIDs as $addedLibraryID) {
$shardID = Zotero_Shards::getByLibraryID($addedLibraryID);
$sql = "SELECT COUNT(*) FROM shardLibraries WHERE libraryID=?";
if (!Zotero_DB::valueQuery($sql, $addedLibraryID, $shardID)) {
throw new Exception("libraryID inserted into `creators` not found in `shardLibraries` ({$addedLibraryID}, {$shardID})");
}
}
}
// Add/update items
if ($xml->items) {
$childItems = array();
$relatedItemsStore = array();
// DOM
$keys = array();
$xmlElements = dom_import_simplexml($xml->items);
$xmlElements = $xmlElements->getElementsByTagName('item');
foreach ($xmlElements as $xmlElement) {
$key = $xmlElement->getAttribute('key');
if (isset($keys[$key])) {
throw new Exception("Item {$key} already processed");
}
$keys[$key] = true;
$missing = Zotero_Items::removeMissingRelatedItems($xmlElement);
$itemObj = Zotero_Items::convertXMLToItem($xmlElement);
if ($missing) {
$relatedItemsStore[$itemObj->libraryID . '_' . $itemObj->key] = $missing;
}
if (!$itemObj->getSourceKey()) {
try {
$itemObj->save($userID);
} catch (Exception $e) {
if (strpos($e->getMessage(), 'libraryIDs_do_not_match') !== false) {
throw new Exception($e->getMessage() . " (" . $itemObj->key . ")");
}
throw $e;
}
} else {
$childItems[] = $itemObj;
}
}
unset($keys);
unset($xml->items);
//.........这里部分代码省略.........