Skip to content

Commit

Permalink
Add resave commands for elements
Browse files Browse the repository at this point in the history
  • Loading branch information
engram-design committed May 9, 2023
1 parent 1b0ee05 commit b668e9a
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions src/Events.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@

use Craft;
use craft\base\Plugin;
use craft\console\Application as ConsoleApplication;
use craft\console\Controller as ConsoleController;
use craft\console\controllers\ResaveController;
use craft\events\DefineConsoleActionsEvent;
use craft\events\PluginEvent;
use craft\events\RebuildConfigEvent;
use craft\events\RegisterComponentTypesEvent;
Expand Down Expand Up @@ -79,6 +83,10 @@ public function init()
$this->_registerVariables();
$this->_registerElementTypes();
$this->_registerPurchasableTypes();

if (Craft::$app->getRequest()->getIsConsoleRequest()) {
$this->_registerResaveCommand();
}
}

public function getPluginName()
Expand Down Expand Up @@ -281,4 +289,53 @@ private function _registerThirdPartyEventListeners()
}
}

private function _registerResaveCommand()
{
if (!Craft::$app instanceof ConsoleApplication) {
return;
}

Event::on(ResaveController::class, ConsoleController::EVENT_DEFINE_ACTIONS, function(DefineConsoleActionsEvent $e) {
$e->actions['events-events'] = [
'action' => function(): int {
$controller = Craft::$app->controller;

return $controller->resaveElements(EventElement::class);
},
'options' => [],
'helpSummary' => 'Re-saves Events events.',
];

$e->actions['events-tickets'] = [
'action' => function(): int {
$controller = Craft::$app->controller;

return $controller->resaveElements(Ticket::class);
},
'options' => [],
'helpSummary' => 'Re-saves Events tickets.',
];

$e->actions['events-tickettypes'] = [
'action' => function(): int {
$controller = Craft::$app->controller;

return $controller->resaveElements(TicketType::class);
},
'options' => [],
'helpSummary' => 'Re-saves Events ticket types.',
];

$e->actions['events-purchasedtickets'] = [
'action' => function(): int {
$controller = Craft::$app->controller;

return $controller->resaveElements(PurchasedTicket::class);
},
'options' => [],
'helpSummary' => 'Re-saves Events purchased tickets.',
];
});
}

}

0 comments on commit b668e9a

Please sign in to comment.