PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backup, Restore, Migration & Clone / 3.3.3
WP STAGING – WordPress Backup, Restore, Migration & Clone v3.3.3
4.9.3 4.9.2 4.9.1 4.9.0 4.8.1 trunk 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.10.0 3.2.0 3.3.1 3.3.2 3.3.3 3.4.1 3.4.3 3.5.0 3.6.0 3.7.1 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.8.6 3.8.7 3.9.0 3.9.1 3.9.2 3.9.3 3.9.4 4.0.0 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.0 4.7.0 4.7.1 4.7.2 4.7.3 4.8.0
wp-staging / Backup / Service / ZlibCompressor.php
wp-staging / Backup / Service Last commit date
Compression 2 years ago Database 2 years ago Multipart 3 years ago BackupAssets.php 3 years ago BackupMetadataEditor.php 3 years ago BackupsFinder.php 2 years ago Compressor.php 2 years ago Extractor.php 2 years ago ZlibCompressor.php 2 years ago
ZlibCompressor.php
80 lines
1 <?php
2
3 namespace WPStaging\Backup\Service;
4
5 use WPStaging\Backup\Service\Compression\CompressionInterface;
6 use WPStaging\Framework\Facades\Hooks;
7
8 class ZlibCompressor
9 {
10 const FILTER_ZLIB_COMPRESSION_ENABLED = 'wpstg.backup.compression.zlib.enabled';
11
12 /** @var CompressionInterface */
13 protected $service;
14
15 public function __construct(CompressionInterface $service)
16 {
17 $this->service = $service;
18 }
19
20 /**
21 * @return bool Whether the server supports compression.
22 */
23 public function supportsCompression(): bool
24 {
25 return function_exists('gzcompress') && function_exists('gzuncompress');
26 }
27
28 /**
29 * @see \WPStaging\Backup\BackupServiceProvider::registerClasses For the filter.
30 * @return bool Whether the user can use compression.
31 */
32 public function canUseCompression(): bool
33 {
34 static $canUseCompression = null;
35
36 if (!is_null($canUseCompression)) {
37 return $canUseCompression;
38 }
39
40 $isPro = defined('WPSTGPRO_VERSION');
41 $license = get_option('wpstg_license_status');
42
43 $hasActiveLicense = is_object($license) && property_exists($license, 'license') && $license->license === 'valid';
44
45 $canUseCompression = $this->supportsCompression() && $isPro && ($hasActiveLicense || wpstg_is_local());
46
47 return $canUseCompression;
48 }
49
50 /**
51 * @return bool True if compression is enabled, false if not.
52 */
53 public function isCompressionEnabled(): bool
54 {
55 static $isEnabled = null;
56 if (is_null($isEnabled)) {
57 $settings = (object)get_option('wpstg_settings', []);
58 $isEnabled = $settings->enableCompression ?? false;
59 }
60
61 $canUseCompression = $this->canUseCompression();
62
63 $isEnabled = Hooks::applyFilters(self::FILTER_ZLIB_COMPRESSION_ENABLED, $isEnabled && $canUseCompression);
64
65 /**
66 * If the user has enabled multipart backups, we disable compression, as these two features are incompatible for now.
67 *
68 * @see \WPStaging\Backup\Dto\Job\JobBackupDataDto::getIsMultipartBackup
69 */
70 $isMultiPartEnabled = Hooks::applyFilters('wpstg.backup.isMultipartBackup', false);
71
72 return $isEnabled && !$isMultiPartEnabled;
73 }
74
75 public function getService(): CompressionInterface
76 {
77 return $this->service;
78 }
79 }
80