9 public function __construct(Dependencies $deps)
12 $this->db = $deps->db;
13 $this->log = $deps->log;
17 * Fetches HTML content of all linkbacks that are marked as "needs update"
19 public function updateAll()
21 $this->log->info('Fetching linkback content..');
22 $res = $this->db->query(
23 'SELECT * FROM linkbacks'
24 . ' WHERE l_use = 1' . $this->sqlNeedsUpdate()
27 while ($pingbackRow = $res->fetch(\PDO::FETCH_OBJ)) {
29 $this->updateContent($pingbackRow);
31 $this->log->info('Finished fetching %d linkback sources.', $items);
34 protected function updateContent($pingbackRow)
37 'Fetching pingback source #%d: %s',
38 $pingbackRow->l_id, $pingbackRow->l_source
41 $req = new \HTTP_Request2($pingbackRow->l_source);
42 $req->setHeader('User-Agent', 'stapibas');
45 'application/xhtml+xml; q=1'
46 . ', text/html; q=0.5'
50 if (intval($res->getStatus() / 100) != 2) {
51 //no 2xx is an error for us
52 $this->log->err('Error fetching pingback source content');
56 $qLid = $this->db->quote($pingbackRow->l_id);
57 $this->db->exec('DELETE FROM linkbackcontent WHERE lc_l_id = ' . $qLid);
58 $this->db->exec('DELETE FROM rbookmarks WHERE rb_l_id = ' . $qLid);
59 $this->db->exec('DELETE FROM rcomments WHERE rc_l_id = ' . $qLid);
60 $this->db->exec('DELETE FROM rlinks WHERE rl_l_id = ' . $qLid);
63 'INSERT INTO linkbackcontent SET'
64 . ' lc_l_id = ' . $qLid
66 . $this->db->quote($res->getHeader('content-type'))
67 . ', lc_fulltext = ' . $this->db->quote($res->getBody())
71 . ' SET l_needs_update = 0'
72 . ' WHERE l_id = ' . $this->db->quote($pingbackRow->l_id)
77 protected function sqlNeedsUpdate()
79 if ($this->deps->options['force']) {
82 return ' AND l_needs_update = 1';