| 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.10/wp-content/plugins/duplicator/src/Utils/Email/ |
Upload File : |
<?php
namespace Duplicator\Utils\Email;
use DUP_Package;
use DUP_Settings;
use DUP_PackageStatus;
use Duplicator\Core\Controllers\ControllersManager;
use Duplicator\Libs\Snap\JsonSerialize\JsonSerialize;
/**
* Email Summary
*/
class EmailSummary
{
const SEND_FREQ_NEVER = 'never';
const SEND_FREQ_DAILY = 'daily';
const SEND_FREQ_WEEKLY = 'weekly';
const SEND_FREQ_MONTHLY = 'monthly';
/**
* Old option key for storing email summary info, used for migrating data to the correct option key
*/
const INFO_OPT_OLD_KEY = 'duplicator-email-summary-info';
const PEVIEW_SLUG = 'duplicator-email-summary-preview';
const INFO_OPT_KEY = 'duplicator_email_summary_info';
/** @var self The singleton instance */
private static $self = null;
/** @var int[] Manual package ids */
private $manualPackageIds = array();
/** @var int[] info about created storages*/
private $failedPackageIds = array();
/**
* Get the singleton instance
*
* @return self
*/
public static function getInstance()
{
if (self::$self == null) {
self::$self = new self();
}
return self::$self;
}
/**
* Create Email Summary object
*/
private function __construct()
{
if (($data = get_option(self::INFO_OPT_KEY)) !== false) {
JsonSerialize::unserializeToObj($data, $this);
}
}
/**
* Returns the preview link
*
* @return string
*/
public static function getPreviewLink()
{
return ControllersManager::getMenuLink(self::PEVIEW_SLUG);
}
/**
* Add package to summary
*
* @param DUP_Package $package The package
* @param int $status The status
*
* @return void
*/
public function addPackage(DUP_Package $package, $status)
{
if ($status !== DUP_PackageStatus::COMPLETE && $status !== DUP_PackageStatus::ERROR) {
return;
}
if ($status === DUP_PackageStatus::COMPLETE) {
$this->manualPackageIds[] = $package->ID;
} elseif ($status === DUP_PackageStatus::ERROR) {
$this->failedPackageIds[] = $package->ID;
}
$this->save();
}
/**
* Returns info about created packages
*
* @return array<int|string, array<string, string|int>>
*/
public function getPackagesInfo()
{
$packagesInfo = array();
$packagesInfo['manual'] = array(
'name' => __('Successful', 'duplicator'),
'count' => count($this->manualPackageIds),
);
$packagesInfo['failed'] = array(
'name' => __('Failed', 'duplicator'),
'count' => count($this->failedPackageIds),
);
return $packagesInfo;
}
/**
* Get all frequency options
*
* @return array<int, string>
*/
public static function getAllFrequencyOptions()
{
return array(
self::SEND_FREQ_NEVER => esc_html__('Never', 'duplicator'),
self::SEND_FREQ_DAILY => esc_html__('Daily', 'duplicator'),
self::SEND_FREQ_WEEKLY => esc_html__('Weekly', 'duplicator'),
self::SEND_FREQ_MONTHLY => esc_html__('Monthly', 'duplicator'),
);
}
/**
* Get the frequency text displayed in the email
*
* @return string
*/
public static function getFrequencyText()
{
$frequency = DUP_Settings::Get('email_summary_frequency');
switch ($frequency) {
case self::SEND_FREQ_DAILY:
return esc_html__('day', 'duplicator');
case self::SEND_FREQ_MONTHLY:
return esc_html__('month', 'duplicator');
case self::SEND_FREQ_WEEKLY:
default:
return esc_html__('week', 'duplicator');
}
}
/**
* Reset plugin data
*
* @return bool True if data has been reset, false otherwise
*/
public function resetData()
{
$this->manualPackageIds = array();
$this->failedPackageIds = array();
return $this->save();
}
/**
* Save plugin data
*
* @return bool True if data has been saved, false otherwise
*/
private function save()
{
return update_option(self::INFO_OPT_KEY, JsonSerialize::serialize($this));
}
}