mirror of
https://github.com/standardebooks/web.git
synced 2025-07-06 14:50:39 -04:00
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:
parent
a9a0782946
commit
c8d5dfb11f
6 changed files with 41 additions and 5 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?
|
||||
class Contributor{
|
||||
public ?int $ContributorId = null;
|
||||
public ?int $EbookId = null;
|
||||
public string $Name;
|
||||
public string $UrlName;
|
||||
public ?string $SortName = null;
|
||||
|
@ -7,6 +9,7 @@ class Contributor{
|
|||
public ?string $MarcRole = null;
|
||||
public ?string $FullName = null;
|
||||
public ?string $NacoafUrl = null;
|
||||
public ?int $SortOrder = null;
|
||||
|
||||
public static function FromProperties(string $name, string $sortName = null, string $fullName = null, string $wikipediaUrl = null, string $marcRole = null, string $nacoafUrl = null): Contributor{
|
||||
$instance = new Contributor();
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?
|
||||
class EbookSource{
|
||||
public ?int $EbookSourceId = null;
|
||||
public ?int $EbookId = null;
|
||||
public EbookSourceType $Type;
|
||||
public string $Url;
|
||||
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
use Safe\DateTimeImmutable;
|
||||
|
||||
class GitCommit{
|
||||
public ?int $GitCommitId = null;
|
||||
public ?int $EbookId = null;
|
||||
public DateTimeImmutable $Created;
|
||||
public string $Message;
|
||||
public string $Hash;
|
||||
|
|
|
@ -4,12 +4,18 @@ require_once('/standardebooks.org/web/lib/Core.php');
|
|||
|
||||
use function Safe\getopt;
|
||||
|
||||
$ignoredProperites = ['Created', 'Updated']; // Ebooks from the filesystem don't have these DB properties set.
|
||||
|
||||
function findObjectDifferences($fs, $db): array{
|
||||
$diffs = [];
|
||||
$fsReflection = new ReflectionClass($fs);
|
||||
$dbReflection = new ReflectionClass($db);
|
||||
|
||||
foreach($fsReflection->getProperties() as $fsProperty){
|
||||
if(in_array($fsProperty->getName(), $ignoredProperites)){
|
||||
continue;
|
||||
}
|
||||
|
||||
$dbProperty = $dbReflection->getProperty($fsProperty->getName());
|
||||
|
||||
try{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue