PluginProbe
Packeta / 2.1
Packeta v2.1
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 +62 -4 1.5.42.1 View file →
@@ -34,13 +34,71 @@
34 34 $this->wpdbAdapter = $wpdbAdapter;
35 35 }
36 36
37 37 /**
38 - * Get all packetery related options.
38 + * @return string[]
39 + */
40 + public function getExpiredTransientsByPrefix( string $prefix ): array {
41 + $transientPrefix = sprintf( '_transient_%s', $prefix );
42 + $transientTimeoutPrefix = sprintf( '_transient_timeout_%s', $prefix );
43 +
44 + return $this->wpdbAdapter->get_col(
45 + $this->wpdbAdapter->prepare(
46 + "SELECT SUBSTRING(`a`.`option_name`, 12)
47 + FROM `{$this->wpdbAdapter->options}` `a`
48 + JOIN `{$this->wpdbAdapter->options}` `b`
49 + ON `b`.`option_name` = CONCAT('_transient_timeout_', SUBSTRING(`a`.`option_name`, 12))
50 + WHERE `a`.`option_name` LIKE %s
51 + AND `a`.`option_name` NOT LIKE %s
52 + AND `b`.`option_value` < %d",
53 + $this->wpdbAdapter->escLike( $transientPrefix ) . '%',
54 + $this->wpdbAdapter->escLike( $transientTimeoutPrefix ) . '%',
55 + time()
56 + )
57 + );
58 + }
59 +
60 + /**
61 + * @param string[] $prefixes
39 62 *
40 - * @return object[]|null
63 + * @return string[]
41 64 */
42 - public function getPluginOptions(): ?array {
43 - return $this->wpdbAdapter->get_results( 'SELECT `option_name` FROM `' . $this->wpdbAdapter->options . "` WHERE `option_name` LIKE 'packetery%'" );
65 + public function getAllTransientsByPrefixes( array $prefixes ): array {
66 + if ( $prefixes === [] ) {
67 + return [];
68 + }
69 +
70 + $optionPrefixes = [];
71 + foreach ( $prefixes as $prefix ) {
72 + $optionPrefixes[] = '_transient_' . $prefix;
73 + }
74 +
75 + $transientNames = [];
76 + $result = $this->getAllOptionNamesByPrefixes( $optionPrefixes );
77 +
78 + foreach ( $result as $optionName ) {
79 + $transientNames[] = preg_replace( '~^_transient_~', '', $optionName );
80 + }
81 +
82 + return $transientNames;
44 83 }
45 84
85 + /**
86 + * @param string[] $prefixes
87 + *
88 + * @return string[]
89 + */
90 + public function getAllOptionNamesByPrefixes( array $prefixes ): array {
91 + if ( $prefixes === [] ) {
92 + return [];
93 + }
94 +
95 + $prefixWhere = [];
96 + foreach ( $prefixes as $prefix ) {
97 + $prefixWhere[] = sprintf( '`option_name` LIKE "%s"', $this->wpdbAdapter->escLike( $prefix ) . '%' );
98 + }
99 +
100 + $prefixWhereDisjunction = implode( ' OR ', $prefixWhere );
101 +
102 + return $this->wpdbAdapter->get_col( "SELECT `option_name` FROM `{$this->wpdbAdapter->options}` WHERE {$prefixWhereDisjunction}" );
103 + }
46 104 }