Skip to content

Commit

Permalink
Fixes due to PR review, docs update
Browse files Browse the repository at this point in the history
  • Loading branch information
balexey88 committed Mar 28, 2024
1 parent d80879a commit e93b755
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 24 deletions.
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* NEW - configuration constant [`WP_STATELESS_BATCH_HEALTHCHECK_INTERVAL`](https://stateless.udx.io/docs/constants/#wp_stateless_batch_healthcheck_interval) defines an interval in minutes for periodical health checks of a batch background process (like data optimization).
* COMPATIBILITY - BuddyBoss Compatibility replaced with [WP-Stateless – BuddyBoss Platform Addon](https://wordpress.org/plugins/wp-stateless-buddyboss-platform-addon/).
* COMPATIBILITY - Elementor Compatibility replaced with [WP-Stateless – Elementor Website Builder Addon](https://wordpress.org/plugins/wp-stateless-elementor-website-builder-addon/).
* COMPATIBILITY - Gravity Form Compatibility does not support older version of Gravity Forms (< 2.3).
* ENHANCEMENT - Allow dismissing notices in Admin Panel only for logged in users.
* ENHANCEMENT - Updated `wp-background-processing` library from from 1.0.2 to 1.1.1.
* ENHANCEMENT - Updated `phpseclib` 3.0.34 to 3.0.37.
Expand Down
1 change: 1 addition & 0 deletions changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* NEW - configuration constant [`WP_STATELESS_BATCH_HEALTHCHECK_INTERVAL`](https://stateless.udx.io/docs/constants/#wp_stateless_batch_healthcheck_interval) defines an interval in minutes for periodical health checks of a batch background process (like data optimization).
* COMPATIBILITY - BuddyBoss Compatibility replaced with [WP-Stateless – BuddyBoss Platform Addon](https://wordpress.org/plugins/wp-stateless-buddyboss-platform-addon/).
* COMPATIBILITY - Elementor Compatibility replaced with [WP-Stateless – Elementor Website Builder Addon](https://wordpress.org/plugins/wp-stateless-elementor-website-builder-addon/).
* COMPATIBILITY - Gravity Form Compatibility does not support older version of Gravity Forms (< 2.3).
* ENHANCEMENT - Allow dismissing notices in Admin Panel only for logged in users.
* ENHANCEMENT - Updated `wp-background-processing` library from from 1.0.2 to 1.1.1.
* ENHANCEMENT - Updated `phpseclib` 3.0.34 to 3.0.37.
Expand Down
4 changes: 1 addition & 3 deletions lib/classes/batch/class-batch-task-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ private function _get_state() {
/**
* Get last state update of the current task
*
* @return array
* @return int|null
*/
private function _get_last_updated() {
return get_site_option( $this->identifier . self::UPDATED_KEY, null );
Expand Down Expand Up @@ -204,11 +204,9 @@ public function start_task($class, $file = null, $email = '') {
*/
public function task($item) {
$result = false;
$description = 'Batch process';

try {
$object = $this->_get_batch_task_object();
$description = $object->get_description();

$result = $object->process_item($item);
$this->_update_state( $object->get_state() );
Expand Down
6 changes: 3 additions & 3 deletions lib/classes/class-addons.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ public function show_messages($addons) {

ud_get_stateless_media()->errors->add([
'key' => $id,
'title' => sprintf(__("%s: Addon for %s is recommended.", ud_get_stateless_media()->domain), ud_get_stateless_media()->name, $title),
'button' => __("Get Addon", ud_get_stateless_media()->domain),
'title' => sprintf(__('WP-Stateless: Install the %s Addon', ud_get_stateless_media()->domain), $title),
'button' => __('Download Addon', ud_get_stateless_media()->domain),
'button_link' => admin_url('upload.php?page=stateless-settings&tab=stless_addons_tab'),
'message' => __("Addon is recommended to ensure the functionality will work properly between <b>{$title}</b> and <b>WP-Stateless</b>.", ud_get_stateless_media()->domain),
'message' => sprintf(__('Download and activate the WP-Stateless addon for %s to ensure compatibility.', ud_get_stateless_media()->domain), $title),
], 'notice');
}
}
Expand Down
8 changes: 1 addition & 7 deletions lib/classes/class-bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -1746,13 +1746,7 @@ public function create_sync_db($force = false) {
* @param $old_site
*/
public function wp_delete_site($old_site) {
global $wpdb;

switch_to_blog($old_site->id);
$table_name = $wpdb->prefix . 'sm_sync';

$sql = "DROP TABLE IF EXISTS $table_name";
$wpdb->query($sql);

ud_stateless_db()->clear_db();

Expand Down Expand Up @@ -2063,7 +2057,7 @@ public function get_notification_email() {
switch ($type) {
case 'true':
// Emails to Admin
return get_option('admin_email');
return get_site_option('admin_email');
case 'custom':
// Emails to Custom Email
return $this->get( 'sm.status_email_address' );
Expand Down
28 changes: 19 additions & 9 deletions lib/classes/class-db.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ class DB {
*/
private $file_meta = '';

/**
* Sync table name
*/
private $sm_sync = '';

/**
* Cache group name
*/
Expand Down Expand Up @@ -91,6 +96,7 @@ protected function __construct() {
$this->files = $this->wpdb->prefix . 'stateless_files';
$this->file_sizes = $this->wpdb->prefix . 'stateless_file_sizes';
$this->file_meta = $this->wpdb->prefix . 'stateless_file_meta';
$this->sm_sync = $this->wpdb->prefix . 'sm_sync';

$image_host = ud_get_stateless_media()->get_gs_host();
$this->bucket_link = apply_filters('wp_stateless_bucket_link', $image_host);
Expand Down Expand Up @@ -124,7 +130,7 @@ private function _init() {
* Getters
*/
public function __get($property) {
if ( in_array($property, ['files', 'file_sizes', 'file_meta']) ) {
if ( in_array($property, ['files', 'file_sizes', 'file_meta', 'sm_sync']) ) {
return $this->$property;
}
}
Expand Down Expand Up @@ -197,8 +203,8 @@ public function create_db() {
* Remove custom DB table on plugin uninstall
*/
public function clear_db() {
$sql = "DROP TABLE IF EXISTS $this->files, $this->file_sizes, $this->file_meta;";
$wpdb->query($sql);
$sql = "DROP TABLE IF EXISTS $this->files, $this->file_sizes, $this->file_meta, $this->sm_sync;";
$this->wpdb->query($sql);
}

/**
Expand Down Expand Up @@ -262,7 +268,6 @@ public function get_file_meta_id($post_id, $key) {
* @param string $image_size - image size name
* @param array $img - image (or image size) data for upload
* @param string $bucketLink - bucket link
* @param int $attachment_id - attachment ID
* @return mixed
*/
public function process_cloud_meta($cloud_meta, $media, $image_size, $img, $bucketLink) {
Expand Down Expand Up @@ -520,6 +525,7 @@ public function delete_post($post_id, $post) {
* Map requested fields into database query< compatible with the old post meta structure
*
* @param array $fields
* @param array $fields_mapping
* @return string
*/
private function _map_fields($fields, $fields_mapping) {
Expand Down Expand Up @@ -690,7 +696,7 @@ public function get_total_files() {
}

/**
* Get file data. If $size_names is set to true, all sizes will be included
* Get file data. If $with_sizes is set to true, all sizes will be included
*
* @param array $meta
* @param int $attachment_id
Expand All @@ -699,7 +705,11 @@ public function get_total_files() {
*/
public function get_file($meta, $attachment_id, $with_sizes = false) {
if ( defined('WP_STATELESS_POSTMETA') && WP_STATELESS_POSTMETA ) {
return get_post_meta($attachment_id, 'sm_cloud', true);
$meta = get_post_meta($attachment_id, 'sm_cloud', true);

if ( !empty($meta) ) {
return $meta;
}
}

// Get values from the cache
Expand All @@ -718,10 +728,10 @@ public function get_file($meta, $attachment_id, $with_sizes = false) {

$meta = $this->wpdb->get_row( $this->wpdb->prepare($sql, $attachment_id), ARRAY_A );

wp_cache_set($cache_key, $meta, $this->cache_group);

if ( empty($meta) ) {
return get_post_meta($attachment_id, 'sm_cloud', true);
} else {
wp_cache_set($cache_key, $meta, $this->cache_group);
}

// Get file size meta data
Expand Down Expand Up @@ -784,7 +794,7 @@ public function get_file_sizes($sizes, $attachment_id) {
* @param mixed $default
* @return mixed
*/
public function get_file_meta_value($post_id, $key, $default) {
public function get_file_meta_value($post_id, $key, $default = null) {
if ( defined('WP_STATELESS_POSTMETA') && WP_STATELESS_POSTMETA ) {
$meta = get_post_meta($post_id, 'sm_cloud', []);

Expand Down
4 changes: 4 additions & 0 deletions lib/classes/status/class-migrations.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ public static function get_status_text($status) {
private function _get_migrations_state($state = null) {
$migrations = [];
$this->migrations = get_site_option(Migrator::MIGRATIONS_KEY, []);

if ( !is_array($this->migrations) ) {
$this->migrations = [];
}

$defaults = [
'description' => '',
Expand Down
4 changes: 4 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ New to Google Cloud? Google is offering you a [$300 credit](https://console.clou
* Serverless platform compatible, including Google App Engine.
* Multisite compatible.

### Addons
* [BuddyBoss Platform Addon](https://wordpress.org/plugins/wp-stateless-buddyboss-platform-addon/)
* [Elementor Website Builder Addon](https://wordpress.org/plugins/wp-stateless-elementor-website-builder-addon/)

### Support, Feedback, & Contribute
We welcome community involvement via the [GitHub repository](https://github.com/udx/wp-stateless).

Expand Down
7 changes: 6 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
=== WP-Stateless - Google Cloud Storage ===
Contributors: usability_dynamics, andypotanin, ideric, maxim.peshkov, planvova, obolgun
Donate link: https://udx.io
Tags: google, google cloud, google cloud storage, cdn, uploads, media, stateless, backup
Tags: google cloud, google cloud storage, cdn, uploads, backup
License: GPLv2 or later
Requires PHP: 8.0
Requires at least: 5.0
Expand Down Expand Up @@ -43,6 +43,10 @@ New to Google Cloud? Google is offering you a [$300 credit](https://console.clou
* Serverless platform compatible, including Google App Engine.
* Multisite compatible.

= Addons =
* [BuddyBoss Platform Addon](https://wordpress.org/plugins/wp-stateless-buddyboss-platform-addon/)
* [Elementor Website Builder Addon](https://wordpress.org/plugins/wp-stateless-elementor-website-builder-addon/)

= Support, Feedback, & Contribute =
We welcome community involvement via the [GitHub repository](https://github.com/udx/wp-stateless).

Expand Down Expand Up @@ -130,6 +134,7 @@ Before upgrading to WP-Stateless 3.0, please, make sure you tested it on your de
* NEW - configuration constant [`WP_STATELESS_BATCH_HEALTHCHECK_INTERVAL`](https://stateless.udx.io/docs/constants/#wp_stateless_batch_healthcheck_interval) defines an interval in minutes for periodical health checks of a batch background process (like data optimization).
* COMPATIBILITY - BuddyBoss Compatibility replaced with [WP-Stateless – BuddyBoss Platform Addon](https://wordpress.org/plugins/wp-stateless-buddyboss-platform-addon/).
* COMPATIBILITY - Elementor Compatibility replaced with [WP-Stateless – Elementor Website Builder Addon](https://wordpress.org/plugins/wp-stateless-elementor-website-builder-addon/).
* COMPATIBILITY - Gravity Form Compatibility does not support older version of Gravity Forms (< 2.3).
* ENHANCEMENT - Allow dismissing notices in Admin Panel only for logged in users.
* ENHANCEMENT - Updated `wp-background-processing` library from from 1.0.2 to 1.1.1.
* ENHANCEMENT - Updated `phpseclib` 3.0.34 to 3.0.37.
Expand Down
2 changes: 1 addition & 1 deletion wp-stateless-media.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Author: UDX
* Version: 4.0.0-RC.1
* Text Domain: stateless-media
* Author URI: https://www.udx.io
* Author URI: https://udx.io
* License: GPLv2 or later
*
* Copyright 2012 - 2024 UDX ( email: [email protected] )
Expand Down

0 comments on commit e93b755

Please sign in to comment.