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
packeta / src / Packetery / Module / Options / Repository.php

Repository.php in Packeta 2.0.9, at src/Packetery/Module/Options/Repository.php

71 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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