Skip to content

Commit

Permalink
format: add unreleased tags and reformat code
Browse files Browse the repository at this point in the history
  • Loading branch information
pauloiankoski committed Jan 15, 2025
1 parent ec261ca commit 2a563d1
Showing 1 changed file with 31 additions and 10 deletions.
41 changes: 31 additions & 10 deletions src/EventTickets/Migrations/AddAmountColumnToEventTicketsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,45 @@
/**
* @unreleased
*/
class AddAmountColumnToEventTicketsTable extends Migration {
class AddAmountColumnToEventTicketsTable extends Migration
{
/**
* @inheritdoc
*
* @unreleased
*/
public static function id() {
public static function id()
{
return 'give-events-add-amount-column-to-events-tickets-table';
}

public static function title() {
/**
* @unreleased
*/
public static function title()
{
return 'Add "amount" column to give_event_tickets table';
}

/**
* @inheritdoc
*
* @unreleased
*/
public static function timestamp() {
return strtotime( '2022-03-18 12:00:00' );
public static function timestamp()
{
return strtotime('2022-03-18 12:00:00');
}

/**
* @inheritdoc
*
* @unreleased
*
* @throws DatabaseMigrationException
*/
public function run() {
public function run()
{
global $wpdb;

$eventTicketsTable = $wpdb->give_event_tickets;
Expand All @@ -43,23 +58,29 @@ public function run() {
}

/**
* @unreleased
*
* @throws DatabaseMigrationException
*/
private function addAmountColumn($wpdb, $eventTicketsTable) {
private function addAmountColumn($wpdb, $eventTicketsTable)
{
$sql = "ALTER TABLE $eventTicketsTable
ADD COLUMN amount INT UNSIGNED NOT NULL AFTER donation_id";

try {
maybe_add_column($eventTicketsTable, 'amount', $sql);
} catch (DatabaseQueryException $exception) {
throw new DatabaseMigrationException( "An error occurred while adding the amount column to the $eventTicketsTable table", 0, $exception );
throw new DatabaseMigrationException("An error occurred while adding the amount column to the $eventTicketsTable table", 0, $exception);
}
}

/**
* @unreleased
*
* @throws DatabaseMigrationException
*/
private function migrateTicketPrices($wpdb, $eventTicketsTable, $eventTicketTypesTable) {
private function migrateTicketPrices($wpdb, $eventTicketsTable, $eventTicketTypesTable)
{
$sql = "UPDATE $eventTicketsTable eventTickets
JOIN $eventTicketTypesTable evenTicketTypes
ON eventTickets.ticket_type_id = evenTicketTypes.id
Expand All @@ -68,7 +89,7 @@ private function migrateTicketPrices($wpdb, $eventTicketsTable, $eventTicketType
try {
$wpdb->query($sql);
} catch (DatabaseQueryException $exception) {
throw new DatabaseMigrationException( "An error occurred while migrating data to the amount column in the $eventTicketsTable table", 0, $exception );
throw new DatabaseMigrationException("An error occurred while migrating data to the amount column in the $eventTicketsTable table", 0, $exception);
}
}
};

0 comments on commit 2a563d1

Please sign in to comment.