private function getAllowedQuotaInBytes($group_id)
 {
     $allowed_quota_in_GB = $this->project_quota_manager->getProjectCustomQuota($group_id);
     if (!$allowed_quota_in_GB) {
         $allowed_quota_in_GB = $this->disk_usage_manager->getProperty('allowed_quota');
     }
     return $this->gigabytesToBytes($allowed_quota_in_GB);
 }
Beispiel #2
0
 * along with Codendi; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
require 'pre.php';
require_once dirname(__FILE__) . '/../include/Statistics_DiskUsageHtml.class.php';
// First, check plugin availability
$pluginManager = PluginManager::instance();
$p = $pluginManager->getPluginByName('statistics');
if (!$p || !$pluginManager->isPluginAvailable($p)) {
    header('Location: ' . get_server_url());
}
// Grant access only to site admin
if (!UserManager::instance()->getCurrentUser()->isSuperUser()) {
    header('Location: ' . get_server_url());
}
$duMgr = new Statistics_DiskUsageManager();
$duHtml = new Statistics_DiskUsageHtml($duMgr);
$vFunc = new Valid_WhiteList('func', array('show_one_project', 'show_top_projects', 'show_service', 'show_top_users', 'show_one_user'));
$vFunc->required();
if ($request->valid($vFunc)) {
    $func = $request->get('func');
} else {
    $func = 'show_service';
}
$vStartDate = new Valid('start_date');
$vStartDate->addRule(new Rule_Date());
$vStartDate->required();
if ($request->valid($vStartDate)) {
    $startDate = $request->get('start_date');
} else {
    $startDate = date('Y-m-d', strtotime('-1 week'));
    header('Location: ' . get_server_url());
}
$vGroupId = new Valid_GroupId();
$vGroupId->required();
if ($request->valid($vGroupId)) {
    $groupId = $request->get('group_id');
    $project = ProjectManager::instance()->getProject($groupId);
} else {
    header('Location: ' . get_server_url());
}
// Grant access only to project admins
$user = UserManager::instance()->getCurrentUser();
if (!$project->userIsAdmin($user)) {
    header('Location: ' . get_server_url());
}
$duMgr = new Statistics_DiskUsageManager();
$vServices = new Valid_WhiteList('services', array_keys($duMgr->getProjectServices(false)));
$vServices->required();
if ($request->validArray($vServices)) {
    $services = $request->get('services');
} else {
    $services = array_keys($duMgr->getProjectServices(false));
}
$vStartDate = new Valid('start_date');
$vStartDate->addRule(new Rule_Date());
$vStartDate->required();
if ($request->valid($vStartDate)) {
    $startDate = $request->get('start_date');
} else {
    $startDate = '';
}
Beispiel #4
0
 /**
  * Delete custom quota for a project
  *
  * @param Array $projects List of projects for which custom quota will be deleted
  *
  * @return Void
  */
 public function deleteCustomQuota($projects)
 {
     if (empty($projects)) {
         $GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('plugin_statistics', 'nothing_to_delete'));
     } else {
         $list = array();
         $names = array();
         $dum = new Statistics_DiskUsageManager();
         $defaultQuota = $dum->getProperty('allowed_quota');
         $historyDao = new ProjectHistoryDao(CodendiDataAccess::instance());
         foreach ($projects as $projectId => $name) {
             $list[] = $projectId;
             $names[] = $name;
             $historyDao->groupAddHistory("restore_default_quota", intval($defaultQuota), $projectId);
         }
         if ($this->dao->deleteCustomQuota($list)) {
             $GLOBALS['Response']->addFeedback('info', $GLOBALS['Language']->getText('plugin_statistics', 'quota_deleted', array(join(', ', $names))));
         } else {
             $GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('plugin_statistics', 'delete_error'));
         }
     }
 }
Beispiel #5
0
} else {
    header('Location: ' . get_server_url());
}
// Grant access only to project admins
$user = UserManager::instance()->getCurrentUser();
if (!$project->userIsAdmin($user)) {
    header('Location: ' . get_server_url());
}
$vPeriod = new Valid_WhiteList('period', array('year', 'months'));
$vPeriod->required();
if ($request->valid($vPeriod)) {
    $period = $request->get('period');
} else {
    $period = 'months';
}
$duMgr = new Statistics_DiskUsageManager();
$duHtml = new Statistics_DiskUsageHtml($duMgr);
// selected service
$vServices = new Valid_WhiteList('services', array_keys($duMgr->getProjectServices(false)));
$vServices->required();
if ($request->validArray($vServices)) {
    $selectedServices = $request->get('services');
} else {
    $selectedServices = array_keys($duMgr->getProjectServices(false));
}
if ($project && !$project->isError()) {
    // Prepare params
    $serviceParam = '';
    $first = true;
    foreach ($selectedServices as $serv) {
        if ($first != true) {
<?php

// This script is for development use only
require_once 'pre.php';
require_once dirname(__FILE__) . '/../include/Statistics_DiskUsageManager.class.php';
$dum = new Statistics_DiskUsageManager();
$dum->collectAll();
Beispiel #7
0
function exportDiskUsageForDate(Statistics_Services_UsageFormatter $csv_exporter, $date, $column_name)
{
    $disk_usage_manager = new Statistics_DiskUsageManager();
    $disk_usage = $disk_usage_manager->returnTotalSizeOfProjects($date);
    $disk_usage = $csv_exporter->formatSizeInMegaBytes($disk_usage);
    $csv_exporter->buildDatas($disk_usage, $column_name);
}
 private function diskUsage()
 {
     $this->logger->debug(__METHOD__);
     $dum = new Statistics_DiskUsageManager();
     $dum->collectAll();
 }
 /**
  *
  */
 protected function _diskUsage()
 {
     $dum = new Statistics_DiskUsageManager();
     $dum->collectAll();
 }
$pluginManager = PluginManager::instance();
$p = $pluginManager->getPluginByName('statistics');
if (!$p || !$pluginManager->isPluginAvailable($p)) {
    header('Location: ' . get_server_url());
}
$vGroupId = new Valid_GroupId();
$vGroupId->required();
if ($request->valid($vGroupId)) {
    $groupId = $request->get('group_id');
    $project = ProjectManager::instance()->getProject($groupId);
} else {
    header('Location: ' . get_server_url());
}
$func = $request->getValidated('func', new Valid_WhiteList('usage', 'progress'), '');
//Get dates for start and end period to watch statistics
$duMgr = new Statistics_DiskUsageManager();
$statPeriod = $duMgr->getProperty('statistics_period');
if (!$statPeriod) {
    $statPeriod = 3;
}
$endDate = date('Y-m-d');
$startDate = date('Y-m-d', mktime(0, 0, 0, date('m') - $statPeriod, date('d'), date('y')));
$services = $duMgr->getProjectServices();
// Display graph
$graph = new Statistics_DiskUsageGraph($duMgr);
if ($func == 'usage') {
    //Retreive the config param & convert it to bytes
    $quota = $duMgr->getProperty('allowed_quota');
    $pqm = new ProjectQuotaManager();
    $customQuota = $pqm->getProjectCustomQuota($groupId);
    if ($customQuota) {