PluginProbe
Packeta / 2.0.9
Packeta v2.0.9
2.3.2 2.3.1 trunk 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.3.0 1.3.1 1.3.2 1.4 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 All 56 releases
← All changes | src/Packetery/Module/Options/Repository.php +45 -5 1.42.0.9 View file →
@@ -8,8 +8,10 @@
8 8 declare( strict_types=1 );
9 9
10 10 namespace Packetery\Module\Options;
11 11
12 +use Packetery\Module\WpdbAdapter;
13 +
12 14 /**
13 15 * Class Repository.
14 16 *
15 17 * @package Packetery\Module\Options
@@ -16,15 +18,53 @@
16 18 */
17 19 class Repository {
18 20
19 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 + /**
20 38 * Get all packetery related options.
21 39 *
22 - * @return array|object|null
40 + * @return object[]|null
23 41 */
24 - public function getPluginOptions() {
25 - global $wpdb;
42 + public function getPluginOptions(): ?array {
43 + return $this->wpdbAdapter->get_results( 'SELECT `option_name` FROM `' . $this->wpdbAdapter->options . "` WHERE `option_name` LIKE 'packetery%'" );
44 + }
26 45
27 - return $wpdb->get_results( "SELECT `option_name` FROM $wpdb->options WHERE `option_name` LIKE 'packetery%'" );
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 + );
28 69 }
29 -
30 70 }