+ throw exception is guids not appropriated to local site url
* basename extraction support multibyte strings filenames
This commit is contained in:
@ -1,7 +1,8 @@
|
||||
<?php namespace WpsMcloud\Actions\Convert\Replacer;
|
||||
|
||||
use WpsMcloud\Actions\Convert\ReplacerService;
|
||||
use WpsMcloud\Models\PostAttachment;
|
||||
use WpsMcloud\Actions\Convert\ReplacerService;
|
||||
use WpsMcloud\Exceptions\UrlDetectException;
|
||||
|
||||
class PostAttachmentReplacer
|
||||
{
|
||||
@ -36,6 +37,20 @@ class PostAttachmentReplacer
|
||||
$post->getUrl()
|
||||
);
|
||||
|
||||
if ($this->mcloudPostUrl == $post->getUrl()) {
|
||||
throw new UrlDetectException(
|
||||
sprintf(<<<EOF
|
||||
Your site url has manual changed in wp-config and not appropriate with post attachments guids.
|
||||
Guid: %s
|
||||
Manual url: %s
|
||||
|
||||
EOF,
|
||||
$post->getUrl(),
|
||||
$replacer->getUploadsDirBaseUrl()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$this->mcloudPostBaseUrl = trailingslashit(
|
||||
str_replace($this->post->getBasename(), '', $this->mcloudPostUrl)
|
||||
);
|
||||
|
@ -1,9 +1,9 @@
|
||||
<?php namespace WpsMcloud\Actions\Convert;
|
||||
|
||||
use WpsMcloud\Support\Http;
|
||||
use WpsMcloud\Support\Counters;
|
||||
use WpsMcloud\Actions\Convert;
|
||||
use WpsMcloud\Models\PostAttachment;
|
||||
use WpsMcloud\Support\Counters;
|
||||
use WpsMcloud\Support\Http;
|
||||
|
||||
class ReplacerService
|
||||
{
|
||||
@ -72,7 +72,7 @@ class ReplacerService
|
||||
$meta['sizes'] = $newSizes;
|
||||
}
|
||||
|
||||
update_post_meta( $post->getId(), '_wp_attachment_metadata', $meta );
|
||||
$post->setAttachmentMetaData($meta);
|
||||
|
||||
Counters::$processedImages++;
|
||||
}
|
||||
|
6
src/Exceptions/UrlDetectException.php
Normal file
6
src/Exceptions/UrlDetectException.php
Normal file
@ -0,0 +1,6 @@
|
||||
<?php namespace WpsMcloud\Exceptions;
|
||||
|
||||
class UrlDetectException extends WpstudioMediaCloudTransformException
|
||||
{
|
||||
|
||||
}
|
@ -1,7 +1,5 @@
|
||||
<?php namespace WpsMcloud\Models;
|
||||
|
||||
use JetBrains\PhpStorm\Pure;
|
||||
|
||||
class PostAttachment
|
||||
{
|
||||
const META_KEY_FLAGGED_AS_404 = '_wp_media_cloud_transform_404';
|
||||
@ -47,7 +45,7 @@ class PostAttachment
|
||||
|
||||
public function getBasename(): string
|
||||
{
|
||||
return basename($this->getUrl());
|
||||
return mb_basename($this->getUrl());
|
||||
}
|
||||
|
||||
public function getPostMimeType(): string
|
||||
@ -57,7 +55,6 @@ class PostAttachment
|
||||
|
||||
public function setAttachmentMetaData(array $meta)
|
||||
{
|
||||
|
||||
update_post_meta($this->getId(), self::META_KEY_ATTACHMENT_METADATA, $meta);
|
||||
}
|
||||
|
||||
|
10
src/Support/helpers.php
Normal file
10
src/Support/helpers.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
if (!function_exists('mb_basename')) {
|
||||
function mb_basename(string $file)
|
||||
{
|
||||
$filenameParts = explode('/', $file);
|
||||
|
||||
return end($filenameParts);
|
||||
}
|
||||
}
|
@ -30,6 +30,7 @@ add_action('admin_menu', fn () => add_submenu_page(
|
||||
//
|
||||
// $ilabClassLoader = new Composer\Autoload\ClassLoader();
|
||||
// $ilabLoader->unregister();
|
||||
include __DIR__ . '/src/Support/helpers.php';
|
||||
|
||||
$localVendorAutoloadPath = 'vendor/autoload.php';
|
||||
$projectVendorAutoloadPath = ABSPATH . 'vendor/autoload.php';
|
||||
|
Reference in New Issue
Block a user