Permalink
Browse files

Added script to refresh an entry's GUID

  • Loading branch information...
davidmerfield committed Jan 8, 2019
1 parent dee0ccb commit 351dcc28ceaa1ae0f480beea4f85cbab15ea5034
Showing with 44 additions and 0 deletions.
  1. +20 −0 scripts/entry/refreshGUID.js
  2. +24 −0 scripts/get/entry.js
@@ -0,0 +1,20 @@
var Entry = require("../../app/models/entry");
var get = require("../get/entry");
var helper = require("../../app/helper");
var guid = helper.guid;

get(process.argv[2], function(err, user, blog, entry) {
if (err) throw err;

console.log('Old GUID:', entry.guid);

entry.guid = "entry_" + guid();

console.log('New GUID:', entry.guid);

Entry.set(blog.id, entry.path, entry, function(err) {
if (err) throw err;

console.log("Refreshed GUID of entry:", process.argv[2]);
});
});
@@ -0,0 +1,24 @@
var User = require("../../app/models/user");
var Entry = require("../../app/models/entry");
var Blog = require("../../app/models/blog");
var parseUrl = require("url").parse;

// Takes a URL and fetches the blog, user and entry

module.exports = function get(url, callback) {
url = parseUrl(url);

Blog.get({ domain: url.host }, function(err, blog) {
if (err || !blog) return callback(err || new Error("No blog"));

User.getById(blog.owner, function(err, user) {
if (err || !user) return callback(err || new Error("No user"));

Entry.getByUrl(blog.id, url.path, function(entry) {
if (!entry) return callback(new Error("No entry"));

callback(err, user, blog, entry);
});
});
});
};

0 comments on commit 351dcc2

Please sign in to comment.