Skip to content

Commit

Permalink
feat(demos): add missing/dnm demoskill subtypes
Browse files Browse the repository at this point in the history
  • Loading branch information
themightychris committed Aug 22, 2022
1 parent f19ad91 commit 6725b9f
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Slate\CBL\Demonstrations;


class DidNotMeetDemonstrationSkill extends DemonstrationSkill
{

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Slate\CBL\Demonstrations;


class MissingDemonstrationSkill extends DemonstrationSkill
{

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Slate\CBL\Demonstrations;


$tableName = DemonstrationSkill::$tableName;
$historyTableName = DemonstrationSkill::getHistoryTableName();

// skip if table doesn't exist
if (!static::tableExists($tableName)) {
printf("Skipping migration because table `%s` does not yet exist\n", $tableName);
return static::STATUS_SKIPPED;
}

// skip if Class column already contains DidNotMeet subclass
if (static::hasColumnEnumValue($tableName, 'Class', DidNotMeetDemonstrationSkill::class)) {
printf("Skipping migration because column `%s`.`Class` already has value '%s'\n", $tableName, DidNotMeetDemonstrationSkill::class);
return static::STATUS_SKIPPED;
}

// add new Class value
static::addColumnEnumValue($tableName, 'Class', DidNotMeetDemonstrationSkill::class);
static::addColumnEnumValue($historyTableName, 'Class', DidNotMeetDemonstrationSkill::class);
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace Slate\CBL\Demonstrations;

use DB;


$tableName = DemonstrationSkill::$tableName;
$historyTableName = DemonstrationSkill::getHistoryTableName();

// skip if table doesn't exist
if (!static::tableExists($tableName)) {
printf("Skipping migration because table `%s` does not yet exist\n", $tableName);
return static::STATUS_SKIPPED;
}

// skip if Class column already contains Missing subclass
if (static::hasColumnEnumValue($tableName, 'Class', MissingDemonstrationSkill::class)) {
printf("Skipping migration because column `%s`.`Class` already has value '%s'\n", $tableName, MissingDemonstrationSkill::class);
return static::STATUS_SKIPPED;
}

// add new Class value
static::addColumnEnumValue($tableName, 'Class', MissingDemonstrationSkill::class);
static::addColumnEnumValue($historyTableName, 'Class', MissingDemonstrationSkill::class);

// migrate legacy missing demonstrations
DB::nonQuery(
'UPDATE `%s` SET Class = "%s", DemonstratedLevel = NULL WHERE Class = "%s" AND DemonstratedLevel = 0',
[
$tableName,
DB::escape(MissingDemonstrationSkill::class),
DB::escape(DemonstrationSkill::class)
]
);
printf(
"Updated %u DemonstrationSkill records with Rating = 0 to MissingDemonstrationSkill class\n",
DB::affectedRows()
);

0 comments on commit 6725b9f

Please sign in to comment.