| Server IP : 38.190.208.107 / Your IP : 216.73.217.46 Web Server : nginx/1.28.1 System : Linux ht2026040333114 6.1.0-10-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.37-1 (2023-07-03) x86_64 User : root ( 0) PHP Version : 8.2.28 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv,eval,assert,passthru,system,exec,shell_exec,popen,proc_open MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /www/wwwroot/wp.12/wp-content/plugins/duplicator/src/Utils/CachesPurge/ |
Upload File : |
<?php
namespace Duplicator\Utils\CachesPurge;
use DUP_Log;
use Error;
use Exception;
class CacheItem
{
/**
* name of purge element (usualli plugin name)
*
* @var string
*/
protected $name = '';
/**
* check function, returns true if the element is to be purged
*
* @var callable|bool
*/
protected $checkCallback = null;
/**
* Purge cache callback
*
* @var callable
*/
protected $purgeCallback = null;
/**
* Message when cache is purged
*
* @var string
*/
protected $purgedMessage = '';
/**
* Construnctor
*
* @param string $name item name
* @param bool|callable $checkCallback check callback, return true if cache of current item have to removed
* @param callable $purgeCallback purge cache callback
*/
public function __construct($name, $checkCallback, $purgeCallback)
{
if (strlen($name) == 0) {
throw new Exception('name can\'t be empty');
}
$this->name = $name;
if (!is_bool($checkCallback) && !is_callable($checkCallback)) {
throw new Exception('checkCallback must be boolean or callable');
}
$this->checkCallback = $checkCallback;
/* purge callback may not exist if the referenced plugin is not initialized.
* That's why the check is performed only if you actually purge the plugin
*/
$this->purgeCallback = $purgeCallback;
$this->purgedMessage = sprintf(__('All caches on <b>%s</b> have been purged.', 'duplicator'), $this->name);
}
/**
* overwrite default purged message
*
* @param string $message message if item have benn purged
*
* @return void
*/
public function setPurgedMessage($message)
{
$this->purgedMessage = $message;
}
/**
* purge caches item
*
* @param string $message message if item have benn purged
*
* @return bool
*/
public function purge(&$message)
{
try {
if (
(is_bool($this->checkCallback) && $this->checkCallback) ||
call_user_func($this->checkCallback) == true
) {
DUP_Log::trace('Purge ' . $this->name);
if (!is_callable($this->purgeCallback)) {
throw new Exception('purgeCallback must be callable');
}
call_user_func($this->purgeCallback);
$message = $this->purgedMessage;
}
return true;
} catch (Exception $e) {
DUP_Log::trace('Error purge ' . $this->name . ' message:' . $e->getMessage());
$message = sprintf(__('Error on caches purge of <b>%s</b>.', 'duplicator'), $this->name);
return false;
} catch (Error $e) {
DUP_Log::trace('Error purge ' . $this->name . ' message:' . $e->getMessage());
$message = sprintf(__('Error on caches purge of <b>%s</b>.', 'duplicator'), $this->name);
return false;
}
}
}