本文整理汇总了PHP中Zotero_DB::close方法的典型用法代码示例。如果您正苦于以下问题:PHP Zotero_DB::close方法的具体用法?PHP Zotero_DB::close怎么用?PHP Zotero_DB::close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zotero_DB
的用法示例。
在下文中一共展示了Zotero_DB::close方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testAutoReconnect
public function testAutoReconnect()
{
Zotero_DB::query("SET wait_timeout = 1");
Zotero_DB::query("SET @foo='bar'");
$this->assertEquals("bar", Zotero_DB::valueQuery("SELECT @foo"));
sleep(3);
try {
Zotero_DB::valueQuery("SELECT @foo");
$fail = true;
} catch (Exception $e) {
$this->assertContains("MySQL server has gone away", $e->getMessage());
}
if (isset($fail)) {
$this->fail("Reconnect should not be automatic");
}
Zotero_DB::close();
$this->assertEquals(false, Zotero_DB::valueQuery("SELECT @foo"));
}
示例2: processUploadInternal
//.........这里部分代码省略.........
if ($xml->deleted) {
// Delete collections
if ($xml->deleted->collections) {
Zotero_Collections::deleteFromXML($xml->deleted->collections, $userID);
}
// Delete items
if ($xml->deleted->items) {
Zotero_Items::deleteFromXML($xml->deleted->items, $userID);
}
// Delete creators
if ($xml->deleted->creators) {
Zotero_Creators::deleteFromXML($xml->deleted->creators, $userID);
}
// Delete saved searches
if ($xml->deleted->searches) {
Zotero_Searches::deleteFromXML($xml->deleted->searches, $userID);
}
// Delete tags
if ($xml->deleted->tags) {
$xmlElements = dom_import_simplexml($xml->deleted->tags);
$xmlElements = $xmlElements->getElementsByTagName('tag');
foreach ($xmlElements as $xmlElement) {
$libraryID = (int) $xmlElement->getAttribute('libraryID');
$key = $xmlElement->getAttribute('key');
$tagObj = Zotero_Tags::getByLibraryAndKey($libraryID, $key);
if (!$tagObj) {
continue;
}
// We need to update all items on the deleted tag
$modifiedItems = array_merge($modifiedItems, array_map(function ($key) use($libraryID) {
return $libraryID . "/" . $key;
}, $tagObj->getLinkedItems(true)));
}
Zotero_Tags::deleteFromXML($xml->deleted->tags, $userID);
}
// Delete relations
if ($xml->deleted->relations) {
Zotero_Relations::deleteFromXML($xml->deleted->relations, $userID);
}
// Delete relations
if ($xml->deleted->settings) {
Zotero_Settings::deleteFromXML($xml->deleted->settings, $userID);
}
}
$toUpdate = array();
foreach ($modifiedItems as $item) {
// libraryID/key string
if (is_string($item)) {
if (isset($savedItems[$item])) {
continue;
}
$savedItems[$item] = true;
list($libraryID, $key) = explode("/", $item);
$item = Zotero_Items::getByLibraryAndKey($libraryID, $key);
if (!$item) {
// Item was deleted
continue;
}
} else {
$lk = $item->libraryID . "/" . $item->key;
if (isset($savedItems[$lk])) {
continue;
}
$savedItems[$lk] = true;
}
$toUpdate[] = $item;
}
Zotero_Items::updateVersions($toUpdate, $userID);
unset($savedItems);
unset($modifiedItems);
try {
self::removeUploadProcess($processID);
} catch (Exception $e) {
if (strpos($e->getMessage(), 'MySQL server has gone away') !== false) {
// Reconnect
error_log("Reconnecting to MySQL master");
Zotero_DB::close();
self::removeUploadProcess($processID);
} else {
throw $e;
}
}
// Send notifications for changed libraries
foreach ($affectedLibraries as $libraryID) {
Zotero_Notifier::trigger('modify', 'library', $libraryID);
}
Zotero_DB::commit();
if ($profile) {
$shardID = Zotero_Shards::getByUserID($userID);
Zotero_DB::profileEnd($shardID);
}
// Return timestamp + 1, to keep the next /updated call
// (using >= timestamp) from returning this data
return $timestamp + 1;
} catch (Exception $e) {
Zotero_DB::rollback(true);
self::removeUploadProcess($processID);
throw $e;
}
}
示例3: processUploadFromQueue
public static function processUploadFromQueue($syncProcessID)
{
if (Z_Core::probability(30)) {
$sql = "DELETE FROM syncProcesses WHERE started < (NOW() - INTERVAL 180 MINUTE)";
Zotero_DB::query($sql);
}
if (Z_Core::probability(30)) {
$sql = "UPDATE syncUploadQueue SET started=NULL WHERE started IS NOT NULL AND errorCheck!=1 AND\n\t\t\t\t\t\tstarted < (NOW() - INTERVAL 12 MINUTE) AND finished IS NULL AND dataLength<250000";
Zotero_DB::query($sql);
}
if (Z_Core::probability(30)) {
$sql = "UPDATE syncUploadQueue SET tries=0 WHERE started IS NULL AND\n\t\t\t\t\ttries>=5 AND finished IS NULL";
Zotero_DB::query($sql);
}
Zotero_DB::beginTransaction();
// Get a queued process
$smallestFirst = Z_CONFIG::$SYNC_UPLOAD_SMALLEST_FIRST;
$sortByQuota = !empty(Z_CONFIG::$SYNC_UPLOAD_SORT_BY_QUOTA);
$sql = "SELECT syncUploadQueue.* FROM syncUploadQueue ";
if ($sortByQuota) {
$sql .= "LEFT JOIN storageAccounts USING (userID) ";
}
$sql .= "WHERE started IS NULL ";
if (self::$minErrorCheckRequiredSize) {
$sql .= "AND (errorCheck=2 OR dataLength<" . self::$minErrorCheckRequiredSize . ") ";
}
if ($smallestFirst && self::$maxSmallestSize) {
$sql .= "AND dataLength<" . self::$maxSmallestSize . " ";
}
$sql .= "ORDER BY tries > 4, ";
if ($sortByQuota) {
$sql .= "quota DESC, ";
}
if ($smallestFirst) {
//$sql .= "ROUND(dataLength / 1024 / 10), ";
$sql .= "dataLength, ";
}
$sql .= "added LIMIT 1 FOR UPDATE";
$row = Zotero_DB::rowQuery($sql);
// No pending processes
if (!$row) {
Zotero_DB::commit();
return 0;
}
$host = gethostbyname(gethostname());
$startedTimestamp = microtime(true);
list($started, $startedMS) = self::getTimestampParts($startedTimestamp);
$sql = "UPDATE syncUploadQueue SET started=FROM_UNIXTIME(?), processorHost=INET_ATON(?) WHERE syncUploadQueueID=?";
Zotero_DB::query($sql, array($started, $host, $row['syncUploadQueueID']));
Zotero_DB::commit();
Zotero_DB::close();
$processData = array("syncUploadQueueID" => $row['syncUploadQueueID'], "userID" => $row['userID'], "dataLength" => $row['dataLength']);
Z_Core::$MC->set("syncUploadProcess_" . $syncProcessID, $processData, 86400);
$error = false;
$lockError = false;
try {
$xml = new SimpleXMLElement($row['xmldata']);
$timestamp = self::processUploadInternal($row['userID'], $xml, $row['syncUploadQueueID'], $syncProcessID);
} catch (Exception $e) {
$error = true;
$code = $e->getCode();
$msg = $e->getMessage();
}
Zotero_DB::beginTransaction();
// Mark upload as finished — NULL indicates success
if (!$error) {
$sql = "UPDATE syncUploadQueue SET finished=FROM_UNIXTIME(?) WHERE syncUploadQueueID=?";
Zotero_DB::query($sql, array($timestamp, $row['syncUploadQueueID']));
try {
$sql = "INSERT INTO syncUploadProcessLog\n\t\t\t\t\t\t(userID, dataLength, processorHost, processDuration, totalDuration, error)\n\t\t\t\t\t\tVALUES (?,?,INET_ATON(?),?,?,?)";
Zotero_DB::query($sql, array($row['userID'], $row['dataLength'], $host, round((double) microtime(true) - $startedTimestamp, 2), max(0, min(time() - strtotime($row['added']), 65535)), 0));
} catch (Exception $e) {
Z_Core::logError($e);
}
try {
self::processPostWriteLog($row['syncUploadQueueID'], $row['userID'], $timestamp);
} catch (Exception $e) {
Z_Core::logError($e);
}
try {
// Index new items
Zotero_Processors::notifyProcessors('index');
} catch (Exception $e) {
Z_Core::logError($e);
}
} else {
if (strpos($msg, "Lock wait timeout exceeded; try restarting transaction") !== false || strpos($msg, "Deadlock found when trying to get lock; try restarting transaction") !== false || strpos($msg, "Too many connections") !== false || strpos($msg, "Can't connect to MySQL server") !== false || $code == Z_ERROR_LIBRARY_TIMESTAMP_ALREADY_USED || $code == Z_ERROR_SHARD_READ_ONLY || $code == Z_ERROR_SHARD_UNAVAILABLE) {
Z_Core::logError($e);
$sql = "UPDATE syncUploadQueue SET started=NULL, tries=tries+1 WHERE syncUploadQueueID=?";
Zotero_DB::query($sql, $row['syncUploadQueueID']);
$lockError = true;
} else {
// As of PHP 5.3.2 we can't serialize objects containing SimpleXMLElements,
// and since the stack trace includes one, we have to catch this and
// manually reconstruct an exception
try {
$serialized = serialize($e);
} catch (Exception $e2) {
//$id = substr(md5(uniqid(rand(), true)), 0, 10);
//file_put_contents("/tmp/uploadError_$id", $e);
//.........这里部分代码省略.........