Skip to content

Commit

Permalink
Merge pull request #36 from pressidium/next
Browse files Browse the repository at this point in the history
1.2.1
  • Loading branch information
over-engineer authored Nov 6, 2023
2 parents be679e5 + 6a053c9 commit 0809cf2
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
28 changes: 27 additions & 1 deletion includes/Database/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,25 @@ public function get_table_slug(): string {
return $this->sanitize_table_name( $this->get_table_name() );
}

/**
* Check if a table exists in the database.
*
* @param string $table_name The name of the table to check.
*
* @return bool `true` if the table exists, `false` if it doesn't.
*/
private function exists( string $table_name ): bool {
global $wpdb;

// Use `$wpdb->get_var()` to execute a SQL query to check for the table's existence
$result = $wpdb->get_var(
$wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $table_name ) )
);

// If the result matches the provided table name, the table exists; otherwise, it doesn't
return $result === $table_name;
}

/**
* Insert a row into the table.
*
Expand Down Expand Up @@ -268,8 +287,15 @@ public function create(): void {
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
}

$table_name = $this->prefix . $this->get_table_slug();

if ( $this->exists( $table_name ) ) {
// Table already exists, do nothing
return;
}

$schema = Schema::create(
$this->prefix . $this->get_table_slug(),
$table_name,
$this->charset_collate,
function( Blueprint $table ) {
$this->get_table_schema( $table );
Expand Down
4 changes: 2 additions & 2 deletions pressidium-cookie-consent.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Pressidium Cookie Consent
* Plugin URI: https://github.com/pressidium/pressidium-cookie-consent/
* Description: Lightweight, user-friendly and customizable cookie consent banner to help you comply with the EU GDPR cookie law and CCPA regulations.
* Version: 1.2.0
* Version: 1.2.1
* Author: Pressidium
* Author URI: https://pressidium.com/
* Text Domain: pressidium-cookie-consent
Expand All @@ -27,7 +27,7 @@
*/
function setup_constants(): void {
if ( ! defined( 'Pressidium\WP\CookieConsent\VERSION' ) ) {
define( 'Pressidium\WP\CookieConsent\VERSION', '1.2.0' );
define( 'Pressidium\WP\CookieConsent\VERSION', '1.2.1' );
}

if ( ! defined( 'Pressidium\WP\CookieConsent\PLUGIN_DIR' ) ) {
Expand Down
6 changes: 5 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Tags: cookie, consent, gdpr, ccpa, cookies
Requires at least: 6.0
Tested up to: 6.3
Requires PHP: 7.4
Stable Tag: 1.2.0
Stable Tag: 1.2.1
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -150,6 +150,10 @@ If you have spotted any bugs, or would like to request additional features from

== Changelog ==

= 1.2.1: Nov 6, 2023 =

* Check if the table already exists in the database before attempting to create it

= 1.2.0: Oct 2, 2023 =

* Add a new Consent Records tab to the settings page to be able to provide proof of consent for auditing purposes
Expand Down

0 comments on commit 0809cf2

Please sign in to comment.