first commit
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\Media\Translate\Endpoint;
|
||||
|
||||
use WPML\Ajax\IHandler;
|
||||
use WPML\Collect\Support\Collection;
|
||||
use WPML\FP\Obj;
|
||||
use WPML\LIB\WP\Option;
|
||||
use function WPML\Container\make;
|
||||
use WPML\FP\Right;
|
||||
|
||||
class DuplicateFeaturedImages implements IHandler {
|
||||
public function run( Collection $data ) {
|
||||
if ( ! $this->shouldDuplicateFeaturedImages() ) {
|
||||
return Right::of( 0 );
|
||||
}
|
||||
|
||||
$numberLeft = $data->get( 'remaining', null );
|
||||
|
||||
return Right::of(
|
||||
make( \WPML_Media_Attachments_Duplication::class )->batch_duplicate_featured_images( false, $numberLeft )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
private function shouldDuplicateFeaturedImages() {
|
||||
return (bool) Obj::pathOr( false, [ 'new_content_settings', 'duplicate_featured' ], Option::getOr( '_wpml_media', [] ) );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\Media\Translate\Endpoint;
|
||||
|
||||
use WPML\Ajax\IHandler;
|
||||
use WPML\Collect\Support\Collection;
|
||||
use function WPML\Container\make;
|
||||
use WPML\FP\Right;
|
||||
|
||||
class FinishMediaTranslation implements IHandler {
|
||||
public function run( Collection $data ) {
|
||||
make( \WPML_Media_Attachments_Duplication::class )->batch_mark_processed( false );
|
||||
return Right::of( true );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\Media\Translate\Endpoint;
|
||||
|
||||
use WPML\Ajax\IHandler;
|
||||
use WPML\Collect\Support\Collection;
|
||||
use function WPML\Container\make;
|
||||
use WPML\FP\Left;
|
||||
use WPML\FP\Right;
|
||||
use WPML\Media\Option;
|
||||
use WPML\Utilities\KeyedLock;
|
||||
|
||||
class PrepareForTranslation implements IHandler {
|
||||
const LOCK_RELEASE_TIMEOUT = 2 * MINUTE_IN_SECONDS;
|
||||
|
||||
public function run( Collection $data ) {
|
||||
if ( Option::isSetupFinished() ) {
|
||||
return Left::of( [ 'key' => false ] );
|
||||
}
|
||||
|
||||
$lock = make( KeyedLock::class, [ ':name' => self::class ] );
|
||||
$key = $lock->create( $data->get( 'key' ), self::LOCK_RELEASE_TIMEOUT );
|
||||
|
||||
if ( $key ) {
|
||||
make( \WPML_Media_Attachments_Duplication::class )->batch_scan_prepare( false );
|
||||
|
||||
return Right::of( [ 'key' => $key, ] );
|
||||
} else {
|
||||
return Left::of( [ 'key' => 'in-use', ] );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace WPML\Media\Translate\Endpoint;
|
||||
|
||||
use WPML\Ajax\IHandler;
|
||||
use WPML\Collect\Support\Collection;
|
||||
use function WPML\Container\make;
|
||||
use WPML\FP\Right;
|
||||
|
||||
class TranslateExistingMedia implements IHandler {
|
||||
public function run( Collection $data ) {
|
||||
return Right::of(
|
||||
make( \WPML_Media_Attachments_Duplication::class )->batch_translate_media( false )
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user