#!/usr/bin/env php fetchAll($query); $tables = array_map("reset", $result); $mainTables = array_filter($tables, function ($table) { if (preg_match('/^BI_audit/', $table)) return true; return false; }); sort($mainTables); $refTables = []; foreach ($mainTables as $tableFrom) { foreach ($mainTables as $tableTo) { try { $refTables[] = ACL::getRefTable("default_db/{$tableFrom}/{$tableFrom}", "default_db__x3A__{$tableTo}:{$tableTo}"); } catch (Exception $e) { } } } $refTables = array_filter($refTables, function ($table) { if (preg_match('/_VIEW$/', $table)) return false; return true; }); sort($refTables); echo "Główne tabele do wyczyszczenia: (" . count($mainTables) . "):\n" . implode(", ", $mainTables) . "\n\n"; echo "Tabele relacyjne do wyczyszczenia (" . count($refTables) . "):\n" . implode(", ", $refTables) . "\n\n"; $prompt = null; while (!in_array($prompt, ['t', 'n'])) { $prompt = strtolower(readline("Jesteś pewien, że chcesz wyczyścić te wszystkie tabele? [T/N]: ")); } if ($prompt === 'n') die("Przerywam\n"); try { Lib::loadClass('Token'); $pass = Config::getConfFile('default_db')['pass']; $tokenObj = new Token($pass); $token = $tokenObj->genToken(); echo "Token: {$token}\n"; $hash = readline("Hash: "); if ($pass !== $tokenObj->verify($hash)) die("Błędny token, przerywam\n"); } catch (Exception $e) { die("Wystąpił nieznany błąd, przerywam\n"); } $prompt = null; while (!in_array($prompt, ['t', 'n'])) { $prompt = strtolower(readline("Na pewno jesteś pewien, że chcesz wyczyścić te wszystkie tabele? [T/N]: ")); } if ($prompt === 'n') die("Przerywam\n"); echo "\nCzyszczę tabele:\n"; foreach (array_merge($mainTables, $refTables) as $table) { echo $table; try { DB::getPDO()->query("truncate table `{$table}`"); echo " - OK\n"; } catch (Exception $e) { echo " - ERROR\n"; } }