Created
June 10, 2018 22:40
-
-
Save udvarit/e5927b8ceb2220db8d7113ee96618e71 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment