Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 64 additions & 16 deletions Block/Adminhtml/Product/Edit/NewVideo.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,65 @@
*/
namespace Cloudinary\Cloudinary\Block\Adminhtml\Product\Edit;

use Cloudinary\Cloudinary\Core\ConfigurationBuilder;
use Cloudinary\Cloudinary\Core\ConfigurationInterface;
use Magento\Backend\Block\Template\Context;
use Magento\Framework\Data\FormFactory;
use Magento\Framework\Json\EncoderInterface;
use Magento\Framework\Registry;
use Magento\Framework\UrlInterface;
use Magento\ProductVideo\Helper\Media;

/**
* @SuppressWarnings(PHPMD.DepthOfInheritance)
*/
class NewVideo extends \Magento\ProductVideo\Block\Adminhtml\Product\Edit\NewVideo
{
/**
* @var array|null
*/
protected $_cloudinaryConfig;

/**
* @var \Cloudinary\Cloudinary\Core\ConfigurationBuilder
* @var ConfigurationInterface
*/
private $configuration;

/**
* @var ConfigurationBuilder
*/
protected $_cloudinaryConfigurationBuilder;

/**
* @param \Magento\Backend\Block\Template\Context $context
* @param \Magento\Framework\Registry $registry
* @param \Magento\Framework\Data\FormFactory $formFactory
* @param \Magento\ProductVideo\Helper\Media $mediaHelper
* @param \Magento\Framework\Json\EncoderInterface $jsonEncoder
* @param \Cloudinary\Cloudinary\Core\ConfigurationBuilder $cloudinaryConfigurationBuilder
* @param array $data
* @method __construct
* @param Context $context
* @param Registry $registry
* @param FormFactory $formFactory
* @param Media $mediaHelper
* @param EncoderInterface $jsonEncoder
* @param ConfigurationInterface $configuration
* @param ConfigurationBuilder $cloudinaryConfigurationBuilder
* @param array $data
*/
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Framework\Registry $registry,
\Magento\Framework\Data\FormFactory $formFactory,
\Magento\ProductVideo\Helper\Media $mediaHelper,
\Magento\Framework\Json\EncoderInterface $jsonEncoder,
\Cloudinary\Cloudinary\Core\ConfigurationBuilder $cloudinaryConfigurationBuilder,
Context $context,
Registry $registry,
FormFactory $formFactory,
Media $mediaHelper,
EncoderInterface $jsonEncoder,
ConfigurationInterface $configuration,
ConfigurationBuilder $cloudinaryConfigurationBuilder,
array $data = []
) {
parent::__construct($context, $registry, $formFactory, $mediaHelper, $jsonEncoder, $data);
parent::__construct(
$context,
$registry,
$formFactory,
$mediaHelper,
$jsonEncoder,
$data
);
$this->configuration = $configuration;
$this->_cloudinaryConfigurationBuilder = $cloudinaryConfigurationBuilder;
}

Expand Down Expand Up @@ -67,7 +95,7 @@ public function getWidgetOptions()
'htmlId' => $this->getHtmlId(),
'youTubeApiKey' => $this->mediaHelper->getYouTubeApiKey(),
'videoSelector' => $this->videoSelector,
'cloudinaryPlaceholder' => $this->getViewFileUrl('Cloudinary_Cloudinary::images/cloudinary_vertical_logo_for_white_bg.svg')
'cloudinaryPlaceholder' => $this->getPlaceholderUrl(),
]
);
}
Expand Down Expand Up @@ -110,4 +138,24 @@ protected function getCloudinaryConfigUrl()
]
);
}

/**
* @return string
*/
protected function getPlaceholderUrl()
{
$storeManager = $this->configuration->getStoreManager();
$configPaths = [
'catalog/placeholder/image_placeholder',
'catalog/placeholder/small_image_placeholder',
'thumbnail_placeholder',
];
foreach ($configPaths as $configPath) {
if (($path = $storeManager->getStore()->getConfig($configPath))) {
return $storeManager->getStore()->getBaseUrl(UrlInterface::URL_TYPE_MEDIA) . 'catalog/product/placeholder/' . $path;
break;
}
}
return $this->getViewFileUrl('Cloudinary_Cloudinary::images/cloudinary_cloud_glyph_blue.png');
}
}
19 changes: 14 additions & 5 deletions Command/DownloadImages.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Cloudinary\Cloudinary\Model\BatchDownloader;
use Cloudinary\Cloudinary\Model\Configuration;
use Cloudinary\Cloudinary\Model\Logger\OutputLogger;
use Magento\Framework\ObjectManagerInterface;
use Magento\Framework\Registry;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -27,9 +28,9 @@ class DownloadImages extends Command
private $_override = false;

/**
* @var BatchDownloader
* @var ObjectManagerInterface
*/
private $batchDownloader;
private $objectManager;

/**
* @var OutputLogger
Expand All @@ -41,20 +42,25 @@ class DownloadImages extends Command
*/
private $coreRegistry;

/**
* @var BatchDownloader
*/
private $batchDownloader;

