本文整理匯總了PHP中nzedb\db\Settings::beginTransaction方法的典型用法代碼示例。如果您正苦於以下問題:PHP Settings::beginTransaction方法的具體用法?PHP Settings::beginTransaction怎麽用?PHP Settings::beginTransaction使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類nzedb\db\Settings
的用法示例。
在下文中一共展示了Settings::beginTransaction方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: scan
/**
* Loop over range of wanted headers, insert headers into DB.
*
* @param array $groupMySQL The group info from mysql.
* @param int $first The oldest wanted header.
* @param int $last The newest wanted header.
* @param string $type Is this partrepair or update or backfill?
* @param null|array $missingParts If we are running in partrepair, the list of missing article numbers.
*
* @return array Empty on failure.
*/
public function scan($groupMySQL, $first, $last, $type = 'update', $missingParts = null)
{
// Start time of scan method and of fetching headers.
$startLoop = microtime(true);
// Check if MySQL tables exist, create if they do not, get their names at the same time.
$tableNames = $this->_groups->getCBPTableNames($this->_tablePerGroup, $groupMySQL['id']);
$returnArray = [];
$partRepair = $type === 'partrepair';
$addToPartRepair = $type === 'update' && $this->_partRepair;
// Download the headers.
if ($partRepair === true) {
// This is slower but possibly is better with missing headers.
$headers = $this->_nntp->getOverview($first . '-' . $last, true, false);
} else {
$headers = $this->_nntp->getXOVER($first . '-' . $last);
}
// If there was an error, try to reconnect.
if ($this->_nntp->isError($headers)) {
// Increment if part repair and return false.
if ($partRepair === true) {
$this->_pdo->queryExec(sprintf('UPDATE missed_parts SET attempts = attempts + 1 WHERE group_id = %d AND numberid %s', $groupMySQL['id'], $first == $last ? '= ' . $first : 'IN (' . implode(',', range($first, $last)) . ')'));
return $returnArray;
}
// This is usually a compression error, so try disabling compression.
$this->_nntp->doQuit();
if ($this->_nntp->doConnect(false) !== true) {
return $returnArray;
}
// Re-select group, download headers again without compression and re-enable compression.
$this->_nntp->selectGroup($groupMySQL['name']);
$headers = $this->_nntp->getXOVER($first . '-' . $last);
$this->_nntp->enableCompression();
// Check if the non-compression headers have an error.
if ($this->_nntp->isError($headers)) {
$message = $headers->code == 0 ? 'Unknown error' : $headers->message;
$this->log("Code {$headers->code}: {$message}\nSkipping group: {$groupMySQL['name']}", __FUNCTION__, Logger::LOG_WARNING, 'error');
return $returnArray;
}
}
// Start of processing headers.
$startCleaning = microtime(true);
// End of the getting data from usenet.
$timeHeaders = number_format($startCleaning - $startLoop, 2);
// Check if we got headers.
$msgCount = count($headers);
if ($msgCount < 1) {
return $returnArray;
}
// Get highest and lowest article numbers/dates.
$iterator1 = 0;
$iterator2 = $msgCount - 1;
while (true) {
if (!isset($returnArray['firstArticleNumber']) && isset($headers[$iterator1]['Number'])) {
$returnArray['firstArticleNumber'] = $headers[$iterator1]['Number'];
$returnArray['firstArticleDate'] = $headers[$iterator1]['Date'];
}
if (!isset($returnArray['lastArticleNumber']) && isset($headers[$iterator2]['Number'])) {
$returnArray['lastArticleNumber'] = $headers[$iterator2]['Number'];
$returnArray['lastArticleDate'] = $headers[$iterator2]['Date'];
}
// Break if we found non empty articles.
if (isset($returnArray['firstArticleNumber']) && isset($returnArray['lastArticleNumber'])) {
break;
}
// Break out if we couldn't find anything.
if ($iterator1++ >= $msgCount - 1 || $iterator2-- <= 0) {
break;
}
}
$headersRepaired = $articles = $rangeNotReceived = $collectionIDs = $binariesUpdate = $headersReceived = $headersNotInserted = [];
$notYEnc = $headersBlackListed = 0;
$partsQuery = $partsCheck = sprintf('INSERT IGNORE INTO %s (binaryid, number, messageid, partnumber, size) VALUES ', $tableNames['pname']);
$this->_pdo->beginTransaction();
// Loop articles, figure out files/parts.
foreach ($headers as $header) {
// Check if we got the article or not.
if (isset($header['Number'])) {
$headersReceived[] = $header['Number'];
} else {
if ($addToPartRepair) {
$rangeNotReceived[] = $header['Number'];
}
continue;
}
// If set we are running in partRepair mode.
if ($partRepair === true && !is_null($missingParts)) {
if (!in_array($header['Number'], $missingParts)) {
// If article isn't one that is missing skip it.
continue;
//.........這裏部分代碼省略.........