| 1 | <?php |
|---|
| 2 | $page_title = "Allmydata - Deep Size"; |
|---|
| 3 | |
|---|
| 4 | require(".inc/includes.php"); |
|---|
| 5 | require(".inc/ui/dbconnection.php"); |
|---|
| 6 | |
|---|
| 7 | // get the batch_id for this run |
|---|
| 8 | $query = "select max(batch_id) from user_space_usage where true"; |
|---|
| 9 | $q_results = mysql_query($query); |
|---|
| 10 | if($q_results) { |
|---|
| 11 | $results = mysql_fetch_row($q_results); |
|---|
| 12 | $batch_id = $results[0]; |
|---|
| 13 | $batch_id = $batch_id + 1; |
|---|
| 14 | } else { |
|---|
| 15 | $batch_id = 0; |
|---|
| 16 | } |
|---|
| 17 | |
|---|
| 18 | // get list of accounts and then figure out amount of space used |
|---|
| 19 | $query = "select * from user where base_uri <> '' and active = 1 order by account_id desc"; |
|---|
| 20 | $q_results = mysql_query($query); |
|---|
| 21 | $i = 1; |
|---|
| 22 | while($results = mysql_fetch_array($q_results)) { |
|---|
| 23 | $base_uri = $results['base_uri']; |
|---|
| 24 | $account_id = $results['account_id']; |
|---|
| 25 | $email = $results['email']; |
|---|
| 26 | $ch = curl_init(); |
|---|
| 27 | $uri_url = "http://prodtahoe5.allmydata.com:8123/uri/"; |
|---|
| 28 | $full_url = $uri_url . urlencode($base_uri) . "?t=deep-stats"; |
|---|
| 29 | curl_setopt($ch, CURLOPT_URL, $full_url); |
|---|
| 30 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|---|
| 31 | $stats_data_raw = curl_exec($ch); |
|---|
| 32 | $stats_data = json_decode($stats_data_raw); |
|---|
| 33 | $size = floatval($stats_data->{'size-immutable-files'})/(1000*1000); |
|---|
| 34 | $inner_query = "update user set used_quota=" . $size . " where account_id = ". $account_id; |
|---|
| 35 | $results = mysql_query($inner_query); |
|---|
| 36 | $inner_query = "insert into user_space_usage (account_id, batch_id, mb_used) values ({$account_id}, {$batch_id}, {$size})"; |
|---|
| 37 | echo $account_id . " " . $size . " " . $batch_id . "\n"; |
|---|
| 38 | $results = mysql_query($inner_query); |
|---|
| 39 | $i = $i + 1; |
|---|
| 40 | } |
|---|
| 41 | ?> |
|---|