Skip to content

Commit 3857548

Browse files
author
pini-girit
committed
Initial Commit (After copying everything from the original 'cloudinary_magento' repository)
0 parents  commit 3857548

File tree

113 files changed

+6328
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+6328
-0
lines changed

.gitignore

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#==== OS / Editors / etc... ===================#
2+
.DS_Store
3+
.project
4+
.idea
5+
.phpintel
6+
*.sublime-*
7+
.directory
8+
.ftpconfig
9+
.tags
10+
.tags1
11+
Thumbs.db
12+
*Thumbs.db
13+
*.girit-local*
14+
*~
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace Cloudinary\Cloudinary\Api;
4+
5+
use Magento\Framework\Api\SearchResultsInterface;
6+
use Magento\Framework\Api\SearchCriteriaInterface;
7+
8+
interface SynchronisationRepositoryInterface
9+
{
10+
/**
11+
* @param SearchCriteriaInterface $searchCriteria
12+
* @return SearchResultsInterface
13+
*/
14+
public function getList(SearchCriteriaInterface $searchCriteria);
15+
16+
/**
17+
* @param string $imagePath
18+
*
19+
* @return SearchResultsInterface
20+
*/
21+
public function getListByImagePath($imagePath);
22+
}

Block/Adminhtml/Form/Field/Free.php

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
3+
namespace Cloudinary\Cloudinary\Block\Adminhtml\Form\Field;
4+
5+
use Magento\Backend\Block\Template\Context;
6+
use Magento\Config\Block\System\Config\Form\Field;
7+
use Magento\Framework\Data\Form\Element\AbstractElement;
8+
use Cloudinary\Cloudinary\Core\ConfigurationInterface;
9+
use Cloudinary\Cloudinary\Model\Config\Backend\Free as FreeBackendModel;
10+
11+
class Free extends Field
12+
{
13+
/**
14+
* @var ConfigurationInterface
15+
*/
16+
private $configuration;
17+
18+
/**
19+
* @var FreeBackendModel
20+
*/
21+
private $model;
22+
23+
/**
24+
* @param Context $context
25+
* @param ConfigurationInterface $configuration
26+
* @param FreeBackendModel $model
27+
* @param array $data
28+
*/
29+
public function __construct(
30+
Context $context,
31+
ConfigurationInterface $configuration,
32+
FreeBackendModel $model,
33+
array $data = []
34+
) {
35+
$this->configuration = $configuration;
36+
$this->model = $model;
37+
38+
parent::__construct($context, $data);
39+
}
40+
41+
/**
42+
* @return $this
43+
*/
44+
protected function _beforeToHtml()
45+
{
46+
$this->setTemplate('Cloudinary_Cloudinary::config/free.phtml');
47+
return $this;
48+
}
49+
50+
/**
51+
* @param AbstractElement $element
52+
* @return string
53+
*/
54+
protected function _getElementHtml(AbstractElement $element)
55+
{
56+
return sprintf(
57+
'%s%s',
58+
$element->getElementHtml(),
59+
$this->model->hasAccountConfigured() ? $this->toHtml() : ''
60+
);
61+
}
62+
}

Command/ResetAll.php

+174
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
<?php
2+
3+
namespace Cloudinary\Cloudinary\Command;
4+
5+
use Symfony\Component\Console\Command\Command;
6+
use Symfony\Component\Console\Input\InputInterface;
7+
use Symfony\Component\Console\Output\OutputInterface;
8+
use Symfony\Component\Console\Question\Question;
9+
use Symfony\Component\Console\Question\ConfirmationQuestion;
10+
use Symfony\Component\Console\Helper\QuestionHelper;
11+
use Magento\User\Model\UserFactory;
12+
use Magento\User\Model\User;
13+
use Cloudinary\Cloudinary\Helper\Reset;
14+
15+
class ResetAll extends Command
16+
{
17+
const DESCRIPTION = 'Removes all Cloudinary synchronisation data and ' .
18+
'resets all configuration back to the default settings.';
19+
const WARNING_FORMAT = '<fg=white;bg=red>%s</>';
20+
const PRE_ACTION_WARNING1 = 'This command will remove all Cloudinary synchronisation data and ' .
21+
'reset all configuration back to the default settings.';
22+
const PRE_ACTION_WARNING2 = 'This process cannot be reversed - we recommend that you backup ' .
23+
'your database before proceeding.';
24+
const PRE_ACTION_MESSAGES = [
25+
'In order for images to be served from Cloudinary after a reset, you will need to:',
26+
'* Clear configuration cache',
27+
'* Reconfigure module',
28+
'* Enable the module',
29+
'* Enable auto upload mapping or perform a manual migration'
30+
];
31+
const CONFIRM_MESSAGE = 'Continue with this action? (y/n) ';
32+
const ADMIN_NAME_REQUEST = 'Please enter your Magento administrator name: ';
33+
const ADMIN_USER_NOT_FOUND = 'Error - administrator account not found.';
34+
const ADMIN_PASSWORD_REQUEST = 'Please enter your Magento administrator password: ';
35+
const ADMIN_PASSWORD_INCORRECT = 'Error - incorrect administrator password.';
36+
const COMPLETE_MESSAGE1 = 'All Cloudinary module data has been reset.';
37+
const COMPLETE_MESSAGE2 = 'Please clear your configuration cache to ensure changes take effect.';
38+
39+
/**
40+
* @var UserFactory
41+
*/
42+
private $userFactory;
43+
44+
/**
45+
* @var Reset
46+
*/
47+
private $resetHelper;
48+
49+
50+
public function __construct(UserFactory $userFactory, Reset $resetHelper)
51+
{
52+
parent::__construct('cloudinary:reset');
53+
$this->userFactory = $userFactory;
54+
$this->resetHelper = $resetHelper;
55+
}
56+
57+
protected function configure()
58+
{
59+
$this->setDescription(self::DESCRIPTION);
60+
}
61+
62+
/**
63+
* @param InputInterface $input
64+
* @param OutputInterface $output
65+
*
66+
* @return void
67+
*/
68+
protected function execute(InputInterface $input, OutputInterface $output)
69+
{
70+
$this->displayPreActionMessage($output);
71+
72+
$helper = $this->getHelper('question');
73+
if (!$this->confirmActionStart($input, $output, $helper)) {
74+
return;
75+
}
76+
77+
$adminUser = $this->getAdminUser($this->readAdminName($input, $output, $helper));
78+
if (!$adminUser->getId()) {
79+
$output->writeln(self::ADMIN_USER_NOT_FOUND);
80+
return;
81+
}
82+
83+
$adminPassword = $this->readAdminPassword($input, $output, $helper);
84+
if (!$this->authenticate($adminUser, $adminPassword)) {
85+
$output->writeln(self::ADMIN_PASSWORD_INCORRECT);
86+
return;
87+
}
88+
89+
$this->resetHelper->resetModule();
90+
91+
$output->writeln(self::COMPLETE_MESSAGE1);
92+
$output->writeln(self::COMPLETE_MESSAGE2);
93+
}
94+
95+
/**
96+
* @param OutputInterface $output
97+
*/
98+
private function displayPreActionMessage(OutputInterface $output)
99+
{
100+
$output->writeln(sprintf(self::WARNING_FORMAT, self::PRE_ACTION_WARNING1));
101+
$output->writeln(sprintf(self::WARNING_FORMAT, self::PRE_ACTION_WARNING2));
102+
103+
array_map(
104+
function($line) use ($output) {
105+
$output->writeln(sprintf('<comment>%s</comment>', $line));
106+
},
107+
self::PRE_ACTION_MESSAGES
108+
);
109+
}
110+
111+
/**
112+
* @param InputInterface $input
113+
* @param OutputInterface $output
114+
* @param QuestionHelper $helper
115+
* @return bool
116+
*/
117+
private function confirmActionStart(InputInterface $input, OutputInterface $output, QuestionHelper $helper)
118+
{
119+
$confirmationQuestion = new ConfirmationQuestion(self::CONFIRM_MESSAGE, false);
120+
121+
return (bool)$helper->ask($input, $output, $confirmationQuestion);
122+
}
123+
124+
/**
125+
* @param InputInterface $input
126+
* @param OutputInterface $output
127+
* @param QuestionHelper $helper
128+
* @return string
129+
*/
130+
private function readAdminName(InputInterface $input, OutputInterface $output, QuestionHelper $helper)
131+
{
132+
$nameQuestion = new Question(self::ADMIN_NAME_REQUEST);
133+
$response = $helper->ask($input, $output, $nameQuestion);
134+
return is_string($response) ? $response : '';
135+
}
136+
137+
/**
138+
* @param string $username
139+
* @return User
140+
*/
141+
private function getAdminUser($username)
142+
{
143+
return $this->userFactory->create()->loadByUsername($username);
144+
}
145+
146+
/**
147+
* @param InputInterface $input
148+
* @param OutputInterface $output
149+
* @param QuestionHelper $helper
150+
* @return string
151+
*/
152+
private function readAdminPassword(InputInterface $input, OutputInterface $output, QuestionHelper $helper)
153+
{
154+
$passwordQuestion = new Question(self::ADMIN_PASSWORD_REQUEST);
155+
$passwordQuestion->setHidden(true);
156+
$response = $helper->ask($input, $output, $passwordQuestion);
157+
return is_string($response) ? $response : '';
158+
}
159+
160+
/**
161+
* @param User $user
162+
* @param string $password
163+
* @return bool
164+
*/
165+
private function authenticate(User $user, $password)
166+
{
167+
try {
168+
return $user->verifyIdentity($password);
169+
} catch (\Exception $e) {
170+
}
171+
172+
return false;
173+
}
174+
}

