| 1 |
<?php |
| 2 |
|
| 3 |
namespace Give\Log\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 CreateNewLogTables |
| 12 |
* @package Give\Log\Migrations |
| 13 |
* |
| 14 |
* @since 2.10.0 |
| 15 |
*/ |
| 16 |
class CreateNewLogTable extends Migration |
| 17 |
{ |
| 18 |
/** |
| 19 |
* @return string |
| 20 |
*/ |
| 21 |
public static function id() |
| 22 |
{ |
| 23 |
return 'create_new_log_table'; |
| 24 |
} |
| 25 |
|
| 26 |
/** |
| 27 |
* @return string |
| 28 |
*/ |
| 29 |
public static function title() |
| 30 |
{ |
| 31 |
return esc_html__('Create new give_log table', 'give'); |
| 32 |
} |
| 33 |
|
| 34 |
/** |
| 35 |
* @return int |
| 36 |
*/ |
| 37 |
public static function timestamp() |
| 38 |
{ |
| 39 |
return strtotime('2021-01-28 12:00'); |
| 40 |
} |
| 41 |
|
| 42 |
public function run() |
| 43 |
{ |
| 44 |
global $wpdb; |
| 45 |
|
| 46 |
$table = "{$wpdb->prefix}give_log"; |
| 47 |
$charset = DB::get_charset_collate(); |
| 48 |
|
| 49 |
$sql = "CREATE TABLE {$table} ( |
| 50 |
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, |
| 51 |
log_type VARCHAR(16) NOT NULL, |
| 52 |
data text NOT NULL, |
| 53 |
category VARCHAR(64) NOT NULL, |
| 54 |
source VARCHAR(64) NOT NULL, |
| 55 |
date DATETIME NOT NULL, |
| 56 |
PRIMARY KEY (id), |
| 57 |
KEY log_type (log_type), |
| 58 |
KEY category (category), |
| 59 |
KEY source (source) |
| 60 |
) {$charset}"; |
| 61 |
|
| 62 |
try { |
| 63 |
DB::delta($sql); |
| 64 |
} catch (DatabaseQueryException $exception) { |
| 65 |
throw new DatabaseMigrationException('An error occurred while creating the give_log table', 0, $exception); |
| 66 |
} |
| 67 |
} |
| 68 |
} |
| 69 |
|