File "shortpixel_queue_db.php"
Full path: /home/kosmetik/public_html/wp-content/plugins/shortpixel-image-optimiser/class/external/shortpixel_queue_db.php
File
size: 3.6 B
MIME-type: text/x-php
Charset: utf-8
Download Open Edit Advanced Editor Back
<?php
use ShortPixel\ShortPixelLogger\ShortPixelLogger as Log;
class ShortPixelQueueDB extends ShortPixelQueue
{
protected $ctrl;
protected $settings;
const THE_OPTION = 'shortpixel_prioq';
const THE_TRANSIENT = 'shortpixel_prioq_lock';
const BULK_TYPE_OPTIMIZE = 0;
const BULK_TYPE_RESTORE = 1;
const BULK_TYPE_CLEANUP = 2;
const BULK_TYPE_CLEANUP_PENDING = 3;
const BULK_NEVER = 0;
const BULK_RUNNING = 1;
const BULK_PAUSED = 2;
const BULK_FINISHED = 3;
public function __construct($controller, $settings)
{
$this->ctrl = $controller;
$this->settings = $settings;
}
public static function get()
{
$queue = self::openQ(LOCK_SH);
if ($queue === false) {
return array();
}
Log::addDebug('DBQ - Get ' . $queue);
$itemsRaw = $queue;
$items = strlen($itemsRaw) ? self::parseQ($itemsRaw) : array();
$fp = null;
self::closeQ($fp);
return $items;
}
public static function set($items)
{
$queue = self::openQ();
if ($queue === false) {
return false;
}
Log::addDebug('DBQ - Set ' . implode(',', $items));
update_option(self::THE_OPTION, implode(',', $items), false);
$fp = null;
self::closeQ($fp);
return true;
}
public function apply($callable, $extra = false)
{
$queue = self::openQ();
if ($queue === false) {
return false;
}
$itemsRaw = $queue;
Log::addDebug('Apply' . $itemsRaw);
$items = strlen($itemsRaw) ? self::parseQ($itemsRaw) : array();
if ($extra) {
$items = call_user_func($callable, $items, $extra);
} else {
$items = call_user_func($callable, $items);
}
update_option(self::THE_OPTION, implode(',', $items), false);
$fp = null;
self::closeQ($fp);
return $items;
}
public static function testQ()
{
$fp = self::openQ();
if ($fp === false) {
return false;
}
self::closeQ($fp);
return true;
}
protected static function openQ($lock = LOCK_EX)
{
$trans = get_transient(self::THE_TRANSIENT);
Log::addDebug('OpenQ', array($trans));
if (!$trans === false) {
return false;
}
Log::addDebug('OpenQ -- opened');
wp_cache_delete(self::THE_OPTION, 'options');
$queue = get_option(self::THE_OPTION, '');
set_transient(self::THE_TRANSIENT, 'true', 60);
return $queue;
}
protected static function closeQ($fp)
{
Log::addDebug('CloseQ');
delete_transient(self::THE_TRANSIENT);
}
public static function resetPrio()
{
self::set(array());
}
public function processing()
{
return $this->bulkRunning() || count($this->get());
}
public function remove($ID)
{
$queue = $this->openQ();
if ($queue === false) {
return false;
}
$items = $queue;
$items = self::parseQ($items);
$items = is_array($items) ? $items : array();
$newItems = array();
$found = false;
foreach ($items as $item) {
if ($item != $ID) {
$newItems[] = $item;
} else {
$found = true;
}
}
if ($found) {
update_option(self::THE_OPTION, implode(',', $newItems), false);
Log::addDebug('DBQ - Found and Removing ' . $ID);
}
$fp = null;
$this->closeQ($fp);
return $found;
}
}