Skip to content

Commit

Permalink
Table: when uninstalling, delete version info if not exists. (#109)
Browse files Browse the repository at this point in the history
This change ensures that the Table version info (currently saved in wp_options) is always deleted if drop() fails because the tables already do not exist.

Fixes #108. Props @Mai-Saad.
  • Loading branch information
JJJ authored May 28, 2021
1 parent 3e34bcb commit 0d168fb
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions table.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,11 +285,15 @@ public function get_version() {
}

/**
* Install a database table by creating the table and setting the version.
* Install a database table
*
* Creates the table and sets the version information if successful.
*
* @since 1.0.0
*/
public function install() {

// Try to create the table
$created = $this->create();

// Set the DB version if create was successful
Expand All @@ -299,15 +303,20 @@ public function install() {
}

/**
* Destroy a database table by dropping the table and deleting the version.
* Uninstall a database table
*
* Drops the table and deletes the version information if successful and/or
* the table does not exist anymore.
*
* @since 1.0.0
*/
public function uninstall() {

// Try to drop the table
$dropped = $this->drop();

// Delete the DB version if drop was successful
if ( true === $dropped ) {
// Delete the DB version if drop was successful or table does not exist
if ( ( true === $dropped ) || ! $this->exists() ) {
$this->delete_db_version();
}
}
Expand Down

0 comments on commit 0d168fb

Please sign in to comment.