Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/clone/wp-conte.../plugins/wordpres.../src/actions/importin.../aioseo
File: aioseo-posts-importing-action.php
<?php
[0] Fix | Delete
[1] Fix | Delete
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Given it's a very specific case.
[2] Fix | Delete
namespace Yoast\WP\SEO\Actions\Importing\Aioseo;
[3] Fix | Delete
[4] Fix | Delete
use wpdb;
[5] Fix | Delete
use Yoast\WP\SEO\Actions\Importing\Abstract_Aioseo_Importing_Action;
[6] Fix | Delete
use Yoast\WP\SEO\Helpers\Image_Helper;
[7] Fix | Delete
use Yoast\WP\SEO\Helpers\Import_Cursor_Helper;
[8] Fix | Delete
use Yoast\WP\SEO\Helpers\Indexable_Helper;
[9] Fix | Delete
use Yoast\WP\SEO\Helpers\Indexable_To_Postmeta_Helper;
[10] Fix | Delete
use Yoast\WP\SEO\Helpers\Options_Helper;
[11] Fix | Delete
use Yoast\WP\SEO\Helpers\Sanitization_Helper;
[12] Fix | Delete
use Yoast\WP\SEO\Models\Indexable;
[13] Fix | Delete
use Yoast\WP\SEO\Repositories\Indexable_Repository;
[14] Fix | Delete
use Yoast\WP\SEO\Services\Importing\Aioseo\Aioseo_Replacevar_Service;
[15] Fix | Delete
use Yoast\WP\SEO\Services\Importing\Aioseo\Aioseo_Robots_Provider_Service;
[16] Fix | Delete
use Yoast\WP\SEO\Services\Importing\Aioseo\Aioseo_Robots_Transformer_Service;
[17] Fix | Delete
use Yoast\WP\SEO\Services\Importing\Aioseo\Aioseo_Social_Images_Provider_Service;
[18] Fix | Delete
[19] Fix | Delete
/**
[20] Fix | Delete
* Importing action for AIOSEO post data.
[21] Fix | Delete
*/
[22] Fix | Delete
class Aioseo_Posts_Importing_Action extends Abstract_Aioseo_Importing_Action {
[23] Fix | Delete
[24] Fix | Delete
/**
[25] Fix | Delete
* The plugin of the action.
[26] Fix | Delete
*/
[27] Fix | Delete
public const PLUGIN = 'aioseo';
[28] Fix | Delete
[29] Fix | Delete
/**
[30] Fix | Delete
* The type of the action.
[31] Fix | Delete
*/
[32] Fix | Delete
public const TYPE = 'posts';
[33] Fix | Delete
[34] Fix | Delete
/**
[35] Fix | Delete
* The map of aioseo to yoast meta.
[36] Fix | Delete
*
[37] Fix | Delete
* @var array
[38] Fix | Delete
*/
[39] Fix | Delete
protected $aioseo_to_yoast_map = [
[40] Fix | Delete
'title' => [
[41] Fix | Delete
'yoast_name' => 'title',
[42] Fix | Delete
'transform_method' => 'simple_import_post',
[43] Fix | Delete
],
[44] Fix | Delete
'description' => [
[45] Fix | Delete
'yoast_name' => 'description',
[46] Fix | Delete
'transform_method' => 'simple_import_post',
[47] Fix | Delete
],
[48] Fix | Delete
'og_title' => [
[49] Fix | Delete
'yoast_name' => 'open_graph_title',
[50] Fix | Delete
'transform_method' => 'simple_import_post',
[51] Fix | Delete
],
[52] Fix | Delete
'og_description' => [
[53] Fix | Delete
'yoast_name' => 'open_graph_description',
[54] Fix | Delete
'transform_method' => 'simple_import_post',
[55] Fix | Delete
],
[56] Fix | Delete
'twitter_title' => [
[57] Fix | Delete
'yoast_name' => 'twitter_title',
[58] Fix | Delete
'transform_method' => 'simple_import_post',
[59] Fix | Delete
'twitter_import' => true,
[60] Fix | Delete
],
[61] Fix | Delete
'twitter_description' => [
[62] Fix | Delete
'yoast_name' => 'twitter_description',
[63] Fix | Delete
'transform_method' => 'simple_import_post',
[64] Fix | Delete
'twitter_import' => true,
[65] Fix | Delete
],
[66] Fix | Delete
'canonical_url' => [
[67] Fix | Delete
'yoast_name' => 'canonical',
[68] Fix | Delete
'transform_method' => 'url_import_post',
[69] Fix | Delete
],
[70] Fix | Delete
'keyphrases' => [
[71] Fix | Delete
'yoast_name' => 'primary_focus_keyword',
[72] Fix | Delete
'transform_method' => 'keyphrase_import',
[73] Fix | Delete
],
[74] Fix | Delete
'og_image_url' => [
[75] Fix | Delete
'yoast_name' => 'open_graph_image',
[76] Fix | Delete
'social_image_import' => true,
[77] Fix | Delete
'social_setting_prefix_aioseo' => 'og_',
[78] Fix | Delete
'social_setting_prefix_yoast' => 'open_graph_',
[79] Fix | Delete
'transform_method' => 'social_image_url_import',
[80] Fix | Delete
],
[81] Fix | Delete
'twitter_image_url' => [
[82] Fix | Delete
'yoast_name' => 'twitter_image',
[83] Fix | Delete
'social_image_import' => true,
[84] Fix | Delete
'social_setting_prefix_aioseo' => 'twitter_',
[85] Fix | Delete
'social_setting_prefix_yoast' => 'twitter_',
[86] Fix | Delete
'transform_method' => 'social_image_url_import',
[87] Fix | Delete
],
[88] Fix | Delete
'robots_noindex' => [
[89] Fix | Delete
'yoast_name' => 'is_robots_noindex',
[90] Fix | Delete
'transform_method' => 'post_robots_noindex_import',
[91] Fix | Delete
'robots_import' => true,
[92] Fix | Delete
],
[93] Fix | Delete
'robots_nofollow' => [
[94] Fix | Delete
'yoast_name' => 'is_robots_nofollow',
[95] Fix | Delete
'transform_method' => 'post_general_robots_import',
[96] Fix | Delete
'robots_import' => true,
[97] Fix | Delete
'robot_type' => 'nofollow',
[98] Fix | Delete
],
[99] Fix | Delete
'robots_noarchive' => [
[100] Fix | Delete
'yoast_name' => 'is_robots_noarchive',
[101] Fix | Delete
'transform_method' => 'post_general_robots_import',
[102] Fix | Delete
'robots_import' => true,
[103] Fix | Delete
'robot_type' => 'noarchive',
[104] Fix | Delete
],
[105] Fix | Delete
'robots_nosnippet' => [
[106] Fix | Delete
'yoast_name' => 'is_robots_nosnippet',
[107] Fix | Delete
'transform_method' => 'post_general_robots_import',
[108] Fix | Delete
'robots_import' => true,
[109] Fix | Delete
'robot_type' => 'nosnippet',
[110] Fix | Delete
],
[111] Fix | Delete
'robots_noimageindex' => [
[112] Fix | Delete
'yoast_name' => 'is_robots_noimageindex',
[113] Fix | Delete
'transform_method' => 'post_general_robots_import',
[114] Fix | Delete
'robots_import' => true,
[115] Fix | Delete
'robot_type' => 'noimageindex',
[116] Fix | Delete
],
[117] Fix | Delete
];
[118] Fix | Delete
[119] Fix | Delete
/**
[120] Fix | Delete
* Represents the indexables repository.
[121] Fix | Delete
*
[122] Fix | Delete
* @var Indexable_Repository
[123] Fix | Delete
*/
[124] Fix | Delete
protected $indexable_repository;
[125] Fix | Delete
[126] Fix | Delete
/**
[127] Fix | Delete
* The WordPress database instance.
[128] Fix | Delete
*
[129] Fix | Delete
* @var wpdb
[130] Fix | Delete
*/
[131] Fix | Delete
protected $wpdb;
[132] Fix | Delete
[133] Fix | Delete
/**
[134] Fix | Delete
* The image helper.
[135] Fix | Delete
*
[136] Fix | Delete
* @var Image_Helper
[137] Fix | Delete
*/
[138] Fix | Delete
protected $image;
[139] Fix | Delete
[140] Fix | Delete
/**
[141] Fix | Delete
* The indexable_to_postmeta helper.
[142] Fix | Delete
*
[143] Fix | Delete
* @var Indexable_To_Postmeta_Helper
[144] Fix | Delete
*/
[145] Fix | Delete
protected $indexable_to_postmeta;
[146] Fix | Delete
[147] Fix | Delete
/**
[148] Fix | Delete
* The indexable helper.
[149] Fix | Delete
*
[150] Fix | Delete
* @var Indexable_Helper
[151] Fix | Delete
*/
[152] Fix | Delete
protected $indexable_helper;
[153] Fix | Delete
[154] Fix | Delete
/**
[155] Fix | Delete
* The social images provider service.
[156] Fix | Delete
*
[157] Fix | Delete
* @var Aioseo_Social_Images_Provider_Service
[158] Fix | Delete
*/
[159] Fix | Delete
protected $social_images_provider;
[160] Fix | Delete
[161] Fix | Delete
/**
[162] Fix | Delete
* Class constructor.
[163] Fix | Delete
*
[164] Fix | Delete
* @param Indexable_Repository $indexable_repository The indexables repository.
[165] Fix | Delete
* @param wpdb $wpdb The WordPress database instance.
[166] Fix | Delete
* @param Import_Cursor_Helper $import_cursor The import cursor helper.
[167] Fix | Delete
* @param Indexable_Helper $indexable_helper The indexable helper.
[168] Fix | Delete
* @param Indexable_To_Postmeta_Helper $indexable_to_postmeta The indexable_to_postmeta helper.
[169] Fix | Delete
* @param Options_Helper $options The options helper.
[170] Fix | Delete
* @param Image_Helper $image The image helper.
[171] Fix | Delete
* @param Sanitization_Helper $sanitization The sanitization helper.
[172] Fix | Delete
* @param Aioseo_Replacevar_Service $replacevar_handler The replacevar handler.
[173] Fix | Delete
* @param Aioseo_Robots_Provider_Service $robots_provider The robots provider service.
[174] Fix | Delete
* @param Aioseo_Robots_Transformer_Service $robots_transformer The robots transfomer service.
[175] Fix | Delete
* @param Aioseo_Social_Images_Provider_Service $social_images_provider The social images provider service.
[176] Fix | Delete
*/
[177] Fix | Delete
public function __construct(
[178] Fix | Delete
Indexable_Repository $indexable_repository,
[179] Fix | Delete
wpdb $wpdb,
[180] Fix | Delete
Import_Cursor_Helper $import_cursor,
[181] Fix | Delete
Indexable_Helper $indexable_helper,
[182] Fix | Delete
Indexable_To_Postmeta_Helper $indexable_to_postmeta,
[183] Fix | Delete
Options_Helper $options,
[184] Fix | Delete
Image_Helper $image,
[185] Fix | Delete
Sanitization_Helper $sanitization,
[186] Fix | Delete
Aioseo_Replacevar_Service $replacevar_handler,
[187] Fix | Delete
Aioseo_Robots_Provider_Service $robots_provider,
[188] Fix | Delete
Aioseo_Robots_Transformer_Service $robots_transformer,
[189] Fix | Delete
Aioseo_Social_Images_Provider_Service $social_images_provider
[190] Fix | Delete
) {
[191] Fix | Delete
parent::__construct( $import_cursor, $options, $sanitization, $replacevar_handler, $robots_provider, $robots_transformer );
[192] Fix | Delete
[193] Fix | Delete
$this->indexable_repository = $indexable_repository;
[194] Fix | Delete
$this->wpdb = $wpdb;
[195] Fix | Delete
$this->image = $image;
[196] Fix | Delete
$this->indexable_helper = $indexable_helper;
[197] Fix | Delete
$this->indexable_to_postmeta = $indexable_to_postmeta;
[198] Fix | Delete
$this->social_images_provider = $social_images_provider;
[199] Fix | Delete
}
[200] Fix | Delete
[201] Fix | Delete
// phpcs:disable WordPress.DB.PreparedSQL.NotPrepared -- Reason: They are already prepared.
[202] Fix | Delete
[203] Fix | Delete
/**
[204] Fix | Delete
* Returns the total number of unimported objects.
[205] Fix | Delete
*
[206] Fix | Delete
* @return int The total number of unimported objects.
[207] Fix | Delete
*/
[208] Fix | Delete
public function get_total_unindexed() {
[209] Fix | Delete
if ( ! $this->aioseo_helper->aioseo_exists() ) {
[210] Fix | Delete
return 0;
[211] Fix | Delete
}
[212] Fix | Delete
[213] Fix | Delete
$limit = false;
[214] Fix | Delete
$just_detect = true;
[215] Fix | Delete
$indexables_to_create = $this->wpdb->get_col( $this->query( $limit, $just_detect ) );
[216] Fix | Delete
[217] Fix | Delete
$number_of_indexables_to_create = \count( $indexables_to_create );
[218] Fix | Delete
$completed = $number_of_indexables_to_create === 0;
[219] Fix | Delete
$this->set_completed( $completed );
[220] Fix | Delete
[221] Fix | Delete
return $number_of_indexables_to_create;
[222] Fix | Delete
}
[223] Fix | Delete
[224] Fix | Delete
/**
[225] Fix | Delete
* Returns the limited number of unimported objects.
[226] Fix | Delete
*
[227] Fix | Delete
* @param int $limit The maximum number of unimported objects to be returned.
[228] Fix | Delete
*
[229] Fix | Delete
* @return int|false The limited number of unindexed posts. False if the query fails.
[230] Fix | Delete
*/
[231] Fix | Delete
public function get_limited_unindexed_count( $limit ) {
[232] Fix | Delete
if ( ! $this->aioseo_helper->aioseo_exists() ) {
[233] Fix | Delete
return 0;
[234] Fix | Delete
}
[235] Fix | Delete
[236] Fix | Delete
$just_detect = true;
[237] Fix | Delete
$indexables_to_create = $this->wpdb->get_col( $this->query( $limit, $just_detect ) );
[238] Fix | Delete
[239] Fix | Delete
$number_of_indexables_to_create = \count( $indexables_to_create );
[240] Fix | Delete
$completed = $number_of_indexables_to_create === 0;
[241] Fix | Delete
$this->set_completed( $completed );
[242] Fix | Delete
[243] Fix | Delete
return $number_of_indexables_to_create;
[244] Fix | Delete
}
[245] Fix | Delete
[246] Fix | Delete
/**
[247] Fix | Delete
* Imports AIOSEO meta data and creates the respective Yoast indexables and postmeta.
[248] Fix | Delete
*
[249] Fix | Delete
* @return Indexable[]|false An array of created indexables or false if aioseo data was not found.
[250] Fix | Delete
*/
[251] Fix | Delete
public function index() {
[252] Fix | Delete
if ( ! $this->aioseo_helper->aioseo_exists() ) {
[253] Fix | Delete
return false;
[254] Fix | Delete
}
[255] Fix | Delete
[256] Fix | Delete
$limit = $this->get_limit();
[257] Fix | Delete
$aioseo_indexables = $this->wpdb->get_results( $this->query( $limit ), \ARRAY_A );
[258] Fix | Delete
$created_indexables = [];
[259] Fix | Delete
[260] Fix | Delete
$completed = \count( $aioseo_indexables ) === 0;
[261] Fix | Delete
$this->set_completed( $completed );
[262] Fix | Delete
[263] Fix | Delete
// Let's build the list of fields to check their defaults, to identify whether we're gonna import AIOSEO data in the indexable or not.
[264] Fix | Delete
$check_defaults_fields = [];
[265] Fix | Delete
foreach ( $this->aioseo_to_yoast_map as $yoast_mapping ) {
[266] Fix | Delete
// We don't want to check all the imported fields.
[267] Fix | Delete
if ( ! \in_array( $yoast_mapping['yoast_name'], [ 'open_graph_image', 'twitter_image' ], true ) ) {
[268] Fix | Delete
$check_defaults_fields[] = $yoast_mapping['yoast_name'];
[269] Fix | Delete
}
[270] Fix | Delete
}
[271] Fix | Delete
[272] Fix | Delete
$last_indexed_aioseo_id = 0;
[273] Fix | Delete
foreach ( $aioseo_indexables as $aioseo_indexable ) {
[274] Fix | Delete
$last_indexed_aioseo_id = $aioseo_indexable['id'];
[275] Fix | Delete
[276] Fix | Delete
$indexable = $this->indexable_repository->find_by_id_and_type( $aioseo_indexable['post_id'], 'post' );
[277] Fix | Delete
[278] Fix | Delete
// Let's ensure that the current post id represents something that we want to index (eg. *not* shop_order).
[279] Fix | Delete
if ( ! \is_a( $indexable, 'Yoast\WP\SEO\Models\Indexable' ) ) {
[280] Fix | Delete
continue;
[281] Fix | Delete
}
[282] Fix | Delete
[283] Fix | Delete
if ( $this->indexable_helper->check_if_default_indexable( $indexable, $check_defaults_fields ) ) {
[284] Fix | Delete
$indexable = $this->map( $indexable, $aioseo_indexable );
[285] Fix | Delete
$this->indexable_helper->save_indexable( $indexable );
[286] Fix | Delete
[287] Fix | Delete
// To ensure that indexables can be rebuild after a reset, we have to store the data in the postmeta table too.
[288] Fix | Delete
$this->indexable_to_postmeta->map_to_postmeta( $indexable );
[289] Fix | Delete
}
[290] Fix | Delete
[291] Fix | Delete
$last_indexed_aioseo_id = $aioseo_indexable['id'];
[292] Fix | Delete
[293] Fix | Delete
$created_indexables[] = $indexable;
[294] Fix | Delete
}
[295] Fix | Delete
[296] Fix | Delete
$cursor_id = $this->get_cursor_id();
[297] Fix | Delete
$this->import_cursor->set_cursor( $cursor_id, $last_indexed_aioseo_id );
[298] Fix | Delete
[299] Fix | Delete
return $created_indexables;
[300] Fix | Delete
}
[301] Fix | Delete
[302] Fix | Delete
// phpcs:enable WordPress.DB.PreparedSQL.NotPrepared
[303] Fix | Delete
[304] Fix | Delete
/**
[305] Fix | Delete
* Maps AIOSEO meta data to Yoast meta data.
[306] Fix | Delete
*
[307] Fix | Delete
* @param Indexable $indexable The Yoast indexable.
[308] Fix | Delete
* @param array $aioseo_indexable The AIOSEO indexable.
[309] Fix | Delete
*
[310] Fix | Delete
* @return Indexable The created indexables.
[311] Fix | Delete
*/
[312] Fix | Delete
public function map( $indexable, $aioseo_indexable ) {
[313] Fix | Delete
foreach ( $this->aioseo_to_yoast_map as $aioseo_key => $yoast_mapping ) {
[314] Fix | Delete
// For robots import.
[315] Fix | Delete
if ( isset( $yoast_mapping['robots_import'] ) && $yoast_mapping['robots_import'] ) {
[316] Fix | Delete
$yoast_mapping['subtype'] = $indexable->object_sub_type;
[317] Fix | Delete
$indexable->{$yoast_mapping['yoast_name']} = $this->transform_import_data( $yoast_mapping['transform_method'], $aioseo_indexable, $aioseo_key, $yoast_mapping, $indexable );
[318] Fix | Delete
[319] Fix | Delete
continue;
[320] Fix | Delete
}
[321] Fix | Delete
[322] Fix | Delete
// For social images, like open graph and twitter image.
[323] Fix | Delete
if ( isset( $yoast_mapping['social_image_import'] ) && $yoast_mapping['social_image_import'] ) {
[324] Fix | Delete
$image_url = $this->transform_import_data( $yoast_mapping['transform_method'], $aioseo_indexable, $aioseo_key, $yoast_mapping, $indexable );
[325] Fix | Delete
[326] Fix | Delete
// Update the indexable's social image only where there's actually a url to import, so as not to lose the social images that we came up with when we originally built the indexable.
[327] Fix | Delete
if ( ! empty( $image_url ) ) {
[328] Fix | Delete
$indexable->{$yoast_mapping['yoast_name']} = $image_url;
[329] Fix | Delete
[330] Fix | Delete
$image_source_key = $yoast_mapping['social_setting_prefix_yoast'] . 'image_source';
[331] Fix | Delete
$indexable->$image_source_key = 'imported';
[332] Fix | Delete
[333] Fix | Delete
$image_id_key = $yoast_mapping['social_setting_prefix_yoast'] . 'image_id';
[334] Fix | Delete
$indexable->$image_id_key = $this->image->get_attachment_by_url( $image_url );
[335] Fix | Delete
[336] Fix | Delete
if ( $yoast_mapping['yoast_name'] === 'open_graph_image' ) {
[337] Fix | Delete
$indexable->open_graph_image_meta = null;
[338] Fix | Delete
}
[339] Fix | Delete
}
[340] Fix | Delete
continue;
[341] Fix | Delete
}
[342] Fix | Delete
[343] Fix | Delete
// For twitter import, take the respective open graph data if the appropriate setting is enabled.
[344] Fix | Delete
if ( isset( $yoast_mapping['twitter_import'] ) && $yoast_mapping['twitter_import'] && $aioseo_indexable['twitter_use_og'] ) {
[345] Fix | Delete
$aioseo_indexable['twitter_title'] = $aioseo_indexable['og_title'];
[346] Fix | Delete
$aioseo_indexable['twitter_description'] = $aioseo_indexable['og_description'];
[347] Fix | Delete
}
[348] Fix | Delete
[349] Fix | Delete
if ( ! empty( $aioseo_indexable[ $aioseo_key ] ) ) {
[350] Fix | Delete
$indexable->{$yoast_mapping['yoast_name']} = $this->transform_import_data( $yoast_mapping['transform_method'], $aioseo_indexable, $aioseo_key, $yoast_mapping, $indexable );
[351] Fix | Delete
}
[352] Fix | Delete
}
[353] Fix | Delete
[354] Fix | Delete
return $indexable;
[355] Fix | Delete
}
[356] Fix | Delete
[357] Fix | Delete
/**
[358] Fix | Delete
* Transforms the data to be imported.
[359] Fix | Delete
*
[360] Fix | Delete
* @param string $transform_method The method that is going to be used for transforming the data.
[361] Fix | Delete
* @param array $aioseo_indexable The data of the AIOSEO indexable data that is being imported.
[362] Fix | Delete
* @param string $aioseo_key The name of the specific set of data that is going to be transformed.
[363] Fix | Delete
* @param array $yoast_mapping Extra details for the import of the specific data that is going to be transformed.
[364] Fix | Delete
* @param Indexable $indexable The Yoast indexable that we are going to import the transformed data into.
[365] Fix | Delete
*
[366] Fix | Delete
* @return string|bool|null The transformed data to be imported.
[367] Fix | Delete
*/
[368] Fix | Delete
protected function transform_import_data( $transform_method, $aioseo_indexable, $aioseo_key, $yoast_mapping, $indexable ) {
[369] Fix | Delete
return \call_user_func( [ $this, $transform_method ], $aioseo_indexable, $aioseo_key, $yoast_mapping, $indexable );
[370] Fix | Delete
}
[371] Fix | Delete
[372] Fix | Delete
/**
[373] Fix | Delete
* Returns the number of objects that will be imported in a single importing pass.
[374] Fix | Delete
*
[375] Fix | Delete
* @return int The limit.
[376] Fix | Delete
*/
[377] Fix | Delete
public function get_limit() {
[378] Fix | Delete
/**
[379] Fix | Delete
* Filter 'wpseo_aioseo_post_indexation_limit' - Allow filtering the number of posts indexed during each indexing pass.
[380] Fix | Delete
*
[381] Fix | Delete
* @param int $max_posts The maximum number of posts indexed.
[382] Fix | Delete
*/
[383] Fix | Delete
$limit = \apply_filters( 'wpseo_aioseo_post_indexation_limit', 25 );
[384] Fix | Delete
[385] Fix | Delete
if ( ! \is_int( $limit ) || $limit < 1 ) {
[386] Fix | Delete
$limit = 25;
[387] Fix | Delete
}
[388] Fix | Delete
[389] Fix | Delete
return $limit;
[390] Fix | Delete
}
[391] Fix | Delete
[392] Fix | Delete
/**
[393] Fix | Delete
* Populates the needed data array based on which columns we use from the AIOSEO indexable table.
[394] Fix | Delete
*
[395] Fix | Delete
* @return array The needed data array that contains all the needed columns.
[396] Fix | Delete
*/
[397] Fix | Delete
public function get_needed_data() {
[398] Fix | Delete
$needed_data = \array_keys( $this->aioseo_to_yoast_map );
[399] Fix | Delete
\array_push( $needed_data, 'id', 'post_id', 'robots_default', 'og_image_custom_url', 'og_image_type', 'twitter_image_custom_url', 'twitter_image_type', 'twitter_use_og' );
[400] Fix | Delete
[401] Fix | Delete
return $needed_data;
[402] Fix | Delete
}
[403] Fix | Delete
[404] Fix | Delete
/**
[405] Fix | Delete
* Populates the needed robot data array to be used in validating against its structure.
[406] Fix | Delete
*
[407] Fix | Delete
* @return array The needed data array that contains all the needed columns.
[408] Fix | Delete
*/
[409] Fix | Delete
public function get_needed_robot_data() {
[410] Fix | Delete
$needed_robot_data = [];
[411] Fix | Delete
[412] Fix | Delete
foreach ( $this->aioseo_to_yoast_map as $yoast_mapping ) {
[413] Fix | Delete
if ( isset( $yoast_mapping['robot_type'] ) ) {
[414] Fix | Delete
$needed_robot_data[] = $yoast_mapping['robot_type'];
[415] Fix | Delete
}
[416] Fix | Delete
}
[417] Fix | Delete
[418] Fix | Delete
return $needed_robot_data;
[419] Fix | Delete
}
[420] Fix | Delete
[421] Fix | Delete
/**
[422] Fix | Delete
* Creates a query for gathering AiOSEO data from the database.
[423] Fix | Delete
*
[424] Fix | Delete
* @param int $limit The maximum number of unimported objects to be returned.
[425] Fix | Delete
* @param bool $just_detect Whether we want to just detect if there are unimported objects. If false, we want to actually import them too.
[426] Fix | Delete
*
[427] Fix | Delete
* @return string The query to use for importing or counting the number of items to import.
[428] Fix | Delete
*/
[429] Fix | Delete
public function query( $limit = false, $just_detect = false ) {
[430] Fix | Delete
$table = $this->aioseo_helper->get_table();
[431] Fix | Delete
[432] Fix | Delete
$select_statement = 'id';
[433] Fix | Delete
if ( ! $just_detect ) {
[434] Fix | Delete
// If we want to import too, we need the actual needed data from AIOSEO indexables.
[435] Fix | Delete
$needed_data = $this->get_needed_data();
[436] Fix | Delete
[437] Fix | Delete
$select_statement = \implode( ', ', $needed_data );
[438] Fix | Delete
}
[439] Fix | Delete
[440] Fix | Delete
$cursor_id = $this->get_cursor_id();
[441] Fix | Delete
$cursor = $this->import_cursor->get_cursor( $cursor_id );
[442] Fix | Delete
[443] Fix | Delete
/**
[444] Fix | Delete
* Filter 'wpseo_aioseo_post_cursor' - Allow filtering the value of the aioseo post import cursor.
[445] Fix | Delete
*
[446] Fix | Delete
* @param int $import_cursor The value of the aioseo post import cursor.
[447] Fix | Delete
*/
[448] Fix | Delete
$cursor = \apply_filters( 'wpseo_aioseo_post_import_cursor', $cursor );
[449] Fix | Delete
[450] Fix | Delete
$replacements = [ $cursor ];
[451] Fix | Delete
[452] Fix | Delete
$limit_statement = '';
[453] Fix | Delete
if ( ! empty( $limit ) ) {
[454] Fix | Delete
$replacements[] = $limit;
[455] Fix | Delete
$limit_statement = ' LIMIT %d';
[456] Fix | Delete
}
[457] Fix | Delete
[458] Fix | Delete
// phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Reason: There is no unescaped user input.
[459] Fix | Delete
return $this->wpdb->prepare(
[460] Fix | Delete
"SELECT {$select_statement} FROM {$table} WHERE id > %d ORDER BY id{$limit_statement}",
[461] Fix | Delete
$replacements
[462] Fix | Delete
);
[463] Fix | Delete
// phpcs:enable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
[464] Fix | Delete
}
[465] Fix | Delete
[466] Fix | Delete
/**
[467] Fix | Delete
* Minimally transforms data to be imported.
[468] Fix | Delete
*
[469] Fix | Delete
* @param array $aioseo_data All of the AIOSEO data to be imported.
[470] Fix | Delete
* @param string $aioseo_key The AIOSEO key that contains the setting we're working with.
[471] Fix | Delete
*
[472] Fix | Delete
* @return string The transformed meta data.
[473] Fix | Delete
*/
[474] Fix | Delete
public function simple_import_post( $aioseo_data, $aioseo_key ) {
[475] Fix | Delete
return $this->simple_import( $aioseo_data[ $aioseo_key ] );
[476] Fix | Delete
}
[477] Fix | Delete
[478] Fix | Delete
/**
[479] Fix | Delete
* Transforms URL to be imported.
[480] Fix | Delete
*
[481] Fix | Delete
* @param array $aioseo_data All of the AIOSEO data to be imported.
[482] Fix | Delete
* @param string $aioseo_key The AIOSEO key that contains the setting we're working with.
[483] Fix | Delete
*
[484] Fix | Delete
* @return string The transformed URL.
[485] Fix | Delete
*/
[486] Fix | Delete
public function url_import_post( $aioseo_data, $aioseo_key ) {
[487] Fix | Delete
return $this->url_import( $aioseo_data[ $aioseo_key ] );
[488] Fix | Delete
}
[489] Fix | Delete
[490] Fix | Delete
/**
[491] Fix | Delete
* Plucks the keyphrase to be imported from the AIOSEO array of keyphrase meta data.
[492] Fix | Delete
*
[493] Fix | Delete
* @param array $aioseo_data All of the AIOSEO data to be imported.
[494] Fix | Delete
* @param string $aioseo_key The AIOSEO key that contains the setting we're working with, aka keyphrases.
[495] Fix | Delete
*
[496] Fix | Delete
* @return string|null The plucked keyphrase.
[497] Fix | Delete
*/
[498] Fix | Delete
public function keyphrase_import( $aioseo_data, $aioseo_key ) {
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function