| @@ -34,71 +34,37 @@ | ||
| 34 | 34 | $this->wpdbAdapter = $wpdbAdapter; |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | /** |
| 38 | - * @return string[] | |
| 38 | + * Get all packetery related options. | |
| 39 | + * | |
| 40 | + * @return object[]|null | |
| 39 | 41 | */ |
| 40 | - public function getExpiredTransientsByPrefix( string $prefix ): array { | |
| 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 ) { | |
| 41 | 54 | $transientPrefix = sprintf( '_transient_%s', $prefix ); |
| 42 | 55 | $transientTimeoutPrefix = sprintf( '_transient_timeout_%s', $prefix ); |
| 43 | 56 | |
| 44 | - return $this->wpdbAdapter->get_col( | |
| 57 | + return $this->wpdbAdapter->query( | |
| 45 | 58 | $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", | |
| 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", | |
| 53 | 64 | $this->wpdbAdapter->escLike( $transientPrefix ) . '%', |
| 54 | 65 | $this->wpdbAdapter->escLike( $transientTimeoutPrefix ) . '%', |
| 55 | 66 | time() |
| 56 | 67 | ) |
| 57 | 68 | ); |
| 58 | - } | |
| 59 | - | |
| 60 | - /** | |
| 61 | - * @param string[] $prefixes | |
| 62 | - * | |
| 63 | - * @return string[] | |
| 64 | - */ | |
| 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; | |
| 83 | - } | |
| 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 | 69 | } |
| 104 | 70 | } |