Skip to content

Commit

Permalink
Merge branch '2.3-develop' into 3rd-party-dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammedsalem authored Mar 13, 2018
2 parents 50c16e0 + 726a5c9 commit c642334
Show file tree
Hide file tree
Showing 28 changed files with 1,216 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

use Magento\Framework\App\Filesystem\DirectoryList;

/**
* Delete image files.
*/
class DeleteFiles extends \Magento\Cms\Controller\Adminhtml\Wysiwyg\Images
{
/**
Expand All @@ -19,29 +22,40 @@ class DeleteFiles extends \Magento\Cms\Controller\Adminhtml\Wysiwyg\Images
*/
protected $resultRawFactory;

/**
* @var \Magento\Framework\App\Filesystem\DirectoryResolver
*/
private $directoryResolver;

/**
* Constructor
*
* @param \Magento\Backend\App\Action\Context $context
* @param \Magento\Framework\Registry $coreRegistry
* @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
* @param \Magento\Framework\Controller\Result\RawFactory $resultRawFactory
* @param \Magento\Framework\App\Filesystem\DirectoryResolver|null $directoryResolver
*/
public function __construct(
\Magento\Backend\App\Action\Context $context,
\Magento\Framework\Registry $coreRegistry,
\Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory,
\Magento\Framework\Controller\Result\RawFactory $resultRawFactory
\Magento\Framework\Controller\Result\RawFactory $resultRawFactory,
\Magento\Framework\App\Filesystem\DirectoryResolver $directoryResolver = null
) {
parent::__construct($context, $coreRegistry);

$this->resultRawFactory = $resultRawFactory;
$this->resultJsonFactory = $resultJsonFactory;
parent::__construct($context, $coreRegistry);
$this->directoryResolver = $directoryResolver
?: $this->_objectManager->get(\Magento\Framework\App\Filesystem\DirectoryResolver::class);
}

/**
* Delete file from media storage
* Delete file from media storage.
*
* @return \Magento\Framework\Controller\ResultInterface
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function execute()
{
Expand All @@ -54,6 +68,11 @@ public function execute()
/** @var $helper \Magento\Cms\Helper\Wysiwyg\Images */
$helper = $this->_objectManager->get(\Magento\Cms\Helper\Wysiwyg\Images::class);
$path = $this->getStorage()->getSession()->getCurrentPath();
if (!$this->directoryResolver->validatePath($path, DirectoryList::MEDIA)) {
throw new \Magento\Framework\Exception\LocalizedException(
__('Directory %1 is not under storage root path.', $path)
);
}
foreach ($files as $file) {
$file = $helper->idDecode($file);
/** @var \Magento\Framework\Filesystem $filesystem */
Expand All @@ -64,11 +83,13 @@ public function execute()
$this->getStorage()->deleteFile($filePath);
}
}

