The Twig API

craft.nuke is read-only, and always will be. A template rendered by a visitor’s request is not a place from which content should be removable.

Methods

CallReturns
craft.nuke.stats()Totals: runs, strikes, sweeps, removed, plus lastSweep and lastStrike.
craft.nuke.runs(limit, type)Recent runs, newest first. type is 'strike', 'sweep' or omitted.
craft.nuke.lastSweep()The most recent real sweep, or null.
craft.nuke.nextSweep()An ISO-8601 string for the next scheduled sweep, or null if none is scheduled.
craft.nuke.isPro()Whether Pro is active.

A run

PropertyWhat it is
id, type, statustype is strike or sweep.
summaryThe target as a sentence.
noteWhatever was written against the run.
removed, failed, durationDenormalised, so listing runs needs no JSON parsing.
scheduledWhether the scheduler started it.
dateCreatedA DateTime.
userThe user, or null for a console or scheduled run.
backupPathPath of the pre-strike backup, or null.
target, preview, outcomeThe raw records, as arrays.
cpUrlLink to the run screen.
drift()Removed minus predicted, or null when there is nothing to compare.
statusLabel(), statusColor()For rendering, in Craft’s own status vocabulary.

A maintenance panel

{% set last = craft.nuke.lastSweep() %}

{% if last %}
  <p>
    Last swept {{ last.dateCreated|date('j M, H:i') }},
    removing {{ last.removed|number_format }} things
    in {{ last.duration|number_format(1) }}s.
  </p>
{% else %}
  <p>Never swept.</p>
{% endif %}

{% set next = craft.nuke.nextSweep() %}
{% if next %}
  <p>Next sweep {{ next|date('D j M, H:i') }}.</p>
{% endif %}

<ul>
  {% for run in craft.nuke.runs(5, 'strike') %}
    <li>
      <a href="{{ run.cpUrl }}">{{ run.summary }}</a>
      — {{ run.removed|number_format }} removed,
      {{ run.dateCreated|date('j M') }}
      {% if run.failed %}<strong>({{ run.failed }} failed)</strong>{% endif %}
    </li>
  {% endfor %}
</ul>

Watching for a stale schedule

A scheduled sweep that has quietly stopped running is exactly the kind of thing nobody notices. Worth surfacing somewhere:

{% set last = craft.nuke.lastSweep() %}
{% if craft.nuke.nextSweep() and (not last or last.dateCreated < now|date_modify('-14 days')) %}
  <p class="warning">Housekeeping has not run in a fortnight — check the cron job.</p>
{% endif %}

Permissions

craft.nuke does not check permissions — it is a template API, and what a template chooses to show is the template’s decision. Do not print a run’s summary on a public page without thinking about it: it names your sections.