Action

Scan Version History

Posted by agiletortoise, Last update 5 days ago

Scans all version histories for all drafts looking for a snippet of text. If any drafts are found with this text in one of their version histories, create a new summary draft with links to the current version of each draft.

When run, you will be prompted for the text to find. It will be searched with simple case-insensitive matching.

Useful for troubleshooting a case where you know a text existed in a previous version of a draft, but that draft cannot be found with normal search because the text is no longer in the current version of the draft.

Steps

  • script

    let f = () => {
    	let matches = []
    
    	let p = new Prompt()
    	p.title = "Scan Version History"
    	p.message = "Scans the text of draft version histories for a specific piece of text. Useful if the current version of the draft no longer contains the text. After running, a new draft will be created summarizing the finding with links to matching drafts."
    
    	p.addTextField("q", "Find", "")
    	p.addButton("Start")
    
    	if(!p.show()) { return false }
    
    	let q = p.fieldValues["q"]
    	if(q.length == 0) {
    		return false
    	}
    
    	// loop over all drafts looking at versions
    	const all = Draft.query("", "all", [])
    	for (let d of all) {
    		if (d.versions.length == 0) {
    			continue
    		}
    		let ix = 1
    		for (let v of d.versions) {
    			if (v.content.toLowerCase().includes(q.toLowerCase())) {
    				matches.push(d)
    			}
    		}
    	}
    
    	if (matches.length == 0) {
    		alert(`No matches for the string "${q}" found in version histories`)
    		return false
    	}
    
    	let s = "# Scan Version History Results\n\n"
    	for(let d of matches) {
    		s += `* [${d.displayTitle}](${d.permalink})
    `
    	}
    	let d = new Draft()
    	d.content = s
    	d.update()
    	editor.load(d)
    }
    
    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.