diff --git a/config/sql/se/Collections.sql b/config/sql/se/Collections.sql index 84d38dec..2a6d99ff 100644 --- a/config/sql/se/Collections.sql +++ b/config/sql/se/Collections.sql @@ -2,7 +2,7 @@ CREATE TABLE `Collections` ( `CollectionId` int(10) unsigned NOT NULL AUTO_INCREMENT, `Name` varchar(255) NOT NULL, `UrlName` varchar(255) NOT NULL, - `Type` varchar(255) NULL, + `Type` enum('series', 'set') NULL, PRIMARY KEY (`CollectionId`), UNIQUE KEY `idxUnique` (`UrlName`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; diff --git a/lib/Collection.php b/lib/Collection.php index 8c6b8a95..66e7d9ce 100644 --- a/lib/Collection.php +++ b/lib/Collection.php @@ -10,7 +10,7 @@ class Collection{ public int $CollectionId; public string $Name; public string $UrlName; - public ?string $Type = null; + public ?CollectionType $Type = null; protected ?string $_Url = null; protected function GetUrl(): ?string{ @@ -59,7 +59,7 @@ class Collection{ $error->Add(new Exceptions\StringTooLongException('Collection name: '. $this->Name)); } - if($this->Type !== null && ($this->Type != 'series' && $this->Type != 'set')){ + if($this->Type !== null && ($this->Type != CollectionType::Series && $this->Type != CollectionType::Set)){ $error->Add(new Exceptions\InvalidCollectionTypeException($this->Type)); } diff --git a/lib/CollectionType.php b/lib/CollectionType.php new file mode 100644 index 00000000..f3de077e --- /dev/null +++ b/lib/CollectionType.php @@ -0,0 +1,6 @@ +SequenceNumber = (int)$s; } foreach($xml->xpath('/package/metadata/meta[@refines="#' . $id . '"][@property="collection-type"]') ?: [] as $s){ - $cm->Collection->Type = (string)$s; + $cm->Collection->Type = CollectionType::tryFrom((string)$s) ?? CollectionType::Unknown; } $collectionMemberships[] = $cm; }