Add properties that were previously omitted

PHP 8.3 (part of Ubuntu 24.04) outputs a deprecated warning for properties that
were not in the class definition. Error below. There were a few of these
missing from the `Ebook`, `GitCommit`, `CollectionMembership`, `EbookSource`,
and `Contributor` classes. Adding them doesn't change any functionality, but it
does make it clearer what properties a class has.

Some of these properties are never set for `Ebook` instances created from the
filesystem, i.e., `Created` and `Updated`, and some of them need to be manually
set to make `Ebook` instances from the filesystem and the database match, e.g.,
`GitCommitId`, `CollectionEbookId`, `EbookSourceId`, and `ContributorId`.
Making the `Ebook` instances from the filesystem and the database match each
other makes it easier to spot bugs in the future.

Previous errors with PHP 8.3:

```
PHP Deprecated:  Creation of dynamic property Ebook::$Created is deprecated in /standardebooks.org/web/lib/Traits/Accessor.php on line 42
PHP Deprecated:  Creation of dynamic property Ebook::$Updated is deprecated in /standardebooks.org/web/lib/Traits/Accessor.php on line 42
PHP Deprecated:  Creation of dynamic property GitCommit::$GitCommitId is deprecated in /standardebooks.org/web/lib/DbConnection.php on line 286
PHP Deprecated:  Creation of dynamic property GitCommit::$EbookId is deprecated in /standardebooks.org/web/lib/DbConnection.php on line 286
PHP Deprecated:  Creation of dynamic property GitCommit::$GitCommitId is deprecated in /standardebooks.org/web/lib/DbConnection.php on line 286
PHP Deprecated:  Creation of dynamic property GitCommit::$EbookId is deprecated in /standardebooks.org/web/lib/DbConnection.php on line 286
PHP Deprecated:  Creation of dynamic property GitCommit::$GitCommitId is deprecated in /standardebooks.org/web/lib/DbConnection.php on line 286
PHP Deprecated:  Creation of dynamic property GitCommit::$EbookId is deprecated in /standardebooks.org/web/lib/DbConnection.php on line 286
PHP Deprecated:  Creation of dynamic property GitCommit::$GitCommitId is deprecated in /standardebooks.org/web/lib/DbConnection.php on line 286
PHP Deprecated:  Creation of dynamic property GitCommit::$EbookId is deprecated in /standardebooks.org/web/lib/DbConnection.php on line 286
PHP Deprecated:  Creation of dynamic property GitCommit::$GitCommitId is deprecated in /standardebooks.org/web/lib/DbConnection.php on line 286
PHP Deprecated:  Creation of dynamic property GitCommit::$EbookId is deprecated in /standardebooks.org/web/lib/DbConnection.php on line 286
PHP Deprecated:  Creation of dynamic property CollectionMembership::$CollectionEbookId is deprecated in /standardebooks.org/web/lib/Traits/Accessor.php on line 42
PHP Deprecated:  Creation of dynamic property CollectionMembership::$EbookId is deprecated in /standardebooks.org/web/lib/Traits/Accessor.php on line 42
PHP Deprecated:  Creation of dynamic property CollectionMembership::$CollectionId is deprecated in /standardebooks.org/web/lib/Traits/Accessor.php on line 42
PHP Deprecated:  Creation of dynamic property EbookSource::$EbookSourceId is deprecated in /standardebooks.org/web/lib/DbConnection.php on line 286
PHP Deprecated:  Creation of dynamic property EbookSource::$EbookId is deprecated in /standardebooks.org/web/lib/DbConnection.php on line 286
PHP Deprecated:  Creation of dynamic property EbookSource::$EbookSourceId is deprecated in /standardebooks.org/web/lib/DbConnection.php on line 286
PHP Deprecated:  Creation of dynamic property EbookSource::$EbookId is deprecated in /standardebooks.org/web/lib/DbConnection.php on line 286
PHP Deprecated:  Creation of dynamic property Contributor::$ContributorId is deprecated in /standardebooks.org/web/lib/DbConnection.php on line 286
PHP Deprecated:  Creation of dynamic property Contributor::$EbookId is deprecated in /standardebooks.org/web/lib/DbConnection.php on line 286
PHP Deprecated:  Creation of dynamic property Contributor::$SortOrder is deprecated in /standardebooks.org/web/lib/DbConnection.php on line 286
```
This commit is contained in:
Mike Colagrosso 2024-08-09 10:06:36 -06:00 committed by Alex Cabal
parent a9a0782946
commit c8d5dfb11f
6 changed files with 41 additions and 5 deletions

