| 1 |
<?php |
| 2 |
|
| 3 |
namespace Give\Campaigns\Migrations\RevenueTable; |
| 4 |
|
| 5 |
use Give\Framework\Database\DB; |
| 6 |
use Give\Framework\Database\Exceptions\DatabaseQueryException; |
| 7 |
use Give\Framework\Migrations\Contracts\Migration; |
| 8 |
use Give\Framework\Migrations\Exceptions\DatabaseMigrationException; |
| 9 |
|
| 10 |
/** |
| 11 |
* @since 4.0.0 |
| 12 |
*/ |
| 13 |
class AddIndexes extends Migration |
| 14 |
{ |
| 15 |
/** |
| 16 |
* @inheritDoc |
| 17 |
*/ |
| 18 |
public static function id(): string |
| 19 |
{ |
| 20 |
return 'add_indexes_to_revenue_table'; |
| 21 |
} |
| 22 |
|
| 23 |
/** |
| 24 |
* @inheritDoc |
| 25 |
*/ |
| 26 |
public static function title(): string |
| 27 |
{ |
| 28 |
return 'Add indexes to revenue table'; |
| 29 |
} |
| 30 |
|
| 31 |
/** |
| 32 |
* @inheritdoc |
| 33 |
*/ |
| 34 |
public static function timestamp(): string |
| 35 |
{ |
| 36 |
return strtotime('2024-10-14 00:00:02'); |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* @inheritDoc |
| 41 |
* @throws DatabaseMigrationException |
| 42 |
*/ |
| 43 |
public function run() |
| 44 |
{ |
| 45 |
global $wpdb; |
| 46 |
|
| 47 |
try { |
| 48 |
DB::query("ALTER TABLE {$wpdb->give_revenue} ADD INDEX (form_id), ADD INDEX (campaign_id)"); |
| 49 |
} catch (DatabaseQueryException $exception) { |
| 50 |
throw new DatabaseMigrationException("An error occurred while updating the {$wpdb->give_revenue} table", 0, |
| 51 |
$exception); |
| 52 |
} |
| 53 |
} |
| 54 |
} |
| 55 |
|