summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2021-02-28 00:06:06 +0300
committerAndrew Dolgov <[email protected]>2021-02-28 00:06:06 +0300
commit96aec41484554074189bd13607e689d946835d95 (patch)
tree0f15c462be53f9b07a5dc3ed3c1e5358c769ff4a
parent1abb8eaf818b64133b91a4fc27a81ce42803296c (diff)
remove posts which fail to return reddit json
-rwxr-xr-xinit.php22
1 files changed, 16 insertions, 6 deletions
diff --git a/init.php b/init.php
index b11e14b..1311b33 100755
--- a/init.php
+++ b/init.php
@@ -50,18 +50,28 @@ class Reddit_Delay extends Plugin {
$target = $xpath->query("//atom:feed")->item(0);
while ($row = $sth->fetch()) {
- Debug::log(sprintf("[delay] pulling from cache: %s [%s]",
- $row["link"], $row["orig_ts"]), Debug::$LOG_VERBOSE);
+ $reddit_json = UrlHelper::fetch(["url" => $row["link"] . "/.json"]);
- $tmpdoc = new DOMDocument();
+ if ($reddit_json) {
+ Debug::log(sprintf("[delay] pulling from cache: %s [%s]",
+ $row["link"], $row["orig_ts"]), Debug::$LOG_VERBOSE);
- if ($tmpdoc->loadXML($row["item"])) {
- $tmpxpath = new DOMXPath($tmpdoc);
+ $tmpdoc = new DOMDocument();
- $imported_entry = $doc->importNode($tmpxpath->query("//entry")->item(0), true);
+ if ($tmpdoc->loadXML($row["item"])) {
+ $tmpxpath = new DOMXPath($tmpdoc);
+
+ $imported_entry = $doc->importNode($tmpxpath->query("//entry")->item(0), true);
+
+ $dsth->execute([$row["id"]]);
+ }
+ } else {
+ Debug::log(sprintf("[delay] json fetch failed, post deleted? removing: %s [%s]",
+ $row["link"], $row["orig_ts"]), Debug::$LOG_VERBOSE);
$dsth->execute([$row["id"]]);
}
+
}
}