Activator.php
2 months ago
Assets.php
1 month ago
Blocks.php
10 months ago
Database.php
8 months ago
Encrypt.php
7 months ago
Database.php
39 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Hostinger\Reach\Setup; |
| 4 | |
| 5 | use Hostinger\Reach\Admin\Database\DatabaseTable; |
| 6 | |
| 7 | if ( ! defined( 'ABSPATH' ) ) { |
| 8 | die; |
| 9 | } |
| 10 | |
| 11 | class Database { |
| 12 | |
| 13 | /** @var DatabaseTable[] */ |
| 14 | private array $tables; |
| 15 | |
| 16 | public function __construct( array $tables ) { |
| 17 | $this->tables = $tables; |
| 18 | } |
| 19 | |
| 20 | public function init(): void { |
| 21 | $db_version_option = HOSTINGER_REACH_PLUGIN_SLUG . '-db-version'; |
| 22 | $database_version = get_option( |
| 23 | $db_version_option, |
| 24 | '' |
| 25 | ); |
| 26 | |
| 27 | if ( $database_version !== HOSTINGER_REACH_DB_VERSION ) { |
| 28 | $this->create_tables(); |
| 29 | update_option( $db_version_option, HOSTINGER_REACH_DB_VERSION, false ); |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | private function create_tables(): void { |
| 34 | foreach ( $this->tables as $table ) { |
| 35 | $table->create(); |
| 36 | } |
| 37 | } |
| 38 | } |
| 39 |