| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace Yatra\Hooks; |
| 6 |
|
| 7 |
use Yatra\Migration\MigrationProgress; |
| 8 |
use Yatra\Migration\ProMigrationReadiness; |
| 9 |
|
| 10 |
/** |
| 11 |
* WordPress admin notice when legacy Yatra 2.x / Pro 2.x data exists and migration is incomplete. |
| 12 |
* Intentionally not dismissible so upgrades are not missed; use Tools → Migration when done. |
| 13 |
*/ |
| 14 |
class MigrationAdminNoticeHooks |
| 15 |
{ |
| 16 |
public static function init(): void |
| 17 |
{ |
| 18 |
if (!is_admin()) { |
| 19 |
return; |
| 20 |
} |
| 21 |
|
| 22 |
add_action('admin_notices', [self::class, 'renderNotice'], 20); |
| 23 |
} |
| 24 |
|
| 25 |
public static function renderNotice(): void |
| 26 |
{ |
| 27 |
if (!current_user_can('manage_options')) { |
| 28 |
return; |
| 29 |
} |
| 30 |
|
| 31 |
if (!class_exists(MigrationProgress::class)) { |
| 32 |
return; |
| 33 |
} |
| 34 |
|
| 35 |
$migration = new MigrationProgress(); |
| 36 |
if (!$migration->legacyMigrationNeedsAttention()) { |
| 37 |
return; |
| 38 |
} |
| 39 |
|
| 40 |
$toolsUrl = admin_url('admin.php?page=yatra&subpage=tools&tools_tab=migration'); |
| 41 |
|
| 42 |
echo '<div class="notice notice-warning yatra-legacy-migration-notice"><p>'; |
| 43 |
echo '<strong>' . esc_html__('Yatra: Data migration required', 'yatra') . '</strong> — '; |
| 44 |
echo esc_html__( |
| 45 |
'Legacy Yatra 2.x or Yatra Pro 2.x data was detected. Open Tools → Migration to move trips, bookings, and settings into Yatra 3.x.', |
| 46 |
'yatra' |
| 47 |
); |
| 48 |
echo '</p>'; |
| 49 |
|
| 50 |
$pro = ProMigrationReadiness::getState(); |
| 51 |
if (!$pro['ready'] && $pro['warning_message'] !== '') { |
| 52 |
echo '<p><strong>' . esc_html__('Yatra Pro:', 'yatra') . '</strong> '; |
| 53 |
echo esc_html($pro['warning_message']); |
| 54 |
echo '</p>'; |
| 55 |
} |
| 56 |
|
| 57 |
echo '<p>'; |
| 58 |
printf( |
| 59 |
'<a class="button button-primary" href="%s">%s</a>', |
| 60 |
esc_url($toolsUrl), |
| 61 |
esc_html__('Open Tools → Migration', 'yatra') |
| 62 |
); |
| 63 |
echo '</p></div>'; |
| 64 |
} |
| 65 |
} |
| 66 |
|