JFIF $ d d 7 * Z qn )ZP 0 !1 A "#a$2Qr D8 a Ri [f \m I ykI w0 c u F c Rı?lO7 к _f˓ [C $殷WF< _W ԣ s Kc ëI zyQy /_LK ℂ ;C",p F A : /] =H ~ , l s / 9 ć: [=/#f ; ) x { ٛE Q )~ = 𘙲r*2~ a _V = ' ku m F D } KYYC )( { * g& f `툪 r y ` = ^ c J. I ]( * `wq 1dđ #̩ ͑ 0 ; H ] u 搂 @:~ ו K L N s h } O I R* 8 :2 ! lD JV o ( 3 = M ( z Ȱ+i *N A r6K n S l ) ! J J Ӂ* % ݉?|D } d5: eP0 R; {$X' x F @ .ÊB {,WJ uQ ɲRI ;9 Q E琯 6 2fT .DU J ;*c P A\IL Nj! J ۱+ O\ ͔ ] ޒ S J ȧ c%A N ol ՎprU L Zԛe r E2= X D Xg VQeӓ k y P7 U* o m Q I s ,K `) 6\G3t?pgjr m ۛجw luGt f h 9uyP 0D;Uڽ"OXl i f $ ) &|ML 0 Z rm1 [ H XP l P R0 'G=i 2N +0 e 2 ]] 9 VT P O 7 h(F * 癈 ' = Q VZD F,d ߬ ~ T X G[ `le 69C R(!S2! P < 0 x < !1AQ "Raq 02Br #S CTb ? Ζ "]mH5WR 7 k.ۛ ! } Q~ + yԏ z |@ T20 S~ K e k *zF f^2X *( @ 8 r ? C I uI|֓>^Ex LgNU Y+{.R Ѫ τV YT D I 6 2 '8Y2 7'\T P.6 d &˦ @V q i |8 -O Ε ] ʔ U= T L 8= ;6c | !qfF3 a ů& ~$ l} 'NW U s$U k^S V : U#6w + +s &r+n ڐ { @ 29gL u " T Ù M=6 (^ "7 r}=6Yݾ lC u hquymp Ǧ G jhs ǜNl ɻ} o 7 #S6 a w 4 ! OS r D 5 7 % | ?x> L | / nD 6?/8 w # [ ) L 7 +6〼T A T g ! %5 Mm Z /c -{1_Je "| ^$ 'O & ޱմ < H vNqϡQ$ < 6 &Nݛ ֨tǻN (9 n ru~'όN sMG& ,uH Kw *Ī 5@ u6 BԒ i YN * f 0 _ GhKW u lT <nj- 0{ M L~ | /a v\ E = ?1 \ɟuq Ђ Y O a K ޡP q $ H8o Q˼EV ~ k 0 h' L Pp M -M" m^ !6l nմ 쮝C U T . ! :vMǨb h ډ Vc r @~p # !1QAa q ? AL0L x LU 4 d ; x " 16ad0 7.\ߋ 0 = P l v/ " c A Ay A|2pO8"d MV #1] = \ " ˡ ] k v I9 d ۓ & q ) ǐq E ꞅ v "P )q X &Q З non]я u ג./ ; gZ$ M QР 2M ]h ni 0 P $ێ 3CɏGjώy : m c # S_ l@ '_ \m|C 2`K _ 1 cIvGc $? PCQ S+D ? K aײ k Fr b 8 ύ NEدg ĝ U 3 6 #Ik+ v { v i ( ވ ? a e) X xy/*@Q Ǽ Ծ ) $ IWO l c G; !i k{ gOŀ L ('x T rb $ w) R $ & N1E td U3Uȉ1p M"N* (DNy d96.(jQ) X 5 c QɎMy W ? Q *!R > 6=7)Xj 5`J ] e 8%t ! + ' ! 1Q 5 !1 AQaq ё #2 "0BRb ? G t^ ## .l lQ T $ v , ,m 㵜5u bV =sY+ @d { N ! dn O < .- B; _w J t 6;Q Jd. Q c%p{ 1 ,sND dF H I0 Гo X ш e黅X ۢ F :)[ F G X ƹ / w _c MeD ,ʡc c . W D tA $ j@ : ) - #u c1< @ۗ9F ) KJ- hpP] _ x [ q B lb p ʖ w q " LFGd ƶ * s +ډ_Zc " ? % t[I P 6 J ]# =ɺ V v v CGs Gh1 > )6 |e y ? L ӣ m,4 G W Ui ` ] uJVo VDG< SB 6ϏQ @ TiU l y O U 0 kfV ~ ~}S Z @ *WU Ui ## ; s /[ = ! 7}" W N ] ' (L ! ~ y5 g9T̅J kbM' +s :S +B) v @ M j e C f j E 0 Y\Qn z G 1 д~ W o{T 9?` Rm yhsy3 !HAD ] m c1 ~ 2 L S u7x T ;j$ `} 4-> L# vzŏ I L S ֭ T { r jGK C ; b pU= - ` Bs K. S F w4 M q] Z dH S 0 ) tLg
<?php
// phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery -- Direct $wpdb query is required for this operation.
// phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching -- some query operations need to always receive the most up-to-date or actual data directly from the database, reducing the risk of serving stale information.
/**
* Semaphore Lock Management
* Adapted from WP Social under the GPL - thanks to Alex King (https://github.com/crowdfavorite/wp-social)
*/
class UpdraftPlus_Semaphore {
/**
* Initializes the semaphore object.
*
* @static
* @return UpdraftPlus_Semaphore
*/
public static function factory() {
return new self;
}
/**
* Lock Broke
*
* @var boolean
*/
protected $lock_broke = false;
public $lock_name = 'lock';
/**
* Attempts to start the lock. If the rename works, the lock is started.
*
* @return bool
*/
public function lock() {
global $wpdb, $updraftplus;
// Attempt to set the lock
// phpcs:disable WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter -- Dynamic table name ($wpdb->options) and lock name used in semaphore queries cannot be parameterized
$affected = $wpdb->query("
UPDATE $wpdb->options
SET option_name = 'updraftplus_locked_".$this->lock_name."'
WHERE option_name = 'updraftplus_unlocked_".$this->lock_name."'
");
// phpcs:enable WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter
if ('0' == $affected && !$this->stuck_check()) {
$updraftplus->log('Semaphore lock ('.$this->lock_name.', '.$wpdb->options.') failed (line '.__LINE__.')');
return false;
}
// Check to see if all processes are complete
// phpcs:disable WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter -- Dynamic table name ($wpdb->options) and lock name used in semaphore queries cannot be parameterized
$affected = $wpdb->query("
UPDATE $wpdb->options
SET option_value = CAST(option_value AS UNSIGNED) + 1
WHERE option_name = 'updraftplus_semaphore_".$this->lock_name."'
AND option_value = '0'
");
// phpcs:enable WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter
if ('1' != $affected) {
if (!$this->stuck_check()) {
$updraftplus->log('Semaphore lock ('.$this->lock_name.', '.$wpdb->options.') failed (line '.__LINE__.')');
return false;
}
// Reset the semaphore to 1
// phpcs:disable WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter -- Dynamic table name ($wpdb->options) and lock name used in semaphore queries cannot be parameterized
$wpdb->query("
UPDATE $wpdb->options
SET option_value = '1'
WHERE option_name = 'updraftplus_semaphore_".$this->lock_name."'
");
// phpcs:enable WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter
$updraftplus->log('Semaphore ('.$this->lock_name.', '.$wpdb->options.') reset to 1');
}
// Set the lock time
// phpcs:disable WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter -- Dynamic table name ($wpdb->options) and lock name used in semaphore queries cannot be parameterized
$wpdb->query($wpdb->prepare("
UPDATE $wpdb->options
SET option_value = %s
WHERE option_name = 'updraftplus_last_lock_time_".$this->lock_name."'
", current_time('mysql', 1)));
// phpcs:enable WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter
$updraftplus->log('Set semaphore last lock ('.$this->lock_name.') time to '.current_time('mysql', 1));
$updraftplus->log('Semaphore lock ('.$this->lock_name.') complete');
return true;
}
public static function ensure_semaphore_exists($semaphore) {
// Make sure the options for semaphores exist
global $wpdb, $updraftplus;
$results = $wpdb->get_results(
$wpdb->prepare(
"SELECT option_id FROM $wpdb->options WHERE option_name IN (%s, %s, %s, %s)",
"updraftplus_locked_$semaphore",
"updraftplus_unlocked_$semaphore",
"updraftplus_last_lock_time_$semaphore",
"updraftplus_semaphore_$semaphore"
)
);
if (!is_array($results) || count($results) < 3) {
if (is_array($results) && count($results) > 0) {
$updraftplus->log("Semaphore ($semaphore, ".$wpdb->options.") in an impossible/broken state - fixing (".count($results).")");
} else {
$updraftplus->log("Semaphore ($semaphore, ".$wpdb->options.") being initialised");
}
$wpdb->query(
$wpdb->prepare(
"DELETE FROM $wpdb->options WHERE option_name IN (%s, %s, %s, %s)",
'updraftplus_locked_'.$semaphore,
'updraftplus_unlocked_'.$semaphore,
'updraftplus_last_lock_time_'.$semaphore,
'updraftplus_semaphore_'.$semaphore
)
);
$wpdb->query(
$wpdb->prepare(
"INSERT INTO $wpdb->options (option_name, option_value, autoload) VALUES (%s, %s, %s), (%s, %s, %s), (%s, %s, %s)",
'updraftplus_unlocked_'.$semaphore,
'1',
'no',
'updraftplus_last_lock_time_'.$semaphore,
current_time('mysql', 1),
'no',
'updraftplus_semaphore_'.$semaphore,
'0',
'no'
)
);
}
}
/**
* Increment the semaphore.
*
* @param array $filters
* @return Updraft_Semaphore
*/
public function increment(array $filters = array()) {
global $wpdb, $updraftplus;
if (count($filters)) {
// Loop through all of the filters and increment the semaphore
foreach ($filters as $priority) {
for ($i = 0, $j = count($priority); $i < $j; ++$i) {
$this->increment();
}
}
} else {
// phpcs:disable WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter -- Dynamic table name ($wpdb->options) and lock name used in semaphore queries cannot be parameterized
$wpdb->query("
UPDATE $wpdb->options
SET option_value = CAST(option_value AS UNSIGNED) + 1
WHERE option_name = 'updraftplus_semaphore_".$this->lock_name."'
");
// phpcs:enable WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter
$updraftplus->log('Incremented the semaphore ('.$this->lock_name.') by 1');
}
return $this;
}
/**
* Decrements the semaphore.
*
* @return void
*/
public function decrement() {
global $wpdb, $updraftplus;
// phpcs:disable WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter -- Dynamic table name ($wpdb->options) and lock name used in semaphore queries cannot be parameterized
$wpdb->query("
UPDATE $wpdb->options
SET option_value = CAST(option_value AS UNSIGNED) - 1
WHERE option_name = 'updraftplus_semaphore_".$this->lock_name."'
AND CAST(option_value AS UNSIGNED) > 0
");
// phpcs:enable WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter
$updraftplus->log('Decremented the semaphore ('.$this->lock_name.') by 1');
}
/**
* Unlocks the process.
*
* @return bool
*/
public function unlock() {
global $wpdb, $updraftplus;
// Decrement for the master process.
$this->decrement();
// phpcs:disable WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter -- Dynamic table name ($wpdb->options) and lock name used in semaphore queries cannot be parameterized
$result = $wpdb->query("
UPDATE $wpdb->options
SET option_name = 'updraftplus_unlocked_".$this->lock_name."'
WHERE option_name = 'updraftplus_locked_".$this->lock_name."'
");
// phpcs:enable WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter
if ('1' == $result) {
$updraftplus->log('Semaphore ('.$this->lock_name.') unlocked');
return true;
}
$updraftplus->log('Semaphore ('.$this->lock_name.', '.$wpdb->options.') still locked ('.$result.')');
return false;
}
/**
* Attempts to jiggle the stuck lock loose.
*
* @return bool
*/
private function stuck_check() {
global $wpdb, $updraftplus;
// Check to see if we already broke the lock.
if ($this->lock_broke) {
return true;
}
$current_time = current_time('mysql', 1);
$three_minutes_before = gmdate('Y-m-d H:i:s', time()-(defined('UPDRAFTPLUS_SEMAPHORE_LOCK_WAIT') ? UPDRAFTPLUS_SEMAPHORE_LOCK_WAIT : 180));
// phpcs:disable WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter -- Dynamic table name ($wpdb->options) and lock name used in semaphore queries cannot be parameterized
$affected = $wpdb->query($wpdb->prepare("
UPDATE $wpdb->options
SET option_value = %s
WHERE option_name = 'updraftplus_last_lock_time_".$this->lock_name."'
AND option_value <= %s
", $current_time, $three_minutes_before));
// phpcs:enable WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter
if ('1' == $affected) {
$updraftplus->log('Semaphore ('.$this->lock_name.', '.$wpdb->options.') was stuck, set lock time to '.$current_time);
$this->lock_broke = true;
return true;
}
// Check if lock is greater that 24 hours
$last_lock_time = strtotime(UpdraftPlus_Options::get_updraft_option('updraftplus_last_lock_time_'.$this->lock_name, $current_time));
$next_day = strtotime($current_time.' +1 day');
if ($last_lock_time > $next_day) {
$this->lock_broke = true;
return true;
}
return false;
}
/**
* Remove a given lock from the options table in the database
*
* @return Boolean True if the lock has successfully been removed, false otherwise
*/
public function delete_lock() {
global $wpdb;
return (bool) $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->options} WHERE option_name = %s", $this->lock_name));
}
} // End UpdraftPlus_Semaphore