PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / trunk
Yoast SEO – Advanced SEO with real-time guidance and built-in AI vtrunk
28.6 28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 All 130 releases
← All changes | src/actions/importing/aioseo/aioseo-cleanup-action.php +17 -51 18.3 → trunk View file →
@@ -5,14 +5,11 @@
5 5
6 6 use wpdb;
7 7 use Yoast\WP\SEO\Actions\Importing\Abstract_Aioseo_Importing_Action;
8 8 use Yoast\WP\SEO\Helpers\Options_Helper;
9 -use Yoast\WP\SEO\Helpers\Wpdb_Helper;
10 9
11 10 /**
12 11 * Importing action for cleaning up AIOSEO data.
13 - *
14 - * @phpcs:disable Yoast.NamingConventions.ObjectNameDepth.MaxExceeded
15 12 */
16 13 class Aioseo_Cleanup_Action extends Abstract_Aioseo_Importing_Action {
17 14
18 15 /**
@@ -17,19 +14,19 @@
17 14
18 15 /**
19 16 * The plugin of the action.
20 17 */
21 - const PLUGIN = 'aioseo';
18 + public const PLUGIN = 'aioseo';
22 19
23 20 /**
24 21 * The type of the action.
25 22 */
26 - const TYPE = 'cleanup';
23 + public const TYPE = 'cleanup';
27 24
28 25 /**
29 26 * The AIOSEO meta_keys to be cleaned up.
30 27 *
31 - * @var array
28 + * @var array<string>
32 29 */
33 30 protected $aioseo_postmeta_keys = [
34 31 '_aioseo_title',
35 32 '_aioseo_description',
@@ -46,41 +43,19 @@
46 43 */
47 44 protected $wpdb;
48 45
49 46 /**
50 - * The wpdb helper.
51 - *
52 - * @var Wpdb_Helper
53 - */
54 - protected $wpdb_helper;
55 -
56 - /**
57 47 * Class constructor.
58 48 *
59 - * @param wpdb $wpdb The WordPress database instance.
60 - * @param Options_Helper $options The options helper.
61 - * @param Wpdb_Helper $wpdb_helper The wpdb_helper helper.
49 + * @param wpdb $wpdb The WordPress database instance.
50 + * @param Options_Helper $options The options helper.
62 51 */
63 - public function __construct(
64 - wpdb $wpdb,
65 - Options_Helper $options,
66 - Wpdb_Helper $wpdb_helper
67 - ) {
68 - $this->wpdb = $wpdb;
69 - $this->options = $options;
70 - $this->wpdb_helper = $wpdb_helper;
52 + public function __construct( wpdb $wpdb, Options_Helper $options ) {
53 + $this->wpdb = $wpdb;
54 + $this->options = $options;
71 55 }
72 56
73 57 /**
74 - * Retrieves the AIOSEO table name along with the db prefix.
75 - *
76 - * @return string The AIOSEO table name along with the db prefix.
77 - */
78 - protected function get_aioseo_table() {
79 - return $this->wpdb->prefix . 'aioseo_posts';
80 - }
81 -
82 - /**
83 58 * Retrieves the postmeta along with the db prefix.
84 59 *
85 60 * @return string The postmeta table name along with the db prefix.
86 61 */
@@ -88,23 +63,14 @@
88 63 return $this->wpdb->prefix . 'postmeta';
89 64 }
90 65
91 66 /**
92 - * Determines if the AIOSEO database table exists.
93 - *
94 - * @return bool True if the table is found.
95 - */
96 - protected function aioseo_exists() {
97 - return $this->wpdb_helper->table_exists( $this->get_aioseo_table() ) === true;
98 - }
99 -
100 - /**
101 67 * Just checks if the cleanup has been completed in the past.
102 68 *
103 69 * @return int The total number of unimported objects.
104 70 */
105 71 public function get_total_unindexed() {
106 - if ( ! $this->aioseo_exists() ) {
72 + if ( ! $this->aioseo_helper->aioseo_exists() ) {
107 73 return 0;
108 74 }
109 75
110 76 return ( ! $this->get_completed() ) ? 1 : 0;
@@ -117,9 +83,9 @@
117 83 *
118 84 * @return int|false The limited number of unindexed posts. False if the query fails.
119 85 */
120 86 public function get_limited_unindexed_count( $limit ) {
121 - if ( ! $this->aioseo_exists() ) {
87 + if ( ! $this->aioseo_helper->aioseo_exists() ) {
122 88 return 0;
123 89 }
124 90
125 91 return ( ! $this->get_completed() ) ? 1 : 0;
@@ -139,9 +105,8 @@
139 105 $meta_data = $this->wpdb->query( $this->cleanup_postmeta_query() );
140 106 $aioseo_table_truncate_done = $this->wpdb->query( $this->truncate_query() );
141 107 // phpcs:enable WordPress.DB.PreparedSQL.NotPrepared
142 108
143 -
144 109 if ( $meta_data === false && $aioseo_table_truncate_done === false ) {
145 110 return false;
146 111 }
147 112
@@ -164,24 +129,25 @@
164 129
165 130 // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Reason: There is no unescaped user input.
166 131 return $this->wpdb->prepare(
167 132 "DELETE FROM {$table} WHERE meta_key IN (" . \implode( ', ', \array_fill( 0, \count( $meta_keys_to_delete ), '%s' ) ) . ')',
168 - $meta_keys_to_delete
133 + $meta_keys_to_delete,
169 134 );
170 135 // phpcs:enable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
171 136 }
172 137
173 138 /**
174 - * Creates a TRUNCATE query string for emptying the AIOSEO indexable table.
139 + * Creates a TRUNCATE query string for emptying the AIOSEO indexable table, if it exists.
175 140 *
176 141 * @return string The query to use for importing or counting the number of items to import.
177 142 */
178 143 public function truncate_query() {
179 - if ( ! $this->aioseo_exists() ) {
180 - return true;
144 + if ( ! $this->aioseo_helper->aioseo_exists() ) {
145 + // If the table doesn't exist, we need a string that will amount to a quick query that doesn't return false when ran.
146 + return 'SELECT 1';
181 147 }
182 148
183 - $table = $this->get_aioseo_table();
149 + $table = $this->aioseo_helper->get_table();
184 150
185 151 return "TRUNCATE TABLE {$table}";
186 152 }
187 153
@@ -193,9 +159,9 @@
193 159 public function get_limit() {
194 160 /**
195 161 * Filter 'wpseo_aioseo_cleanup_limit' - Allow filtering the number of posts indexed during each indexing pass.
196 162 *
197 - * @api int The maximum number of posts cleaned up.
163 + * @param int $max_posts The maximum number of posts cleaned up.
198 164 */
199 165 $limit = \apply_filters( 'wpseo_aioseo_cleanup_limit', 25 );
200 166
201 167 if ( ! \is_int( $limit ) || $limit < 1 ) {