From c8d5dfb11f712a8a90a4eb4d6531a76384e4d2ee Mon Sep 17 00:00:00 2001 From: Mike Colagrosso Date: Fri, 9 Aug 2024 10:06:36 -0600 Subject: [PATCH] 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 ``` --- lib/CollectionMembership.php | 3 +++ lib/Contributor.php | 3 +++ lib/Ebook.php | 30 +++++++++++++++++++++++++----- lib/EbookSource.php | 2 ++ lib/GitCommit.php | 2 ++ scripts/update-ebook-database | 6 ++++++ 6 files changed, 41 insertions(+), 5 deletions(-) diff --git a/lib/CollectionMembership.php b/lib/CollectionMembership.php index 7ded2833..ce23103a 100644 --- a/lib/CollectionMembership.php +++ b/lib/CollectionMembership.php @@ -7,6 +7,9 @@ use function Safe\preg_replace; class CollectionMembership{ use Traits\Accessor; + public ?int $CollectionEbookId = null; + public ?int $EbookId = null; + public ?int $CollectionId = null; public ?int $SequenceNumber = null; protected ?Collection $_Collection = null; } diff --git a/lib/Contributor.php b/lib/Contributor.php index e6723a98..0a3b0795 100644 --- a/lib/Contributor.php +++ b/lib/Contributor.php @@ -1,5 +1,7 @@ $_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(); } } diff --git a/lib/EbookSource.php b/lib/EbookSource.php index 6adcbd91..96ab6f5a 100644 --- a/lib/EbookSource.php +++ b/lib/EbookSource.php @@ -1,5 +1,7 @@ getProperties() as $fsProperty){ + if(in_array($fsProperty->getName(), $ignoredProperites)){ + continue; + } + $dbProperty = $dbReflection->getProperty($fsProperty->getName()); try{