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

[4.7] Upgrade events #3675

Draft
wants to merge 2 commits into
base: 4.7
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- '4.x'
- '4.7'
pull_request:
permissions:
contents: read
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG-WIP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Release Notes for Craft Commerce 4.7 (WIP)

## Unreleased
13 changes: 13 additions & 0 deletions src/console/controllers/UpgradeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use craft\commerce\console\Controller;
use craft\commerce\db\Table;
use craft\commerce\elements\conditions\addresses\PostalCodeFormulaConditionRule;
use craft\commerce\events\UpgradeEvent;
use craft\commerce\Plugin;
use craft\commerce\records\Store;
use craft\db\Connection;
Expand Down Expand Up @@ -51,6 +52,11 @@
*/
class UpgradeController extends Controller
{
/**
* @event Event The event that is triggered before the v3 columns and tables are dropped.
*/
const EVENT_BEFORE_DROP_V3_DATABASE_ENTITIES = 'beforeDropV3DatabaseEntities';

/**
* @inheritdoc
*/
Expand Down Expand Up @@ -316,6 +322,13 @@ public function actionRun(): int
return ExitCode::UNSPECIFIED_ERROR;
}

$event = new UpgradeEvent();
$event->v3columnMap = $this->_v3droppableColumns;
$event->v3tables = $this->_v3tables;
if($this->hasEventHandlers(self::EVENT_BEFORE_DROP_V3_DATABASE_ENTITIES)) {
$this->trigger(self::EVENT_BEFORE_DROP_V3_DATABASE_ENTITIES, $event);
}

$this->stdout("Cleaning up tables…");
foreach ($this->_v3tables as $table) {
Db::dropAllForeignKeysToTable($table, $this->db);
Expand Down
29 changes: 29 additions & 0 deletions src/events/UpgradeEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
/**
* @link https://craftcms.com/
* @copyright Copyright (c) Pixel & Tonic, Inc.
* @license https://craftcms.github.io/license/
*/

namespace craft\commerce\events;

use craft\commerce\models\Email;
use yii\base\Event;

/**
* Class UpgradeEvent
*
* @author Pixel & Tonic, Inc. <[email protected]>
*/
class UpgradeEvent extends Event
{
/**
* @var array $columns
*/
public array $v3columnMap = [];

/**
* @var array $v3tables
*/
public array $v3tables = [];
}