Skip to content

Instantly share code, notes, and snippets.

@CanRau
Last active February 8, 2020 17:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save CanRau/d92ed6baaa84d305bca1 to your computer and use it in GitHub Desktop.
Save CanRau/d92ed6baaa84d305bca1 to your computer and use it in GitHub Desktop.
<?php
/* Batch delete all fields containing order_ in name */
foreach($fields->find("name%=order_") as $field) {
$fields->delete($field);
if (!$fields->get($field)) echo "<p>field {$field->name} was deleted.</p>";
}
/* list all templates and provide ability to delete unused ones */
if ($input->post->submit) {
foreach ($input->post as $t) {
// proceed only if the input is an integer different from 0
if (!(int)$t) return;
$t = $templates->get($t);
$templates->delete($t);
$name = $t->name;
// delete the fieldgroup associated with this template. more info in the next post
$fg = $fieldgroups->get($name);
$fieldgroups->delete($fg);
// verify that the template is not there and print the confirmation
if (!$templates->get($t)) echo "<p>template {$name} was deleted.</p>";
}
} else {
// print the form
echo "<form method='post'>";
echo "<ul>";
foreach ($templates as $t) {
// name of the temlate and number of pages it uses
echo "<li>" . $t->name . " (" . $t->getNumPages() . " pages)";
// include checkbox if the template is not used by pages, and set it's id as value
if (!$t->getNumPages()) echo " <input type='checkbox' value='{$t->id}' name='{$t->name}'>";
echo "</li>";
}
echo "</ul>";
echo "<input type='submit' value='delete these' name='submit'>";
echo "</form>";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment