There are 5 commits in this PR, 3 small, 1 large, and 1 extra large. I could send these commits one at a time in different PRs if you would prefer. I don't think breaking up the extra large commit would make it clearer because it's attacking the large constructor.
(extra large) Rename the constructor Ebook::__construct() to static Ebook::FromFilesystem()
I added GetFoo() methods for all the derived properties like GetUrl(), GetHasDownloads(), etc. That logic is reusable to Ebook objects no matter if they were created from Ebook::FromFilesystem() or Ebook::GetByIdentifier().
The result is that Ebook.php got more verbose. I personally think the logic for each property is now clearer, but it might be a shock to see how much bigger the file is.
Also in the commit: Collection, Contributor, EbookSource, and GitCommit need zero-argument constructors for DbConnection::ExecuteQuery(), so I renamed the existing constructors to static factory methods:
Collection::FromName()
Contributor::FromProperties()
EbookSource::FromTypeAndUrl()
GitCommit::FromLog()
The DB path uses the zero-argument constructors, and the filesystem path uses the static factory methods.
(large) I added a step to update-ebook-database so that it:
a. creates an Ebook from the filesystem
b. updates the DB
c. reads back the Ebook from the DB and ensures that the two Ebook instances match
It's extra work, and I'm bad at PHP reflection so the implementation could be better, but it was useful while developing and debugging. It gives me the confidence to move onto the read path tasks like updating ebook.php knowing that we can pull valid Ebook instances from the DB. My local DB has 961 Ebook records, and the script didn't find any object differences.
There are 5 commits in this PR, 3 small, 1 large, and 1 extra large. I could send these commits one at a time in different PRs if you would prefer. I don't think breaking up the extra large commit would make it clearer because it's attacking the large constructor.
Ebook::__construct()
tostatic Ebook::FromFilesystem()
We discussed this back in February in #336.
I added
GetFoo()
methods for all the derived properties likeGetUrl()
,GetHasDownloads()
, etc. That logic is reusable toEbook
objects no matter if they were created fromEbook::FromFilesystem()
orEbook::GetByIdentifier()
.The result is that
Ebook.php
got more verbose. I personally think the logic for each property is now clearer, but it might be a shock to see how much bigger the file is.Also in the commit:
Collection
,Contributor
,EbookSource
, andGitCommit
need zero-argument constructors forDbConnection::ExecuteQuery()
, so I renamed the existing constructors to static factory methods:Collection::FromName()
Contributor::FromProperties()
EbookSource::FromTypeAndUrl()
GitCommit::FromLog()
The DB path uses the zero-argument constructors, and the filesystem path uses the static factory methods.
update-ebook-database
so that it:a. creates an
Ebook
from the filesystem b. updates the DB c. reads back theEbook
from the DB and ensures that the twoEbook
instances matchIt's extra work, and I'm bad at PHP reflection so the implementation could be better, but it was useful while developing and debugging. It gives me the confidence to move onto the read path tasks like updating
ebook.php
knowing that we can pull validEbook
instances from the DB. My local DB has 961Ebook
records, and the script didn't find any object differences.