Changeset View
Changeset View
Standalone View
Standalone View
branches/5.2.x/core/kernel/utility/temp_handler.php
Show First 20 Lines • Show All 982 Lines • ▼ Show 20 Line(s) | |||||
// another user is coping data from temp table to live -> release lock and try again after 1 second | // another user is coping data from temp table to live -> release lock and try again after 1 second | ||||
$conn->ChangeQuery('UNLOCK TABLES'); | $conn->ChangeQuery('UNLOCK TABLES'); | ||||
$sleep_count++; | $sleep_count++; | ||||
sleep(1); | sleep(1); | ||||
} | } | ||||
} while ($another_coping_active && ($sleep_count <= 30)); | } while ($another_coping_active && ($sleep_count <= 30)); | ||||
if ($sleep_count > 30) { | if ($sleep_count > 30) { | ||||
// another coping process failed to finished in 30 seconds | // Another coping process failed to finished in 30 seconds. | ||||
$error_message = $this->Application->Phrase('la_error_TemporaryTableCopyingFailed'); | $error_message = $this->Application->Phrase('la_error_TemporaryTableCopyingFailed'); | ||||
$this->Application->SetVar('_temp_table_message', $error_message); | $this->Application->SetVar('_temp_table_message', $error_message); | ||||
$log = $this->Application->log('Parallel item saving attempt detected'); | |||||
$log->addTrace(); | |||||
$log->setLogLevel(kLogger::LL_ERROR); | |||||
$log->write(); | |||||
return false; | return false; | ||||
} | } | ||||
// mark, that we are coping from temp to live right now, so other similar attempt (from another script) will fail | /* | ||||
$fields_hash = Array ( | * Mark, that we are coping from temp to live right now, | ||||
'SessionKey' => $this->Application->GetSID(), | * so other similar attempt (from another script) will fail. | ||||
'Timestamp' => adodb_mktime(), | */ | ||||
'MainPrefix' => $this->Tables['Prefix'], | $semaphore_id = $this->createSemaphore($conn, $master_ids); | ||||
'MainIDs' => implode(',', $master_ids), | |||||
); | |||||
$conn->doInsert($fields_hash, TABLE_PREFIX.'Semaphores'); | |||||
$semaphore_id = $conn->getInsertID(); | |||||
// unlock table now to prevent permanent lock in case, when coping will end with SQL error in the middle | // unlock table now to prevent permanent lock in case, when coping will end with SQL error in the middle | ||||
$conn->ChangeQuery('UNLOCK TABLES'); | $conn->ChangeQuery('UNLOCK TABLES'); | ||||
$ids = $this->DoCopyTempToOriginal($this->Tables, null, $master_ids); | $ids = $this->DoCopyTempToOriginal($this->Tables, null, $master_ids); | ||||
// remove mark, that we are coping from temp to live | // remove mark, that we are coping from temp to live | ||||
$conn->Query('LOCK TABLES '.TABLE_PREFIX.'Semaphores WRITE'); | $conn->Query('LOCK TABLES '.TABLE_PREFIX.'Semaphores WRITE'); | ||||
$sql = 'DELETE FROM ' . TABLE_PREFIX . 'Semaphores | $sql = 'DELETE FROM ' . TABLE_PREFIX . 'Semaphores | ||||
WHERE SemaphoreId = ' . $semaphore_id; | WHERE SemaphoreId = ' . $semaphore_id; | ||||
$conn->ChangeQuery($sql); | $conn->ChangeQuery($sql); | ||||
$conn->ChangeQuery('UNLOCK TABLES'); | $conn->ChangeQuery('UNLOCK TABLES'); | ||||
return $ids; | return $ids; | ||||
} | } | ||||
/** | |||||
* Creates a semaphore. | |||||
* | |||||
* @param IDBConnection $conn Database connection. | |||||
* @param array $master_ids Master record IDs. | |||||
* | |||||
* @return integer | |||||
*/ | |||||
protected function createSemaphore(IDBConnection $conn, array $master_ids) | |||||
{ | |||||
$fields_hash = array( | |||||
'SessionKey' => $this->Application->GetSID(), | |||||
'Timestamp' => adodb_mktime(), | |||||
'MainPrefix' => $this->Tables['Prefix'], | |||||
'MainIDs' => implode(',', $master_ids), | |||||
'UserId' => $this->Application->RecallVar('user_id'), | |||||
'IPAddress' => $this->Application->getClientIp(), | |||||
'Hostname' => $_SERVER['HTTP_HOST'], | |||||
'RequestURI' => $_SERVER['REQUEST_URI'], | |||||
'Backtrace' => serialize(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS)), | |||||
); | |||||
$conn->doInsert($fields_hash, TABLE_PREFIX . 'Semaphores'); | |||||
return $conn->getInsertID(); | |||||
} | |||||
function CancelEdit($master=null) | function CancelEdit($master=null) | ||||
{ | { | ||||
if (!isset($master)) $master = $this->Tables; | if (!isset($master)) $master = $this->Tables; | ||||
$this->DropTempTable($master['TableName']); | $this->DropTempTable($master['TableName']); | ||||
if ( getArrayValue($master, 'SubTables') ) { | if ( getArrayValue($master, 'SubTables') ) { | ||||
foreach ($master['SubTables'] as $sub_table) { | foreach ($master['SubTables'] as $sub_table) { | ||||
$this->CancelEdit($sub_table); | $this->CancelEdit($sub_table); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 79 Lines • Show Last 20 Lines |