Command/StopMigration.php

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
namespace Cloudinary\Cloudinary\Command;
4+
5+
use Cloudinary\Cloudinary\Model\MigrationTask;
6+
use Symfony\Component\Console\Command\Command;
7+
use Symfony\Component\Console\Input\InputInterface;
8+
use Symfony\Component\Console\Output\OutputInterface;
9+
10+
class StopMigration extends Command
11+
{
12+
const NOP_MESSAGE = 'No upload running to stop.';
13+
const STOPPED_MESSAGE = 'Upload manually stopped.';
14+
15+
/**
16+
* @var MigrationTask
17+
*/
18+
private $migrationTask;
19+
20+
/**
21+
* @param MigrationTask $migrationTask
22+
*/
23+
public function __construct(MigrationTask $migrationTask)
24+
{
25+
parent::__construct('cloudinary:upload:stop');
26+
27+
$this->migrationTask = $migrationTask;
28+
}
29+
30+
/**
31+
* Configure the command
32+
*
33+
* @return void
34+
*/
35+
protected function configure()
36+
{
37+
$this->setDescription('Stops any currently running upload.');
38+
}
39+
40+
/**
41+
* @param InputInterface $input
42+
* @param OutputInterface $output
43+
*
44+
* @return void
45+
*/
46+
protected function execute(InputInterface $input, OutputInterface $output)
47+
{
48+
if ($this->migrationTask->hasStarted()) {
49+
$this->migrationTask->stop();
50+
$output->writeln(self::STOPPED_MESSAGE);
51+
} else {
52+
$output->writeln(self::NOP_MESSAGE);
53+
}
54+
}
55+
}

Command/UploadImages.php

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
namespace Cloudinary\Cloudinary\Command;
4+
5+
use Cloudinary\Cloudinary\Model\BatchUploader;
6+
use Cloudinary\Cloudinary\Model\Logger\OutputLogger;
7+
use Symfony\Component\Console\Command\Command;
8+
use Symfony\Component\Console\Input\InputInterface;
9+
use Symfony\Component\Console\Output\OutputInterface;
10+
11+
class UploadImages extends Command
12+
{
13+
/**
14+
* @var BatchUploader
15+
*/
16+
private $batchUploader;
17+
18+
/**
19+
* @var OutputLogger
20+
*/
21+
private $outputLogger;
22+
23+
/**
24+
* @param BatchUploader $batchUploader
25+
*/
26+
public function __construct(BatchUploader $batchUploader, OutputLogger $outputLogger)
27+
{
28+
parent::__construct('cloudinary:upload:all');
29+
30+
$this->batchUploader = $batchUploader;
31+
$this->outputLogger = $outputLogger;
32+
}
33+
34+
/**
35+
* Configure the command
36+
*
37+
* @return void
38+
*/
39+
protected function configure()
40+
{
41+
$this->setName('cloudinary:upload:all');
42+
$this->setDescription('Upload unsynchronised images');
43+
}
44+
45+
/**
46+
* @param InputInterface $input
47+
* @param OutputInterface $output
48+
*
49+
* @return void
50+
*/
51+
protected function execute(InputInterface $input, OutputInterface $output)
52+
{
53+
try {
54+
$this->outputLogger->setOutput($output);
55+
$this->batchUploader->uploadUnsynchronisedImages($this->outputLogger);
56+
} catch (\Exception $e) {
57+
$output->writeln($e->getMessage());
58+
}
59+
}
60+
}

0 commit comments

Comments
 (0)