PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 2.13.1
GiveWP – Donation Plugin and Fundraising Platform v2.13.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 2.31.0 2.31.1 All 253 releases
give / src / Revenue / Migrations / CreateRevenueTable.php
CreateRevenueTable.php
59 lines 1.3 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\Exceptions\DatabaseQueryException;
6 use Give\Framework\Migrations\Contracts\Migration;
7 use Give\Framework\Migrations\Exceptions\DatabaseMigrationException;
8 use Give\Framework\Database\DB;
9 use Give\Helpers\Table;
10
11 class CreateRevenueTable extends Migration {
12 /**
13 * @inheritDoc
14 *
15 * @since 2.9.0
16 */
17 public static function id() {
18 return 'create_revenue_table';
19 }
20
21 /**
22 * @inheritDoc
23 *
24 * @since 2.9.0
25 */
26 public static function timestamp() {
27 return strtotime( '2019-09-16' );
28 }
29
30 /**
31 * @inheritDoc
32 *
33 * @since 2.9.0
34 * @since 2.9.2 throw an exception if there is a SQL error and add log
35 *
36 * @throws DatabaseMigrationException
37 */
38 public function run() {
39 global $wpdb;
40
41 $charset_collate = $wpdb->get_charset_collate();
42 $tableName = "{$wpdb->prefix}give_revenue";
43
44 $sql = "CREATE TABLE {$tableName} (
45 id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
46 donation_id bigint UNSIGNED NOT NULL,
47 form_id bigint UNSIGNED NOT NULL,
48 amount int UNSIGNED NOT NULL,
49 PRIMARY KEY (id)
50 ) {$charset_collate};";
51
52 try {
53 DB::delta( $sql );
54 } catch ( DatabaseQueryException $exception ) {
55 throw new DatabaseMigrationException( 'An error occurred creating the revenue table: ' . print_r( $exception->getQueryErrors(), true ) );
56 }
57 }
58 }
59