Skip to content

Commit

Permalink
Merge pull request #832 from PennyDreadfulMTG/dark-ages
Browse files Browse the repository at this point in the history
Various improvements
  • Loading branch information
bakert authored Nov 10, 2024
2 parents aeb9976 + f332aba commit 9125579
Show file tree
Hide file tree
Showing 152 changed files with 4,083 additions and 1,911 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"files": [
"gatherling/Helpers/cards.php",
"gatherling/Helpers/database.php",
"gatherling/Helpers/email.php",
"gatherling/Helpers/helpers.php",
"gatherling/Helpers/templates.php"
]
Expand Down
136 changes: 136 additions & 0 deletions gatherling/Data/sql/migrations/77.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
-- Up until 2021 sets were sometimes added without codes.
UPDATE cardsets SET code = 'ALA' WHERE name = 'Alara Reborn';
UPDATE cardsets SET code = 'ALL' WHERE name = 'Alliances';
UPDATE cardsets SET code = 'ATQ' WHERE name = 'Antiquities';
UPDATE cardsets SET code = 'APC' WHERE name = 'Apocalypse';
UPDATE cardsets SET code = 'ARN' WHERE name = 'Arabian Nights';
UPDATE cardsets SET code = 'AVR' WHERE name = 'Avacyn Restored';
UPDATE cardsets SET code = 'BOK' WHERE name = 'Betrayers of Kamigawa';
UPDATE cardsets SET code = 'BNG' WHERE name = 'Born of the Gods';
UPDATE cardsets SET code = 'CHK' WHERE name = 'Champions of Kamigawa';
UPDATE cardsets SET code = '6ED' WHERE name = 'Classic Sixth Edition';
UPDATE cardsets SET code = 'CSP' WHERE name = 'Coldsnap';
UPDATE cardsets SET code = 'CMD' WHERE name = 'Commander';
UPDATE cardsets SET code = 'C13' WHERE name = 'Commander 2013 Edition';
UPDATE cardsets SET code = 'C14' WHERE name = 'Commander 2014';
UPDATE cardsets SET code = 'C15' WHERE name = 'Commander 2015';
UPDATE cardsets SET code = 'C16' WHERE name = 'Commander 2016';
UPDATE cardsets SET code = 'CON' WHERE name = 'Conflux';
UPDATE cardsets SET code = 'CNS' WHERE name = 'Conspiracy';
UPDATE cardsets SET code = 'CN2' WHERE name = 'Conspiracy: Take the Crown';
UPDATE cardsets SET code = 'DKA' WHERE name = 'Dark Ascension';
UPDATE cardsets SET code = 'DST' WHERE name = 'Darksteel';
UPDATE cardsets SET code = 'DIS' WHERE name = 'Dissension';
UPDATE cardsets SET code = 'DGM' WHERE name = 'Dragon''s Maze';
UPDATE cardsets SET code = 'DTK' WHERE name = 'Dragons of Tarkir';
UPDATE cardsets SET code = 'DDH' WHERE name = 'Duel Decks: Ajani vs. Nicol Bolas';
UPDATE cardsets SET code = 'DDC' WHERE name = 'Duel Decks: Divine vs. Demonic';
UPDATE cardsets SET code = 'DDF' WHERE name = 'Duel Decks: Elspeth vs. Tezzeret';
UPDATE cardsets SET code = 'EVG' WHERE name = 'Duel Decks: Elves vs. Goblins';
UPDATE cardsets SET code = 'DDD' WHERE name = 'Duel Decks: Garruk vs. Liliana';
UPDATE cardsets SET code = 'DDJ' WHERE name = 'Duel Decks: Izzet vs. Golgari';
UPDATE cardsets SET code = 'DD2' WHERE name = 'Duel Decks: Jace vs. Chandra';
UPDATE cardsets SET code = 'DDG' WHERE name = 'Duel Decks: Knights vs. Dragons';
UPDATE cardsets SET code = 'DDE' WHERE name = 'Duel Decks: Phyrexia vs. the Coalition';
UPDATE cardsets SET code = 'DDK' WHERE name = 'Duel Decks: Sorin vs. Tibalt';
UPDATE cardsets SET code = 'DDI' WHERE name = 'Duel Decks: Venser vs. Koth';
UPDATE cardsets SET code = '8ED' WHERE name = 'Eighth Edition';
UPDATE cardsets SET code = 'EMA' WHERE name = 'Eternal Masters';
UPDATE cardsets SET code = 'EVE' WHERE name = 'Eventide';
UPDATE cardsets SET code = 'EXO' WHERE name = 'Exodus';
UPDATE cardsets SET code = 'FEM' WHERE name = 'Fallen Empires';
UPDATE cardsets SET code = 'FRF' WHERE name = 'Fate Reforged';
UPDATE cardsets SET code = '5DN' WHERE name = 'Fifth Dawn';
UPDATE cardsets SET code = '5ED' WHERE name = 'Fifth Edition';
UPDATE cardsets SET code = '4ED' WHERE name = 'Fourth Edition';
UPDATE cardsets SET code = 'V14' WHERE name = 'From the Vault: Annihilation';
UPDATE cardsets SET code = 'FUT' WHERE name = 'Future Sight';
UPDATE cardsets SET code = 'GTC' WHERE name = 'Gatecrash';
UPDATE cardsets SET code = 'GPT' WHERE name = 'Guildpact';
UPDATE cardsets SET code = 'HML' WHERE name = 'Homelands';
UPDATE cardsets SET code = 'ICE' WHERE name = 'Ice Age';
UPDATE cardsets SET code = 'IMA' WHERE name = 'Iconic Masters';
UPDATE cardsets SET code = 'ISD' WHERE name = 'Innistrad';
UPDATE cardsets SET code = 'INV' WHERE name = 'Invasion';
UPDATE cardsets SET code = 'JOU' WHERE name = 'Journey into Nyx';
UPDATE cardsets SET code = 'JUD' WHERE name = 'Judgment';
UPDATE cardsets SET code = 'KTK' WHERE name = 'Khans of Tarkir';
UPDATE cardsets SET code = 'LEG' WHERE name = 'Legends';
UPDATE cardsets SET code = 'LGN' WHERE name = 'Legions';
UPDATE cardsets SET code = 'LEA' WHERE name = 'Limited Edition Alpha';
UPDATE cardsets SET code = 'LEB' WHERE name = 'Limited Edition Beta';
UPDATE cardsets SET code = 'LRW' WHERE name = 'Lorwyn';
UPDATE cardsets SET code = 'M10' WHERE name = 'Magic 2010';
UPDATE cardsets SET code = 'M11' WHERE name = 'Magic 2011';
UPDATE cardsets SET code = 'M12' WHERE name = 'Magic 2012';
UPDATE cardsets SET code = 'M13' WHERE name = 'Magic 2013';
UPDATE cardsets SET code = 'M14' WHERE name = 'Magic 2014';
UPDATE cardsets SET code = 'M15' WHERE name = 'Magic 2015';
UPDATE cardsets SET code = 'MED' WHERE name = 'Masters Edition';
UPDATE cardsets SET code = 'ME2' WHERE name = 'Masters Edition II';
UPDATE cardsets SET code = 'ME3' WHERE name = 'Masters Edition III';
UPDATE cardsets SET code = 'ME4' WHERE name = 'Masters Edition IV';
UPDATE cardsets SET code = 'MMQ' WHERE name = 'Mercadian Masques';
UPDATE cardsets SET code = 'MIR' WHERE name = 'Mirage';
UPDATE cardsets SET code = 'MRD' WHERE name = 'Mirrodin';
UPDATE cardsets SET code = 'MBS' WHERE name = 'Mirrodin Besieged';
UPDATE cardsets SET code = 'MMA' WHERE name = 'Modern Masters';
UPDATE cardsets SET code = 'MM2' WHERE name = 'Modern Masters 2015';
UPDATE cardsets SET code = 'MM3' WHERE name = 'Modern Masters 2017 Edition';
UPDATE cardsets SET code = 'MOR' WHERE name = 'Morningtide';
UPDATE cardsets SET code = 'NEM' WHERE name = 'Nemesis';
UPDATE cardsets SET code = 'NPH' WHERE name = 'New Phyrexia';
UPDATE cardsets SET code = '9ED' WHERE name = 'Ninth Edition';
UPDATE cardsets SET code = 'ODY' WHERE name = 'Odyssey';
UPDATE cardsets SET code = 'ONS' WHERE name = 'Onslaught';
UPDATE cardsets SET code = 'PLC' WHERE name = 'Planar Chaos';
UPDATE cardsets SET code = 'HOP' WHERE name = 'Planechase';
UPDATE cardsets SET code = 'PC2' WHERE name = 'Planechase 2012 Edition';
UPDATE cardsets SET code = 'PLS' WHERE name = 'Planeshift';
UPDATE cardsets SET code = 'PCY' WHERE name = 'Prophecy';
UPDATE cardsets SET code = 'RAV' WHERE name = 'Ravnica: City of Guilds';
UPDATE cardsets SET code = 'RTR' WHERE name = 'Return to Ravnica';
UPDATE cardsets SET code = '3ED' WHERE name = 'Revised Edition';
UPDATE cardsets SET code = 'ROE' WHERE name = 'Rise of the Eldrazi';
UPDATE cardsets SET code = 'SOK' WHERE name = 'Saviors of Kamigawa';
UPDATE cardsets SET code = 'SOM' WHERE name = 'Scars of Mirrodin';
UPDATE cardsets SET code = 'SCG' WHERE name = 'Scourge';
UPDATE cardsets SET code = '7ED' WHERE name = 'Seventh Edition';
UPDATE cardsets SET code = 'SHM' WHERE name = 'Shadowmoor';
UPDATE cardsets SET code = 'ALA' WHERE name = 'Shards of Alara';
UPDATE cardsets SET code = 'STH' WHERE name = 'Stronghold';
UPDATE cardsets SET code = 'TMP' WHERE name = 'Tempest';
UPDATE cardsets SET code = 'TPR' WHERE name = 'Tempest Remastered';
UPDATE cardsets SET code = '10E' WHERE name = 'Tenth Edition';
UPDATE cardsets SET code = 'DRK' WHERE name = 'The Dark';
UPDATE cardsets SET code = 'THS' WHERE name = 'Theros';
UPDATE cardsets SET code = 'TSP' WHERE name = 'Time Spiral';
UPDATE cardsets SET code = 'TSB' WHERE name = 'Time Spiral Timeshifted Special';
UPDATE cardsets SET code = 'TOR' WHERE name = 'Torment';
UPDATE cardsets SET code = '2ED' WHERE name = 'Unlimited Edition';
UPDATE cardsets SET code = 'UDS' WHERE name = 'Urzas Destiny';
UPDATE cardsets SET code = 'ULG' WHERE name = 'Urzas Legacy';
UPDATE cardsets SET code = 'USG' WHERE name = 'Urzas Saga';
UPDATE cardsets SET code = 'PVAN' WHERE name = 'Vanguard';
UPDATE cardsets SET code = 'VMA' WHERE name = 'Vintage Masters';
UPDATE cardsets SET code = 'VIS' WHERE name = 'Visions';
UPDATE cardsets SET code = 'WTH' WHERE name = 'Weatherlight';
UPDATE cardsets SET code = 'WWK' WHERE name = 'Worldwake';
UPDATE cardsets SET code = 'ZEN' WHERE name = 'Zendikar';
-- And now we can make that column not null.
ALTER TABLE cardsets ALTER COLUMN code SET NOT NULL;
-- Some sets are missing their release date.
UPDATE cardsets SET released = '2015-11-13' WHERE name = 'Commander 2015';
UPDATE cardsets SET released = '2016-11-11' WHERE name = 'Commander 2016';
UPDATE cardsets SET released = '2014-06-06' WHERE name = 'Conspiracy';
UPDATE cardsets SET released = '2016-08-26' WHERE name = 'Conspiracy: Take the Crown';
UPDATE cardsets SET released = '2016-06-10' WHERE name = 'Eternal Masters';
UPDATE cardsets SET released = '2014-08-22' WHERE name = 'From the Vault: Annihilation';
UPDATE cardsets SET released = '2017-11-17' WHERE name = 'Iconic Masters';
UPDATE cardsets SET released = '2015-05-22' WHERE name = 'Modern Masters 2015';
UPDATE cardsets SET released = '2017-03-17' WHERE name = 'Modern Masters 2017 Edition';
UPDATE cardsets SET released = '2015-05-06' WHERE name = 'Tempest Remastered';
-- And now we can make that column not null.
ALTER TABLE cardsets ALTER COLUMN released SET NOT NULL;
-- Get rid of the last updated column, we don't set it or update it anywhere.
ALTER TABLE cardsets DROP COLUMN last_updated;
4 changes: 4 additions & 0 deletions gatherling/Data/sql/migrations/78.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- Update the 76 events where private is not set …
UPDATE events SET private = 0 WHERE private IS NULL;
-- … and now make it not null.
ALTER TABLE events ALTER COLUMN private SET NOT NULL;
1 change: 1 addition & 0 deletions gatherling/Data/sql/migrations/79.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE formats DROP COLUMN is_meta_format;
4 changes: 2 additions & 2 deletions gatherling/util/email.php → gatherling/Helpers/email.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

