Skip to content

Commit

Permalink
* Massive overhaul of Elementor integration. Media Cloud now will sup…
Browse files Browse the repository at this point in the history
…port any Elementor addon and running the

  **Elementor Update Task** is super safe.  Instead of the brute force text search/replace we were doing before, we are
  now analyzing every installed Elementor widget's properties for images to update and then walking your Elementor post
  or page's structure to update accordingly.
* Rewrote the Storage Browser from the ground up.  Much much much faster and can now handle buckets of any size and
  file count.
* **Update Elementor** task now generates a report on what was replaced/updated on your Elementor pages/posts.
* Support for custom sizes in images in Elementor.
* New integration for Google Web Stories.  If you use Google Web Stories, you may need to run the "Update Web Stories"
  task to make sure all of your URLs are correct.  You should only have to run this task once, though you will need to
  run it again anytime you change Media Cloud's config in such a way that it changes the URLs to your images.
* Fix for "dynamically" resized images using Imgix that ignored the image's default parameters set in the image editor.
* Fix for URL replacement where two or more of the same images at different sizes were being replaced by a single size
  when using the classic editor.
* When adding media to a post that links to the original media, we are now replacing those URLs as well.  You can turn
  this off in **Cloud Storage Settings** in the **URL Replacement** category.
* Disable optimizers during migrate task to prevent certain images from being skipped.
* Fix for built-in ShortPixel optimization
* Fixed Unlink From Cloud task not scrubbing all S3 metadata
* Fix for imgix urls being double urlencoded
* Fix for image sizes in gallery blocks in Gutenberg
* PHP 8 compatibility fixes
* Fix for direct uploads going to unicode directory names
* CLI commands have been "namespaced" and some names have changed.  For example, what used to be
  `wp mediacloud migrateToCloud` is now `wp mediacloud:storage migrate`.
* The Update Elementor command line is now `wp mediacloud:elementor update`
* Verify Library task can now be accessed from the menu
* Verify Library task has a new option, **Include Local** that will verify everything in your Media Library, including
  items that are not on cloud storage.  This is a good first step prior to migrating your library for the first time to
  see if you are missing any local files which may cause your migration to fail.
* Added new setting toggle **Replace URLs** in **Cloud Storage Settings** that allows you to turn off Media Cloud's
  realtime URL replacement.  If you've been using Media Cloud since day zero of your WordPress site (you haven't
  migrated an existing site) and haven't changed any settings which would change the URL for your cloud storage since
  then (for example adding a CDN or enabling imgix), you may be able to turn this setting off.   Note that the URL
  replacement overhead is very minimal to begin with so the potential performance gain won't be noticeable in most cases.
* When Debugging is enabled, Media Cloud will now log to Query Monitor's log if you have that plugin installed
  and activated.
* Added **Reset Task Data** to the Task Manager to clear out all task data from the database, aka the nuclear option.
* Added Report Viewer to view the reports that the various tasks that Media Cloud runs produces.
* Added new CLI command `wp mediacloud:storage replace` which will search and replace URLs in your database.  When used
  in conjunction with the new **Replace URLs** toggle in **Cloud Storage Settings** you can minimize all of the work
  that Media Cloud is doing on the front end to make sure that URLs are correct.  ***There are a lot of caveats to using
  this command***.  Please read this article for more information:
  https://support.mediacloud.press/articles/advanced-usage/command-line/replace-urls
* Compatibility fixes with HyperDB and LudicrousDB
* Fix for settings sometimes not being saved when using Redis object caching
* The Media Cloud heartbeat now only runs for administrators or users who have the `mcloud_heartbeat` capability
  • Loading branch information
jawngee committed Feb 9, 2021
1 parent 973b444 commit fa39642
Show file tree
Hide file tree
Showing 85 changed files with 3,869 additions and 1,899 deletions.
60 changes: 60 additions & 0 deletions classes/Tasks/CLIReporter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php


namespace MediaCloud\Plugin\Tasks;

class CLIReporter implements ITaskReporter {
/** @var array */
protected $headerFields = [];

protected $data = [];

protected $format = 'table';

/**
* CLITableReporter constructor.
*
* @param array $headerFields
* @param string $format
*/
public function __construct(array $headerFields, string $format = 'table') {
$this->headerFields = $headerFields;
$this->format = $format;
}

/**
* @inheritDoc
*/
public function open() {
}

/**
* @inheritDoc
*/
public function add(array $data) {
$item = [];
for($i = 0; $i < count($data); $i++) {
if ($i >= count($this->headerFields)) {
break;
}

$item[$this->headerFields[$i]] = $data[$i];
}

$this->data[] = $item;
}

/**
* @inheritDoc
*/
public function close() {
\WP_CLI\Utils\format_items($this->format, $this->data, $this->headerFields);
}

/**
* @inheritDoc
*/
public function headerFields(): array {
return $this->headerFields;
}
}
39 changes: 39 additions & 0 deletions classes/Tasks/ITaskReporter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

