Action

Restore Blanks

Posted by agiletortoise, Last update about 5 hours ago

Look for blank drafts, and restore them to the content of the most recent version in the version history. Optionally, assign a tag to the modified drafts.

Steps

  • script

    // look for blank drafts, and restore them to their most recent version
    let f = () => {
    	let blanks = Draft.query("/^$/", "all", [])
    	if (blanks.length == 0) {
    		alert("No blank drafts found.")
    		return false
    	}
    
    	let p = new Prompt()
    	p.title = "Restore Blank Drafts"
    	p.message = `Found ${blanks.length} draft(s).
    	
    Restore the content of these drafts to the content of the most recent version in their version history? Optionally, enter a tag below to have that tag assigned to each draft so they can be filtered for review.`
    
    	p.addTextField("tag", "Tag to assign", "")
    	p.isCancellable = true
    	p.addButton("Restore Blanks")
    
    	if(!p.show()) { return false }
    
    	// loop over blanks, and restore if a version exists
    	let ct = 0
    	let tag = p.fieldValues["tag"]
    	
    	for (let d of blanks) {
    		if (d.versions.length > 0) {
    			let v = d.versions[0]
    			if (v.content.length > 0) {
    				d.content = v.content
    				if (tag.length > 0) {
    					d.addTag(tag)
    				}
    				d.update()
    				ct++
    			}
    		}
    	}
    	alert(`Restored ${ct} draft(s)`)
    }
    
    if(!f()) {
    	context.cancel()
    }

Options

  • After Success Default
    Notification Info
    Log Level Info
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.