Use new code style
This commit is contained in:
@ -36,8 +36,7 @@ class Base_Installer {
|
||||
public function get_steps() {
|
||||
|
||||
return array();
|
||||
|
||||
} // end get_steps;
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs through all the steps to see if they are all done or not.
|
||||
@ -51,18 +50,13 @@ class Base_Installer {
|
||||
$all_done = true;
|
||||
|
||||
foreach ($this->get_steps() as $step) {
|
||||
|
||||
if ($step['done'] === false) {
|
||||
|
||||
$all_done = false;
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end foreach;
|
||||
}
|
||||
}
|
||||
|
||||
return $all_done;
|
||||
|
||||
} // end all_done;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the installer.
|
||||
@ -88,30 +82,22 @@ class Base_Installer {
|
||||
/*
|
||||
* No installer on this class.
|
||||
*/
|
||||
if (!is_callable($callable)) {
|
||||
|
||||
if ( ! is_callable($callable)) {
|
||||
return $status;
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
$wpdb->query('START TRANSACTION');
|
||||
|
||||
call_user_func($callable);
|
||||
|
||||
} catch (\Throwable $e) {
|
||||
|
||||
$wpdb->query('ROLLBACK');
|
||||
|
||||
return new \WP_Error($installer, $e->getMessage());
|
||||
|
||||
} // end try;
|
||||
}
|
||||
|
||||
$wpdb->query('COMMIT');
|
||||
|
||||
return $status;
|
||||
|
||||
} // end handle;
|
||||
|
||||
} // end class Base_Installer;
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@
|
||||
|
||||
namespace WP_Ultimo\Installers;
|
||||
|
||||
use \WP_Ultimo\Integrations\Host_Providers\Closte_Host_Provider;
|
||||
use WP_Ultimo\Integrations\Host_Providers\Closte_Host_Provider;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
@ -31,30 +31,28 @@ class Core_Installer extends Base_Installer {
|
||||
*/
|
||||
public function init() {
|
||||
|
||||
add_filter('wu_core_installer_install_sunrise', function() {
|
||||
add_filter(
|
||||
'wu_core_installer_install_sunrise',
|
||||
function () {
|
||||
|
||||
$is_closte = defined('CLOSTE_CLIENT_API_KEY') && CLOSTE_CLIENT_API_KEY;
|
||||
$is_closte = defined('CLOSTE_CLIENT_API_KEY') && CLOSTE_CLIENT_API_KEY;
|
||||
|
||||
if ($is_closte) {
|
||||
if ($is_closte) {
|
||||
if ( ! (defined('SUNRISE') && SUNRISE)) {
|
||||
|
||||
if (!(defined('SUNRISE') && SUNRISE)) {
|
||||
// translators: %s is a URL to a documentation link.
|
||||
$closte_message = sprintf(__('You are using Closte and they prevent the wp-config.php file from being written to. <a href="%s" target="_blank">Follow these instructions to do it manually</a>.', 'wp-ultimo'), wu_get_documentation_url('wp-ultimo-closte-config'));
|
||||
|
||||
// translators: %s is a URL to a documentation link.
|
||||
$closte_message = sprintf(__('You are using Closte and they prevent the wp-config.php file from being written to. <a href="%s" target="_blank">Follow these instructions to do it manually</a>.', 'wp-ultimo' ), wu_get_documentation_url('wp-ultimo-closte-config'));
|
||||
throw new \Exception($closte_message);
|
||||
}
|
||||
|
||||
throw new \Exception($closte_message);
|
||||
return true;
|
||||
}
|
||||
|
||||
} // end if;
|
||||
|
||||
return true;
|
||||
|
||||
} // end if;
|
||||
|
||||
return false;
|
||||
|
||||
});
|
||||
|
||||
} // end init;
|
||||
return false;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of migration steps.
|
||||
@ -89,8 +87,7 @@ class Core_Installer extends Base_Installer {
|
||||
);
|
||||
|
||||
return $steps;
|
||||
|
||||
} // end get_steps;
|
||||
}
|
||||
|
||||
/**
|
||||
* Installs our custom database tables.
|
||||
@ -112,10 +109,8 @@ class Core_Installer extends Base_Installer {
|
||||
);
|
||||
|
||||
if (in_array($table_name, $exclude_list, true)) {
|
||||
|
||||
continue;
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
$success = $table->install();
|
||||
|
||||
@ -125,12 +120,9 @@ class Core_Installer extends Base_Installer {
|
||||
$error_message = sprintf(__('Installation of the table %s failed', 'wp-ultimo'), $table->get_name());
|
||||
|
||||
throw new \Exception($error_message);
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end foreach;
|
||||
|
||||
} // end _install_database_tables;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies the sunrise.php file and adds the SUNRISE constant.
|
||||
@ -144,10 +136,8 @@ class Core_Installer extends Base_Installer {
|
||||
$copy = \WP_Ultimo\Sunrise::try_upgrade();
|
||||
|
||||
if (is_wp_error($copy)) {
|
||||
|
||||
throw new \Exception($copy->get_error_message());
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow host providers to install the constant differently.
|
||||
@ -160,19 +150,13 @@ class Core_Installer extends Base_Installer {
|
||||
$short_circuit = apply_filters('wu_core_installer_install_sunrise', false);
|
||||
|
||||
if ($short_circuit) {
|
||||
|
||||
return;
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
$success = \WP_Ultimo\Helpers\WP_Config::get_instance()->inject_wp_config_constant('SUNRISE', true);
|
||||
|
||||
if (is_wp_error($success)) {
|
||||
|
||||
throw new \Exception($success->get_error_message());
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end _install_sunrise;
|
||||
|
||||
} // end class Core_Installer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@
|
||||
|
||||
namespace WP_Ultimo\Installers;
|
||||
|
||||
use \WP_Ultimo\Logger;
|
||||
use WP_Ultimo\Logger;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
@ -42,8 +42,7 @@ class Default_Content_Installer extends Base_Installer {
|
||||
require_once wu_path('inc/functions/product.php');
|
||||
|
||||
require_once wu_path('inc/functions/checkout-form.php');
|
||||
|
||||
} // end init;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if we already created a template site.
|
||||
@ -58,8 +57,7 @@ class Default_Content_Installer extends Base_Installer {
|
||||
$d = wu_get_site_domain_and_path('template');
|
||||
|
||||
return domain_exists($d->domain, $d->path, get_current_network_id());
|
||||
|
||||
} // end done_creating_template_site;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if we already created the base products.
|
||||
@ -73,15 +71,12 @@ class Default_Content_Installer extends Base_Installer {
|
||||
*/
|
||||
$has_tables_installed = \WP_Ultimo\Loaders\Table_Loader::get_instance()->is_installed();
|
||||
|
||||
if (!$has_tables_installed) {
|
||||
|
||||
if ( ! $has_tables_installed) {
|
||||
return false;
|
||||
}
|
||||
|
||||
} // end if;
|
||||
|
||||
return !empty(wu_get_plans());
|
||||
|
||||
} // end done_creating_products;
|
||||
return ! empty(wu_get_plans());
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if we already created the base checkout form.
|
||||
@ -95,15 +90,12 @@ class Default_Content_Installer extends Base_Installer {
|
||||
*/
|
||||
$has_tables_installed = \WP_Ultimo\Loaders\Table_Loader::get_instance()->is_installed();
|
||||
|
||||
if (!$has_tables_installed) {
|
||||
|
||||
if ( ! $has_tables_installed) {
|
||||
return false;
|
||||
}
|
||||
|
||||
} // end if;
|
||||
|
||||
return !empty(wu_get_checkout_forms());
|
||||
|
||||
} // end done_creating_checkout_forms;
|
||||
return ! empty(wu_get_checkout_forms());
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if we already created the system emails and the template email.
|
||||
@ -117,15 +109,12 @@ class Default_Content_Installer extends Base_Installer {
|
||||
*/
|
||||
$has_tables_installed = \WP_Ultimo\Loaders\Table_Loader::get_instance()->is_installed();
|
||||
|
||||
if (!$has_tables_installed) {
|
||||
|
||||
if ( ! $has_tables_installed) {
|
||||
return false;
|
||||
}
|
||||
|
||||
} // end if;
|
||||
|
||||
return !empty(wu_get_all_system_emails());
|
||||
|
||||
} // end done_creating_emails;
|
||||
return ! empty(wu_get_all_system_emails());
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if we already created the custom login page.
|
||||
@ -137,17 +126,14 @@ class Default_Content_Installer extends Base_Installer {
|
||||
|
||||
$page_id = wu_get_setting('default_login_page');
|
||||
|
||||
if (!$page_id) {
|
||||
|
||||
if ( ! $page_id) {
|
||||
return false;
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
$page = get_post($page_id);
|
||||
|
||||
return !empty($page);
|
||||
|
||||
} // end done_creating_login_page;
|
||||
return ! empty($page);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of migration steps.
|
||||
@ -210,8 +196,7 @@ class Default_Content_Installer extends Base_Installer {
|
||||
);
|
||||
|
||||
return $steps;
|
||||
|
||||
} // end get_steps;
|
||||
}
|
||||
|
||||
// Default_Content_Installers start below
|
||||
|
||||
@ -236,20 +221,15 @@ class Default_Content_Installer extends Base_Installer {
|
||||
$status = wu_create_site($template_site);
|
||||
|
||||
if (is_wp_error($status)) {
|
||||
|
||||
throw new \Exception($status->get_error_message());
|
||||
}
|
||||
|
||||
} // end if;
|
||||
|
||||
if (!$status) {
|
||||
|
||||
if ( ! $status) {
|
||||
$error_message = __('Template Site was not created. Maybe a site with the /template path already exists?', 'wp-ultimo');
|
||||
|
||||
throw new \Exception($error_message);
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end _install_create_template_site;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a example products.
|
||||
@ -333,22 +313,17 @@ class Default_Content_Installer extends Base_Installer {
|
||||
);
|
||||
|
||||
foreach ($products as $product_data) {
|
||||
|
||||
$status = wu_create_product($product_data);
|
||||
|
||||
if (is_wp_error($status)) {
|
||||
|
||||
throw new \Exception($status->get_error_message());
|
||||
}
|
||||
|
||||
} // end if;
|
||||
|
||||
$status->set_featured_image_id($images[$product_data['slug']]);
|
||||
$status->set_featured_image_id($images[ $product_data['slug'] ]);
|
||||
|
||||
$status->save();
|
||||
|
||||
} // end foreach;
|
||||
|
||||
} // end _install_create_products;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new checkout form as an example.
|
||||
@ -368,16 +343,12 @@ class Default_Content_Installer extends Base_Installer {
|
||||
$status = wu_create_checkout_form($checkout_form);
|
||||
|
||||
if (is_wp_error($status)) {
|
||||
|
||||
throw new \Exception($status->get_error_message());
|
||||
|
||||
} else {
|
||||
|
||||
$status->use_template('single-step');
|
||||
|
||||
$status->save();
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
$post_content = '
|
||||
<!-- wp:shortcode -->
|
||||
@ -400,17 +371,14 @@ class Default_Content_Installer extends Base_Installer {
|
||||
$page_id = wp_insert_post($post_details);
|
||||
|
||||
if (is_wp_error($page_id)) {
|
||||
|
||||
throw new \Exception($page_id->get_error_message());
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
/*
|
||||
* Set page as the default registration page.
|
||||
*/
|
||||
wu_save_setting('default_registration_page', $page_id);
|
||||
|
||||
} // end _install_create_checkout;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the template email, invoice template and system emails.
|
||||
@ -422,8 +390,7 @@ class Default_Content_Installer extends Base_Installer {
|
||||
public function _install_create_emails() {
|
||||
|
||||
\WP_Ultimo\Managers\Email_Manager::get_instance()->create_all_system_emails();
|
||||
|
||||
} // end _install_create_emails;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates custom login page.
|
||||
@ -451,10 +418,8 @@ class Default_Content_Installer extends Base_Installer {
|
||||
$page_id = wp_insert_post($page_args);
|
||||
|
||||
if (is_wp_error($page_id)) {
|
||||
|
||||
throw new \Exception($page_id->get_error_message());
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
/*
|
||||
* Enable a custom login page.
|
||||
@ -465,7 +430,5 @@ class Default_Content_Installer extends Base_Installer {
|
||||
* Set page as the default login page.
|
||||
*/
|
||||
wu_save_setting('default_login_page', $page_id);
|
||||
|
||||
} // end _install_create_login_page;
|
||||
|
||||
} // end class Default_Content_Installer;
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user