PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.16.8
GiveWP – Donation Plugin and Fundraising Platform v4.16.8
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 / MigrationLog / Migrations / CreateMigrationsTable.php
CreateMigrationsTable.php
70 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\MigrationLog\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 /**
11 * Class CreateMigrationsTable
12 * @package Give\MigrationLog\Migrations
13 *
14 * @since 2.10.0
15 */
16 class CreateMigrationsTable extends Migration
17 {
18 /**
19 * @return string
20 */
21 public static function id()
22 {
23 return 'create_migrations_table';
24 }
25
26 /**
27 * @return string
28 */
29 public static function title()
30 {
31 return esc_html__('Create new give_migrations table', 'give');
32 }
33
34 /**
35 * @return int
36 */
37 public static function timestamp()
38 {
39 /**
40 * For this migration, we have to use the earliest possible date because we will be using
41 * the table created with this migration to store the status of the migration
42 */
43 return strtotime('1970-01-01 00:00');
44 }
45
46 /**
47 * @since 2.21.0 Add Check whether table installed before adding it to database.
48 * @throws DatabaseMigrationException
49 */
50 public function run()
51 {
52 $table = DB::prefix('give_migrations');
53 $charset = DB::get_charset_collate();
54
55 $sql = "CREATE TABLE IF NOT EXISTS {$table} (
56 id VARCHAR(180) NOT NULL,
57 status VARCHAR(16) NOT NULL,
58 error text NULL,
59 last_run DATETIME NOT NULL,
60 PRIMARY KEY (id)
61 ) {$charset}";
62
63 try {
64 DB::delta($sql);
65 } catch (DatabaseQueryException $exception) {
66 throw new DatabaseMigrationException("An error occurred while creating the {$table} table", 0, $exception);
67 }
68 }
69 }
70