| 1 |
<?php |
| 2 |
/** |
| 3 |
* Class Repository. |
| 4 |
* |
| 5 |
* @package Packetery\Module\Options |
| 6 |
*/ |
| 7 |
|
| 8 |
declare( strict_types=1 ); |
| 9 |
|
| 10 |
namespace Packetery\Module\Options; |
| 11 |
|
| 12 |
use Packetery\Module\WpdbAdapter; |
| 13 |
|
| 14 |
/** |
| 15 |
* Class Repository. |
| 16 |
* |
| 17 |
* @package Packetery\Module\Options |
| 18 |
*/ |
| 19 |
class Repository { |
| 20 |
|
| 21 |
/** |
| 22 |
* WpdbAdapter. |
| 23 |
* |
| 24 |
* @var WpdbAdapter |
| 25 |
*/ |
| 26 |
private $wpdbAdapter; |
| 27 |
|
| 28 |
/** |
| 29 |
* Constructor. |
| 30 |
* |
| 31 |
* @param WpdbAdapter $wpdbAdapter WpdbAdapter. |
| 32 |
*/ |
| 33 |
public function __construct( WpdbAdapter $wpdbAdapter ) { |
| 34 |
$this->wpdbAdapter = $wpdbAdapter; |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* Get all packetery related options. |
| 39 |
* |
| 40 |
* @return object[]|null |
| 41 |
*/ |
| 42 |
public function getPluginOptions(): ?array { |
| 43 |
return $this->wpdbAdapter->get_results( 'SELECT `option_name` FROM `' . $this->wpdbAdapter->options . "` WHERE `option_name` LIKE 'packetery%'" ); |
| 44 |
} |
| 45 |
|
| 46 |
/** |
| 47 |
* Fork of delete_expired_transients. |
| 48 |
* |
| 49 |
* @param string $prefix Custom transient prefix. |
| 50 |
* |
| 51 |
* @return int|bool |
| 52 |
*/ |
| 53 |
public function deleteExpiredTransientsByPrefix( string $prefix ) { |
| 54 |
$transientPrefix = sprintf( '_transient_%s', $prefix ); |
| 55 |
$transientTimeoutPrefix = sprintf( '_transient_timeout_%s', $prefix ); |
| 56 |
|
| 57 |
return $this->wpdbAdapter->query( |
| 58 |
$this->wpdbAdapter->prepare( |
| 59 |
"DELETE a, b FROM {$this->wpdbAdapter->options} a, {$this->wpdbAdapter->options} b |
| 60 |
WHERE a.option_name LIKE %s |
| 61 |
AND a.option_name NOT LIKE %s |
| 62 |
AND b.option_name = CONCAT( '_transient_timeout_', SUBSTRING( a.option_name, 12 ) ) |
| 63 |
AND b.option_value < %d", |
| 64 |
$this->wpdbAdapter->escLike( $transientPrefix ) . '%', |
| 65 |
$this->wpdbAdapter->escLike( $transientTimeoutPrefix ) . '%', |
| 66 |
time() |
| 67 |
) |
| 68 |
); |
| 69 |
} |
| 70 |
} |
| 71 |
|