Skip to content

Commit

Permalink
create table if not exists when set account id
Browse files Browse the repository at this point in the history
  • Loading branch information
davodsaraei committed Nov 27, 2020
1 parent 6d947e1 commit 1fa344d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
12 changes: 12 additions & 0 deletions classes/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@

require_once 'Woocommerce.php';
require_once 'ListTable.php';
require_once 'Installer.php';


use AffiliIR\Woocommerce as AffiliIR_Woocommerce;
use AffiliIR\ListTable as AffiliIR_ListTable;
use AffiliIR\Installer as AffiliIR_Installer;

class Action
{
Expand Down Expand Up @@ -81,6 +83,8 @@ public function setAccountId()
$condition = isset($_POST['affili_set_account_id']) && $nonce;

if($condition) {
$this->createTableIfNotExists();

$account_id = sanitize_text_field($_POST['account_id']);
$data = [
'name' => 'account_id',
Expand Down Expand Up @@ -338,4 +342,12 @@ public function findCategoryAjax()
echo json_encode( $return );
wp_die();
}

private function createTableIfNotExists()
{
$sql = AffiliIR_Installer::sqlString();
$table_name = $this->wpdb->prefix.AffiliIR_Installer::$table;

maybe_create_table($table_name, $sql);
}
}
21 changes: 14 additions & 7 deletions classes/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@ public static function activation()
return;
}

$sql = self::sqlString();

dbDelta($sql);
update_option(self::$table.'_db_version', $db_version);
}

public static function deactivation()
{
//
}

public static function sqlString()
{
global $wpdb;

$table_name = $wpdb->prefix.self::$table;
Expand All @@ -32,12 +45,6 @@ public static function activation()
) {$charset_collate};"
;

dbDelta($sql);
update_option(self::$table.'_db_version', $db_version);
}

public static function deactivation()
{
//
return $sql;
}
}

0 comments on commit 1fa344d

Please sign in to comment.