Monday, November 08, 2010 at 12:05 AM.
system.verbs.builtins.radio.utilities.changeUpstreamServer
<<10/6/01; 11:54:05 PM by JES <<This script changes your default upstream server to the new server at Radio.xmlStorageSystem.Com. <<Radio.xmlStorageSystem.Com will be the default server for all Radio UserLand 7.1 installations. <<The script first moves your weblog files into the www/system/upstream folder, and updates your weblog prefs. <<Next, it registers with the new xmlStorageSystem server, and creates a #upstream.xml file which points at your new account. The original #upstream.xml is backed up to #upstream.bkp. <<Last, it invalidates the upstream cache for all the files in the upstream folder, causing the files to be upstreamed to the new server. local (server = "radio.xmlstoragesystem.com"); local (port = 80); local (protocol = "xml-rpc"); local (rpcPath = "/RPC2"); local (soapAction = "/xmlStorageSystem"); local (passwordName = "defaultXssPassword"); bundle { //ask for a password if needed if string (user.radio.prefs.passwords.[passwordName]) == "" { if not dialog.getPassword ("Enter a password for your upstream account:", @user.radio.prefs.passwords.[passwordName]) { return (false)}}}; local (upstreamFolder, upstreamRelativeFolder); bundle { //get the absolute and relative path to the upstream folder upstreamRelativeFolder = radio.data.folderNames.wwwSystemSubfolderName + "/" + radio.data.folderNames.wwwUpstreamSubfolderName + "/"; upstreamFolder = radio.file.getSubFolder (upstreamRelativeFolder)}; bundle { //move the weblog to the upstream folder, if necessary; update prefs local (adrblog = radio.weblog.init ()); local (adrprefs = @adrblog^.prefs); local (weblogFolder, homePageFileName, rssFileName); bundle { //calculate the original weblog folder, and home page filename weblogFolder = adrprefs^.homePageFilePath; weblogFolder = string.popSuffix (weblogFolder, "/") + "/"; homePageFileName = string.delete (adrprefs^.homePageFilePath, 1, sizeOf (weblogFolder)); weblogFolder = string.popLeading (weblogFolder, "/"); weblogFolder = radio.file.getAbsolutePath (weblogFolder)}; if weblogFolder != upstreamFolder { //move all the files to the upstream folder local (pc = file.getPathChar ()); on moveFile (fname) { local (f = weblogFolder + fname); if file.exists (f) { file.move (f, upstreamFolder)}}; moveFile (homePageFileName); moveFile ("rss.xml"); moveFile ("categories" + pc); moveFile ("2001" + pc); moveFile ("2000" + pc); moveFile ("1999" + pc)}; bundle { //update prefs adrprefs^.homePageFilePath = upstreamRelativeFolder + homePageFileName; adrprefs^.rssFilePath = upstreamRelativeFolder + "rss.xml"; adrprefs^.rssCategoryFolderPath = upstreamRelativeFolder + "categories/"}}; local (upstreamSpecPath = upstreamFolder + radio.data.fileNames.upstreamFileName); bundle { //make a backup of the existing #upstream.xml local (backupFileName = "#upstream_backup.txt"); local (backupPath = upstreamFolder + backupFileName); if file.exists (backupPath) { file.delete (backupPath)}; if file.exists (upstreamSpecPath) { file.rename (upstreamSpecPath, backupFileName)}; if file.exists (upstreamFolder + "#upstream.bkp") { //this will confuse the upstreaming code -- delete the file. file.delete (upstreamFolder + "#upstream.bkp")}}; local (greeting); bundle { //register with the new server local (data, response); bundle { //init the data table new (tableType, @data); data.server = server; data.port = port; data.protocol = protocol; data.rpcPath = rpcPath; data.soapAction = soapAction; data.flDebug = false}; if not xmlStorageSystem.register (user.prefs.mailAddress, user.radio.prefs.passwords.[passwordName], user.prefs.name, @greeting, @data, @response) { scriptError ("Can't register with " + server + " because the server returned an error: \"" + greeting + "\".")}; user.radio.prefs.usernum = response.usernum}; bundle { //write out the new spec local (adrdriver); radio.upstream.findDriver ("xmlStorageSystem", @adrdriver); adrdriver^.saveUpstreamSpec (upstreamSpecPath, string (user.radio.prefs.usernum), user.prefs.name, passwordName, protocol, server, port)}; bundle { //invalidate cache local (adr); for adr in @user.radio.settings.files { local (name = nameOf (adr^)); if name beginsWith upstreamFolder { adr^.modified = date (0); if defined (adr^.upstream) { adr^.upstream.url = ""; adr^.upstream.whenLastUploaded = date (0)}}}}; dialog.alert ("The server said: " + greeting + ".")
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.