Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions inc/apis/schemas/domain-create.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
// Exit if accessed directly
defined('ABSPATH') || exit;

use WP_Ultimo\Database\Domains\Domain_Stage;

/**
* Schema for domain@create.
*
Expand Down Expand Up @@ -49,11 +51,12 @@
'type' => 'string',
'required' => true,
'enum' => [
'checking-dns',
'checking-ssl-cert',
'done-without-ssl',
'done',
'failed',
Domain_Stage::CHECKING_DNS,
Domain_Stage::CHECKING_SSL,
Domain_Stage::DONE_WITHOUT_SSL,
Domain_Stage::DONE,
Domain_Stage::FAILED,
Domain_Stage::SSL_FAILED,
],
],
'date_created' => [
Expand Down
13 changes: 8 additions & 5 deletions inc/apis/schemas/domain-update.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
// Exit if accessed directly
defined('ABSPATH') || exit;

use WP_Ultimo\Database\Domains\Domain_Stage;

/**
* Schema for domain@update.
*
Expand Down Expand Up @@ -49,11 +51,12 @@
'type' => 'string',
'required' => false,
'enum' => [
'checking-dns',
'checking-ssl-cert',
'done-without-ssl',
'done',
'failed',
Domain_Stage::CHECKING_DNS,
Domain_Stage::CHECKING_SSL,
Domain_Stage::DONE_WITHOUT_SSL,
Domain_Stage::DONE,
Domain_Stage::FAILED,
Domain_Stage::SSL_FAILED,
],
],
'date_created' => [
Expand Down
8 changes: 5 additions & 3 deletions inc/class-faker.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use Exception;
use Faker as Lib_Faker;
use WP_Ultimo\Database\Domains\Domain_Stage;
use WP_Ultimo\Models\Membership;
use WP_Ultimo\Models\Product;

Expand Down Expand Up @@ -184,6 +185,7 @@ private function get_random_data($model) {
return false;
}
}
return false;
}

/**
Expand Down Expand Up @@ -481,9 +483,9 @@ public function generate_fake_domain($number = 1): void {

$faker = $this->get_faker();
$stage_options = [
'checking-dns',
'checking-ssl-cert',
'done',
Domain_Stage::CHECKING_DNS,
Domain_Stage::CHECKING_SSL,
Domain_Stage::DONE,
];

$stage_checking_dns = $stage_options[0];
Expand Down
4 changes: 4 additions & 0 deletions inc/database/domains/class-domain-stage.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class Domain_Stage extends Enum {

const FAILED = 'failed';

const SSL_FAILED = 'ssl-failed';

const CHECKING_DNS = 'checking-dns';

const CHECKING_SSL = 'checking-ssl-cert';
Expand All @@ -46,6 +48,7 @@ protected function classes() {

return [
static::FAILED => 'wu-bg-red-200 wu-text-red-700',
static::SSL_FAILED => 'wu-bg-red-200 wu-text-red-700',
static::CHECKING_DNS => 'wu-bg-blue-200 wu-text-blue-700',
static::CHECKING_SSL => 'wu-bg-yellow-200 wu-text-yellow-700',
static::DONE => 'wu-bg-green-200 wu-text-green-700',
Expand All @@ -63,6 +66,7 @@ protected function labels() {

return [
static::FAILED => __('DNS Failed', 'ultimate-multisite'),
static::SSL_FAILED => __('SSL Failed', 'ultimate-multisite'),
static::CHECKING_DNS => __('Checking DNS', 'ultimate-multisite'),
static::CHECKING_SSL => __('Checking SSL', 'ultimate-multisite'),
static::DONE => __('Ready', 'ultimate-multisite'),
Expand Down
2 changes: 1 addition & 1 deletion inc/database/domains/class-domains-schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class Domains_Schema extends Schema {

[
'name' => 'stage',
'type' => 'enum(\'checking-dns\', \'checking-ssl-cert\', \'done-without-ssl\', \'done\', \'failed\')',
'type' => 'enum(\'' . Domain_Stage::CHECKING_DNS . '\', \'' . Domain_Stage::CHECKING_SSL . '\', \'' . Domain_Stage::DONE_WITHOUT_SSL . '\', \'' . Domain_Stage::DONE . '\', \'' . Domain_Stage::FAILED . '\', \'' . Domain_Stage::SSL_FAILED . '\')',
'default' => 'checking-dns',
'transition' => true,
'sortable' => true,
Expand Down
39 changes: 29 additions & 10 deletions inc/database/domains/class-domains-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,18 @@ final class Domains_Table extends Table {
* @since 2.0.0
* @var string
*/
protected $version = '2.0.1-revision.20230601';
protected $version = '2.0.1-revision.20260109';

/**
* List of table upgrades.
*
* @var array
* Use real callbacks.
*/
protected $upgrades = [
'2.0.1-revision.20230601' => 20_230_601,
];

public function __construct() {
$this->upgrades = [
'2.0.1-revision.20230601' => [$this, 'allow_nulls'],
'2.0.1-revision.20260109' => [$this, 'update_enum'],
];
parent::__construct();
}

