| 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 |
use Yoast\WP\SEO\WordPress\Wrapper; |
| 8 |
|
| 9 |
/** |
| 10 |
* Class AddHasAncestorsColumn. |
| 11 |
*/ |
| 12 |
class AddHasAncestorsColumn extends Migration { |
| 13 |
|
| 14 |
/** |
| 15 |
* The plugin this migration belongs to. |
| 16 |
* |
| 17 |
* @var string |
| 18 |
*/ |
| 19 |
public static $plugin = 'free'; |
| 20 |
|
| 21 |
/** |
| 22 |
* Migration up. |
| 23 |
*/ |
| 24 |
public function up() { |
| 25 |
$this->add_column( |
| 26 |
Model::get_table_name( 'Indexable' ), |
| 27 |
'has_ancestors', |
| 28 |
'boolean', |
| 29 |
[ |
| 30 |
'default' => false, |
| 31 |
] |
| 32 |
); |
| 33 |
|
| 34 |
Wrapper::get_wpdb()->query( |
| 35 |
' |
| 36 |
UPDATE ' . Model::get_table_name( 'Indexable' ) . ' |
| 37 |
SET has_ancestors = 1 |
| 38 |
WHERE id IN ( SELECT indexable_id FROM ' . Model::get_table_name( 'Indexable_Hierarchy' ) . ' ) |
| 39 |
' |
| 40 |
); |
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* Migration down. |
| 45 |
*/ |
| 46 |
public function down() { |
| 47 |
$this->remove_column( Model::get_table_name( 'Indexable' ), 'has_ancestors' ); |
| 48 |
} |
| 49 |
} |
| 50 |
|