Clean up some class inheritance issues in feeds

This commit is contained in:
Alex Cabal 2022-06-29 17:04:16 -05:00
parent 2ef5ce6551
commit 18f761929a
3 changed files with 18 additions and 9 deletions

View file

@ -1,4 +1,5 @@
<? <?
use Safe\DateTime;
use function Safe\file_get_contents; use function Safe\file_get_contents;
use function Safe\file_put_contents; use function Safe\file_put_contents;
use function Safe\preg_replace; use function Safe\preg_replace;
@ -28,6 +29,15 @@ class AtomFeed extends Feed{
return $this->XmlString; return $this->XmlString;
} }
public function SaveIfChanged(): void{
// Did we actually update the feed? If so, write to file and update the index
if($this->HasChanged($this->Path)){
// Files don't match, save the file
$this->Updated = new DateTime();
$this->Save();
}
}
protected function HasChanged(string $path): bool{ protected function HasChanged(string $path): bool{
if(!is_file($path)){ if(!is_file($path)){
return true; return true;

View file

@ -40,15 +40,6 @@ class Feed{
return ''; return '';
} }
public function SaveIfChanged(): void{
// Did we actually update the feed? If so, write to file and update the index
if($this->HasChanged($this->Path)){
// Files don't match, save the file
$this->Updated = new DateTime();
$this->Save();
}
}
public function Save(): void{ public function Save(): void{
$feed = $this->GetXmlString(); $feed = $this->GetXmlString();

View file

@ -23,6 +23,14 @@ class RssFeed extends Feed{
return $this->XmlString; return $this->XmlString;
} }
public function SaveIfChanged(): void{
// Did we actually update the feed? If so, write to file and update the index
if($this->HasChanged($this->Path)){
// Files don't match, save the file
$this->Save();
}
}
protected function HasChanged(string $path): bool{ protected function HasChanged(string $path): bool{
// RSS doesn't have information about when an item was updated, // RSS doesn't have information about when an item was updated,
// only when it was first published. So, we approximate on whether the feed // only when it was first published. So, we approximate on whether the feed