srchub

srchub Commit Details


Date:2014-12-27 14:26:17 (10 years 2 months ago)
Author:Natalie Adams
Branch:master
Commit:2d814d43e885e143c1aec91058e4e38776a6c6f9
Parents: f6447abf597ee64b0f020848d10a6d83f3e32e7e
Message:Fixing issue 82 Fixing old issue 44

Changes:

File differences

indefero/scripts/calculateforgecron.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
/**
 * Get a forge size.
 *
 * @return array Associative array with the size of each element
 */
function IDF_Views_Admin_getForgeSize($force=false)
{
    $conf = new IDF_Gconf();
    $conf->setModel((object) array('_model'=>'IDF_Forge', 'id'=> 1));
    $res = array();
    $res['repositories'] = 0;
    foreach (Pluf::factory('IDF_Project')->getList() as $prj) {
        $size = $prj->getRepositorySize($force);
        if ($size != -1) {
            $res['repositories'] += $size;
        }
    }
    $last_eval = $conf->getVal('downloads_size_check_date', 0);
    if (Pluf::f('idf_no_size_check', false) or
        (!$force and $last_eval > time()-172800)) {
        $res['downloads'] = $conf->getVal('downloads_size', 0);
    } else {
        $conf->setVal('downloads_size_check_date', time());
        $total = 0;
        foreach(Pluf::factory("IDF_Upload")->getList() as $issuefile)
        {
            $total += $issuefile->filesize;
        }
        $res['downloads'] = $total;
        $conf->setVal('downloads_size', $res['downloads']);
    }
    $last_eval = $conf->getVal('attachments_size_check_date', 0);
    if (Pluf::f('idf_no_size_check', false) or
        (!$force and $last_eval > time()-172800)) {
        $res['attachments'] = $conf->getVal('attachments_size', 0);
    } else {
        $total = 0;
        foreach(Pluf::factory("IDF_IssueFile")->getList() as $issuefile)
        {
            $total += $issuefile->filesize;
        }
        $res['attachments'] = $total;
        $conf->setVal('attachments_size_check_date', time());
        $conf->setVal('attachments_size', $res['attachments']);
    }
    $last_eval = $conf->getVal('database_size_check_date', 0);
    if (Pluf::f('idf_no_size_check', false) or
        (!$force and $last_eval > time()-172800)) {
        $res['database'] = $conf->getVal('database_size', 0);
    } else {
        $conf->setVal('database_size_check_date', time());
        $res['database'] = IDF_Views_Admin_getForgeDbSize();
        $conf->setVal('database_size', $res['database']);
    }
    $res['total'] = $res['repositories'] + $res['downloads'] + $res['attachments'] + $res['database'];
    return $res;
}
/**
 * Get the database size as given by the database.
 *
 * @return int Database size
 */
function IDF_Views_Admin_getForgeDbSize()
{
    $db = Pluf::db();
    if (Pluf::f('db_engine') == 'SQLite') {
        return filesize(Pluf::f('db_database'));
    }
    switch (Pluf::f('db_engine')) {
        case 'PostgreSQL':
            $sql = 'SELECT relname, pg_total_relation_size(CAST(relname AS
TEXT)) AS size FROM pg_class AS pgc, pg_namespace AS pgn
     WHERE pg_table_is_visible(pgc.oid) IS TRUE AND relkind = \'r\'
     AND pgc.relnamespace = pgn.oid
     AND pgn.nspname NOT IN (\'information_schema\', \'pg_catalog\')';
            break;
        case 'MySQL':
        default:
            $sql = 'SHOW TABLE STATUS FROM `'.Pluf::f('db_database').'`';
            break;
    }
    $rs = $db->select($sql);
    $total = 0;
    switch (Pluf::f('db_engine')) {
        case 'PostgreSQL':
            foreach ($rs as $table) {
                $total += $table['size'];
            }
            break;
        case 'MySQL':
        default:
            foreach ($rs as $table) {
                $total += $table['Data_length'] + $table['Index_length'];
            }
            break;
    }
    return $total;
}
require dirname(__FILE__).'/../src/IDF/conf/path.php';
require 'Pluf.php';
Pluf::start(dirname(__FILE__).'/../src/IDF/conf/idf.php');
Pluf_Dispatcher::loadControllers(Pluf::f('idf_views'));
IDF_Views_Admin_getForgeSize(true);
indefero/src/IDF/Views/Admin.php
628628
629629
630630
631
631
632632
633633
634634
635
636
637
638
635
636
637
638
639
640
639641
640642
641643
......
643645
644646
645647
648
649
650
651
652
653
646654
647
648
649
650
651655
652656
653657
    }
    $last_eval = $conf->getVal('downloads_size_check_date', 0);
    if (Pluf::f('idf_no_size_check', false) or
              (!$force and $last_eval > time()-172800)) {
        (!$force and $last_eval > time()-172800)) {
        $res['downloads'] = $conf->getVal('downloads_size', 0);
    } else {
        $conf->setVal('downloads_size_check_date', time());
        $cmd = Pluf::f('idf_exec_cmd_prefix', '').'du -sk '
            .escapeshellarg(Pluf::f('upload_path'));
        $out = explode(' ', shell_exec($cmd), 2);
        $res['downloads'] = $out[0]*1024;
        $total = 0;
        foreach(Pluf::factory("IDF_Upload")->getList() as $issuefile)
        {
            $total += $issuefile->filesize;
        }
        $res['downloads'] = $total;
        $conf->setVal('downloads_size', $res['downloads']);
    }
    $last_eval = $conf->getVal('attachments_size_check_date', 0);
        (!$force and $last_eval > time()-172800)) {
        $res['attachments'] = $conf->getVal('attachments_size', 0);
    } else {
        $total = 0;
        foreach(Pluf::factory("IDF_IssueFile")->getList() as $issuefile)
        {
            $total += $issuefile->filesize;
        }
        $res['attachments'] = $total;
        $conf->setVal('attachments_size_check_date', time());
        $cmd = Pluf::f('idf_exec_cmd_prefix', '').'du -sk '
            .escapeshellarg(Pluf::f('upload_path'));
        $out = explode(' ', shell_exec($cmd), 2);
        $res['attachments'] = $out[0]*1024;
        $conf->setVal('attachments_size', $res['attachments']);
    }
    $last_eval = $conf->getVal('database_size_check_date', 0);

Archive Download the corresponding diff file

Branches

Number of commits:
Page rendered in 0.09721s using 21 queries.