| 1 | #! /usr/bin/env php |
|---|
| 2 | <?php |
|---|
| 3 | require_once(dirname($argv[0]) . "/utilities.php"); |
|---|
| 4 | require_once(IA_ROOT_DIR."common/db/round.php"); |
|---|
| 5 | require_once(IA_ROOT_DIR."common/db/job.php"); |
|---|
| 6 | |
|---|
| 7 | ini_set("memory_limit", "128M"); |
|---|
| 8 | |
|---|
| 9 | // validate argv |
|---|
| 10 | log_assert(4 <= $argc, "Expecting at least two arguments: round user destination (all)"); |
|---|
| 11 | $round = $argv[1]; |
|---|
| 12 | $user = $argv[2]; |
|---|
| 13 | $dest = implode(explode('/', $argv[3]), '/'); |
|---|
| 14 | $all = getattr($argv, 4, false); |
|---|
| 15 | |
|---|
| 16 | db_connect(); |
|---|
| 17 | $query = sprintf("SELECT id FROM ia_round WHERE id LIKE '%%%s%%'", db_escape($round)); |
|---|
| 18 | $rounds = db_fetch_all($query); |
|---|
| 19 | |
|---|
| 20 | $total = 0; |
|---|
| 21 | foreach ($rounds as $round) { |
|---|
| 22 | $tasks = round_get_tasks($round['id'], 0, null, $user); |
|---|
| 23 | |
|---|
| 24 | foreach ($tasks as $task) { |
|---|
| 25 | $filters = array('user' => $user, |
|---|
| 26 | 'task' => $task['id'], |
|---|
| 27 | 'round' => $round['id']); |
|---|
| 28 | if ($all) { |
|---|
| 29 | $range = 666013; |
|---|
| 30 | } else { |
|---|
| 31 | $range = 1; |
|---|
| 32 | } |
|---|
| 33 | $jobs = job_get_range($filters, 0, $range); |
|---|
| 34 | $total += count($jobs); |
|---|
| 35 | |
|---|
| 36 | foreach ($jobs as $job) { |
|---|
| 37 | $job = job_get_by_id($job['id'], true); |
|---|
| 38 | $fname = $dest.'/'.$user.'-'.$task['id']; |
|---|
| 39 | if ($all) { |
|---|
| 40 | $fname .= '-'.$job['id']; |
|---|
| 41 | } |
|---|
| 42 | $fname .= '.'.$job['compiler_id']; |
|---|
| 43 | |
|---|
| 44 | $fp = @fopen($fname, 'w'); |
|---|
| 45 | if (!$fp) { |
|---|
| 46 | log_warn("Nu s-a putut deschide fisierul ".$fname); |
|---|
| 47 | continue; |
|---|
| 48 | } |
|---|
| 49 | if (!fwrite($fp, $job['file_contents'])) { |
|---|
| 50 | log_warn("Nu s-a putut scrie in fisierul ".$fname); |
|---|
| 51 | continue; |
|---|
| 52 | } |
|---|
| 53 | fclose($fp); |
|---|
| 54 | } |
|---|
| 55 | } |
|---|
| 56 | } |
|---|
| 57 | log_print("S-au extras ".$total." surse pentru ".$user); |
|---|
| 58 | ?> |
|---|