| 1 |
<?php |
| 2 |
|
| 3 |
namespace Give\Revenue\Migrations; |
| 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 |
class CreateRevenueTable extends Migration |
| 11 |
{ |
| 12 |
/** |
| 13 |
* @inheritDoc |
| 14 |
* |
| 15 |
* @since 2.9.0 |
| 16 |
*/ |
| 17 |
public static function id() |
| 18 |
{ |
| 19 |
return 'create_revenue_table'; |
| 20 |
} |
| 21 |
|
| 22 |
/** |
| 23 |
* @inheritDoc |
| 24 |
* |
| 25 |
* @since 2.9.0 |
| 26 |
*/ |
| 27 |
public static function timestamp() |
| 28 |
{ |
| 29 |
return strtotime('2019-09-16'); |
| 30 |
} |
| 31 |
|
| 32 |
/** |
| 33 |
* @inheritDoc |
| 34 |
* |
| 35 |
* @since 2.9.0 |
| 36 |
* @since 2.9.2 throw an exception if there is a SQL error and add log |
| 37 |
* |
| 38 |
* @throws DatabaseMigrationException |
| 39 |
*/ |
| 40 |
public function run() |
| 41 |
{ |
| 42 |
global $wpdb; |
| 43 |
|
| 44 |
$charset_collate = $wpdb->get_charset_collate(); |
| 45 |
$tableName = "{$wpdb->prefix}give_revenue"; |
| 46 |
|
| 47 |
$sql = "CREATE TABLE {$tableName} ( |
| 48 |
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, |
| 49 |
donation_id bigint UNSIGNED NOT NULL, |
| 50 |
form_id bigint UNSIGNED NOT NULL, |
| 51 |
amount int UNSIGNED NOT NULL, |
| 52 |
PRIMARY KEY (id) |
| 53 |
) {$charset_collate};"; |
| 54 |
|
| 55 |
try { |
| 56 |
DB::delta($sql); |
| 57 |
} catch (DatabaseQueryException $exception) { |
| 58 |
throw new DatabaseMigrationException( |
| 59 |
'An error occurred creating the revenue table: ' . print_r($exception->getQueryErrors(), true) |
| 60 |
); |
| 61 |
} |
| 62 |
} |
| 63 |
} |
| 64 |
|