Monday, November 08, 2010 at 12:04 AM.
system.verbs.builtins.radio.backup.verifyOneMonth
on verifyOneMonth (year, month, adrErrorMessage) {
<<Changes
<<12/3/02; 1:58:43 PM by JES
<<Handle the case where a post does not have a categories sub-table. Added check for flNotOnHomePage.
<<11/30/02; 4:36:23 PM by JES
<<Created. Verify the weblog posts in one month's RSS archive file.
on error (s) {
adrErrorMessage^ = "Verification of backup failed because " + s};
local (pc = file.getPathChar ());
local (f = user.radio.backup.prefs.folder + "posts" + pc + year + pc + string.padwithzeros (month, 2) + ".xml");
if not file.exists (f) {
error ("the weblog backup for " + month + "/" + year + " does not exist.");
return (false)};
local (adrdata = radio.weblog.init ());
local (adrposts = @adrdata^.posts);
local (xtext = string (file.readwholefile (f)));
local (posts); new (tabletype, @posts);
try { //import the posts and compare against the posts in weblogData.posts
radio.backup.restoreOneMonth (xtext, @posts);
local (adr, ctposts);
for adr in adrposts {
local (dy, mo, yr, hr, min, sec);
date.get (adr^.when, @dy, @mo, @yr, @hr, @min, @sec);
if mo == month and yr == year { //post should be in the backup
local (name = nameOf (adr^));
local (adrbkp = @posts.[name]);
local (postnum = number (name));
if not defined (adrbkp^) {
error ("post number " + postnum + " is not backed up.");
return (false)};
if defined (adrbkp^.categories) and defined (adr^.categories) {
if not table.compareContents (@adrbkp^.categories, @adr^.categories) {
error ("the category list for the backup of post number " + postnum + " is not correct.");
return (false)}}
else { //categories table is in only one or the other -- it must be empty or it's an error
if defined (adrbkp^.categories) {
if sizeOf (adrbkp^.categories) > 0 {
error ("the category list for the backup of post number " + postnum + " is not correct.");
return (false)}};
if defined (adr^.categories) {
if sizeOf (adr^.categories) > 0 {
error ("the category list for the backup of post number " + postnum + " is not correct.");
return (false)}}};
bundle { //flNotOnHomePage
local (flPostOnHomePage = true);
if defined (adr^.flNotOnHomePage) {
flPostOnHomePage = (not adr^.flNotOnHomePage)};
local (flBkpOnHomePage = true);
if defined (adrbkp^.flNotOnHomePage) {
flBkpOnHomePage = (not adrbkp^.flNotOnHomePage)};
if flPostOnHomePage != flBkpOnHomePage {
if flPostOnHomePage {
error ("the backup of post number " + postnum + " is not in the Home Page category, but the original post is.");
return (false)}
else {
error ("the backup of post number " + postnum + " is in the Home Page category, but the original post is not.");
return (false)}}};
local (text, backuptext);
bundle { //set text and backuptext -- we don't care about line endings or leading/trailing whitespace
backuptext = string.trimWhiteSpace (string.replaceAll (string (adrbkp^.text), "\r\n", "\r"));
text = string.trimWhiteSpace (string.replaceAll (string (adr^.text), "\r\n", "\r"))};
if text != backuptext {
error ("the backed up text of post number " + postnum + " is not correct.");
return (false)};
ctposts++}};
if sizeOf (posts) != ctposts { //the backup has posts in it which have been deleted
error ("the weblog backup for \"" + month + "/" + year + " contains posts which are not in the weblog.");
return (false)}}
else { //some other error
error ("an error occurred importing backed up posts for " + month + "/" + year + ": " + tryerror);
return (false)};
return (true)};
bundle { //test code
local (s);
<<verifyOneMonth (2002, 11, @s)
verifyOneMonth (2002, 1, @s);
dialog.notify (s)}
This listing is for code that runs in the OPML Editor environment. I created these listings because I wanted the search engines to index it, so that when I want to look up something in my codebase I don't have to use the much slower search functionality in my object database. Dave Winer.