return $this->resultRawFactory->create();
} catch (\Exception $e) {
$result = ['error' => true, 'message' => $e->getMessage()];
/** @var \Magento\Framework\Controller\Result\Json $resultJson */
$resultJson = $this->resultJsonFactory->create();

return $resultJson->setData($result);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
*/
namespace Magento\Cms\Controller\Adminhtml\Wysiwyg\Images;

use Magento\Framework\App\Filesystem\DirectoryList;

/**
* Delete image folder.
*/
class DeleteFolder extends \Magento\Cms\Controller\Adminhtml\Wysiwyg\Images
{
/**
Expand All @@ -18,38 +23,55 @@ class DeleteFolder extends \Magento\Cms\Controller\Adminhtml\Wysiwyg\Images
*/
protected $resultRawFactory;

/**
* @var \Magento\Framework\App\Filesystem\DirectoryResolver
*/
private $directoryResolver;

/**
* @param \Magento\Backend\App\Action\Context $context
* @param \Magento\Framework\Registry $coreRegistry
* @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
* @param \Magento\Framework\Controller\Result\RawFactory $resultRawFactory
* @param \Magento\Framework\App\Filesystem\DirectoryResolver|null $directoryResolver
*/
public function __construct(
\Magento\Backend\App\Action\Context $context,
\Magento\Framework\Registry $coreRegistry,
\Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory,
\Magento\Framework\Controller\Result\RawFactory $resultRawFactory
\Magento\Framework\Controller\Result\RawFactory $resultRawFactory,
\Magento\Framework\App\Filesystem\DirectoryResolver $directoryResolver = null
) {
parent::__construct($context, $coreRegistry);
$this->resultRawFactory = $resultRawFactory;
$this->resultJsonFactory = $resultJsonFactory;
parent::__construct($context, $coreRegistry);
$this->directoryResolver = $directoryResolver
?: $this->_objectManager->get(\Magento\Framework\App\Filesystem\DirectoryResolver::class);
}

/**
* Delete folder action
* Delete folder action.
*
* @return \Magento\Framework\Controller\ResultInterface
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function execute()
{
try {
$path = $this->getStorage()->getCmsWysiwygImages()->getCurrentPath();
if (!$this->directoryResolver->validatePath($path, DirectoryList::MEDIA)) {
throw new \Magento\Framework\Exception\LocalizedException(
__('Directory %1 is not under storage root path.', $path)
);
}
$this->getStorage()->deleteDirectory($path);

return $this->resultRawFactory->create();
} catch (\Exception $e) {
$result = ['error' => true, 'message' => $e->getMessage()];
/** @var \Magento\Framework\Controller\Result\Json $resultJson */
$resultJson = $this->resultJsonFactory->create();

return $resultJson->setData($result);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,65 @@
*/
namespace Magento\Cms\Controller\Adminhtml\Wysiwyg\Images;

use Magento\Framework\App\Filesystem\DirectoryList;

/**
* Creates new folder.
*/
class NewFolder extends \Magento\Cms\Controller\Adminhtml\Wysiwyg\Images
{
/**
* @var \Magento\Framework\Controller\Result\JsonFactory
*/
protected $resultJsonFactory;

/**
* @var \Magento\Framework\App\Filesystem\DirectoryResolver
*/
private $directoryResolver;

/**
* @param \Magento\Backend\App\Action\Context $context
* @param \Magento\Framework\Registry $coreRegistry
* @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
* @param \Magento\Framework\App\Filesystem\DirectoryResolver|null $directoryResolver
*/
public function __construct(
\Magento\Backend\App\Action\Context $context,
\Magento\Framework\Registry $coreRegistry,
\Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
\Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory,
\Magento\Framework\App\Filesystem\DirectoryResolver $directoryResolver = null
) {
$this->resultJsonFactory = $resultJsonFactory;
parent::__construct($context, $coreRegistry);
$this->resultJsonFactory = $resultJsonFactory;
$this->directoryResolver = $directoryResolver
?: $this->_objectManager->get(\Magento\Framework\App\Filesystem\DirectoryResolver::class);
}

/**
* New folder action
* New folder action.
*
* @return \Magento\Framework\Controller\ResultInterface
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function execute()
{
try {
$this->_initAction();
$name = $this->getRequest()->getPost('name');
$path = $this->getStorage()->getSession()->getCurrentPath();
if (!$this->directoryResolver->validatePath($path, DirectoryList::MEDIA)) {
throw new \Magento\Framework\Exception\LocalizedException(
__('Directory %1 is not under storage root path.', $path)
);
}
$result = $this->getStorage()->createDirectory($name, $path);
} catch (\Exception $e) {
$result = ['error' => true, 'message' => $e->getMessage()];
}
/** @var \Magento\Framework\Controller\Result\Json $resultJson */
$resultJson = $this->resultJsonFactory->create();

return $resultJson->setData($result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,64 @@
*/
namespace Magento\Cms\Controller\Adminhtml\Wysiwyg\Images;

use Magento\Framework\App\Filesystem\DirectoryList;

/**
* Upload image.
*/
class Upload extends \Magento\Cms\Controller\Adminhtml\Wysiwyg\Images
{
/**
* @var \Magento\Framework\Controller\Result\JsonFactory
*/
protected $resultJsonFactory;

/**
* @var \Magento\Framework\App\Filesystem\DirectoryResolver
*/
private $directoryResolver;

/**
* @param \Magento\Backend\App\Action\Context $context
* @param \Magento\Framework\Registry $coreRegistry
* @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
* @param \Magento\Framework\App\Filesystem\DirectoryResolver|null $directoryResolver
*/
public function __construct(
\Magento\Backend\App\Action\Context $context,
\Magento\Framework\Registry $coreRegistry,
\Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
\Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory,
\Magento\Framework\App\Filesystem\DirectoryResolver $directoryResolver = null
) {
$this->resultJsonFactory = $resultJsonFactory;
parent::__construct($context, $coreRegistry);
$this->resultJsonFactory = $resultJsonFactory;
$this->directoryResolver = $directoryResolver
?: $this->_objectManager->get(\Magento\Framework\App\Filesystem\DirectoryResolver::class);
}

/**
* Files upload processing
* Files upload processing.
*
* @return \Magento\Framework\Controller\ResultInterface
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function execute()
{
try {
$this->_initAction();
$targetPath = $this->getStorage()->getSession()->getCurrentPath();
$result = $this->getStorage()->uploadFile($targetPath, $this->getRequest()->getParam('type'));
$path = $this->getStorage()->getSession()->getCurrentPath();
if (!$this->directoryResolver->validatePath($path, DirectoryList::MEDIA)) {
throw new \Magento\Framework\Exception\LocalizedException(
__('Directory %1 is not under storage root path.', $path)
);
}
$result = $this->getStorage()->uploadFile($path, $this->getRequest()->getParam('type'));
} catch (\Exception $e) {
$result = ['error' => $e->getMessage(), 'errorcode' => $e->getCode()];
}
/** @var \Magento\Framework\Controller\Result\Json $resultJson */
$resultJson = $this->resultJsonFactory->create();

return $resultJson->setData($result);
}
}
14 changes: 11 additions & 3 deletions app/code/Magento/Cms/Helper/Wysiwyg/Images.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
use Magento\Framework\App\Filesystem\DirectoryList;

/**
* Wysiwyg Images Helper
* Wysiwyg Images Helper.
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class Images extends \Magento\Framework\App\Helper\AbstractHelper
{
Expand Down Expand Up @@ -156,17 +158,23 @@ public function convertPathToId($path)
}

/**
* Decode HTML element id
* Decode HTML element id.
*
* @param string $id
* @return string
* @throws \InvalidArgumentException When path contains restricted symbols.
*/
public function convertIdToPath($id)
{
if ($id === \Magento\Theme\Helper\Storage::NODE_ROOT) {
return $this->getStorageRoot();
} else {
return $this->getStorageRoot() . $this->idDecode($id);
$path = $this->getStorageRoot() . $this->idDecode($id);
if (preg_match('/\.\.(\\\|\/)/', $path)) {
throw new \InvalidArgumentException('Path is invalid');
}

return $path;
}
}

Expand Down
Loading

0 comments on commit c642334

Please sign in to comment.