PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.16.9
GiveWP – Donation Plugin and Fundraising Platform v4.16.9
4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 All 255 releases
give / src / Revenue / Migrations / CreateRevenueTable.php

CreateRevenueTable.php in GiveWP – Donation Plugin and Fundraising Platform 4.16.9, at src/Revenue/Migrations/CreateRevenueTable.php

64 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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