/**
* @method __construct
* @param BatchDownloader $batchDownloader
* @param ObjectManagerInterface $objectManager
* @param OutputLogger $outputLogger
* @param Registry $coreRegistry
*/
public function __construct(
BatchDownloader $batchDownloader,
ObjectManagerInterface $objectManager,
OutputLogger $outputLogger,
Registry $coreRegistry
) {
parent::__construct('cloudinary:download:all');

$this->batchDownloader = $batchDownloader;
$this->objectManager = $objectManager;
$this->outputLogger = $outputLogger;
$this->coreRegistry = $coreRegistry;
}
Expand Down Expand Up @@ -100,6 +106,9 @@ protected function configure()
protected function execute(InputInterface $input, OutputInterface $output)
{
try {
$this->batchDownloader = $this->objectManager
->get(\Cloudinary\Cloudinary\Model\BatchDownloader::class);

if ($input->getOption(self::OVERRIDE) && $this->confirmQuestion(self::OVERRIDE_CONFIRM_MESSAGE, $input, $output)) {
$this->_override = true;
}
Expand Down
21 changes: 12 additions & 9 deletions Command/ProductGalleryApiQueueProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,37 @@

namespace Cloudinary\Cloudinary\Command;

use Cloudinary\Cloudinary\Cron\ProductGalleryApiQueue;
use Magento\Framework\App\State as AppState;
use Magento\Framework\ObjectManagerInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class ProductGalleryApiQueueProcess extends Command
{
/**
* @var AppState
* @var ObjectManagerInterface
*/
private $appState;
private $objectManager;

/**
* @var ProductGalleryApiQueue
* @var AppState
*/
private $job;
private $appState;

/**
* @method __construct
* @param ObjectManagerInterface $objectManager
* @param AppState $appState
* @param ProductGalleryApiQueue $job
*/
public function __construct(
AppState $appState,
ProductGalleryApiQueue $job
ObjectManagerInterface $objectManager,
AppState $appState
) {
parent::__construct('cloudinary:product-gallery-api-queue:process');

$this->objectManager = $objectManager;
$this->appState = $appState;
$this->job = $job;
}

/**
Expand All @@ -54,6 +54,9 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->job = $this->objectManager
->get(\Cloudinary\Cloudinary\Cron\ProductGalleryApiQueue::class);

$this->appState->setAreaCode(\Magento\Framework\App\Area::AREA_CRONTAB);
return $this->job
->setOutput($output)
Expand Down
33 changes: 24 additions & 9 deletions Command/ResetAll.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@

namespace Cloudinary\Cloudinary\Command;

use Cloudinary\Cloudinary\Helper\Reset;
use Magento\Framework\ObjectManagerInterface;
use Magento\User\Model\User;
use Magento\User\Model\UserFactory;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\Question;
use Symfony\Component\Console\Question\ConfirmationQuestion;
use Symfony\Component\Console\Helper\QuestionHelper;
use Magento\User\Model\UserFactory;
use Magento\User\Model\User;
use Cloudinary\Cloudinary\Helper\Reset;
use Symfony\Component\Console\Question\Question;

class ResetAll extends Command
{
Expand All @@ -36,6 +37,11 @@ class ResetAll extends Command
const COMPLETE_MESSAGE1 = 'All Cloudinary module data has been reset.';
const COMPLETE_MESSAGE2 = 'Please clear your configuration cache to ensure changes take effect.';

/**
* @var ObjectManagerInterface
*/
private $objectManager;

/**
* @var UserFactory
*/
Expand All @@ -46,12 +52,18 @@ class ResetAll extends Command
*/
private $resetHelper;


public function __construct(UserFactory $userFactory, Reset $resetHelper)
{
/**
* @method __construct
* @param ObjectManagerInterface $objectManager
* @param UserFactory $userFactory
*/
public function __construct(
ObjectManagerInterface $objectManager,
UserFactory $userFactory
) {
parent::__construct('cloudinary:reset');
$this->objectManager = $objectManager;
$this->userFactory = $userFactory;
$this->resetHelper = $resetHelper;
}

protected function configure()
Expand All @@ -67,6 +79,9 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->resetHelper = $this->objectManager
->get(\Cloudinary\Cloudinary\Helper\Reset::class);

$this->displayPreActionMessage($output);

$helper = $this->getHelper('question');
Expand Down
15 changes: 12 additions & 3 deletions Command/StopMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Cloudinary\Cloudinary\Command;

use Cloudinary\Cloudinary\Model\MigrationTask;
use Magento\Framework\ObjectManagerInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand All @@ -12,19 +13,24 @@ class StopMigration extends Command
const NOP_MESSAGE = 'No upload/download running to stop.';
const STOPPED_MESSAGE = 'Upload/Download manually stopped.';

/**
* @var ObjectManagerInterface
*/
private $objectManager;

/**
* @var MigrationTask
*/
private $migrationTask;

/**
* @param MigrationTask $migrationTask
* @param ObjectManagerInterface $objectManager
*/
public function __construct(MigrationTask $migrationTask)
public function __construct(ObjectManagerInterface $objectManager)
{
parent::__construct('cloudinary:migration:stop');

$this->migrationTask = $migrationTask;
$this->objectManager = $objectManager;
}

/**
Expand All @@ -45,6 +51,9 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->migrationTask = $this->objectManager
->get(\Cloudinary\Cloudinary\Model\MigrationTask::class);

if ($this->migrationTask->hasStarted()) {
$this->migrationTask->stop();
$output->writeln(self::STOPPED_MESSAGE);
Expand Down
Loading