View file

@ -69,6 +69,8 @@ class Ebook{
public ?string $WikipediaUrl = null;
public DateTimeImmutable $EbookCreated;
public DateTimeImmutable $EbookUpdated;
public DateTimeImmutable $Created;
public DateTimeImmutable $Updated;
public ?int $TextSinglePageByteCount = null;
/** @var array<GitCommit> $_GitCommits */
protected $_GitCommits = null;
@ -1571,12 +1573,17 @@ class Ebook{
private function InsertCollectionMemberships(): void{
foreach($this->CollectionMemberships as $collectionMembership){
$collectionMembership->EbookId = $this->EbookId;
$collectionMembership->CollectionId = $collectionMembership->Collection->CollectionId;
Db::Query('
INSERT into CollectionEbooks (EbookId, CollectionId, SequenceNumber)
values (?,
?,
?)
', [$this->EbookId, $collectionMembership->Collection->CollectionId, $collectionMembership->SequenceNumber]);
', [$collectionMembership->EbookId, $collectionMembership->CollectionId, $collectionMembership->SequenceNumber]);
$collectionMembership->CollectionEbookId = Db::GetLastInsertedId();
}
}
@ -1591,13 +1598,17 @@ class Ebook{
private function InsertGitCommits(): void{
foreach($this->GitCommits as $commit){
$commit->EbookId = $this->EbookId;
Db::Query('
INSERT into GitCommits (EbookId, Created, Message, Hash)
values (?,
?,
?,
?)
', [$this->EbookId, $commit->Created, $commit->Message, $commit->Hash]);
', [$commit->EbookId, $commit->Created, $commit->Message, $commit->Hash]);
$commit->GitCommitId = Db::GetLastInsertedId();
}
}
@ -1612,12 +1623,16 @@ class Ebook{
private function InsertSources(): void{
foreach($this->Sources as $source){
$source->EbookId = $this->EbookId;
Db::Query('
INSERT into EbookSources (EbookId, Type, Url)
values (?,
?,
?)
', [$this->EbookId, $source->Type->value, $source->Url]);
', [$source->EbookId, $source->Type->value, $source->Url]);
$source->EbookSourceId = Db::GetLastInsertedId();
}
}
@ -1633,6 +1648,9 @@ class Ebook{
private function InsertContributors(): void{
$allContributors = array_merge($this->Authors, $this->Illustrators, $this->Translators, $this->Contributors);
foreach($allContributors as $sortOrder => $contributor){
$contributor->EbookId = $this->EbookId;
$contributor->SortOrder = $sortOrder;
Db::Query('
INSERT into Contributors (EbookId, Name, UrlName, SortName, WikipediaUrl, MarcRole, FullName,
NacoafUrl, SortOrder)
@ -1645,9 +1663,11 @@ class Ebook{
?,
?,
?)
', [$this->EbookId, $contributor->Name, $contributor->UrlName, $contributor->SortName,
', [$contributor->EbookId, $contributor->Name, $contributor->UrlName, $contributor->SortName,
$contributor->WikipediaUrl, $contributor->MarcRole, $contributor->FullName,
$contributor->NacoafUrl, $sortOrder]);
$contributor->NacoafUrl, $contributor->SortOrder]);
$contributor->ContributorId = Db::GetLastInsertedId();
}
}