| 1 |
<?php |
| 2 |
|
| 3 |
namespace Yoast\WP\SEO\Config\Migrations; |
| 4 |
|
| 5 |
use Yoast\WP\Lib\Migrations\Migration; |
| 6 |
use Yoast\WP\Lib\Model; |
| 7 |
|
| 8 |
/** |
| 9 |
* Class DeleteDuplicateIndexables. |
| 10 |
*/ |
| 11 |
class DeleteDuplicateIndexables extends Migration { |
| 12 |
|
| 13 |
/** |
| 14 |
* The plugin this migration belongs to. |
| 15 |
* |
| 16 |
* @var string |
| 17 |
*/ |
| 18 |
public static $plugin = 'free'; |
| 19 |
|
| 20 |
/** |
| 21 |
* Migration up. |
| 22 |
* |
| 23 |
* @return void |
| 24 |
*/ |
| 25 |
public function up() { |
| 26 |
$table_name = $this->get_table_name(); |
| 27 |
|
| 28 |
/* |
| 29 |
* Deletes duplicate indexables that have the same object_id and object_type. |
| 30 |
* The rows with a higher ID are deleted as those should be unused and could be outdated. |
| 31 |
*/ |
| 32 |
$this->query( 'DELETE wyi FROM ' . $table_name . ' wyi INNER JOIN ' . $table_name . ' wyi2 WHERE wyi2.object_id = wyi.object_id AND wyi2.object_type = wyi.object_type AND wyi2.id < wyi.id;' ); |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* Migration down. |
| 37 |
* |
| 38 |
* @return void |
| 39 |
*/ |
| 40 |
public function down() { |
| 41 |
// Nothing to do. |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* Retrieves the table name to use. |
| 46 |
* |
| 47 |
* @return string The table name to use. |
| 48 |
*/ |
| 49 |
protected function get_table_name() { |
| 50 |
return Model::get_table_name( 'Indexable' ); |
| 51 |
} |
| 52 |
} |
| 53 |
|