// Copyright (c) 2016 Interfacelab LLC. All rights reserved.
//
// Released under the GPLv3 license
// http://www.gnu.org/licenses/gpl-3.0.html
//
// **********************************************************************
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// **********************************************************************

namespace MediaCloud\Plugin\Tasks;

interface ITaskReporter {
/**
* Open the task reporter for writing
*/
public function open();

/**
* Writes data to the reporter
* @param array $data
*/
public function add(array $data);

/**
* Closes the reporter
*/
public function close();

/**
* Returns the header fields for the report
*
* @return array
*/
public function headerFields(): array;
}
59 changes: 59 additions & 0 deletions classes/Tasks/MultiReporter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php


namespace MediaCloud\Plugin\Tasks;


class MultiReporter implements ITaskReporter {
/** @var ITaskReporter[] */
protected $reporters = [];

/**
* MultiReporter constructor.
*
* @param ITaskReporter[]|null $reporters
*/
public function __construct(?array $reporters = null) {
if (!empty($reporters)) {
$this->reporters = $reporters;
}
}

public function addReporter(ITaskReporter $reporter) {
$this->reporters[] = $reporter;
}

/**
* @inheritDoc
*/
public function open() {
foreach($this->reporters as $reporter) {
$reporter->open();
}
}

/**
* @inheritDoc
*/
public function add(array $data) {
foreach($this->reporters as $reporter) {
$reporter->add($data);
}
}

/**
* @inheritDoc
*/
public function close() {
foreach($this->reporters as $reporter) {
$reporter->close();
}
}

/**
* @inheritDoc
*/
public function headerFields(): array {
return (count($this->reporters) > 0) ? $this->reporters[0]->headerFields() : [];
}
}
13 changes: 13 additions & 0 deletions classes/Tasks/TaskDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,19 @@ protected static function installTokenTable() {

//endregion

//region Nuke

public static function nukeData() {
global $wpdb;

$wpdb->query("delete from {$wpdb->base_prefix}mcloud_task");
$wpdb->query("delete from {$wpdb->base_prefix}mcloud_task_data");
$wpdb->query("delete from {$wpdb->base_prefix}mcloud_task_schedule");
$wpdb->query("delete from {$wpdb->base_prefix}mcloud_task_token");
}

//endregion

//region Tokens

public static function setToken($token, $tokenVal) {
Expand Down
14 changes: 14 additions & 0 deletions classes/Tasks/TaskManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ private function setupHooks() {
add_action('wp_ajax_mcloud_start_task', [$this, 'actionStartTask']);
add_action('wp_ajax_mcloud_cancel_task', [$this, 'actionCancelTask']);
add_action('wp_ajax_mcloud_cancel_all_tasks', [$this, 'actionCancelAllTasks']);
add_action('wp_ajax_mcloud_nuke_all_tasks', [$this, 'actionNukeAllTasks']);
add_action('wp_ajax_mcloud_task_status', [$this, 'actionTaskStatus']);
add_action('wp_ajax_mcloud_all_task_statuses', [$this, 'actionAllTaskStatuses']);

Expand Down Expand Up @@ -340,6 +341,19 @@ public function actionCancelAllTasks() {
wp_send_json(['status' => 'ok', 'message', 'Tasks cancelled.']);
}

/**
* Cancels all running tasks
*/
public function actionNukeAllTasks() {
Logger::info("Nuking All Tasks ... ", [], __METHOD__, __LINE__);
check_ajax_referer('mcloud_nuke_all_tasks', 'nonce');

// SQL TO DELETE IT ALL EVERYTHING
TaskDatabase::nukeData();

wp_send_json(['status' => 'ok', 'message', 'Tasks cancelled.']);
}


public function actionClearTaskHistory() {
Logger::info("Clearing Task History ... ", [], __METHOD__, __LINE__);
Expand Down
55 changes: 46 additions & 9 deletions classes/Tasks/TaskReporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@
use MediaCloud\Vendor\Monolog\Handler\StreamHandler;
use MediaCloud\Vendor\Monolog\Logger as MonologLogger;

class TaskReporter {
class TaskReporter implements ITaskReporter {
/** @var null|Task */
private $task = null;
private $headerFields = [];

private $reportCSV = null;
private $taskFileName = null;
private $alwaysGenerate = false;
private $loggerAdded = false;

protected $headerFields = [];

/**
* TaskReporter constructor.
*
* @param Task|string $taskorArray
* @param Task|string $taskOrFileName
* @param array $headerFields
*/
public function __construct($taskOrFileName, array $headerFields, bool $alwaysGenerate = false) {
Expand All @@ -46,6 +46,42 @@ public function __construct($taskOrFileName, array $headerFields, bool $alwaysGe
$this->alwaysGenerate = $alwaysGenerate;
}

public static function reporterDirectory(?string $file = null) {
$reportDir = trailingslashit(WP_CONTENT_DIR).'mcloud-reports';
if (is_multisite() && !is_network_admin()) {
$reportDir .= '/'.get_current_blog_id();
}

if (!file_exists($reportDir)) {
@mkdir($reportDir, 0755, true);
}

if (!file_exists($reportDir)) {
return null;
}

if (!empty($file)) {
return trailingslashit($reportDir).$file;
}

return $reportDir;
}

public static function reporterUrl(?string $file = null) {
if (is_multisite() && !is_network_admin()) {
$url = content_url('/mcloud-reports/'.get_current_blog_id());
$url = site_url(parse_url($url, PHP_URL_PATH));
} else {
$url = content_url('/mcloud-reports');
}

if (!empty($file)) {
return trailingslashit($url).$file;
}

return $url;
}

public function open() {
if (!$this->alwaysGenerate && empty(TaskSettings::instance()->generateReports)) {
return false;
Expand All @@ -59,12 +95,9 @@ public function open() {
return false;
}

$reportDir = trailingslashit(WP_CONTENT_DIR).'mcloud-reports';
if (!file_exists($reportDir)) {
@mkdir($reportDir, 0755, true);
}
$reportDir = static::reporterDirectory();

if (file_exists($reportDir)) {
if (!empty($reportDir)) {
if (!empty($this->taskFileName)) {
if (strpos($this->taskFileName, '/') !== 0) {
$this->taskFileName = trailingslashit($reportDir).$this->taskFileName;
Expand Down Expand Up @@ -129,4 +162,8 @@ public function close() {
}
}
}

public function headerFields(): array {
return $this->headerFields;
}
}
31 changes: 28 additions & 3 deletions classes/Tools/DynamicImages/DynamicImagesTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
use function MediaCloud\Plugin\Utilities\parse_req;

abstract class DynamicImagesTool extends Tool {
protected $forcedEnabled = false;

/** @var DynamicImagesToolSettings */
protected $settings = null;

Expand All @@ -42,6 +44,10 @@ public function __construct($toolName, $toolInfo, $toolManager) {
parent::__construct($toolName, $toolInfo, $toolManager);

add_filter('media-cloud/dynamic-images/enabled', function($enabled){
if ($this->forcedEnabled) {
return $this->forcedEnabled;
}

if (!$enabled) {
return $this->enabled();
}
Expand Down Expand Up @@ -115,10 +121,9 @@ public function setup() {

$this->hookupUI();

add_filter('wp_get_attachment_url', [$this, 'getAttachmentURL'], 10000, 2);
add_filter('wp_prepare_attachment_for_js', array($this, 'prepareAttachmentForJS'), 1000, 3);
$this->setupHooks();

add_filter('image_downsize', [$this, 'imageDownsize'], 1000, 3);
add_filter('wp_prepare_attachment_for_js', array($this, 'prepareAttachmentForJS'), 1000, 3);

add_filter('image_get_intermediate_size', [$this, 'imageGetIntermediateSize'], 0, 3);

Expand Down Expand Up @@ -230,12 +235,32 @@ public function setup() {
}, 100000, 3);
}

protected function setupHooks() {
add_filter('wp_get_attachment_url', [$this, 'getAttachmentURL'], 10000, 2);
add_filter('image_downsize', [$this, 'imageDownsize'], 1000, 3);
}

protected function tearDownHooks() {
remove_filter('wp_get_attachment_url', [$this, 'getAttachmentURL'], 10000);
remove_filter('image_downsize', [$this, 'imageDownsize'], 1000);
}

public function registerSettings() {
parent::registerSettings();

register_setting('ilab-imgix-preset', 'ilab-imgix-presets');
register_setting('ilab-imgix-preset', 'ilab-imgix-size-presets');
}

public function forceEnable($enabled) {
$this->forcedEnabled = $enabled;
if ($this->forcedEnabled) {
$this->setupHooks();
} else {
$this->tearDownHooks();
}
}

//endregion

//region URL Generation
Expand Down
Loading

0 comments on commit fa39642

Please sign in to comment.