Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/wp-conte.../plugins/wordfenc.../modules/login-se.../classes/utility
File: databaselock.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace WordfenceLS;
[2] Fix | Delete
[3] Fix | Delete
use RuntimeException;
[4] Fix | Delete
[5] Fix | Delete
class Utility_DatabaseLock implements Utility_Lock {
[6] Fix | Delete
[7] Fix | Delete
const DEFAULT_TIMEOUT = 30;
[8] Fix | Delete
const MAX_TIMEOUT = 120;
[9] Fix | Delete
[10] Fix | Delete
private $wpdb;
[11] Fix | Delete
private $table;
[12] Fix | Delete
private $key;
[13] Fix | Delete
private $timeout;
[14] Fix | Delete
private $expirationTimestamp;
[15] Fix | Delete
[16] Fix | Delete
public function __construct($dbController, $key, $timeout = null) {
[17] Fix | Delete
$this->wpdb = $dbController->get_wpdb();
[18] Fix | Delete
$this->table = $dbController->settings;
[19] Fix | Delete
$this->key = "lock:{$key}";
[20] Fix | Delete
$this->timeout = self::resolveTimeout($timeout);
[21] Fix | Delete
}
[22] Fix | Delete
[23] Fix | Delete
private static function resolveTimeout($timeout) {
[24] Fix | Delete
if ($timeout === null)
[25] Fix | Delete
$timeout = ini_get('max_execution_time');
[26] Fix | Delete
$timeout = (int) $timeout;
[27] Fix | Delete
if ($timeout <= 0 || $timeout > self::MAX_TIMEOUT)
[28] Fix | Delete
return self::DEFAULT_TIMEOUT;
[29] Fix | Delete
return $timeout;
[30] Fix | Delete
}
[31] Fix | Delete
[32] Fix | Delete
private function clearExpired($timestamp) {
[33] Fix | Delete
$this->wpdb->query($this->wpdb->prepare(<<<SQL
[34] Fix | Delete
DELETE
[35] Fix | Delete
FROM {$this->table}
[36] Fix | Delete
WHERE
[37] Fix | Delete
name = %s
[38] Fix | Delete
AND value < %d
[39] Fix | Delete
SQL
[40] Fix | Delete
, $this->key, $timestamp));
[41] Fix | Delete
}
[42] Fix | Delete
[43] Fix | Delete
private function insert($expirationTimestamp) {
[44] Fix | Delete
$result = $this->wpdb->query($this->wpdb->prepare(<<<SQL
[45] Fix | Delete
INSERT IGNORE
[46] Fix | Delete
INTO {$this->table}
[47] Fix | Delete
(name, value, autoload)
[48] Fix | Delete
VALUES(%s, %d, 'no')
[49] Fix | Delete
SQL
[50] Fix | Delete
, $this->key, $expirationTimestamp));
[51] Fix | Delete
return $result === 1;
[52] Fix | Delete
}
[53] Fix | Delete
[54] Fix | Delete
public function acquire($delay = self::DEFAULT_DELAY) {
[55] Fix | Delete
$attempts = (int) ($this->timeout * 1000000 / $delay);
[56] Fix | Delete
for (; $attempts > 0; $attempts--) {
[57] Fix | Delete
$timestamp = time();
[58] Fix | Delete
$this->clearExpired($timestamp);
[59] Fix | Delete
$expirationTimestamp = $timestamp + $this->timeout;
[60] Fix | Delete
$locked = $this->insert($expirationTimestamp);
[61] Fix | Delete
if ($locked) {
[62] Fix | Delete
$this->expirationTimestamp = $expirationTimestamp;
[63] Fix | Delete
return;
[64] Fix | Delete
}
[65] Fix | Delete
usleep($delay);
[66] Fix | Delete
}
[67] Fix | Delete
throw new RuntimeException("Failed to acquire lock {$this->key}");
[68] Fix | Delete
}
[69] Fix | Delete
[70] Fix | Delete
private function delete($expirationTimestamp) {
[71] Fix | Delete
$this->wpdb->delete(
[72] Fix | Delete
$this->table,
[73] Fix | Delete
array (
[74] Fix | Delete
'name' => $this->key,
[75] Fix | Delete
'value' => $expirationTimestamp
[76] Fix | Delete
),
[77] Fix | Delete
array (
[78] Fix | Delete
'%s',
[79] Fix | Delete
'%d'
[80] Fix | Delete
)
[81] Fix | Delete
);
[82] Fix | Delete
}
[83] Fix | Delete
[84] Fix | Delete
public function release() {
[85] Fix | Delete
if ($this->expirationTimestamp === null)
[86] Fix | Delete
return;
[87] Fix | Delete
$this->delete($this->expirationTimestamp);
[88] Fix | Delete
$this->expirationTimestamp = null;
[89] Fix | Delete
}
[90] Fix | Delete
[91] Fix | Delete
}
[92] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function