Skip to content

Commit 8e15dac

Browse files
committed
Add Ignore-Synchronization Option to Cloudinary Download Command
1 parent d00b6f2 commit 8e15dac

5 files changed

Lines changed: 23 additions & 7 deletions

File tree

Command/DownloadImages.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,15 @@ class DownloadImages extends Command
2121
const OVERRIDE = 'override';
2222
const FORCE = 'force';
2323
const ENV = 'env';
24+
const IGNORE_SYNC = 'ignore-synchronization';
2425
/**#@- */
2526

2627
const OVERRIDE_CONFIRM_MESSAGE = "<question>Are you sure you want to override local files (y/n)[n]?</question>";
2728

2829
private $_override = false;
2930

31+
private $_ignoreSync = false;
32+
3033
/**
3134
* @var ObjectManagerInterface
3235
*/
@@ -73,7 +76,7 @@ public function __construct(
7376
protected function configure()
7477
{
7578
$this->setName('cloudinary:download:all');
76-
$this->setDescription('Download images from Cloudinary to the local pub/media dir');
79+
$this->setDescription('Download images from Cloudinary to the local pub/media dir. Optionally, ignore synchronization state and download everything');
7780
$this->setDefinition([
7881
new InputOption(
7982
self::OVERRIDE,
@@ -94,6 +97,12 @@ protected function configure()
9497
'Cloudinary environment variable that will be used during the process',
9598
null
9699
),
100+
new InputOption(
101+
self::IGNORE_SYNC,
102+
'-i',
103+
InputOption::VALUE_NONE,
104+
'Ignore synchronization state and download all images',
105+
)
97106
]);
98107
}
99108

@@ -119,8 +128,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
119128
if ($input->getOption(self::FORCE)) {
120129
$this->coreRegistry->register(Configuration::CONFIG_PATH_ENABLED, true);
121130
}
131+
if ($input->getOption(self::IGNORE_SYNC)) {
132+
$this->_ignoreSync = true;
133+
}
122134
$this->outputLogger->setOutput($output);
123-
$this->batchDownloader->downloadUnsynchronisedImages($this->outputLogger, $this->_override);
135+
$this->batchDownloader->downloadUnsynchronisedImages($this->outputLogger, $this->_override, $this->_ignoreSync);
124136

125137
return 1;
126138

Model/BatchDownloader.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ private function _authorise()
178178
* @return bool
179179
* @throws \Exception
180180
*/
181-
public function downloadUnsynchronisedImages(?OutputInterface $output = null, $override = false)
181+
public function downloadUnsynchronisedImages(?OutputInterface $output = null, $override = false, $ignoreSync = false)
182182
{
183183
if (!$this->_configuration->isEnabled(false)) {
184184
throw new \Exception("Cloudinary seems to be disabled. Please enable it first or pass -f in order to force it on the CLI");
@@ -195,6 +195,10 @@ public function downloadUnsynchronisedImages(?OutputInterface $output = null, $o
195195
$baseMediaPath = $this->_directoryList->getPath(DirectoryList::MEDIA);
196196
$directoryInstance = $this->_fileSystem->getDirectoryWrite(DirectoryList::MEDIA);
197197

198+
if ($ignoreSync) {
199+
$this->displayMessage('<comment>== [Notice] == Process started with ignore-synchronization flag.</comment>');
200+
}
201+
198202
//= Checking migration lock / Start migration
199203
if (!$this->validateMigrationLock()) {
200204
return false;
@@ -265,7 +269,7 @@ public function downloadUnsynchronisedImages(?OutputInterface $output = null, $o
265269

266270
//Flagging as syncronized
267271
$resource->setImage(Image::fromPath($localFilePath, $localFileName));
268-
if ($resource->getImage()->getRelativePath() && !$this->_synchronizationChecker->isSynchronized($resource->getImage()->getRelativePath())) {
272+
if ($ignoreSync || $resource->getImage()->getRelativePath() && !$this->_synchronizationChecker->isSynchronized($resource->getImage()->getRelativePath())) {
269273
$this->displayMessage('<comment>=== [Processing] Flagging As Syncronized...</comment>');
270274
$this->_synchronisationRepository->saveAsSynchronized($resource->getImage()->getRelativePath());
271275
} else {

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "cloudinary/cloudinary-magento2",
33
"description": "Cloudinary Magento 2 Integration.",
44
"type": "magento2-module",
5-
"version": "2.0.2",
5+
"version": "2.1.1",
66
"license": "MIT",
77
"require": {
88
"php": ">=7.3",

etc/module.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0"?>
22
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
3-
<module name="Cloudinary_Cloudinary" setup_version="2.0.2">
3+
<module name="Cloudinary_Cloudinary" setup_version="2.1.1">
44
<sequence>
55
<module name="Magento_ProductVideo"/>
66
<module name="Magento_PageBuilder"/>

view/frontend/requirejs-config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ var config = {
99
},
1010
paths: {
1111
'jquery.lazyload': "Cloudinary_Cloudinary/js/jquery.lazyload.min",
12-
cloudinaryProductGalleryAll: "//product-gallery.cloudinary.com/all"
12+
cloudinaryProductGalleryAll: "//product-gallery.cloudinary.com/latest/all"
1313
},
1414
shim: {
1515
'jquery.lazyload': {

0 commit comments

Comments
 (0)