declare(strict_types=1);

use function Gatherling\Helpers\config;
use function Gatherling\Helpers\logger;
namespace Gatherling\Helpers;

use function Safe\curl_exec;
use function Safe\curl_getinfo;
use function Safe\curl_init;
Expand Down
2 changes: 1 addition & 1 deletion gatherling/Helpers/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function post(): Request

function session(): Request
{
return new Request($_SESSION);
return new Request(isset($_SESSION) ? $_SESSION : []);
}

function server(): Request
Expand Down
3 changes: 1 addition & 2 deletions gatherling/Models/CardSetDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
class CardSetDto extends Dto
{
public string $name;
public ?string $code;
public string $code;
public string $released;
public string $type;
public ?string $last_updated;
public int $count;
public bool $standard_legal;
public bool $modern_legal;
Expand Down
9 changes: 3 additions & 6 deletions gatherling/Models/Decksearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,9 @@ public function getFinalResults(): array|false
// Filter out decks in events that haven't been finalized (and should remain secret for now)
foreach ($tmp_results as $value) {
$sql = '
SELECT
e.finalized
FROM
decks d, entries n, events e
WHERE
d.id = :deck_id AND d.id = n.deck AND n.event_id = e.id';
SELECT e.finalized
FROM decks d, entries n, events e
WHERE d.id = :deck_id AND d.id = n.deck AND n.event_id = e.id';
$finalized = db()->optionalInt($sql, ['deck_id' => $value]);
if ($finalized === null || $finalized) {
array_push($this->finalResults, $value);
Expand Down
86 changes: 54 additions & 32 deletions gatherling/Models/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@
class Event
{
public string $name;
public ?int $id;
public int $id;

public ?int $season;
public ?int $number = null;
public ?string $format = null;
public int $season;
public int $number;
public string $format;

public ?string $start;
public ?int $kvalue = null;
public string $start;
public int $kvalue;
public int $active;
public int $finalized;
public int $prereg_allowed;
public string $threadurl;
public string $reporturl;
public string $metaurl;
public ?int $private;
public int $private;
public int $client;

public int $player_editdecks;
Expand Down Expand Up @@ -57,13 +57,16 @@ class Event
public int $private_finals; // As above, but for finals

public ?int $hastrophy;
private ?bool $new = null;
private bool $new;

public function __construct(int|string $name = '')
{
if ($name == '') {
$this->id = 0;
$this->name = '';
$this->season = 0;
$this->number = 0;
$this->format = '';
$this->mainrounds = 0;
$this->mainstruct = '';
$this->finalrounds = 0;
Expand All @@ -73,7 +76,9 @@ public function __construct(int|string $name = '')
$this->threadurl = '';
$this->reporturl = '';
$this->metaurl = '';
$this->start = null;
$this->private = 0;
$this->start = '';
$this->kvalue = 16;
$this->finalized = 0;
$this->prereg_allowed = 0;
$this->hastrophy = 0;
Expand All @@ -93,31 +98,48 @@ public function __construct(int|string $name = '')
return;
}

if (!$this->new) {
$sql = '
SELECT
id, name, format, host, cohost, series, season, number,
start, kvalue, finalized, prereg_allowed, threadurl,
metaurl, reporturl, active, current_round, player_reportable, player_editdecks,
prereg_cap, private_decks, private_finals, player_reported_draws, late_entry_limit,
`private`, client
FROM
events
$sql = '
SELECT id, name, format, host, cohost, series, season, number, start, kvalue, finalized,
prereg_allowed, threadurl, metaurl, reporturl, active, current_round, player_reportable,
player_editdecks, prereg_cap, private_decks, private_finals, player_reported_draws,
late_entry_limit, `private`, client
FROM events
WHERE ';
if (is_numeric($name)) {
$sql .= 'id = :id';
$params = ['id' => $name];
} else {
$sql .= 'name = :name';
$params = ['name' => $name];
}
$event = db()->selectOnly($sql, EventDto::class, $params);
foreach (get_object_vars($event) as $property => $value) {
$this->$property = $value;
}
}
if (is_numeric($name)) {
$sql .= 'id = :id';
$params = ['id' => $name];
} else {
$sql .= 'name = :name';
$params = ['name' => $name];
}
$event = db()->selectOnly($sql, EventDto::class, $params);
$this->id = $event->id;
$this->name = $event->name;
$this->format = $event->format;
$this->host = $event->host;
$this->cohost = $event->cohost;
$this->series = $event->series;
$this->season = $event->season;
$this->number = $event->number;
$this->start = $event->start;
$this->kvalue = $event->kvalue;
$this->finalized = $event->finalized;
$this->prereg_allowed = $event->prereg_allowed;
$this->threadurl = $event->threadurl;
$this->metaurl = $event->metaurl;
$this->reporturl = $event->reporturl;
$this->active = $event->active;
$this->current_round = $event->current_round;
$this->player_reportable = $event->player_reportable;
$this->player_editdecks = $event->player_editdecks;
$this->prereg_cap = $event->prereg_cap;
$this->private_decks = $event->private_decks;
$this->private_finals = $event->private_finals;
$this->player_reported_draws = $event->player_reported_draws;
$this->late_entry_limit = $event->late_entry_limit;
$this->private = $event->private;
$this->client = $event->client;

// BAKERT remove all casts on mainrounds and finalrounds
$this->standing = new Standings($this->name, '0');

// Main rounds
Expand Down
8 changes: 4 additions & 4 deletions gatherling/Models/EventDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ class EventDto extends Dto
public int $kvalue;
public int $finalized;
public int $prereg_allowed;
public ?string $threadurl;
public ?string $metaurl;
public ?string $reporturl;
public string $threadurl;
public string $metaurl;
public string $reporturl;
public int $active;
public int $current_round;
public int $player_reportable;
Expand All @@ -30,6 +30,6 @@ class EventDto extends Dto
public int $private_finals;
public int $player_reported_draws;
public int $late_entry_limit;
public ?int $private;
public int $private;
public int $client;
}
Loading

0 comments on commit 9125579

Please sign in to comment.