diff options
author | Minteck <contact@minteck.org> | 2023-01-02 20:29:01 +0100 |
---|---|---|
committer | Minteck <contact@minteck.org> | 2023-01-02 20:29:01 +0100 |
commit | e72d0adbcd7e69928a1ef380c7a841c160284c68 (patch) | |
tree | 1b9b9c29bb4fd39b6bdf577375bb91be3b9d6be1 /includes/maintenance | |
parent | c9de96328e59816ff4867abf5feab9fb9bf29511 (diff) | |
download | pluralconnect-e72d0adbcd7e69928a1ef380c7a841c160284c68.tar.gz pluralconnect-e72d0adbcd7e69928a1ef380c7a841c160284c68.tar.bz2 pluralconnect-e72d0adbcd7e69928a1ef380c7a841c160284c68.zip |
Update
Diffstat (limited to 'includes/maintenance')
-rw-r--r-- | includes/maintenance/clearUnused.php | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/includes/maintenance/clearUnused.php b/includes/maintenance/clearUnused.php new file mode 100644 index 0000000..99b6ca4 --- /dev/null +++ b/includes/maintenance/clearUnused.php @@ -0,0 +1,34 @@ +<?php + +$_SERVER['DOCUMENT_ROOT'] = "../.."; + +foreach (array_filter(scandir($_SERVER['DOCUMENT_ROOT'] . "/includes/data/metadata"), function ($i) { return !str_starts_with($i, "."); }) as $file) { + $data = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/metadata/$file"), true); + echo("$file\n"); + + if (!isset($data["bitset"])) { + die(" No bitset?? wtf\n"); + } else { + $bits = str_split(substr(str_repeat("0", 48), 0, 48 - strlen(decbin($data["bitset"]))) . decbin($data["bitset"])); + echo(" Old:\n"); + echo(" " . str_replace("+", "\e[92m1\e[39m", str_replace("-", "\e[31m0\e[39m", implode("", str_replace("0", "-", str_replace("1", "+", $bits))))) . "\n"); + echo(" XXXXXXXXXX X XXXXXX X XX XXXX X\n"); + + $bitsOld = implode("", $bits); + foreach ([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 12, 18, 19, 20, 21, 22, 23, 26, 31, 32, 41, 42, 43, 44, 47] as $bit) { + $bits[$bit] = "0"; + } + + echo(" New:\n"); + echo(" " . str_replace("+", "\e[92m1\e[39m", str_replace("-", "\e[31m0\e[39m", implode("", str_replace("0", "-", str_replace("1", "+", $bits))))) . "\n"); + echo(" XXXXXXXXXX X XXXXXX X XX XXXX X\n"); + echo(" Changed " . levenshtein($bitsOld, implode("", $bits)) . " bit(s)\n"); + + echo(" Backup made in " . substr($file, 0, -5) . "-old.json\n"); + copy($_SERVER['DOCUMENT_ROOT'] . "/includes/data/metadata/$file", $_SERVER['DOCUMENT_ROOT'] . "/includes/data/metadata/" . substr($file, 0, -5) . "-old.json"); + + $data["bitset"] = bindec(implode("", $bits)); + echo(" Saved to " . $file . "\n"); + file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/metadata/$file", json_encode($data)); + } +}
\ No newline at end of file |