Permalink
Browse files

Fix pingback sending

  • Loading branch information...
1 parent 0cc6b6f commit 6b0afa8b396434fdb760cf9254bca86cf673e509 @pvorb committed Mar 4, 2012
Showing with 41 additions and 17 deletions.
  1. +26 −17 comments.js
  2. +1 −0 test/clear.js
  3. +4 −0 test/clear.sh
  4. +5 −0 test/list-pingbacks.js
  5. +5 −0 test/list-pingbacks.sh
View
@@ -307,28 +307,37 @@ Comments.prototype.sendPingbacks = function sendPingbacks(res, pinged) {
if (err)
return pinged(err);
+ if (num != 0)
+ return pinged(new Error('Already sent pingbacks for '+res+'.'));
+
// if not, send pingbacks
- if (num == 0)
- fs.readFile(path.resolve(self.opt.publicDirectory, res), 'utf8',
- function (err, html) {
- if (err)
- return pinged(err);
+ fs.readFile(path.resolve(self.opt.publicDirectory, res), 'utf8',
+ function (err, html) {
+ if (err)
+ return pinged(err);
+
+ Pingback.scan(html, self.opt.urlPrefix+res, function (err, pb) {
+ if (err) {
+ return col.pingbacks.update({ _id: res }, {
+ $set: { sent: true }
+ }, { safe: true, upsert: true }, function (e) {
+ if (e)
+ return pinged(e);
+ pinged(err);
+ });
+ }
- Pingback.scan(html, self.opt.urlPrefix+res, function (err, pb) {
+ // set sent to true for this document and push .href to targets
+ col.pingbacks.update({ _id: res }, {
+ $set: { sent: true },
+ $push: { targets: pb.href }
+ }, { safe: true, upsert: true }, function (err) {
if (err)
- return;
-
- // set sent to true for this document and push .href to targets
- col.pingbacks.update({ _id: res }, {
- $set: { sent: true },
- $push: { targets: pb.href }
- }, { safe: true, upsert: true }, function (err) {
- if (err)
- return pinged(err);
- pinged(pb);
- });
+ return pinged(err);
+ pinged(null, pb);
});
});
+ });
});
});
};
View
@@ -0,0 +1 @@
+db.dropDatabase();
View
@@ -0,0 +1,4 @@
+#!/bin/sh
+
+mongo localhost:27017/source --quiet --eval "printjson(db.dropDatabase())"
+mongo localhost:27017/target --quiet --eval "printjson(db.dropDatabase())"
@@ -0,0 +1,5 @@
+print('pingbacks:');
+db.pingbacks.find().forEach(printjson);
+print();
+print('comments:');
+db.comments.find().forEach(printjson);
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+mongo localhost:27017/source --quiet list-pingbacks.js
+echo ""
+mongo localhost:27017/target --quiet list-pingbacks.js

0 comments on commit 6b0afa8

Please sign in to comment.