updated plugin Easy Digital Downloads version 3.1.1.2

This commit is contained in:
2023-03-17 22:34:04 +00:00
committed by Gitium
parent e8a66564bd
commit 19e086d1c4
647 changed files with 20986 additions and 27305 deletions

View File

@ -0,0 +1,137 @@
<?php
/**
* Notifications Table.
*
* @package EDD
* @subpackage Database\Tables
* @copyright Copyright (c) 2023, Easy Digital Downloads, LLC
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 3.1.1
*/
namespace EDD\Database\Tables;
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
use EDD\Database\Table;
/**
* Setup the notifications database table.
*
* @since 3.1.1
*/
final class Notifications extends Table {
/**
* Table name.
*
* @access protected
* @since 3.1.1
* @var string
*/
protected $name = 'notifications';
/**
* Database version.
*
* @access protected
* @since 3.1.1
* @var int
*/
protected $version = 202302131;
/**
* Array of upgrade versions and methods
*
* @since 3.1.1
*
* @var array
*/
protected $upgrades = array(
'202301251' => 202301251,
'202302131' => 202302131,
);
/**
* Setup the database schema.
*
* @access protected
* @since 3.1.1
* @return void
*/
protected function set_schema() {
$this->schema = "id bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
remote_id varchar(20) DEFAULT NULL,
source varchar(20) NOT NULL DEFAULT 'api',
title text NOT NULL,
content longtext NOT NULL,
buttons longtext DEFAULT NULL,
type varchar(64) NOT NULL DEFAULT 'success',
conditions longtext DEFAULT NULL,
start datetime DEFAULT NULL,
end datetime DEFAULT NULL,
dismissed tinyint(1) UNSIGNED NOT NULL DEFAULT 0,
date_created datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
date_updated datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (id),
KEY dismissed_start_end (dismissed, start, end),
KEY remote_id (remote_id)";
}
/**
* Deletes the original database version option.
*
* @since 3.1.1
* @return bool
*/
protected function __202301251() {
return delete_option( "{$this->table_name}_db_version" );
}
/**
* Upgrade to version 202302131
* - Add the `source` text column and modify the remote_id column.
*
* @since 3.1.1
*
* @return boolean
*/
protected function __202302131() {
$updates = array(
'add-source' => false,
'remote-id' => false,
);
$columns = $this->get_db()->get_results( "SHOW FIELDS FROM {$this->table_name} WHERE Field = 'remote_id';" );
if ( false === $this->column_exists( 'source' ) ) {
$source = $this->get_db()->query(
"ALTER TABLE {$this->table_name} ADD COLUMN `source` varchar(20) NOT NULL DEFAULT 'api' AFTER `remote_id`;"
);
if ( $this->is_success( $source ) ) {
$updates['add-source'] = $this->get_db()->query( "UPDATE {$this->table_name} SET `source` = 'api'" );
}
} else {
$updates['add-source'] = true;
}
$remote_id_column = $this->get_db()->get_row( "SHOW FIELDS FROM {$this->table_name} WHERE Field = 'remote_id'" );
if ( 'varchar(20)' !== $remote_id_column->Type ) {
$updates['remote-id'] = $this->get_db()->query(
"ALTER TABLE {$this->table_name} MODIFY COLUMN `remote_id` varchar(20) DEFAULT NULL;"
);
} else {
$updates['remote-id'] = true;
}
foreach ( $updates as $query_key => $result ) {
if ( ! $this->is_success( $result ) ) {
return false;
}
}
return true;
}
}