Skip to content

Commit

Permalink
Merge pull request #17 from lizardmedia/major-refactor
Browse files Browse the repository at this point in the history
Major refactor
  • Loading branch information
krzysztofkuzniar authored Jan 27, 2020
2 parents 1000006 + cc536b0 commit ac8836d
Show file tree
Hide file tree
Showing 48 changed files with 496 additions and 403 deletions.
17 changes: 14 additions & 3 deletions Api/ProgressHandler/ProgressDataInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,20 @@
*/
interface ProgressDataInterface
{
const FIELD_CURRENT = 'current';
const FIELD_TOTAL = 'total';
const FIELD_PROCESS_TYPE = 'process_type';
/**
* @var string
*/
public const FIELD_CURRENT = 'current';

/**
* @var string
*/
public const FIELD_TOTAL = 'total';

/**
* @var string
*/
public const FIELD_PROCESS_TYPE = 'process_type';

/**
* @return int|null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
declare(strict_types=1);

/**
* File:VarnishPurgerInterface.php
* File:VarnishActionManagerInterface.php
*
* @author Maciej Sławik <[email protected]>
* @copyright Copyright (C) 2019 Lizard Media (http://lizardmedia.pl)
Expand All @@ -13,10 +13,10 @@
use Magento\Catalog\Api\Data\ProductInterface;

/**
* Interface VarnishPurgerInterface
* Interface VarnishActionManagerInterface
* @package LizardMedia\VarnishWarmer\Api
*/
interface VarnishPurgerInterface
interface VarnishActionManagerInterface
{
/**
* Purge *
Expand Down
19 changes: 12 additions & 7 deletions Block/Adminhtml/PurgeMultiple/Form.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

/**
* File: Form.php
*
Expand All @@ -14,13 +17,15 @@
/**
* Class Form
* @package LizardMedia\VarnishWarmer\Block\PurgeMultiple\Form
* @codeCoverageIgnore
*/
class Form extends Container
{
/**
* @return null
* @return void
* @SuppressWarnings(PHPMD.CamelCaseMethodName)
*/
protected function _construct()
protected function _construct(): void
{
$this->_blockGroup = 'LizardMedia_VarnishWarmer';
$this->_controller = 'adminhtml_purgeMultiple_form';
Expand All @@ -34,15 +39,15 @@ protected function _construct()
/**
* @return Phrase
*/
public function getHeaderText()
public function getHeaderText(): Phrase
{
return __('Varnish: purge a group of URLs');
}

/**
* @return null
* @return void
*/
private function updateSaveButton()
private function updateSaveButton(): void
{
$this->buttonList->update(
'save',
Expand All @@ -52,9 +57,9 @@ private function updateSaveButton()
}

/**
* @return null
* @return void
*/
private function removeButtons()
private function removeButtons(): void
{
$this->buttonList->remove('delete');
$this->buttonList->remove('back');
Expand Down
21 changes: 14 additions & 7 deletions Block/Adminhtml/PurgeMultiple/Form/Edit/Form.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

/**
* File: Form.php
*
Expand All @@ -20,18 +23,20 @@
/**
* Class Form
* @package LizardMedia\VarnishWarmer\Block\Adminhtml\Form\PurgeMultiple
* @SuppressWarnings(PHPMD.LongVariable)
* @codeCoverageIgnore
*/
class Form extends Generic
{
/**
* @var string
*/
const PROCESS_URL_FORM_PARAM = 'process_url';
public const PROCESS_URL_FORM_PARAM = 'process_url';

/**
* @var string
*/
const STORE_VIEW_FORM_PARAM = 'store_id';
public const STORE_VIEW_FORM_PARAM = 'store_id';

/**
* @var Store
Expand Down Expand Up @@ -67,26 +72,28 @@ public function __construct(

/**
* @return void
* @SuppressWarnings(PHPMD.CamelCaseMethodName)
*/
protected function _construct()
protected function _construct(): void
{
parent::_construct();
$this->setId('purgemultiple_form');
$this->setTitle(__('Varnish: purge a group of URLs'));
}

/**
* @return WidgetForm
* @return Form
* @throws LocalizedException
* @SuppressWarnings(PHPMD.CamelCaseMethodName)
*/
protected function _prepareForm()
protected function _prepareForm(): self
{
/** @var \Magento\Framework\Data\Form $form */
$form = $this->_formFactory->create(
[
'data' => [
'id' => 'edit_form',
'action' => $this->getFormTargerUrl(),
'action' => $this->getFormTargetUrl(),
'method' => 'post'
]
]
Expand Down Expand Up @@ -135,7 +142,7 @@ protected function _prepareForm()
/**
* @return string
*/
private function getFormTargerUrl()
private function getFormTargetUrl(): string
{
return $this->_urlBuilder->getUrl('lizardmediavarnish/purgemultiple/run');
}
Expand Down
19 changes: 12 additions & 7 deletions Block/Adminhtml/PurgeSingle/Form.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

/**
* File: Form.php
*
Expand All @@ -14,13 +17,15 @@
/**
* Class Form
* @package LizardMedia\VarnishWarmer\Block\Adminhtml\Form
* @codeCoverageIgnore
*/
class Form extends Container
{
/**
* @return null
* @return void
* @SuppressWarnings(PHPMD.CamelCaseMethodName)
*/
protected function _construct()
protected function _construct(): void
{
$this->_blockGroup = 'LizardMedia_VarnishWarmer';
$this->_controller = 'adminhtml_purgeSingle_form';
Expand All @@ -34,15 +39,15 @@ protected function _construct()
/**
* @return Phrase
*/
public function getHeaderText()
public function getHeaderText(): Phrase
{
return __('Varnish: purge single URL');
}

/**
* @return null
* @return void
*/
private function updateSaveButton()
private function updateSaveButton(): void
{
$this->buttonList->update(
'save',
Expand All @@ -52,9 +57,9 @@ private function updateSaveButton()
}

/**
* @return null
* @return void
*/
private function removeButtons()
private function removeButtons(): void
{
$this->buttonList->remove('delete');
$this->buttonList->remove('back');
Expand Down
23 changes: 14 additions & 9 deletions Block/Adminhtml/PurgeSingle/Form/Edit/Form.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

/**
* File: Form.php
*
Expand All @@ -9,7 +12,6 @@
namespace LizardMedia\VarnishWarmer\Block\Adminhtml\PurgeSingle\Form\Edit;

use Magento\Backend\Block\Template\Context;
use Magento\Backend\Block\Widget\Form as WidgetForm;
use Magento\Backend\Block\Widget\Form\Generic;
use Magento\Framework\Data\FormFactory;
use Magento\Framework\Exception\LocalizedException;
Expand All @@ -19,23 +21,24 @@
/**
* Class Form
* @package LizardMedia\VarnishWarmer\Block\Adminhtml\PurgeSingle\Form\Edit
* @codeCoverageIgnore
*/
class Form extends Generic
{
/**
* @var string
*/
const URL_FORM_PARAM = 'url';
public const URL_FORM_PARAM = 'url';

/**
* @var string
*/
const STORE_VIEW_FORM_PARAM = 'store_id';
public const STORE_VIEW_FORM_PARAM = 'store_id';

/**
* @var string
*/
const FORCE_PURGE_FORM_PARAM = 'force_purge';
public const FORCE_PURGE_FORM_PARAM = 'force_purge';

/**
* @var Store
Expand Down Expand Up @@ -63,26 +66,28 @@ public function __construct(

/**
* @return void
* @SuppressWarnings(PHPMD.CamelCaseMethodName)
*/
protected function _construct()
protected function _construct(): void
{
parent::_construct();
$this->setId('purgesingle_form');
$this->setTitle(__('Varnish: purge single URL'));
}

/**
* @return WidgetForm
* @return Form
* @throws LocalizedException
* @SuppressWarnings(PHPMD.CamelCaseMethodName)
*/
protected function _prepareForm()
protected function _prepareForm(): self
{
/** @var \Magento\Framework\Data\Form $form */
$form = $this->_formFactory->create(
[
'data' => [
'id' => 'edit_form',
'action' => $this->getFormTargerUrl(),
'action' => $this->getFormTargetUrl(),
'method' => 'post'
]
]
Expand Down Expand Up @@ -142,7 +147,7 @@ protected function _prepareForm()
/**
* @return string
*/
private function getFormTargerUrl()
private function getFormTargetUrl(): string
{
return $this->_urlBuilder->getUrl('lizardmediavarnish/purgesingle/run');
}
Expand Down
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
### 2.1. ###
* fix for incorrect method for purging process
* adding logging for error request
* minor refactor
* minor refactor

### 2.2 ###
* major refactor
* adding missing return types/types hints
* support PHP 7.3
* fix for case when urls uses store codes inside after domain
27 changes: 20 additions & 7 deletions Console/Command/AbstractPurgeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

namespace LizardMedia\VarnishWarmer\Console\Command;

use LizardMedia\VarnishWarmer\Api\VarnishPurgerInterface;
use LizardMedia\VarnishWarmer\Api\VarnishActionManagerInterface;
use Symfony\Component\Console\Command\Command;
use Magento\Framework\App\State;
use Symfony\Component\Console\Input\InputInterface;

/**
* Class AbstractPurgeCommand
Expand All @@ -27,20 +27,33 @@ class AbstractPurgeCommand extends Command
protected const STORE_VIEW_ID = 'store';

/**
* @var VarnishPurgerInterface
* @var VarnishActionManagerInterface
*/
protected $varnishPurger;
protected $varnishActionManager;

/**
* AbstractPurgeCommand constructor.
* @param VarnishPurgerInterface $varnishPurger
* @param VarnishActionManagerInterface $varnishActionManager
* @param null $name
*/
public function __construct(
VarnishPurgerInterface $varnishPurger,
VarnishActionManagerInterface $varnishActionManager,
$name = null
) {
parent::__construct($name);
$this->varnishPurger = $varnishPurger;
$this->varnishActionManager = $varnishActionManager;
}

/**
* @param InputInterface $input
* @return void
*/
protected function passStoreViewIfSet(InputInterface $input): void
{
$storeViewId = $input->getOption(self::STORE_VIEW_ID);

if (!empty($storeViewId)) {
$this->varnishActionManager->setStoreViewId((int) $storeViewId);
}
}
}
Loading

0 comments on commit ac8836d

Please sign in to comment.