| 1 |
<?php |
| 2 |
|
| 3 |
namespace Yoast\WP\SEO\Actions\Importing; |
| 4 |
|
| 5 |
use wpdb; |
| 6 |
use Yoast\WP\SEO\Conditionals\Updated_Importer_Framework_Conditional; |
| 7 |
use Yoast\WP\SEO\Config\Conflicting_Plugins; |
| 8 |
use Yoast\WP\SEO\Helpers\Import_Cursor_Helper; |
| 9 |
use Yoast\WP\SEO\Helpers\Options_Helper; |
| 10 |
use Yoast\WP\SEO\Helpers\Sanitization_Helper; |
| 11 |
use Yoast\WP\SEO\Services\Importing\Aioseo\Aioseo_Replacevar_Service; |
| 12 |
use Yoast\WP\SEO\Services\Importing\Aioseo\Aioseo_Robots_Provider_Service; |
| 13 |
use Yoast\WP\SEO\Services\Importing\Aioseo\Aioseo_Robots_Transformer_Service; |
| 14 |
use Yoast\WP\SEO\Services\Importing\Conflicting_Plugins_Service; |
| 15 |
|
| 16 |
/** |
| 17 |
* Deactivates plug-ins that cause conflicts with Yoast SEO. |
| 18 |
* |
| 19 |
* @phpcs:disable Yoast.NamingConventions.ObjectNameDepth.MaxExceeded |
| 20 |
*/ |
| 21 |
class Deactivate_Conflicting_Plugins_Action extends Abstract_Aioseo_Importing_Action { |
| 22 |
|
| 23 |
/** |
| 24 |
* The plugin the class deals with. |
| 25 |
* |
| 26 |
* @var string |
| 27 |
*/ |
| 28 |
const PLUGIN = 'conflicting-plugins'; |
| 29 |
|
| 30 |
/** |
| 31 |
* The type the class deals with. |
| 32 |
* |
| 33 |
* @var string |
| 34 |
*/ |
| 35 |
const TYPE = 'deactivation'; |
| 36 |
|
| 37 |
/** |
| 38 |
* The replacevar handler. |
| 39 |
* |
| 40 |
* @var Aioseo_Replacevar_Service |
| 41 |
*/ |
| 42 |
protected $replacevar_handler; |
| 43 |
|
| 44 |
/** |
| 45 |
* Knows all plugins that might possibly conflict. |
| 46 |
* |
| 47 |
* @var Conflicting_Plugins_Service |
| 48 |
*/ |
| 49 |
protected $conflicting_plugins; |
| 50 |
|
| 51 |
/** |
| 52 |
* The list of conflicting plugins |
| 53 |
* |
| 54 |
* @var array |
| 55 |
*/ |
| 56 |
protected $detected_plugins; |
| 57 |
|
| 58 |
/** |
| 59 |
* Class constructor. |
| 60 |
* |
| 61 |
* @param Import_Cursor_Helper $import_cursor The import cursor helper. |
| 62 |
* @param Options_Helper $options The options helper. |
| 63 |
* @param Sanitization_Helper $sanitization The sanitization helper. |
| 64 |
* @param Aioseo_Replacevar_Service $replacevar_handler The replacevar handler. |
| 65 |
* @param Aioseo_Robots_Provider_Service $robots_provider The robots provider service. |
| 66 |
* @param Aioseo_Robots_Transformer_Service $robots_transformer The robots transfomer service. |
| 67 |
* @param Conflicting_Plugins_Service $conflicting_plugins_service The Conflicting plugins Service. |
| 68 |
*/ |
| 69 |
public function __construct( |
| 70 |
Import_Cursor_Helper $import_cursor, |
| 71 |
Options_Helper $options, |
| 72 |
Sanitization_Helper $sanitization, |
| 73 |
Aioseo_Replacevar_Service $replacevar_handler, |
| 74 |
Aioseo_Robots_Provider_Service $robots_provider, |
| 75 |
Aioseo_Robots_Transformer_Service $robots_transformer, |
| 76 |
Conflicting_Plugins_Service $conflicting_plugins_service |
| 77 |
) { |
| 78 |
parent::__construct( $import_cursor, $options, $sanitization, $replacevar_handler, $robots_provider, $robots_transformer ); |
| 79 |
|
| 80 |
$this->conflicting_plugins = $conflicting_plugins_service; |
| 81 |
$this->detected_plugins = []; |
| 82 |
} |
| 83 |
|
| 84 |
/** |
| 85 |
* Get the total number of conflicting plugins. |
| 86 |
*/ |
| 87 |
public function get_total_unindexed() { |
| 88 |
return \count( $this->get_detected_plugins() ); |
| 89 |
} |
| 90 |
|
| 91 |
/** |
| 92 |
* Returns whether the updated importer framework is enabled. |
| 93 |
* |
| 94 |
* @return bool True if the updated importer framework is enabled. |
| 95 |
*/ |
| 96 |
public function is_enabled() { |
| 97 |
$updated_importer_framework_conditional = \YoastSEO()->classes->get( Updated_Importer_Framework_Conditional::class ); |
| 98 |
|
| 99 |
return $updated_importer_framework_conditional->is_met(); |
| 100 |
} |
| 101 |
|
| 102 |
/** |
| 103 |
* Deactivate conflicting plugins. |
| 104 |
*/ |
| 105 |
public function index() { |
| 106 |
$detected_plugins = $this->get_detected_plugins(); |
| 107 |
$this->conflicting_plugins->deactivate_conflicting_plugins( $detected_plugins ); |
| 108 |
|
| 109 |
// We need to conform to the interface, so we report that no indexables were created. |
| 110 |
return []; |
| 111 |
} |
| 112 |
|
| 113 |
/** |
| 114 |
* {@inheritDoc} |
| 115 |
*/ |
| 116 |
public function get_limit() { |
| 117 |
return \count( Conflicting_Plugins::all_plugins() ); |
| 118 |
} |
| 119 |
|
| 120 |
/** |
| 121 |
* Returns the total number of unindexed objects up to a limit. |
| 122 |
* |
| 123 |
* @param int $limit The maximum. |
| 124 |
* |
| 125 |
* @return int The total number of unindexed objects. |
| 126 |
*/ |
| 127 |
public function get_limited_unindexed_count( $limit ) { |
| 128 |
$count = \count( $this->get_detected_plugins() ); |
| 129 |
return ( $count <= $limit ) ? $count : $limit; |
| 130 |
} |
| 131 |
|
| 132 |
/** |
| 133 |
* Returns all detected plugins. |
| 134 |
* |
| 135 |
* @return array The detected plugins. |
| 136 |
*/ |
| 137 |
protected function get_detected_plugins() { |
| 138 |
// The active plugins won't change much. We can reuse the result for the duration of the request. |
| 139 |
if ( \count( $this->detected_plugins ) < 1 ) { |
| 140 |
$this->detected_plugins = $this->conflicting_plugins->detect_conflicting_plugins(); |
| 141 |
} |
| 142 |
return $this->detected_plugins; |
| 143 |
} |
| 144 |
} |
| 145 |
|