| 1 |
<?php |
| 2 |
|
| 3 |
namespace Texty; |
| 4 |
|
| 5 |
use Texty\Models\SmsStat; |
| 6 |
use Texty\Models\SmsStatStore; |
| 7 |
use Texty\Dependencies\WeDevs\WPKit\DataLayer\DataLayerFactory; |
| 8 |
|
| 9 |
/** |
| 10 |
* Installer Class |
| 11 |
*/ |
| 12 |
class Install { |
| 13 |
|
| 14 |
/** |
| 15 |
* Run the isntaller |
| 16 |
*/ |
| 17 |
public function run() { |
| 18 |
$this->create_tables(); |
| 19 |
$installed = get_option( 'texty_installed' ); |
| 20 |
|
| 21 |
if ( ! $installed ) { |
| 22 |
update_option( 'texty_installed', time() ); |
| 23 |
} |
| 24 |
|
| 25 |
update_option( 'texty_version', TEXTY_VERSION ); |
| 26 |
|
| 27 |
// Seed the schema version so the migration runner skips migrations |
| 28 |
// whose changes are already baked into create_tables() above. The |
| 29 |
// upgrade path on existing installs (where this option is missing or |
| 30 |
// older) is handled by Texty\Migrations on plugins_loaded. |
| 31 |
if ( ! get_option( 'texty_db_version' ) ) { |
| 32 |
update_option( 'texty_db_version', TEXTY_VERSION ); |
| 33 |
} |
| 34 |
} |
| 35 |
|
| 36 |
/** |
| 37 |
* Create database tables |
| 38 |
* |
| 39 |
* @return void |
| 40 |
*/ |
| 41 |
public function create_tables() { |
| 42 |
global $wpdb; |
| 43 |
|
| 44 |
require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
| 45 |
|
| 46 |
$charset_collate = $wpdb->get_charset_collate(); |
| 47 |
$table_name = $wpdb->prefix . 'texty_sms_stat'; |
| 48 |
|
| 49 |
$sql = "CREATE TABLE IF NOT EXISTS {$table_name} ( |
| 50 |
id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, |
| 51 |
receiver VARCHAR(20) NOT NULL, |
| 52 |
gateway VARCHAR(50) NOT NULL, |
| 53 |
status VARCHAR(20) DEFAULT NULL, |
| 54 |
notification_id VARCHAR(64) DEFAULT NULL, |
| 55 |
notification_group VARCHAR(32) DEFAULT NULL, |
| 56 |
message TEXT NULL, |
| 57 |
response LONGTEXT NULL, |
| 58 |
created_at DATETIME NOT NULL, |
| 59 |
updated_at DATETIME NOT NULL, |
| 60 |
reference_id VARCHAR(100) DEFAULT NULL, |
| 61 |
KEY created_at_idx (created_at), |
| 62 |
KEY notification_id_idx (notification_id), |
| 63 |
KEY status_idx (status) |
| 64 |
) {$charset_collate};"; |
| 65 |
|
| 66 |
dbDelta( $sql ); |
| 67 |
} |
| 68 |
} |
| 69 |
|