Hi!
This page explains a way you can delete all your cards at once from your Wekan recycle bin. The steps are straightforward:
- Export your Wekan board. In my installation, Hamburger menu on the top right → Export board.
- Save the script below in a file called
clean.php
. Place it next to the JSON you saved from 1. - Open a terminal, navigate to the directory of the JSON and the script, and run the script like so:
$ php clean.php $NAME_OF_THE_JSON_FILE.json
- The script should finish fast and it will create a $NAME_OF_THE_JSON_FILE_filtered.json, so that you can compare with the original if you wish.
- Re-import the filtered JSON into your Wekan instance.
Disclaimer: please note that I have not tested this script thoughoutly. SANDSTORM USERS BEWARE: DO NOT use until the following is fixed: wekan/wekan#1430
Original discussion: wekan/wekan#1625 (comment)
Happy cleaning! @udvarit
The script:
<?php
if(!$argv[1]) {
die("Specify wekan export json file name pls\n");
}
$data = json_decode(file_get_contents($argv[1]), "assoc pls");
// delete archived lists
$archived_list_ids = [];
$data["lists"] = array_filter($data["lists"], function($elem){
global $archived_list_ids;
$active = $elem["archived"] === false;
if(!$active) {
$archived_list_ids []= $elem["_id"];
}
return $active;
});
$data["lists"] = array_values($data["lists"]);
// delete archived cards
$archived_card_ids = [];
$data["cards"] = array_filter($data["cards"], function($elem){
global $archived_card_ids, $archived_list_ids;
$active_card = $elem["archived"] === false && !in_array($elem["listId"], $archived_list_ids);
if(!$active_card) {
$archived_card_ids []= $elem["_id"];
}
return $active_card;
});
$data["cards"] = array_values($data["cards"]);
// delete all activity. Would need to check a lot of references and I don't care much for it
$data["activities"] = [];
// delete all referenced data relating to deleted cards
foreach(["checklists", "checklistItems", "attachments", "comments"] as $data_type) {
$data[$data_type] = array_filter($data[$data_type], function($elem){
global $archived_card_ids;
return !in_array($elem["cardId"], $archived_card_ids);
});
$data[$data_type] = array_values($data[$data_type]);
}
// done!
file_put_contents(
pathinfo($argv[1], PATHINFO_FILENAME) . "_filtered.json",
json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)
);
?>