Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Maintenance] refactor to use new maintenance task from pimcore 5.8 #986

Merged
merged 1 commit into from
May 9, 2019
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@
* @license https://www.coreshop.org/license GNU General Public License version 3 (GPLv3)
*/

namespace CoreShop\Bundle\CoreBundle\EventListener\Order\Expire;
namespace CoreShop\Bundle\CoreBundle\Maintenance;

use CoreShop\Bundle\OrderBundle\Expiration\ProposalExpirationInterface;
use CoreShop\Component\Core\Configuration\ConfigurationServiceInterface;
use Pimcore\Event\System\MaintenanceEvent;
use Pimcore\Model\Schedule\Maintenance\Job;
use Pimcore\Maintenance\TaskInterface;

final class ProposalExpireMaintenanceManagerListener
final class ProposalExpireTask implements TaskInterface
{
/**
* @var ConfigurationServiceInterface
Expand Down Expand Up @@ -47,36 +46,37 @@ final class ProposalExpireMaintenanceManagerListener
/**
* @param ConfigurationServiceInterface $configurationService
* @param ProposalExpirationInterface $proposalExpiration
* @param string $type
* @param int $days
* @param array $params
*/
public function __construct(ConfigurationServiceInterface $configurationService, ProposalExpirationInterface $proposalExpiration, $type, $days = 0, $params = [])
{
public function __construct(
ConfigurationServiceInterface $configurationService,
ProposalExpirationInterface $proposalExpiration,
string $type,
int $days = 0,
array $params = []
) {
$this->configurationService = $configurationService;
$this->proposalExpiration = $proposalExpiration;
$this->type = $type;
$this->days = $days;
$this->params = $params;
}

/**
* @param MaintenanceEvent $maintenanceEvent
*/
public function registerExpire(MaintenanceEvent $maintenanceEvent)
public function execute()
{
$lastMaintenance = $this->configurationService->get(sprintf('system.%s.expire.last_run', $this->type));

if (is_null($lastMaintenance)) {
if (null === $lastMaintenance) {
$lastMaintenance = time() - 90000; //t-25h
}

$timeDiff = time() - $lastMaintenance;

//since maintenance runs every 5 minutes, we need to check if the last update was 24 hours ago
if ($timeDiff > 24 * 60 * 60) {
$manager = $maintenanceEvent->getManager();

$manager->registerJob(new Job(sprintf('coreshop.%s.expire', $this->type), [$this->proposalExpiration, 'expire'], [$this->days, $this->params]));
$this->proposalExpiration->expire($this->days, $this->params);

$this->configurationService->set(sprintf('system.%s.expire.last_run', $this->type), time());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@
* @license https://www.coreshop.org/license GNU General Public License version 3 (GPLv3)
*/

namespace CoreShop\Bundle\CoreBundle\EventListener\Rule;
namespace CoreShop\Bundle\CoreBundle\Maintenance;

use CoreShop\Bundle\RuleBundle\Processor\RuleAvailabilityProcessorInterface;
use CoreShop\Component\Core\Configuration\ConfigurationServiceInterface;
use Pimcore\Event\System\MaintenanceEvent;
use Pimcore\Model\Schedule\Maintenance\Job;
use Pimcore\Maintenance\TaskInterface;

final class AvailabilityCheckMaintenanceListener
final class RuleAvailabilityTask implements TaskInterface
{
/**
* @var ConfigurationServiceInterface
Expand All @@ -41,23 +40,19 @@ public function __construct(
$this->ruleAvailabilityProcessor = $ruleAvailabilityProcessor;
}

/**
* @param MaintenanceEvent $maintenanceEvent
*/
public function registerAvailabilityCheck(MaintenanceEvent $maintenanceEvent)
public function execute()
{
$lastMaintenance = $this->configurationService->get('system.rule.availability_check.last_run');

if (is_null($lastMaintenance)) {
if (null === $lastMaintenance) {
$lastMaintenance = time() - 90000; //t-25h
}

$timeDiff = time() - $lastMaintenance;

//since maintenance runs every 5 minutes, we need to check if the last update was 24 hours ago
if ($timeDiff > 24 * 60 * 60) {
$manager = $maintenanceEvent->getManager();
$manager->registerJob(new Job('coreshop.rule.availability_check', [$this->ruleAvailabilityProcessor, 'process']));
$this->ruleAvailabilityProcessor->process();
$this->configurationService->set('system.rule.availability_check.last_run', time());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,27 +52,27 @@ services:
arguments:
- '@coreshop.core.order_shipment.transformer.order_item_to_shipment_item.inner'

coreshop.cart.expire.maintenance_listener:
class: CoreShop\Bundle\CoreBundle\EventListener\Order\Expire\ProposalExpireMaintenanceManagerListener
coreshop.maintenance.cart.expire_task:
class: CoreShop\Bundle\CoreBundle\Maintenance\ProposalExpireTask
arguments:
- '@coreshop.configuration.service'
- '@coreshop.cart.expire'
- 'cart'
- '%coreshop.cart.expiration.days%'
- { anonymous: '%coreshop.cart.expiration.anonymous%', customer: '%coreshop.cart.expiration.customer%'}
tags:
- { name: kernel.event_listener, event: pimcore.system.maintenance, method: registerExpire }
- { name: pimcore.maintenance.task, type: coreshop_expire_carts }

coreshop.order.expire.maintenance_listener:
class: CoreShop\Bundle\CoreBundle\EventListener\Order\Expire\ProposalExpireMaintenanceManagerListener
coreshop.maintenance.order.expire_task:
class: CoreShop\Bundle\CoreBundle\Maintenance\ProposalExpireTask
arguments:
- '@coreshop.configuration.service'
- '@coreshop.order.expire'
- 'order'
- '%coreshop.order.expiration.days%'
- []
tags:
- { name: kernel.event_listener, event: pimcore.system.maintenance, method: registerExpire }
- { name: pimcore.maintenance.task, type: coreshop_expire_orders }

coreshop.order.number_generator.prefix_suffix:
class: CoreShop\Component\Core\Order\NumberGenerator\SaleNumberGenerator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,13 @@ services:
alias: coreshop.cart_price_rule.cart_rule_applier

# Rules Availability Check
coreshop.rule_availability_assessor.maintenance_listener:
class: CoreShop\Bundle\CoreBundle\EventListener\Rule\AvailabilityCheckMaintenanceListener
coreshop.maintenance.rule_availability_task:
class: CoreShop\Bundle\CoreBundle\Maintenance\RuleAvailabilityTask
arguments:
- '@coreshop.configuration.service'
- '@coreshop.rule_availability_processor'
tags:
- { name: kernel.event_listener, event: pimcore.system.maintenance, method: registerAvailabilityCheck }
- { name: pimcore.maintenance.task, type: coreshop_rule_availability }

coreshop.templating.helper.product_valid_rules:
class: CoreShop\Bundle\CoreBundle\Templating\Helper\ValidPriceRulesHelper
Expand Down