| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- #!/usr/bin/env php
- <?php
- error_reporting(E_ALL & ~E_NOTICE);
- $_SERVER['SERVER_NAME'] = gethostname();
- //require("/Library/Server/Web/Data/Sites/Default/dev-bzyk/se-lib/bootstrap.php");
- require("/Library/Server/Web/Data/Sites/Default/SE/se-lib/bootstrap.php");
- date_default_timezone_set('Europe/Warsaw');
- $query = "show tables";
- $result = DB::getPDO()->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";
- }
- }
|