| 1 |
<?php |
| 2 |
|
| 3 |
namespace Yoast\WP\SEO\Services\Importing; |
| 4 |
|
| 5 |
use Yoast\WP\SEO\Actions\Importing\Importing_Action_Interface; |
| 6 |
|
| 7 |
/** |
| 8 |
* Detects if any data from other SEO plugins is available for importing. |
| 9 |
*/ |
| 10 |
class Importable_Detector { |
| 11 |
|
| 12 |
use Importer_Action_Filter_Trait; |
| 13 |
|
| 14 |
/** |
| 15 |
* All known import actions |
| 16 |
* |
| 17 |
* @var array|Importing_Action_Interface[] |
| 18 |
*/ |
| 19 |
protected $importers; |
| 20 |
|
| 21 |
/** |
| 22 |
* Importable_Detector constructor. |
| 23 |
* |
| 24 |
* @param Importing_Action_Interface ...$importers All of the known importers. |
| 25 |
*/ |
| 26 |
public function __construct( Importing_Action_Interface ...$importers ) { |
| 27 |
$this->importers = $importers; |
| 28 |
} |
| 29 |
|
| 30 |
/** |
| 31 |
* Returns the detected importers that have data to work with. |
| 32 |
* |
| 33 |
* @param string $plugin The plugin name of the importer. |
| 34 |
* @param string $type The type of the importer. |
| 35 |
* |
| 36 |
* @return array The detected importers that have data to work with. |
| 37 |
*/ |
| 38 |
public function detect( $plugin = null, $type = null ) { |
| 39 |
$detectors = $this->filter_actions( $this->importers, $plugin, $type ); |
| 40 |
|
| 41 |
$detected = []; |
| 42 |
foreach ( $detectors as $detector ) { |
| 43 |
if ( $detector->is_enabled() && ! $detector->get_completed() && $detector->get_limited_unindexed_count( 1 ) > 0 ) { |
| 44 |
$detected[ $detector->get_plugin() ][] = $detector->get_type(); |
| 45 |
} |
| 46 |
} |
| 47 |
|
| 48 |
return $detected; |
| 49 |
} |
| 50 |
} |
| 51 |
|