| @@ -4,9 +4,11 @@ | ||
| 4 | 4 | * |
| 5 | 5 | * @package WPSEO\Admin\Import\Plugins |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | -use Yoast\WP\SEO\Actions\Importing\Aioseo_Posts_Importing_Action; | |
| 8 | +use Yoast\WP\SEO\Actions\Importing\Aioseo\Aioseo_Cleanup_Action; | |
| 9 | +use Yoast\WP\SEO\Actions\Importing\Aioseo\Aioseo_Posts_Importing_Action; | |
| 10 | + | |
| 9 | 11 | /** |
| 10 | 12 | * Class with functionality to import & clean All in One SEO Pack post metadata, versions 4 and up. |
| 11 | 13 | */ |
| 12 | 14 | class WPSEO_Import_AIOSEO_V4 extends WPSEO_Plugin_Importer { |
| @@ -59,11 +61,11 @@ | ||
| 59 | 61 | |
| 60 | 62 | /** |
| 61 | 63 | * Mapping between the AiOSEO replace vars and the Yoast replace vars. |
| 62 | 64 | * |
| 65 | + * @see https://yoast.com/help/list-available-snippet-variables-yoast-seo/ | |
| 66 | + * | |
| 63 | 67 | * @var array |
| 64 | - * | |
| 65 | - * @see https://yoast.com/help/list-available-snippet-variables-yoast-seo/ | |
| 66 | 68 | */ |
| 67 | 69 | protected $replace_vars = [ |
| 68 | 70 | // They key is the AiOSEO replace var, the value is the Yoast replace var (see class-wpseo-replace-vars). |
| 69 | 71 | '#author_first_name' => '%%author_first_name%%', |
| @@ -104,15 +106,15 @@ | ||
| 104 | 106 | // At this point we're already looping through all the $clone_keys (this happens in meta_keys_clone() in the abstract class). |
| 105 | 107 | // Now, we'll also loop through the replace_vars array, which holds the mappings between the AiOSEO variables and the Yoast variables. |
| 106 | 108 | // We'll replace all the AiOSEO variables in the temporary table with their Yoast equivalents. |
| 107 | 109 | foreach ( $this->replace_vars as $aioseo_variable => $yoast_variable ) { |
| 108 | - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Reason: We need this query and this is done at many other places as well, for example class-import-rankmath. | |
| 110 | + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- Reason: We need this query and this is done at many other places as well, for example class-import-rankmath. | |
| 109 | 111 | $wpdb->query( |
| 110 | 112 | $wpdb->prepare( |
| 111 | 113 | 'UPDATE tmp_meta_table SET meta_value = REPLACE( meta_value, %s, %s )', |
| 112 | 114 | $aioseo_variable, |
| 113 | - $yoast_variable | |
| 114 | - ) | |
| 115 | + $yoast_variable, | |
| 116 | + ), | |
| 115 | 117 | ); |
| 116 | 118 | } |
| 117 | 119 | |
| 118 | 120 | // The AiOSEO custom fields take the form of `#custom_field-myfield`. |
| @@ -143,12 +145,12 @@ | ||
| 143 | 145 | $unique_custom_fields_or_taxonomies = []; |
| 144 | 146 | |
| 145 | 147 | foreach ( $meta_values as $meta_value ) { |
| 146 | 148 | // Find all custom field replace vars, store them in `$matches`. |
| 147 | - \preg_match_all( | |
| 149 | + preg_match_all( | |
| 148 | 150 | "/#$aioseo_prefix-([\w-]+)/", |
| 149 | 151 | $meta_value, |
| 150 | - $matches | |
| 152 | + $matches, | |
| 151 | 153 | ); |
| 152 | 154 | |
| 153 | 155 | /* |
| 154 | 156 | * `$matches[1]` contain the captured matches of the |
| @@ -156,13 +158,13 @@ | ||
| 156 | 158 | */ |
| 157 | 159 | $custom_fields_or_taxonomies = $matches[1]; |
| 158 | 160 | |
| 159 | 161 | foreach ( $custom_fields_or_taxonomies as $custom_field_or_taxonomy ) { |
| 160 | - $unique_custom_fields_or_taxonomies[ \trim( $custom_field_or_taxonomy ) ] = 1; | |
| 162 | + $unique_custom_fields_or_taxonomies[ trim( $custom_field_or_taxonomy ) ] = 1; | |
| 161 | 163 | } |
| 162 | 164 | } |
| 163 | 165 | |
| 164 | - return \array_keys( $unique_custom_fields_or_taxonomies ); | |
| 166 | + return array_keys( $unique_custom_fields_or_taxonomies ); | |
| 165 | 167 | } |
| 166 | 168 | |
| 167 | 169 | /** |
| 168 | 170 | * Replaces every AIOSEO custom field/taxonomy/etc. replace var with the Yoast version. |
| @@ -173,8 +175,10 @@ | ||
| 173 | 175 | * @param wpdb $wpdb The WordPress database object. |
| 174 | 176 | * @param string $aioseo_prefix The AiOSEO prefix to use |
| 175 | 177 | * (e.g. `custom-field` for custom fields or `tax_name` for custom taxonomies). |
| 176 | 178 | * @param string $yoast_prefix The Yoast prefix to use (e.g. `cf` for custom fields). |
| 179 | + * | |
| 180 | + * @return void | |
| 177 | 181 | */ |
| 178 | 182 | protected function replace_custom_field_or_taxonomy_replace_vars( $unique_custom_fields_or_taxonomies, $wpdb, $aioseo_prefix, $yoast_prefix ) { |
| 179 | 183 | foreach ( $unique_custom_fields_or_taxonomies as $unique_custom_field_or_taxonomy ) { |
| 180 | 184 | $aioseo_variable = "#{$aioseo_prefix}-{$unique_custom_field_or_taxonomy}"; |
| @@ -179,20 +183,20 @@ | ||
| 179 | 183 | foreach ( $unique_custom_fields_or_taxonomies as $unique_custom_field_or_taxonomy ) { |
| 180 | 184 | $aioseo_variable = "#{$aioseo_prefix}-{$unique_custom_field_or_taxonomy}"; |
| 181 | 185 | $yoast_variable = "%%{$yoast_prefix}_{$unique_custom_field_or_taxonomy}%%"; |
| 182 | 186 | |
| 183 | - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 187 | + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 184 | 188 | $wpdb->query( |
| 185 | 189 | $wpdb->prepare( |
| 186 | 190 | 'UPDATE tmp_meta_table SET meta_value = REPLACE( meta_value, %s, %s )', |
| 187 | 191 | $aioseo_variable, |
| 188 | - $yoast_variable | |
| 189 | - ) | |
| 192 | + $yoast_variable, | |
| 193 | + ), | |
| 190 | 194 | ); |
| 191 | 195 | } |
| 192 | 196 | } |
| 193 | 197 | |
| 194 | - // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 198 | + // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 195 | 199 | |
| 196 | 200 | /** |
| 197 | 201 | * Retrieve all the meta values from the temporary meta table that contain |
| 198 | 202 | * at least one AiOSEO custom field replace var. |
| @@ -206,32 +210,32 @@ | ||
| 206 | 210 | protected function get_meta_values_with_custom_field_or_taxonomy( $wpdb, $aioseo_prefix ) { |
| 207 | 211 | return $wpdb->get_col( |
| 208 | 212 | $wpdb->prepare( |
| 209 | 213 | 'SELECT meta_value FROM tmp_meta_table WHERE meta_value LIKE %s', |
| 210 | - "%#$aioseo_prefix-%" | |
| 211 | - ) | |
| 214 | + "%#$aioseo_prefix-%", | |
| 215 | + ), | |
| 212 | 216 | ); |
| 213 | 217 | } |
| 214 | 218 | |
| 215 | - // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 219 | + // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 216 | 220 | |
| 217 | 221 | /** |
| 218 | - * Detects whether there is AIOSEO data to import from their custom table. | |
| 222 | + * Detects whether there is AIOSEO data to import by looking whether the AIOSEO data have been cleaned up. | |
| 219 | 223 | * |
| 220 | 224 | * @return bool Boolean indicating whether there is something to import. |
| 221 | 225 | */ |
| 222 | 226 | protected function detect() { |
| 223 | - $aioseo_posts_import_action = YoastSEO()->classes->get( Aioseo_Posts_Importing_Action::class ); | |
| 224 | - $limit = $aioseo_posts_import_action->get_limit(); | |
| 225 | - return ( $aioseo_posts_import_action->get_limited_unindexed_count( $limit ) > 0 ); | |
| 227 | + $aioseo_cleanup_action = YoastSEO()->classes->get( Aioseo_Cleanup_Action::class ); | |
| 228 | + return ( $aioseo_cleanup_action->get_total_unindexed() > 0 ); | |
| 226 | 229 | } |
| 227 | 230 | |
| 228 | 231 | /** |
| 229 | - * Actually AIOSEO data from their custom table. | |
| 232 | + * Import AIOSEO post data from their custom indexable table. Not currently used. | |
| 230 | 233 | * |
| 231 | 234 | * @return void |
| 232 | 235 | */ |
| 233 | 236 | protected function import() { |
| 237 | + // This is overriden from the import.js and never run. | |
| 234 | 238 | $aioseo_posts_import_action = YoastSEO()->classes->get( Aioseo_Posts_Importing_Action::class ); |
| 235 | 239 | $aioseo_posts_import_action->index(); |
| 236 | 240 | } |
| 237 | 241 | } |