Skip to content

Commit

Permalink
* Fix for Elementor Update task on unicode/utf-8 pages.
Browse files Browse the repository at this point in the history
* Debug log can now be filtered and searched
* Insure logging is using appropriate logging levels
  • Loading branch information
jawngee committed Apr 9, 2021
1 parent e499b46 commit 451cb77
Show file tree
Hide file tree
Showing 16 changed files with 277 additions and 108 deletions.
4 changes: 2 additions & 2 deletions classes/Tools/Storage/Driver/GoogleCloud/GoogleStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public function validateSettings($errorCollector = null) {
$errorCollector->addError("Bucket {$this->settings->bucket} does not exist.");
}

Logger::info("Bucket does not exist.", [], __METHOD__, __LINE__);
Logger::error("Bucket does not exist.", [], __METHOD__, __LINE__);
}
} catch (\Exception $ex) {
if ($errorCollector) {
Expand Down Expand Up @@ -283,7 +283,7 @@ protected function getClient($errorCollector = null) {
$errorCollector->addError("Google configuration is incorrect or missing.");
}

Logger::info('Could not create Google storage client.', [], __METHOD__, __LINE__);
Logger::error('Could not create Google storage client.', [], __METHOD__, __LINE__);
}

return $client;
Expand Down
4 changes: 2 additions & 2 deletions classes/Tools/Storage/Driver/S3/S3Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public function validateSettings($errorCollector = null) {

if (empty($valid) && empty($connectError)) {
try {
Logger::info("Bucket does not exist, trying to list buckets.", [], __METHOD__, __LINE__);
Logger::warning("Bucket does not exist, trying to list buckets.", [], __METHOD__, __LINE__);

$result = $client->listBuckets();
$buckets = $result->get('Buckets');
Expand All @@ -216,7 +216,7 @@ public function validateSettings($errorCollector = null) {
$errorCollector->addError("Bucket {$this->settings->bucket} does not exist.");
}

Logger::info("Bucket does not exist.", [], __METHOD__, __LINE__);
Logger::error("Bucket does not exist.", [], __METHOD__, __LINE__);
}
} catch(AwsException $ex) {
if ($errorCollector) {
Expand Down
24 changes: 12 additions & 12 deletions classes/Tools/Storage/StorageContentHooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ public function fixGutenbergFigures($content) {
}

if (preg_match_all('/(<figure(.*)(?=<\/figure>))/m', $content, $figures)) {
Logger::info("Found ".count($figures[0])." gutenberg figures.");
Logger::info("Found ".count($figures[0])." gutenberg figures.", [], __METHOD__, __LINE__);

foreach($figures[0] as $figureMatch) {
if (preg_match('/<figure(?:.*)class\s*=\s*(?:.*)wp-block-image(?:.*)size-([aA-zZ0-9-_.]+)/', $figureMatch, $sizeMatches)) {
Expand All @@ -263,13 +263,13 @@ public function fixGutenbergFigures($content) {
Logger::info("Image tag missing src attribute: {$imageTagMatch[0]}", [], __METHOD__, __LINE__);
}
} else {
Logger::info("Figure missing img tag: $figureMatch", [], __METHOD__, __LINE__);
Logger::warning("Figure missing img tag: $figureMatch", [], __METHOD__, __LINE__);
}
} else {
Logger::info("Figure missing wp-image class: $figureMatch", [], __METHOD__, __LINE__);
Logger::warning("Figure missing wp-image class: $figureMatch", [], __METHOD__, __LINE__);
}
} else {
Logger::info("Figure missing wp-block-image or size class: $figureMatch", [], __METHOD__, __LINE__);
Logger::warning("Figure missing wp-block-image or size class: $figureMatch", [], __METHOD__, __LINE__);
}
}
}
Expand Down Expand Up @@ -545,7 +545,7 @@ public function filterContent($content, $context = 'post') {
$imageFound = false;

if (!preg_match($srcRegex, $image, $srcMatches) || (strpos($image, 'mcloud-attachment-') !== false)) {
Logger::info("Image tag has no src attribute or is missing mcloud-attachment class: ".$image, [], __METHOD__, __LINE__);
Logger::warning("Image tag has no src attribute or is missing mcloud-attachment class: ".$image, [], __METHOD__, __LINE__);
continue;
}

Expand All @@ -568,7 +568,7 @@ public function filterContent($content, $context = 'post') {
}

if (!empty($id) && empty($size)) {
Logger::info("Found ID '$id' but no size for image tag: ".$image, [], __METHOD__, __LINE__);
Logger::warning("Found ID '$id' but no size for image tag: ".$image, [], __METHOD__, __LINE__);

if (preg_match('/sizes=[\'"]+\(max-(width|height)\:\s*([0-9]+)px/m', $image, $sizeMatches)) {
$which = $sizeMatches[1];
Expand Down Expand Up @@ -596,11 +596,11 @@ public function filterContent($content, $context = 'post') {

if (empty($size)) {
$size = 'full';
Logger::info("Could not find size for image tag, using full: ".$image, [], __METHOD__, __LINE__);
Logger::warning("Could not find size for image tag, using full: ".$image, [], __METHOD__, __LINE__);
}
} else {
$size = 'full';
Logger::info("Could not find size for image tag, using full: ".$image, [], __METHOD__, __LINE__);
Logger::warning("Could not find size for image tag, using full: ".$image, [], __METHOD__, __LINE__);
}
}
}
Expand All @@ -618,7 +618,7 @@ public function filterContent($content, $context = 'post') {
];
}
} else {
Logger::info("Image tag has no class attribute: ".$image, [], __METHOD__, __LINE__);
Logger::warning("Image tag has no class attribute: ".$image, [], __METHOD__, __LINE__);
}

if (!$imageFound && !empty($this->settings->replaceAllImageUrls)) {
Expand Down Expand Up @@ -661,14 +661,14 @@ public function filterContent($content, $context = 'post') {
];
}
} else {
Logger::info("Unable to map URL to post ID using attachment_url_to_postid(): ".$image, [], __METHOD__, __LINE__);
Logger::warning("Unable to map URL to post ID using attachment_url_to_postid(): ".$image, [], __METHOD__, __LINE__);
$this->addToReport(null, 'Image', $matchedUrl, null, 'Unable to map URL to post ID.');
}
} else {
Logger::info("Unable to map URL to post ID, no regex match $imageRegex: ".$image, [], __METHOD__, __LINE__);
Logger::warning("Unable to map URL to post ID, no regex match $imageRegex: ".$image, [], __METHOD__, __LINE__);
}
} else if (!$imageFound) {
Logger::info("Unable to map URL to post ID: ".$image, [], __METHOD__, __LINE__);
Logger::warning("Unable to map URL to post ID: ".$image, [], __METHOD__, __LINE__);
$this->addToReport(null, 'Image', $src, null, 'Unable to map URL to post ID.');
}
}
Expand Down
2 changes: 1 addition & 1 deletion classes/Tools/Storage/StorageGlobals.php
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ public static function deleteOnUpload() {
/** @return bool */
public static function queuedDeletes() {
$canQueue = apply_filters('media-cloud/storage/queue-deletes', true);
Logger::info("StorageGlobals::queuedDeletes - Filter returned: '$canQueue'", [], __METHOD__, __LINE__);
Logger::info("Filter returned: '$canQueue'", [], __METHOD__, __LINE__);
return (!empty($canQueue) && self::instance()->queuedDeletes);
}

Expand Down
14 changes: 7 additions & 7 deletions classes/Tools/Video/Driver/Mux/MuxAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,20 +111,20 @@ public static function validateSignature($muxSignature, $body, $secret, $toleran
}

if (empty($time) || empty($signature) || empty($body)) {
Logger::info("Mux: Missing time and/or signature.", [], __METHOD__, __LINE__);
Logger::error("Mux: Missing time and/or signature.", [], __METHOD__, __LINE__);
return false;
}

$expected = hash_hmac('sha256', "{$time}.{$body}", $secret);

if ($expected !== $signature) {
Logger::info("Mux: Signature mismatch.", [], __METHOD__, __LINE__);
Logger::error("Mux: Signature mismatch.", [], __METHOD__, __LINE__);
return false;
}

$offset = time() - $time;
if ($offset > $tolerance) {
Logger::info("Mux: Signature time tolerance exceeded.", [], __METHOD__, __LINE__);
Logger::error("Mux: Signature time tolerance exceeded.", [], __METHOD__, __LINE__);
return false;
}

Expand All @@ -139,7 +139,7 @@ public static function validateSignature($muxSignature, $body, $secret, $toleran
*/
public static function signingKey() {
if (static::keysAPI() === null) {
Logger::info("Mux: Could not create keys API", [], __METHOD__, __LINE__);
Logger::error("Mux: Could not create keys API", [], __METHOD__, __LINE__);
return null;
}

Expand All @@ -151,15 +151,15 @@ public static function signingKey() {
'privateKey' => $signingKey['privateKey']
];
} else {
Logger::info('Mux: Key expired, creating a new one.', [], __METHOD__, __LINE__);
Logger::warning('Mux: Key expired, creating a new one.', [], __METHOD__, __LINE__);
}
}

try {
$result = static::keysAPI()->createUrlSigningKey();
$muxKey = $result->getData();
if ($muxKey === null) {
Logger::info("Mux: Error creating new signing key.", [], __METHOD__, __LINE__);
Logger::error("Mux: Error creating new signing key.", [], __METHOD__, __LINE__);
return null;
}

Expand All @@ -182,7 +182,7 @@ public static function signingKey() {
'privateKey' => $signingKey['privateKey']
];
} catch (ApiException $ex) {
Logger::info("Mux: Error creating signing key: ".$ex->getMessage(), [], __METHOD__, __LINE__);
Logger::error("Mux: Error creating signing key: ".$ex->getMessage(), [], __METHOD__, __LINE__);
}

return null;
Expand Down
24 changes: 12 additions & 12 deletions classes/Tools/Video/Driver/Mux/MuxHooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ protected function updateAttachmentMeta( $asset )
{

if ( empty($asset->attachmentId) ) {
Logger::info(
Logger::error(
"Mux: Missing attachment id, cannot update meta.",
[],
__METHOD__,
Expand All @@ -119,7 +119,7 @@ protected function updateAttachmentMeta( $asset )
$meta = get_post_meta( $asset->attachmentId, '_wp_attachment_metadata', true );

if ( empty($meta) ) {
Logger::info(
Logger::error(
"Mux: Attachment {$asset->attachmentId} meta is missing or empty, cannot update.",
[],
__METHOD__,
Expand Down Expand Up @@ -156,7 +156,7 @@ protected function createAttachmentForAsset( $asset )
);

if ( MuxAPI::assetAPI() === null ) {
Logger::info(
Logger::error(
"Mux: Unable to create API client",
[],
__METHOD__,
Expand All @@ -169,7 +169,7 @@ protected function createAttachmentForAsset( $asset )
$result = MuxAPI::assetAPI()->getAssetInputInfo( $asset->muxId );

if ( $result === null ) {
Logger::info(
Logger::error(
"Mux: Could not get asset input info for {$asset->muxId}",
[],
__METHOD__,
Expand All @@ -179,7 +179,7 @@ protected function createAttachmentForAsset( $asset )
}

} catch ( \Exception $ex ) {
Logger::info(
Logger::error(
"Mux: Mux error fetching input info: " . $ex->getMessage(),
[],
__METHOD__,
Expand All @@ -190,7 +190,7 @@ protected function createAttachmentForAsset( $asset )
$inputInfos = $result->getData();

if ( empty($inputInfos) ) {
Logger::info(
Logger::error(
"Mux: Could not find asset inputs for {$asset->muxId}",
[],
__METHOD__,
Expand Down Expand Up @@ -255,7 +255,7 @@ protected function assignThumbnailForAsset( $asset )
}

if ( has_post_thumbnail( $asset->attachmentId ) ) {
Logger::info(
Logger::warning(
"Mux: Thumbnail already exists",
[],
__METHOD__,
Expand All @@ -268,7 +268,7 @@ protected function assignThumbnailForAsset( $asset )
$url = $asset->thumbnailUrl();

if ( empty($url) ) {
Logger::info(
Logger::error(
"Mux: Could not generate URL for thumbnail?",
[],
__METHOD__,
Expand All @@ -292,7 +292,7 @@ protected function assignThumbnailForAsset( $asset )
file_put_contents( $filePath, ilab_file_get_contents( $url ) );

if ( !file_exists( $filePath ) ) {
Logger::info(
Logger::error(
"Mux: Could not download image {$url}.",
[],
__METHOD__,
Expand Down Expand Up @@ -516,7 +516,7 @@ public function handleWebhook( $template )
if ( strpos( $_SERVER['REQUEST_URI'], '/__mux/webhook' ) === 0 ) {

if ( !isset( $_SERVER['HTTP_MUX_SIGNATURE'] ) ) {
Logger::info(
Logger::error(
"Mux: Missing Mux Signature",
[],
__METHOD__,
Expand All @@ -530,7 +530,7 @@ public function handleWebhook( $template )
$body = file_get_contents( 'php://input' );

if ( !MuxAPI::validateSignature( $_SERVER['HTTP_MUX_SIGNATURE'], $body, $this->settings->webhookSecret ) ) {
Logger::info(
Logger::error(
"Mux: Invalid Mux Signature",
[],
__METHOD__,
Expand All @@ -544,7 +544,7 @@ public function handleWebhook( $template )
$data = json_decode( $body, true );
$type = arrayPath( $data, 'type', null );
if ( empty($type) ) {
Logger::info(
Logger::error(
"Mux: Webhook missing type. Exiting.",
[],
__METHOD__,
Expand Down
4 changes: 2 additions & 2 deletions classes/Tools/Video/Driver/Mux/MuxTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ public function prepareAttachmentForJS( $response, $attachment, $meta )
$mux['src'] = $asset->videoUrl( false );
$mux['gif'] = $asset->gifUrl( false );
} catch ( \Exception $ex ) {
Logger::info(
Logger::error(
"Mux: Exception fetching Mux Asset {$mux['muxId']}: " . $ex->getMessage(),
[],
__METHOD__,
Expand Down Expand Up @@ -514,7 +514,7 @@ public function deleteAttachment( $id )
try {
MuxAPI::assetAPI()->deleteAsset( $muxId );
} catch ( \Exception $ex ) {
Logger::info(
Logger::error(
'Mux: Error deleting asset from Mux: ' . $ex->getMessage(),
[],
__METHOD__,
Expand Down
2 changes: 1 addition & 1 deletion classes/Utilities/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ function phpMemoryLimit($default = '64M') {
if (function_exists('ini_get')) {
$memory_limit = ini_get('memory_limit');
} else {
Logger::info("ini_get disabled is disabled, unable to determine real memory limit", [], __FUNCTION__, __LINE__);
Logger::warning("ini_get disabled is disabled, unable to determine real memory limit", [], __FUNCTION__, __LINE__);
}

if (empty($memory_limit) || ($memory_limit == -1)) {
Expand Down
Loading

0 comments on commit 451cb77

Please sign in to comment.