本文整理汇总了PHP中Zotero_DB类的典型用法代码示例。如果您正苦于以下问题:PHP Zotero_DB类的具体用法?PHP Zotero_DB怎么用?PHP Zotero_DB使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Zotero_DB类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getName
public static function getName($charsetOrCharsetID)
{
if (isset(self::$charsets[$charsetOrCharsetID])) {
return self::$charsets[$charsetOrCharsetID];
}
$sql = "(SELECT charset FROM charsets WHERE charsetID=?) UNION\n\t\t\t\t(SELECT charset FROM charsets WHERE charset=?) LIMIT 1";
$charset = Zotero_DB::valueQuery($sql, array($charsetOrCharsetID, $charsetOrCharsetID));
self::$charsets[$charsetOrCharsetID] = $charset;
return $charset;
}
示例2: run
public function run($id = null)
{
$this->id = $id;
$this->addr = gethostbyname(gethostname());
if (!Z_CONFIG::$PROCESSORS_ENABLED) {
$sleep = 20;
$this->log("Processors disabled — exiting in {$sleep} seconds");
sleep($sleep);
try {
$this->notifyProcessor("LOCK" . " " . $id);
} catch (Exception $e) {
$this->log($e);
}
return;
}
$this->log("Starting sync processor");
$startTime = microtime(true);
try {
$processed = $this->processFromQueue();
if (Zotero_DB::transactionInProgress()) {
error_log("WARNING: Transaction still in progress after processing!");
}
} catch (Exception $e) {
$this->log($e);
throw $e;
}
$duration = microtime(true) - $startTime;
$error = false;
// Success
if ($processed == 1) {
$this->log("Process completed in " . round($duration, 2) . " seconds");
$signal = "DONE";
} else {
if ($processed == 0) {
$this->log("Exiting with no processes found");
$signal = "NONE";
} else {
if ($processed == -1) {
$this->log("Exiting on lock error");
$signal = "LOCK";
} else {
$this->log("Exiting on error");
$signal = "ERROR";
}
}
}
if ($id) {
try {
$this->notifyProcessor($signal . " " . $id);
} catch (Exception $e) {
$this->log($e);
}
}
}
示例3: add
public static function add($userID)
{
Z_Core::debug("Creating publications library for user {$userID}");
Zotero_DB::beginTransaction();
// Use same shard as user library
$shardID = Zotero_Shards::getByUserID($userID);
$libraryID = Zotero_Libraries::add('publications', $shardID);
$sql = "INSERT INTO userPublications (userID, libraryID) VALUES (?, ?)";
Zotero_DB::query($sql, [$userID, $libraryID]);
Zotero_DB::commit();
return $libraryID;
}
示例4: getCreatorsWithData
public static function getCreatorsWithData($libraryID, $creator, $sortByItemCountDesc = false)
{
$sql = "SELECT creatorID FROM creators ";
if ($sortByItemCountDesc) {
$sql .= "LEFT JOIN itemCreators USING (creatorID) ";
}
$sql .= "WHERE libraryID=? AND firstName COLLATE utf8_bin = ? " . "AND lastName COLLATE utf8_bin = ? AND fieldMode=?";
if ($sortByItemCountDesc) {
$sql .= " ORDER BY IFNULL(COUNT(*), 0) DESC";
}
$ids = Zotero_DB::columnQuery($sql, array($libraryID, $creator->firstName, $creator->lastName, $creator->fieldMode), Zotero_Shards::getByLibraryID($libraryID));
return $ids;
}
示例5: generate
public static function generate()
{
$tries = 5;
while ($tries > 0) {
$str = Zotero_Utilities::randomString(24, 'mixed');
$sql = "SELECT COUNT(*) FROM `keys` WHERE `key`=?";
if (Zotero_DB::valueQuery($sql, $str)) {
$tries--;
continue;
}
return $str;
}
throw new Exception("Unique key could not be generated");
}
示例6: loadChildItems
protected function loadChildItems($reload = false)
{
if ($this->loaded['childItems'] && !$reload) {
return;
}
Z_Core::debug("Loading child items for collection {$this->id}");
if (!$this->id) {
trigger_error('$this->id not set', E_USER_ERROR);
}
$sql = "SELECT itemID FROM collectionItems WHERE collectionID=?";
$ids = Zotero_DB::columnQuery($sql, $this->id, Zotero_Shards::getByLibraryID($this->libraryID));
$this->childItems = $ids ? $ids : [];
$this->loaded['childItems'] = true;
$this->clearChanged('childItems');
}
示例7: getUserGroupLibraries
public static function getUserGroupLibraries($userID)
{
$sql = "SELECT libraryID FROM groupUsers JOIN groups USING (groupID) WHERE userID=?";
$libraryIDs = Zotero_DB::columnQuery($sql, $userID);
if (!$libraryIDs) {
return array();
}
return $libraryIDs;
}
示例8: loadItems
private static function loadItems($libraryID, $itemIDs = array())
{
$shardID = Zotero_Shards::getByLibraryID($libraryID);
$sql = self::getPrimaryDataSQL() . "1";
// TODO: optimize
if ($itemIDs) {
foreach ($itemIDs as $itemID) {
if (!is_int($itemID)) {
throw new Exception("Invalid itemID {$itemID}");
}
}
$sql .= ' AND itemID IN (' . implode(',', array_fill(0, sizeOf($itemIDs), '?')) . ')';
}
$stmt = Zotero_DB::getStatement($sql, "loadItems_" . sizeOf($itemIDs), $shardID);
$itemRows = Zotero_DB::queryFromStatement($stmt, $itemIDs);
$loadedItemIDs = array();
if ($itemRows) {
foreach ($itemRows as $row) {
if ($row['libraryID'] != $libraryID) {
throw new Exception("Item {$itemID} isn't in library {$libraryID}", Z_ERROR_OBJECT_LIBRARY_MISMATCH);
}
$itemID = $row['id'];
$loadedItemIDs[] = $itemID;
// Item isn't loaded -- create new object and stuff in array
if (!isset(self::$objectCache[$itemID])) {
$item = new Zotero_Item();
$item->loadFromRow($row, true);
self::$objectCache[$itemID] = $item;
} else {
self::$objectCache[$itemID]->loadFromRow($row, true);
}
}
}
if (!$itemIDs) {
// If loading all items, remove old items that no longer exist
$ids = array_keys(self::$objectCache);
foreach ($ids as $id) {
if (!in_array($id, $loadedItemIDs)) {
throw new Exception("Unimplemented");
//$this->unload($id);
}
}
}
}
示例9: deleteCachedData
/**
* Delete data from memcached
*/
public static function deleteCachedData($libraryID)
{
$shardID = Zotero_Shards::getByLibraryID($libraryID);
// Clear itemID-specific memcache values
$sql = "SELECT itemID FROM items WHERE libraryID=?";
$itemIDs = Zotero_DB::columnQuery($sql, $libraryID, $shardID);
if ($itemIDs) {
$cacheKeys = array("itemCreators", "itemIsDeleted", "itemRelated", "itemUsedFieldIDs", "itemUsedFieldNames");
foreach ($itemIDs as $itemID) {
foreach ($cacheKeys as $key) {
Z_Core::$MC->delete($key . '_' . $itemID);
}
}
}
/*foreach (Zotero_DataObjects::$objectTypes as $type=>$arr) {
$className = "Zotero_" . $arr['plural'];
call_user_func(array($className, "clearPrimaryDataCache"), $libraryID);
}*/
}
示例10: load
private static function load($libraryID, $ids = [], array $options = [])
{
$loaded = [];
if (!$libraryID) {
throw new Exception("libraryID must be provided");
}
if ($libraryID !== false && !empty(self::$loadedLibraries[$libraryID])) {
return $loaded;
}
$sql = self::getPrimaryDataSQL() . ' AND O.libraryID=?';
$params = [$libraryID];
if ($ids) {
$sql .= ' AND O.' . self::$idColumn . ' IN (' . implode(',', $ids) . ')';
}
$t = microtime();
$rows = Zotero_DB::query($sql, $params, Zotero_Shards::getByLibraryID($libraryID));
foreach ($rows as $row) {
$id = $row['id'];
// Existing object -- reload in place
if (isset(self::$objectCache[$id])) {
self::$objectCache[$id]->loadFromRow($row, true);
$obj = self::$objectCache[$id];
} else {
$class = "Zotero_" . self::$ObjectType;
$obj = new $class();
$obj->loadFromRow($row, true);
if (!$options || !$options->noCache) {
self::registerObject($obj);
}
}
$loaded[$id] = $obj;
}
Z_Core::debug("Loaded " . self::$objectTypePlural . " in " . (microtime() - $t) . "ms");
if (!$ids) {
self::$loadedLibraries[$libraryID] = true;
// If loading all objects, remove cached objects that no longer exist
foreach (self::$objectCache as $obj) {
if ($libraryID !== false && obj . libraryID !== libraryID) {
continue;
}
if (empty($loaded[$obj->id])) {
self::unload($obj->id);
}
}
}
return $loaded;
}
示例11: array
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
//
$awsConfig = ['region' => !empty(Z_CONFIG::$AWS_REGION) ? Z_CONFIG::$AWS_REGION : 'us-east-1', 'version' => 'latest', 'signature' => 'v4'];
// IAM role authentication
if (empty(Z_CONFIG::$AWS_ACCESS_KEY)) {
// If APC cache is available, use that to cache temporary credentials
if (function_exists('apc_store')) {
$cache = new \Doctrine\Common\Cache\ApcCache();
} else {
$cache = new \Doctrine\Common\Cache\FilesystemCache(Z_ENV_BASE_PATH . 'tmp/cache');
}
$awsConfig['credentials'] = new \Aws\DoctrineCacheAdapter($cache);
} else {
$awsConfig['credentials'] = ['key' => Z_CONFIG::$AWS_ACCESS_KEY, 'secret' => Z_CONFIG::$AWS_SECRET_KEY];
示例12: updateLastAdded
private static function updateLastAdded($storageFileID)
{
$sql = "UPDATE storageFiles SET lastAdded=NOW() WHERE storageFileID=?";
Zotero_DB::query($sql, $storageFileID);
}
示例13: loadRelatedItems
private function loadRelatedItems()
{
if (!$this->id) {
return;
}
Z_Core::debug("Loading related items for item {$this->id}");
if ($this->loaded['relatedItems']) {
trigger_error("Related items for item {$this->id} already loaded", E_USER_ERROR);
}
if (!$this->loaded['primaryData']) {
$this->loadPrimaryData(true);
}
// TODO: use a prepared statement
if (!is_numeric($this->id)) {
trigger_error("Invalid itemID '{$this->id}'", E_USER_ERROR);
}
$cacheKey = $this->getCacheKey("itemRelated");
//$ids = Z_Core::$MC->get($cacheKey);
$ids = false;
if ($ids === false) {
$sql = "SELECT linkedItemID FROM itemRelated WHERE itemID=?";
$stmt = Zotero_DB::getStatement($sql, true, Zotero_Shards::getByLibraryID($this->libraryID));
$ids = Zotero_DB::columnQueryFromStatement($stmt, $this->id);
Z_Core::$MC->set($cacheKey, $ids ? $ids : array());
}
$this->relatedItems = $ids ? $ids : array();
$this->loaded['relatedItems'] = true;
}
示例14: load
private function load()
{
//Z_Core::debug("Loading data for search $this->id");
if (!$this->libraryID) {
throw new Exception("Library ID not set");
}
if (!$this->id && !$this->key) {
throw new Exception("ID or key not set");
}
$shardID = Zotero_Shards::getByLibraryID($this->libraryID);
$sql = "SELECT searchID AS id, searchName AS name, dateAdded, dateModified, libraryID, `key`,\n\t\t\t\tMAX(searchConditionID) AS maxSearchConditionID FROM savedSearches\n\t\t\t\tLEFT JOIN savedSearchConditions USING (searchID) WHERE ";
if ($this->id) {
$sql .= "searchID=?";
$params = $this->id;
} else {
$sql .= "libraryID=? AND `key`=?";
$params = array($this->libraryID, $this->key);
}
$sql .= " GROUP BY searchID";
$data = Zotero_DB::rowQuery($sql, $params, $shardID);
$this->loaded = true;
if (!$data) {
return;
}
foreach ($data as $key => $val) {
$this->{$key} = $val;
}
$sql = "SELECT * FROM savedSearchConditions\n\t\t\t\tWHERE searchID=? ORDER BY searchConditionID";
$conditions = Zotero_DB::query($sql, $this->id, $shardID);
foreach ($conditions as $condition) {
/*
if (!Zotero.SearchConditions.get(condition)){
Zotero.debug("Invalid saved search condition '"
+ condition + "' -- skipping", 2);
continue;
}
*/
$searchConditionID = $condition['searchConditionID'];
$this->conditions[$searchConditionID] = array('id' => $searchConditionID, 'condition' => $condition['condition'], 'mode' => $condition['mode'], 'operator' => $condition['operator'], 'value' => $condition['value'], 'required' => $condition['required']);
}
}
示例15: end
private function end()
{
if (!$this->responseXML instanceof SimpleXMLElement) {
throw new Exception("Response XML not provided");
}
if ($this->profile) {
Zotero_DB::profileEnd($this->profileShard, false);
}
if ($this->responseCode) {
switch ($this->responseCode) {
case 201:
header("HTTP/1.1 201 Created");
break;
default:
throw new Exception("Unsupported response code");
}
} else {
$updated = (string) $this->responseXML->updated;
if ($updated) {
$updated = strtotime($updated);
$ifModifiedSince = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? $_SERVER['HTTP_IF_MODIFIED_SINCE'] : false;
$ifModifiedSince = strtotime($ifModifiedSince);
if ($ifModifiedSince >= $updated) {
header('HTTP/1.1 304 Not Modified');
exit;
}
$lastModified = substr(date('r', $updated), 0, -5) . "GMT";
header("Last-Modified: {$lastModified}");
}
}
$xmlstr = $this->responseXML->asXML();
$doc = new DOMDocument('1.0');
$doc->loadXML($xmlstr);
$doc->formatOutput = true;
if ($this->queryParams['pprint']) {
$ppdoc = new DOMDocument('1.0');
// Zero-width spaces to push <feed> beyond Firefox's
// feed auto-detection boundary
$comment = $ppdoc->createComment("");
$ppdoc->appendChild($comment);
$ppdoc->formatOutput = true;
$rootElem = $doc->firstChild;
$importedNode = $ppdoc->importNode($rootElem, true);
$ppdoc->appendChild($importedNode);
$doc = $ppdoc;
}
$xmlstr = $doc->saveXML();
if ($this->queryParams['pprint']) {
header("Content-Type: text/xml");
} else {
header("Content-Type: application/atom+xml");
}
echo $xmlstr;
$this->logRequestTime();
echo ob_get_clean();
exit;
}