/**
* Set up the database schema
Expand All @@ -70,7 +71,7 @@ protected function set_schema(): void {
active tinyint(4) default 1,
primary_domain tinyint(4) default 0,
secure tinyint(4) default 0,
stage enum('checking-dns', 'checking-ssl-cert', 'done', 'failed', 'done-without-ssl') DEFAULT 'checking-dns',
stage enum('" . Domain_Stage::CHECKING_DNS . "', '" . Domain_Stage::CHECKING_SSL . "', '" . Domain_Stage::DONE_WITHOUT_SSL . "', '" . Domain_Stage::DONE . "', '" . Domain_Stage::FAILED . "', '" . Domain_Stage::SSL_FAILED . "') DEFAULT '" . Domain_Stage::CHECKING_DNS . "',
date_created datetime NULL,
date_modified datetime NULL,
PRIMARY KEY (id),
Expand All @@ -83,7 +84,7 @@ protected function set_schema(): void {
*
* @since 2.1.2
*/
protected function __20230601(): bool { // phpcs:ignore PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames.MethodDoubleUnderscore
protected function allow_nulls(): bool {

$null_columns = [
'date_created',
Expand All @@ -102,4 +103,22 @@ protected function __20230601(): bool { // phpcs:ignore PHPCompatibility.Functio

return true;
}

/**
* Adds the ssl-failed stage
*
* @since 2.4.10
*/
protected function update_enum(): bool { // phpcs:ignore PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames.MethodDoubleUnderscore

$query = "ALTER TABLE {$this->table_name} MODIFY COLUMN `stage` enum('" . Domain_Stage::CHECKING_DNS . "', '" . Domain_Stage::CHECKING_SSL . "', '" . Domain_Stage::DONE_WITHOUT_SSL . "', '" . Domain_Stage::DONE . "', '" . Domain_Stage::FAILED . "', '" . Domain_Stage::SSL_FAILED . "') DEFAULT '" . Domain_Stage::CHECKING_DNS . "';";

$result = $this->get_db()->query($query);

if ( ! $this->is_success($result)) {
return false;
}

return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace WP_Ultimo\Integrations\Host_Providers;

use Psr\Log\LogLevel;
use WP_Ultimo\Database\Domains\Domain_Stage;
use WP_Ultimo\Integrations\Host_Providers\Base_Host_Provider;

// Exit if accessed directly
Expand Down Expand Up @@ -99,7 +100,7 @@ public function ssl_tries($max_tries, $domain) {
return $max_tries;
}

if ('checking-ssl-cert' === $domain->get_stage()) {
if (Domain_Stage::CHECKING_SSL === $domain->get_stage()) {
$max_tries = 10;
}

Expand Down
16 changes: 9 additions & 7 deletions inc/managers/class-domain-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
namespace WP_Ultimo\Managers;

use Psr\Log\LogLevel;
use WP_Ultimo\Database\Domains\Domain_Stage;
use WP_Ultimo\Domain_Mapping\Helper;
use WP_Ultimo\Models\Domain;

Expand Down Expand Up @@ -664,9 +665,9 @@ public function async_process_domain_stage($domain_id, $tries = 0): void {
// translators: %s is the domain name
wu_log_add("domain-{$domain_url}", sprintf(__('Starting Check for %s', 'ultimate-multisite'), $domain_url));

if ('checking-dns' === $stage) {
if (Domain_Stage::CHECKING_DNS === $stage) {
if ($domain->has_correct_dns()) {
$domain->set_stage('checking-ssl-cert');
$domain->set_stage(Domain_Stage::CHECKING_SSL);

$domain->save();

Expand All @@ -692,7 +693,7 @@ public function async_process_domain_stage($domain_id, $tries = 0): void {
* Max attempts
*/
if ($tries > $max_tries) {
$domain->set_stage('failed');
$domain->set_stage(Domain_Stage::FAILED);

$domain->save();

Expand Down Expand Up @@ -723,9 +724,9 @@ public function async_process_domain_stage($domain_id, $tries = 0): void {

return;
}
} elseif ('checking-ssl-cert' === $stage) {
} elseif (Domain_Stage::CHECKING_SSL === $stage) {
if ($domain->has_valid_ssl_certificate()) {
$domain->set_stage('done');
$domain->set_stage(Domain_Stage::DONE);

$domain->set_secure(true);

Expand All @@ -742,10 +743,11 @@ public function async_process_domain_stage($domain_id, $tries = 0): void {
* Max attempts
*/
if ($tries > $max_tries) {
$domain->set_stage('done-without-ssl');
// We use SSL FAILED instead of done-without-ssl since ssl is pretty much required
// and we don't want to redirect to a domain with certificate errors.
$domain->set_stage(Domain_Stage::SSL_FAILED);

$domain->save();

wu_log_add(
"domain-{$domain_url}",
// translators: %d is the number of minutes to try again.
Expand Down
11 changes: 6 additions & 5 deletions inc/models/class-domain.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class Domain extends Base_Model {
* @since 2.0.0
* @var string
*/
protected $stage = 'checking-dns';
protected $stage = Domain_Stage::CHECKING_DNS;

/**
* Date when this was created.
Expand All @@ -90,9 +90,10 @@ class Domain extends Base_Model {
* @var array
*/
const INACTIVE_STAGES = [
'checking-dns',
'checking-ssl-cert',
'failed',
Domain_Stage::CHECKING_DNS,
Domain_Stage::CHECKING_SSL,
Domain_Stage::FAILED,
Domain_Stage::SSL_FAILED,
];

/**
Expand Down Expand Up @@ -127,7 +128,7 @@ public function validation_rules() {
return [
'blog_id' => 'required|integer',
'domain' => "required|domain|unique:\WP_Ultimo\Models\Domain,domain,{$id}",
'stage' => 'required|in:checking-dns,checking-ssl-cert,done-without-ssl,done,failed|default:checking-dns',
'stage' => 'required|in:checking-dns,checking-ssl-cert,done-without-ssl,done,failed,ssl-failed|default:checking-dns',
'active' => 'default:1',
'secure' => 'default:0',
'primary_domain' => 'default:0',
Expand Down
Loading