Ejemplo n.º 1
0
 public function execute()
 {
     if (Tools::isConnectedUser()) {
         $teamid = Tools::getSecureGETIntValue('teamid');
         $startTimestamp = Tools::getSecureGETStringValue('startT');
         $endTimestamp = Tools::getSecureGETStringValue('endT');
         $projectIds = Tools::getSecureGETIntValue('projects', 0);
         if (0 != $projectIds) {
             $projectIds = explode(':', $projectIds);
             if (self::$logger->isDebugEnabled()) {
                 self::$logger->debug("team <{$teamid}> projects = <{$projectIds}>");
             }
         } else {
             if (self::$logger->isDebugEnabled()) {
                 self::$logger->debug("team <{$teamid}> display all projects");
             }
             $projectIds = array();
         }
         /* INFO: the following 1 line are MANDATORY and fix the following error:
          * “The image <name> cannot be displayed because it contains errors”
          * Can't call ob_end_clean() if zlib.output_compression is ON
          */
         if (!ini_get('zlib.output_compression')) {
             ob_end_clean();
         }
         $graph = $this->getGanttGraph($teamid, $startTimestamp, $endTimestamp, $projectIds);
         // display graph
         $graph->Stroke();
         SqlWrapper::getInstance()->logStats();
     } else {
         Tools::sendForbiddenAccess();
     }
 }
Ejemplo n.º 2
0
 /**
  * Compute monthly reports for the complete year
  * @return PeriodStats[]
  */
 public function computeReport()
 {
     $now = time();
     $startM = $this->start_month;
     $startD = $this->start_day;
     for ($y = $this->start_year; $y <= date('Y'); $y++) {
         for ($month = $startM; $month < 13; $month++) {
             $startTimestamp = mktime(0, 0, 1, $month, $startD, $y);
             $endTimestamp = mktime(0, 0, 1, $month + 1, $startD, $y);
             if ($startTimestamp > $now) {
                 break;
             }
             $periodStats = new PeriodStats($startTimestamp, $endTimestamp);
             $projectList = array();
             // only projects for specified team, except excluded projects
             $query = "SELECT project_id FROM `codev_team_project_table` " . "WHERE team_id = {$this->teamid} " . "AND codev_team_project_table.type <> " . Project::type_noStatsProject;
             $result = SqlWrapper::getInstance()->sql_query($query);
             if (!$result) {
                 echo "<span style='color:red'>ERROR: Query FAILED</span>";
                 exit;
             }
             while ($row = SqlWrapper::getInstance()->sql_fetch_object($result)) {
                 $projectList[] = $row->project_id;
             }
             $periodStats->projectList = $projectList;
             $periodStats->computeStats();
             $this->periodStatsList[$startTimestamp] = $periodStats;
             $startD = 1;
         }
         $startM = 1;
     }
     return $this->periodStatsList;
 }
Ejemplo n.º 3
0
 /**
  * Create a SQL connection
  * @static
  * @param string $server The MySQL server
  * @param string $username The username
  * @param string $password The password
  * @param string $database_name The name of the database that is to be selected.
  * @return SqlWrapper The SQLWrapper
  */
 public static function createInstance($server, $username, $password, $database_name)
 {
     if (!isset(self::$instance)) {
         $c = __CLASS__;
         self::$instance = new $c($server, $username, $password, $database_name);
     }
     return self::$instance;
 }
Ejemplo n.º 4
0
function execQuery($query)
{
    $result = SqlWrapper::getInstance()->sql_query($query);
    if (!$result) {
        echo "<span style='color:red'>ERROR: Query FAILED {$query}</span>";
        exit;
    }
    return $result;
}
Ejemplo n.º 5
0
function login($user, $password)
{
    $logger = Logger::getLogger('login');
    // WARN: if logger is LoggerAppenderEcho, then logs will break the login Ajax call !
    try {
        $appenders = $logger->getParent()->getAllAppenders();
        $isLog = true;
        foreach ($appenders as $appender) {
            if ('LoggerAppenderEcho' === get_class($appender)) {
                $isLog = false;
                break;
            }
        }
    } catch (Exception $e) {
        // logs should never break application
        $isLog = false;
    }
    $password = md5($password);
    $formattedUser = SqlWrapper::sql_real_escape_string($user);
    $formattedPass = SqlWrapper::sql_real_escape_string($password);
    $query = "SELECT id, username, realname FROM `mantis_user_table` WHERE username = '******' AND password = '******' AND enabled = 1;";
    $result = SqlWrapper::getInstance()->sql_query($query);
    if ($result && SqlWrapper::getInstance()->sql_num_rows($result) == 1 && ($row_login = SqlWrapper::getInstance()->sql_fetch_object($result))) {
        $_SESSION['userid'] = $row_login->id;
        $_SESSION['username'] = $row_login->username;
        $_SESSION['realname'] = $row_login->realname;
        try {
            $user = UserCache::getInstance()->getUser($row_login->id);
            $locale = $user->getDefaultLanguage();
            if (NULL != $locale) {
                $_SESSION['locale'] = $locale;
            }
            $teamid = $user->getDefaultTeam();
            if (0 != $teamid) {
                $_SESSION['teamid'] = $teamid;
            }
            $projid = $user->getDefaultProject();
            if (0 != $projid) {
                $_SESSION['projectid'] = $projid;
            }
        } catch (Exception $e) {
            if ($isLog && self::$logger->isDebugEnabled()) {
                $logger->debug("could not load preferences for user {$row_login->id}");
            }
        }
        if ($isLog) {
            $ua = Tools::getBrowser();
            $browserStr = $ua['name'] . ' ' . $ua['version'] . ' (' . $ua['platform'] . ')';
            $logger->info('user ' . $row_login->id . ' ' . $row_login->username . ' (' . $row_login->realname . '), Team ' . $user->getDefaultTeam() . ', ' . $browserStr);
        }
        return TRUE;
    } else {
        #$error = 'login failed !';
        return FALSE;
    }
}
Ejemplo n.º 6
0
 public static function execSqlScript($sqlfile)
 {
     $sql_queries = self::getSqlQueries($sqlfile);
     $i = 1;
     foreach ($sql_queries as $query) {
         $result = SqlWrapper::getInstance()->sql_query(trim($query));
         if (!$result) {
             return -1;
         }
         ++$i;
     }
     return 0;
 }
Ejemplo n.º 7
0
 public static function execSqlScript($sqlfile)
 {
     $sql_queries = self::getSqlQueries($sqlfile);
     $i = 1;
     foreach ($sql_queries as $query) {
         $result = SqlWrapper::getInstance()->sql_query(trim($query));
         if (!$result) {
             echo "<span style='color:red'>ERROR: Query {$i} FAILED</span>";
             return -1;
         }
         ++$i;
     }
     return 0;
 }
Ejemplo n.º 8
0
 public function getVersionDate()
 {
     if (NULL == $this->versionDate) {
         $query = "SELECT date_order " . "FROM `mantis_project_version_table` " . "WHERE project_id = {$this->projectId} " . "AND version = '{$this->name}';";
         $result = SqlWrapper::getInstance()->sql_query($query);
         if (!$result) {
             echo "<span style='color:red'>ERROR: Query FAILED</span>";
             exit;
         }
         $this->versionDate = 0 != SqlWrapper::getInstance()->sql_num_rows($result) ? SqlWrapper::getInstance()->sql_result($result, 0) : "(none)";
         if ($this->versionDate <= 1) {
             $this->versionDate = "(none)";
         }
     }
     return $this->versionDate;
 }
Ejemplo n.º 9
0
 /**
  * fiches analyzed dont BI non renseignes
  * fiches analyzed dont RAE non renseignes
  * @return ConsistencyError[]
  */
 public function checkAnalyzed()
 {
     // CoDev FDJ custom, defined in Mantis
     $status_analyzed = Config::getVariableKeyFromValue(Config::id_statusNames, 'analyzed');
     $status_accepted = Config::getVariableKeyFromValue(Config::id_statusNames, 'accepted');
     $status_deferred = Config::getVariableKeyFromValue(Config::id_statusNames, 'deferred');
     $FDJ_teamid = Config::getInstance()->getValue(Config::id_ClientTeamid);
     $cerrList = array();
     // select all issues which current status is 'analyzed'
     $query = "SELECT * " . "FROM `mantis_bug_table` " . "WHERE status in ({$status_analyzed}, {$status_accepted}, " . Constants::$status_open . ", {$status_deferred}) ";
     if (0 != count($this->projectList)) {
         $formatedProjects = implode(', ', array_keys($this->projectList));
         $query .= "AND project_id IN ({$formatedProjects}) ";
     }
     $query .= "ORDER BY last_updated DESC, bug_id DESC";
     $result = SqlWrapper::getInstance()->sql_query($query);
     if (!$result) {
         echo "<span style='color:red'>ERROR: Query FAILED</span>";
         exit;
     }
     while ($row = SqlWrapper::getInstance()->sql_fetch_object($result)) {
         $issue = IssueCache::getInstance()->getIssue($row->id, $row);
         if (NULL == $issue->getEffortEstim()) {
             $cerr = new ConsistencyError($row->id, $row->handler_id, $row->status, $row->last_updated, T_("BI not specified: BI = Time(Analysis + Dev + Tests)"));
             $cerr->severity = T_("Error");
             $cerrList[] = $cerr;
         }
         if (is_null($issue->getBacklog())) {
             $cerr = new ConsistencyError($row->bug_id, $row->handler_id, $row->status, $row->last_updated, T_("Backlog not specified: Backlog = Time(BI - Analysis)"));
             $cerr->severity = T_("Error");
             $cerrList[] = $cerr;
         }
         if ($status_analyzed == $row->status) {
             $user = UserCache::getInstance()->getUser($row->handler_id);
             if (!$user->isTeamMember($FDJ_teamid)) {
                 $cerr = new ConsistencyError($row->bug_id, $row->handler_id, $row->status, $row->last_updated, T_("Once analysed, a Task must be assigned to 'FDJ' for validation"));
                 $cerr->severity = T_("Error");
                 $cerrList[] = $cerr;
             }
         }
     }
     // check if fields correctly set
     return $cerrList;
 }
Ejemplo n.º 10
0
Archivo: bvi.php Proyecto: fg-ok/codev
 private function getResolvedIssues($teamid, $userid = 0, $projects = NULL)
 {
     $team = TeamCache::getInstance()->getTeam($teamid);
     if (is_null($projects)) {
         $projects = $team->getProjects(false, false, false);
         $formattedProjects = implode(',', array_keys($projects));
     } else {
         $formattedProjects = implode(',', array_values($projects));
     }
     $formattedUsers = 0 != $userid ? $userid : implode(',', array_keys($team->getActiveMembers()));
     $query = "SELECT id FROM `mantis_bug_table` " . "WHERE project_id IN ({$formattedProjects}) " . "AND handler_id IN ({$formattedUsers}) " . "AND status >= get_project_resolved_status_threshold(project_id) ";
     $result = SqlWrapper::getInstance()->sql_query($query);
     echo "query = {$query}<br>";
     if (!$result) {
         echo "<span style='color:red'>ERROR: Query FAILED</span>";
         exit;
     }
     $isel = new IssueSelection('resolvedIssues');
     while ($row = SqlWrapper::getInstance()->sql_fetch_object($result)) {
         $isel->addIssue($row->id);
     }
     echo implode(',', array_keys($isel->getIssueList()));
     return $isel;
 }
Ejemplo n.º 11
0
 /**
  * Returns all Issues resolved in the period, including re-opened and validated.
  * 
  * @param array $formattedBugidList comma-separated list to be included in SQL request
  * @param int $startTimestamp
  * @param int $endTimestamp
  * @return array bugidList
  */
 private function getResolved($formattedBugidList, $start, $end)
 {
     // all bugs which status changed to 'resolved' whthin the timestamp
     $query = "SELECT bug.id " . "FROM `mantis_bug_table` as bug, `mantis_bug_history_table` as history " . "WHERE bug.id IN ({$formattedBugidList}) " . "AND bug.id = history.bug_id " . "AND history.field_name='status' " . "AND history.date_modified >= {$start} AND history.date_modified < {$end} " . "AND history.new_value = get_project_resolved_status_threshold(project_id) ";
     $result = SqlWrapper::getInstance()->sql_query($query);
     if (!$result) {
         echo "<span style='color:red'>ERROR: Query FAILED</span>";
         exit;
     }
     $resolvedList = array();
     while ($row = SqlWrapper::getInstance()->sql_fetch_object($result)) {
         $resolvedList[] = $row->id;
     }
     // remove duplicated values
     $resolvedList = array_unique($resolvedList);
     return $resolvedList;
 }
Ejemplo n.º 12
0
 /**
  * Get assigned jobs
  * @param array $plist The projects
  * @return mixed[int] The assigned jobs
  */
 private function getAssignedJobTuples(array $plist)
 {
     $query = "SELECT job.id as job_id, job.name AS job_name, project_job.id, project_job.project_id " . "FROM `codev_job_table` as job " . "JOIN `codev_project_job_table` as project_job ON job.id = project_job.job_id " . "ORDER BY project_job.project_id;";
     $result = SqlWrapper::getInstance()->sql_query($query);
     if (!$result) {
         echo "<span style='color:red'>ERROR: Query FAILED</span>";
         exit;
     }
     $projects = array();
     while ($row = SqlWrapper::getInstance()->sql_fetch_object($result)) {
         // if SuiviOp do not allow tu delete
         $desc = $row->job_name . " - " . $plist[$row->project_id];
         $desc = str_replace("'", "\\'", $desc);
         $desc = str_replace('"', "\\'", $desc);
         $projects[$row->id] = array("desc" => $desc, "jobid" => $row->job_id, "jobname" => $row->job_name, "projectid" => $row->project_id, "project" => $plist[$row->project_id]);
     }
     return $projects;
 }
Ejemplo n.º 13
0
/**
 * copy plugin in mantis plugins directory
 *
 * @return bool true if success
 */
function installMantisPlugin($pluginName, $isReplace = true)
{
    try {
        $mantisPluginDir = Constants::$mantisPath . DIRECTORY_SEPARATOR . 'plugins';
        $srcDir = realpath("..") . DIRECTORY_SEPARATOR . 'mantis_plugin' . DIRECTORY_SEPARATOR . $pluginName;
        $destDir = $mantisPluginDir . DIRECTORY_SEPARATOR . $pluginName;
        if (!is_writable($mantisPluginDir)) {
            echo "<span class='warn_font'>Path to mantis plugins directory '" . $mantisPluginDir . "' is NOT writable: {$pluginName} plugin must be installed manualy.</span><br/>";
            return false;
        }
        // do not replace if already installed
        if (!$isReplace && is_dir($destDir)) {
            echo "<span class='success_font'>Mantis {$pluginName} plugin is already installed.</span><br/>";
            return true;
        }
        // remove previous installed CodevTT plugin
        if (is_writable($destDir)) {
            Tools::deleteDir($destDir);
        }
        // copy CodevTT plugin
        if (is_dir($srcDir)) {
            $result = Tools::recurse_copy($srcDir, $destDir);
        } else {
            echo "<span class='error_font'>plugin directory '" . $srcDir . "' NOT found: {$pluginName} plugin must be installed manualy.</span><br/>";
            return false;
        }
        if (!$result) {
            echo "<span class='error_font'>mantis plugin installation failed: {$pluginName} plugin must be installed manualy.</span><br/>";
        }
        // activate plugin
        $query = "INSERT INTO mantis_plugin_table (basename, enabled, protected, priority)" . " SELECT * FROM (SELECT '{$pluginName}', '1', '0', '3') AS tmp" . " WHERE NOT EXISTS (" . " SELECT basename FROM mantis_plugin_table WHERE basename = '{$pluginName}') LIMIT 1;";
        $result = SqlWrapper::getInstance()->sql_query($query);
        if (!$result) {
            echo "<span class='warn_font'>mantis {$pluginName} plugin must be activated manualy.</span><br/>";
        }
    } catch (Exception $e) {
        echo "<span class='error_font'>mantis plugin installation failed: " . $e->getMessage() . "</span><br/>";
        echo "<span class='error_font'>{$pluginName} plugin must be installed manualy.</span><br/>";
        $result = false;
    }
    return $result;
}
Ejemplo n.º 14
0
function updateTeams()
{
    echo "-  Clean teams...<br>";
    flush();
    $mgrId = 37;
    $lbayleId = 2;
    $demoTeamId = 11;
    $stprojId = 24;
    execQuery("UPDATE `codev_team_table` SET `leader_id` = '{$lbayleId}' ");
    //execQuery("UPDATE `codev_team_user_table` SET access_level = 10 WHERE team_id <> $demoTeamId AND user_id = $mgrId");
    execQuery("DELETE FROM `codev_team_user_table` WHERE team_id <> {$demoTeamId} AND user_id = {$mgrId}");
    $resTeams = execQuery("SELECT * FROM `codev_team_table` WHERE id NOT IN (1, {$demoTeamId})");
    while ($rowTeam = SqlWrapper::getInstance()->sql_fetch_object($resTeams)) {
        execQuery("UPDATE `codev_team_table` SET `name` = 'Team" . $rowTeam->id . "' WHERE `id` ='{$rowTeam->id}' ");
    }
    // codev_admin team
    $query = "DELETE FROM `codev_team_user_table` WHERE `team_id` ='1' AND user_id NOT IN (1,{$lbayleId})";
    // admin,lbayle
    execQuery($query);
    // demo team
    execQuery("UPDATE `codev_team_table` SET `name` = 'DEMO_Team' WHERE `id` ='{$demoTeamId}' ");
    execQuery("UPDATE `codev_team_table` SET `leader_id` = '{$mgrId}' WHERE `id` ='{$demoTeamId}' ");
    execQuery("UPDATE `codev_team_table` SET `description` = '' WHERE `id` ='{$demoTeamId}' ");
    execQuery("UPDATE `mantis_project_table` SET `name` = 'SideTasks DEMO_Team' WHERE `id` ='{$stprojId}' ");
}
Ejemplo n.º 15
0
 /**
  * return the posts submitted by a given user,
  *
  * @param int $user_id
  *
  * @return BlogPost[]
  */
 public function getSubmittedPosts($user_id)
 {
     $query = "SELECT * FROM `codev_blog_table` where src_user_id = " . $user_id . ";";
     $result = SqlWrapper::getInstance()->sql_query($query);
     if (!$result) {
         echo "<span style='color:red'>ERROR: Query FAILED</span>";
         exit;
     }
     $submittedPosts = array();
     while ($row = SqlWrapper::getInstance()->sql_fetch_object($result)) {
         $submittedPosts[$row->id] = BlogPostCache::getInstance()->getBlogPost($row->id, $row);
     }
     return $submittedPosts;
 }
Ejemplo n.º 16
0
 /**
  *
  * @param int $value
  */
 public function setDescription($value)
 {
     if ($this->description != $value) {
         $this->description = $value;
         $query = "UPDATE `codev_command_provision_table` SET description = '{$value}' WHERE id = " . $this->id . ";";
         $result = SqlWrapper::getInstance()->sql_query($query);
         if (!$result) {
             echo "<span style='color:red'>ERROR: Query FAILED</span>";
             exit;
         }
     }
 }
Ejemplo n.º 17
0
 /**
  * Return all plugins defined in DB
  * 
  * @return array of plugin descriptions
  */
 public function getPlugins()
 {
     if (NULL == $this->plugins) {
         $plugins = array();
         $query = "SELECT * FROM `codev_plugin_table`;";
         $result = SqlWrapper::getInstance()->sql_query($query);
         if (!$result) {
             echo "<span style='color:red'>ERROR: Query FAILED</span>";
             exit;
         }
         while ($row = SqlWrapper::getInstance()->sql_fetch_object($result)) {
             $className = $row->name;
             $status = $row->status;
             // check that plugin files still exist
             // Note: class_exists() checks if present in classmap.ser but
             // will raise a 'PHP Fatal error' if found in cache but file removed from disk.
             $pluginClassFilename = self::$pluginsDir . DIRECTORY_SEPARATOR . $row->name . DIRECTORY_SEPARATOR . $row->name . '.class.php';
             if (!is_file($pluginClassFilename)) {
                 if (self::PLUGIN_STATUS_REMOVED != $row->status) {
                     self::$logger->error("Plugin file '{$pluginClassFilename}' does not exist !");
                     $this->setPluginStatus($className, self::PLUGIN_STATUS_REMOVED);
                     // update DB
                     $status = self::PLUGIN_STATUS_REMOVED;
                 }
                 $displayedName = $className;
             } else {
                 if (class_exists($className)) {
                     $displayedName = $className::getName();
                 } else {
                     // File exists, but classmap.ser needs an update.
                     $displayedName = $className;
                     $this->setPluginStatus($className, self::PLUGIN_STATUS_REMOVED);
                     // update DB
                     $status = self::PLUGIN_STATUS_REMOVED;
                 }
             }
             $plugin = array('className' => $className, 'displayedName' => $displayedName, 'status' => intval($status), 'domains' => explode(',', $row->domains), 'categories' => explode(',', $row->categories), 'version' => $row->version, 'description' => $row->description);
             $plugins[$className] = $plugin;
         }
         ksort($plugins);
         $this->plugins = $plugins;
     }
     return $this->plugins;
 }
Ejemplo n.º 18
0
 /**
  *
  * returns an array of [user][activity]
  * activity in (elapsed, sidetask, other, external, leave)
  *
  */
 public function execute()
 {
     $team = TeamCache::getInstance()->getTeam($this->teamid);
     $members = $team->getActiveMembers($this->startTimestamp, $this->endTimestamp);
     $formatedUseridString = implode(', ', array_keys($members));
     //$extProjId = Config::getInstance()->getValue(Config::id_externalTasksProject);
     $issueList = $this->inputIssueSel->getIssueList();
     $formatedBugidString = implode(', ', array_keys($issueList));
     $query = "SELECT ROUND(SUM(tt.duration), 2) as duration, prj.name as prjName\n               FROM codev_timetracking_table as tt, mantis_project_table as prj, mantis_bug_table as bug \n               WHERE tt.bugid = bug.id\n               AND bug.project_id = prj.id\n               AND bug.id IN ({$formatedBugidString})\n               AND tt.userid IN ({$formatedUseridString}) ";
     if (isset($this->startTimestamp)) {
         $query .= " AND tt.date >= {$this->startTimestamp} ";
     }
     if (isset($this->endTimestamp)) {
         $query .= " AND tt.date <= {$this->endTimestamp} ";
     }
     $query .= " GROUP BY prj.id\n                  ORDER BY `prj`.`name` ASC";
     $result = SqlWrapper::getInstance()->sql_query($query);
     if (!$result) {
         echo "<span style='color:red'>ERROR: Query FAILED</span>";
         exit;
     }
     $projectLoad = array();
     while ($row = SqlWrapper::getInstance()->sql_fetch_object($result)) {
         $projectLoad["{$row->prjName}"] = (double) $row->duration;
     }
     // ---
     $this->execData = $projectLoad;
 }
 /**
    Compares the EffortEstim to the elapsed time.
 
 
 REM: an issue that has been reopened before endTimestamp will NOT be recorded.
 (For the bugs that where re-opened, the EffortEstim may not have been re-estimated,
 and thus the result is not reliable.)
 
 EffortEstimReliabilityRate = nbResolvedIssues * EffortEstim / elapsed
 
 @param projects: $prodProjectList or your own selection.
 */
 public function getEffortEstimReliabilityRate($projects, $startTimestamp, $endTimestamp)
 {
     $resolvedList = array();
     $EEReliability = array();
     // {'MEE', 'EE'}
     $EEReliability['MEE'] = 0;
     $EEReliability['EE'] = 0;
     $totalElapsed = 0;
     $bugResolvedStatusThreshold = Config::getInstance()->getValue(Config::id_bugResolvedStatusThreshold);
     // --------
     $formatedProjList = implode(', ', $projects);
     if ("" == $formatedProjList) {
         // TODO throw exception
         echo "<div style='color:red'>ERROR getEffortEstimReliabilityRate: no project defined for this team !<br/></div>";
         return 0;
     }
     // all bugs which status changed to 'resolved' whthin the timestamp
     $query = "SELECT mantis_bug_table.id, " . "mantis_bug_history_table.new_value, " . "mantis_bug_history_table.old_value, " . "mantis_bug_history_table.date_modified " . "FROM `mantis_bug_table`, `mantis_bug_history_table` " . "WHERE mantis_bug_table.id = mantis_bug_history_table.bug_id " . "AND mantis_bug_table.project_id IN ({$formatedProjList}) " . "AND mantis_bug_history_table.field_name='status' " . "AND mantis_bug_history_table.date_modified >= {$startTimestamp} " . "AND mantis_bug_history_table.date_modified <  {$endTimestamp} " . "AND mantis_bug_history_table.new_value = {$bugResolvedStatusThreshold} " . " ORDER BY mantis_bug_table.id DESC";
     $result = SqlWrapper::getInstance()->sql_query($query);
     if (!$result) {
         echo "<span style='color:red'>ERROR: Query FAILED</span>";
         exit;
     }
     while ($row = SqlWrapper::getInstance()->sql_fetch_object($result)) {
         // check if the bug has been reopened before endTimestamp
         $issue = IssueCache::getInstance()->getIssue($row->id);
         $latestStatus = $issue->getStatus($this->endTimestamp);
         if ($latestStatus >= $bugResolvedStatusThreshold) {
             // remove doubloons
             if (!in_array($row->id, $resolvedList)) {
                 if (self::$logger->isDebugEnabled()) {
                     self::$logger->debug("getEffortEstimReliabilityRate() Found : bugid = {$row->id}, old_status={$row->old_value}, new_status={$row->new_value}, mgrEE=" . $issue->getMgrEffortEstim() . " date_modified=" . date("d F Y", $row->date_modified) . ", effortEstim=" . $issue->getEffortEstim() . ", BS=" . $issue->getEffortAdd() . ", elapsed = " . $issue->getElapsed());
                 }
                 $resolvedList[] = $row->id;
                 $totalElapsed += $issue->getElapsed();
                 $EEReliability['MEE'] += $issue->getMgrEffortEstim();
                 $EEReliability['EE'] += $issue->getEffortEstim() + $issue->getEffortAdd();
                 if (self::$logger->isDebugEnabled()) {
                     self::$logger->debug("getEffortEstimReliabilityRate(MEE) : " . $EEReliability['MEE'] . " + " . $issue->getMgrEffortEstim() . " = " . ($EEReliability['MEE'] + $issue->getMgrEffortEstim()));
                     self::$logger->debug("getEffortEstimReliabilityRate(EE) : " . $EEReliability['EE'] . " + (" . $issue->getEffortEstim() . " + " . $issue->getEffortAdd() . ") = " . ($EEReliability['EE'] + $issue->getEffortEstim() + $issue->getEffortAdd()));
                 }
             }
         } else {
             $statusName = Constants::$statusNames[$latestStatus];
             if (self::$logger->isDebugEnabled()) {
                 self::$logger->debug("getEffortEstimReliabilityRate REOPENED : bugid = {$row->id} status = " . $statusName);
             }
         }
     }
     // -------
     if (self::$logger->isDebugEnabled()) {
         self::$logger->debug("getEffortEstimReliabilityRate: Reliability (MEE) = " . $EEReliability['MEE'] . " / {$totalElapsed}, nbBugs=" . count($resolvedList));
         self::$logger->debug("getEffortEstimReliabilityRate: Reliability (EE) = " . $EEReliability['EE'] . " / {$totalElapsed}, nbBugs=" . count($resolvedList));
     }
     if (0 != $totalElapsed) {
         $EEReliability['MEE'] /= $totalElapsed;
         $EEReliability['EE'] /= $totalElapsed;
     } else {
         $EEReliability['MEE'] = 0;
         $EEReliability['EE'] = 0;
     }
     return $EEReliability;
 }
Ejemplo n.º 20
0
 /**
  * A command can be included in several ComandSet from different teams.
  *
  * This returns the list of CommandSets where this command is defined.
  *
  * @return CommandSet[] array[commandset_id] = commandsetName
  */
 public function getCommandSetList()
 {
     if (NULL == $this->commandSetList) {
         $query = "SELECT commandset.* FROM `codev_commandset_table` as commandset " . "JOIN `codev_commandset_cmd_table` as commandset_cmd ON commandset.id = commandset_cmd.commandset_id " . "WHERE commandset_cmd.command_id = {$this->id};";
         $result = SqlWrapper::getInstance()->sql_query($query);
         if (!$result) {
             echo "<span style='color:red'>ERROR: Query FAILED</span>";
             exit;
         }
         // a Command can belong to more than one commandset
         $this->commandSetList = array();
         while ($row = SqlWrapper::getInstance()->sql_fetch_object($result)) {
             $cmdset = CommandSetCache::getInstance()->getCommandSet($row->id, $row);
             $this->commandSetList[$row->id] = $cmdset;
             if (self::$logger->isDebugEnabled()) {
                 self::$logger->debug("Command {$this->id} is in commandset {$row->id} (" . $cmdset->getName() . ")");
             }
         }
     }
     return $this->commandSetList;
 }
Ejemplo n.º 21
0
 /**
  * get customField name from id
  *
  * @param int $customFieldId field id
  * @return string field name
  */
 public static function getCustomFieldName($customFieldId)
 {
     if (is_null(self::$customFieldNames)) {
         $extIdField = Config::getInstance()->getValue(Config::id_customField_ExtId);
         $mgrEffortEstimField = Config::getInstance()->getValue(Config::id_customField_MgrEffortEstim);
         $effortEstimField = Config::getInstance()->getValue(Config::id_customField_effortEstim);
         $backlogField = Config::getInstance()->getValue(Config::id_customField_backlog);
         $addEffortField = Config::getInstance()->getValue(Config::id_customField_addEffort);
         $deadLineField = Config::getInstance()->getValue(Config::id_customField_deadLine);
         $deliveryDateField = Config::getInstance()->getValue(Config::id_customField_deliveryDate);
         #$deliveryIdField = Config::getInstance()->getValue(Config::id_customField_deliveryId);
         $customField_type = Config::getInstance()->getValue(Config::id_customField_type);
         self::$customFieldNames = array();
         $query = "SELECT id, name FROM `mantis_custom_field_table` ";
         $result = SqlWrapper::getInstance()->sql_query($query);
         if (!$result) {
             echo "<span style='color:red'>ERROR: Query FAILED</span>";
             exit;
         }
         while ($row = SqlWrapper::getInstance()->sql_fetch_object($result)) {
             $name = NULL;
             switch (intval($row->id)) {
                 case $extIdField:
                     $name = T_('External ID');
                     break;
                 case $customField_type:
                     $name = T_('Type');
                     break;
                 case $backlogField:
                     $name = T_('Backlog');
                     break;
                 case $mgrEffortEstimField:
                     $name = T_('MgrEffortEstim');
                     break;
                 case $effortEstimField:
                     $name = T_('EffortEstim');
                     break;
                 case $backlogField:
                     $name = T_('Backlog');
                     break;
                 case $addEffortField:
                     $name = T_('AddEffortEstim');
                     break;
                 case $deadLineField:
                     $name = T_('Deadline');
                     break;
                 case $deliveryDateField:
                     $name = T_('Delivery Date');
                     break;
                 default:
                     $name = $row->name;
             }
             self::$customFieldNames["{$row->id}"] = $name;
         }
     }
     return self::$customFieldNames["{$customFieldId}"];
 }
Ejemplo n.º 22
0
 /**
  * Add to email queue
  * @param EmailData $p_email_data Email Data structure.
  */
 private function email_queue_add(EmailData $emailData)
 {
     # email cannot be blank
     if (Tools::is_blank($emailData->email)) {
         self::$logger->error('Recipient email is missing');
         return FALSE;
     }
     # subject cannot be blank
     if (Tools::is_blank($emailData->subject)) {
         self::$logger->error('email subject is blank');
         return FALSE;
     }
     # body cannot be blank
     if (Tools::is_blank($emailData->body)) {
         self::$logger->error('email body is blank');
         return FALSE;
     }
     if (Tools::is_blank($emailData->submitted)) {
         $emailData->submitted = time();
     }
     $sqlWrapper = SqlWrapper::getInstance();
     $c_email = SqlWrapper::sql_real_escape_string($emailData->email);
     $c_subject = SqlWrapper::sql_real_escape_string($emailData->subject);
     $c_body = SqlWrapper::sql_real_escape_string($emailData->body);
     $c_metadata = serialize($emailData->metadata);
     $query = "INSERT  INTO `mantis_email_table` (`email`, `subject`, `body`, `submitted`, `metadata`) " . "VALUES ('{$c_email}', '{$c_subject}', '{$c_body}', " . $emailData->submitted . ", '{$c_metadata}');";
     #echo "queue email: $query<br>";
     $result = SqlWrapper::getInstance()->sql_query($query);
     if (!$result) {
         echo "<span style='color:red'>ERROR: Query FAILED</span>";
         exit;
     }
     #self::$logger->error('email sent to '.$emailData->email);
     return TRUE;
 }
Ejemplo n.º 23
0
function updateProjects()
{
    echo "-  Clean projects...\n";
    flush();
    $stprojId = 24;
    // remove ALL files from ALL PROJECTS  (OVH upload fails)
    execQuery("DELETE FROM `mantis_bug_file_table` ");
    execQuery("UPDATE `mantis_project_table` SET `description` = '' ");
    $resStProjects = execQuery("SELECT DISTINCT project_id FROM `codev_team_project_table` WHERE type = 1");
    while ($rowStPrj = SqlWrapper::getInstance()->sql_fetch_object($resStProjects)) {
        execQuery("UPDATE `mantis_project_table` SET `name` = 'SideTasks {$rowStPrj->project_id}' WHERE `id` ='{$rowStPrj->project_id}' ");
    }
    // rename project categories
    /*
       $result1 = execQuery("SELECT * from `mantis_category_table`");
       while($row = SqlWrapper::getInstance()->sql_fetch_object($result1))	{
          $query  = "UPDATE `mantis_category_table` SET `name`='Category_".$row->project_id.$row->id."' WHERE `id`='$row->id' ";
          $result2 = execQuery($query);
       }
    */
    // external tasks project
    execQuery("UPDATE `mantis_project_table` SET `name` = 'ExternalTasks' WHERE `id` ='1' ");
    // demo projects
    execQuery("UPDATE `mantis_project_table` SET `name` = 'SideTasks DEMO_Team' WHERE `id` ='{$stprojId}' ");
}
Ejemplo n.º 24
0
 public static function checkMantisDefaultProjectWorkflow()
 {
     $cerrList = array();
     $query = "SELECT * FROM `mantis_config_table` " . "WHERE project_id = 0 " . "AND config_id = 'status_enum_workflow' ";
     $result = SqlWrapper::getInstance()->sql_query($query);
     if (!$result) {
         echo "<span style='color:red'>ERROR: Query FAILED</span>";
         exit;
     }
     if (0 == SqlWrapper::getInstance()->sql_num_rows($result)) {
         $cerr = new ConsistencyError2(NULL, NULL, NULL, NULL, T_("No default project workflow defined in mantis DB"));
         $cerr->severity = ConsistencyError2::severity_error;
         $cerrList[] = $cerr;
     }
     return $cerrList;
 }
Ejemplo n.º 25
0
/**
 * check if the user has enough privileges to create tables & procedures
 *
 * TODO: if 'CREATE' not set but 'CREATE ROUTINE' set,
 * then this method will not see that 'CREATE' is missing !
 *
 * Note: this is not enough on Windows, you need 'SUPER privilege'
 * see http://codevtt.org/site/?topic=sql-alert-you-do-not-have-the-super-privilege-and-binary-logging-is-enabled
 *
 * @return NULL if OK, or an error message starting with 'ERROR' .
 */
function checkDBprivileges($db_mantis_database = 'bugtracker')
{
    global $logger;
    $mandatoryPriv = array('SELECT', 'INSERT', 'UPDATE', 'DELETE', 'CREATE', 'DROP', 'EXECUTE', 'CREATE ROUTINE', 'ALTER ROUTINE');
    $errStr = NULL;
    #$query = "SHOW GRANTS FOR '$db_mantis_user'@'$db_mantis_host'";
    $query = "SHOW GRANTS FOR CURRENT_USER";
    $result = SqlWrapper::getInstance()->sql_query($query);
    if (!$result) {
        echo "<span style='color:red'>ERROR: Query FAILED</span>";
        exit;
    }
    while ($row = SqlWrapper::getInstance()->sql_fetch_array($result)) {
        if (FALSE != strstr($row[0], "`{$db_mantis_database}`")) {
            if ($logger->isDebugEnabled()) {
                $logger->debug("Privileges: " . $row[0]);
            }
            // all privileges should be ok !
            if (FALSE != strstr($row[0], "GRANT ALL PRIVILEGES")) {
                break;
                // found, get out
            }
            foreach ($mandatoryPriv as $priv) {
                if (!strstr($row[0], $priv)) {
                    $errStr .= "ERROR: user has no {$priv} privileges on {$db_mantis_database}<br>";
                }
            }
            break;
            // found, get out
        }
    }
    if (NULL != $errStr) {
        $allPriv = implode(', ', $mandatoryPriv);
        $errStr .= "Please add the following privileges: {$allPriv}";
        throw new Exception($errStr);
    }
}
Ejemplo n.º 26
0
/**
 * copy plugin in mantis plugins directory
 * info: same functyion exists in install_step3.php
 * @return NULL or error string
 */
function installMantisPlugin($pluginName, $isReplace = true)
{
    try {
        $mantisPluginDir = Constants::$mantisPath . DIRECTORY_SEPARATOR . 'plugins';
        // --- check mantis version (config files have been moved in v1.3)
        if (is_dir(Constants::$mantisPath . DIRECTORY_SEPARATOR . 'config')) {
            // mantis v1.3 or higher
            $srcDir = Constants::$codevRootDir . DIRECTORY_SEPARATOR . 'mantis_plugin' . DIRECTORY_SEPARATOR . 'mantis_1_3' . DIRECTORY_SEPARATOR . $pluginName;
        } else {
            // mantis 1.2
            $srcDir = Constants::$codevRootDir . DIRECTORY_SEPARATOR . 'mantis_plugin' . DIRECTORY_SEPARATOR . 'mantis_1_2' . DIRECTORY_SEPARATOR . $pluginName;
        }
        $destDir = $mantisPluginDir . DIRECTORY_SEPARATOR . $pluginName;
        if (!is_writable($mantisPluginDir)) {
            return "ERROR Path to mantis plugins directory '" . $mantisPluginDir . "' is NOT writable: {$pluginName} plugin must be installed manualy.";
        }
        if (!is_dir($srcDir)) {
            return "ERROR mantis plugin directory '" . $srcDir . "' NOT found !";
        }
        // do not replace if already installed
        if (!$isReplace && is_dir($destDir)) {
            echo "<script type=\"text/javascript\">console.info(\"INFO Mantis {$pluginName} plugin is already installed\");</script>";
            return NULL;
        }
        // remove previous installed plugin
        if (is_writable($destDir)) {
            Tools::deleteDir($destDir);
        }
        // copy plugin
        if (is_dir($srcDir)) {
            $result = Tools::recurse_copy($srcDir, $destDir);
        } else {
            return "ERROR: plugin directory '" . $srcDir . "' NOT found: {$pluginName} plugin must be installed manualy";
        }
        if (!$result) {
            return "ERROR: mantis plugin installation failed: {$pluginName} plugin must be installed manualy";
        }
        // activate plugin
        $query = "INSERT INTO mantis_plugin_table (basename, enabled, protected, priority)" . " SELECT * FROM (SELECT '{$pluginName}', '1', '0', '3') AS tmp" . " WHERE NOT EXISTS (" . " SELECT basename FROM mantis_plugin_table WHERE basename = '{$pluginName}') LIMIT 1;";
        $result = SqlWrapper::getInstance()->sql_query($query);
        if (!$result) {
            return "WARNING: mantis {$pluginName} plugin must be activated manualy";
        }
    } catch (Exception $e) {
        echo "<script type=\"text/javascript\">console.error(\"ERROR mantis plugin installation failed: " . $e->getMessage() . "\");</script>";
        return "ERROR: mantis {$pluginName} plugin installation failed: " . $e->getMessage();
    }
    return NULL;
}
Ejemplo n.º 27
0
 /**
  *
  * @param type $projectid
  * @param String $categories imploded category_id list
  * @param String $reporteridList imploded userid list
  * @param String $handleridList imploded userid list
  */
 private function getIssueSelection($projectid, $categories = NULL, $formattedReporters = NULL, $formattedHandlers = NULL, $formattedStatuses = false)
 {
     $query = "SELECT id from `mantis_bug_table` WHERE project_id = {$projectid} ";
     if (!empty($categories)) {
         $query .= "AND category_id IN ({$categories}) ";
     }
     if (!empty($formattedReporters)) {
         $query .= "AND reporter_id IN ({$formattedReporters}) ";
     }
     if (!empty($formattedHandlers)) {
         $query .= "AND handler_id IN ({$formattedHandlers}) ";
     }
     if (!empty($formattedStatuses)) {
         $query .= "AND status IN ({$formattedStatuses}) ";
     }
     #if (!$withResolved) {
     #   $query .= "AND status < get_project_resolved_status_threshold(project_id) ";
     #}
     $result = SqlWrapper::getInstance()->sql_query($query);
     if (!$result) {
         echo "<span style='color:red'>ERROR: Query FAILED</span>";
         exit;
     }
     $iSel = new IssueSelection('exportODT');
     while ($row = SqlWrapper::getInstance()->sql_fetch_object($result)) {
         $iSel->addIssue($row->id);
     }
     #$iSel->addIssue(694);
     #echo implode(',', array_keys($iSel->getIssueList())).'<br>';
     return $iSel;
 }
Ejemplo n.º 28
0
}
if (1 == Constants::$emailSettings['enable_email_notification']) {
    if (count($argv) > 1) {
        if (is_numeric($argv[1])) {
            $team_id = intval($argv[1]);
        } else {
            echo 'cmd line arg "' . $argv[1] . '" is not a team_id !' . "\n";
            $logger->error('cmd line arg "' . $argv[1] . '" is not a team_id !');
            exit(2);
        }
    }
    //$startT = strtotime("first day of last month");
    //$endT = strtotime("-1 days", time());
    $endT = time();
    $endT = mktime(0, 0, 0, date('m', $endT), date('d', $endT), date('Y', $endT));
    if (is_null($team_id)) {
        $query = "SELECT id FROM `codev_team_table` WHERE enabled = 1;";
        $result = SqlWrapper::getInstance()->sql_query($query);
        if (!$result) {
            echo "<span style='color:red'>ERROR: Query FAILED</span>";
            exit;
        }
        while ($row = SqlWrapper::getInstance()->sql_fetch_object($result)) {
            $team = TeamCache::getInstance()->getTeam($row->id);
            $team->sendTimesheetEmails($startT, $endT);
        }
    } else {
        $team = TeamCache::getInstance()->getTeam($team_id);
        $team->sendTimesheetEmails($startT, $endT);
    }
}
Ejemplo n.º 29
0
/**
 * update 0.99.21 to 0.99.22 (DB v11 to DB v12)
 *
 */
function update_v11_to_v12()
{
    $sqlScriptFilename = '../install/codevtt_update_v11_v12.sql';
    if (!file_exists($sqlScriptFilename)) {
        echo "ERROR: SQL script not found:{$sqlScriptFilename}<br>";
        exit;
    }
    // execute the SQL script
    echo "- Execute SQL script:{$sqlScriptFilename}<br>";
    $retCode = Tools::execSQLscript2($sqlScriptFilename);
    if (0 != $retCode) {
        echo "<span class='error_font'>Could not execSQLscript: {$sqlScriptFilename}</span><br/>";
        exit;
    }
    // --- create new categories for ExternalTasksProject
    $extTasksProjId = Config::getInstance()->getValue(Config::id_externalTasksProject);
    // create leave category
    $query = "INSERT INTO `mantis_category_table`  (`project_id`, `user_id`, `name`, `status`) " . "VALUES ('{$extTasksProjId}','0','Leave', '0');";
    $result = execQuery($query);
    $catLeaveId = SqlWrapper::getInstance()->sql_insert_id();
    // create otherInternal category
    $query = "INSERT INTO `mantis_category_table`  (`project_id`, `user_id`, `name`, `status`) " . "VALUES ('{$extTasksProjId}','0','Other activity', '0');";
    $result = execQuery($query);
    $catOtherInternalId = SqlWrapper::getInstance()->sql_insert_id();
    // update codev_config_table
    Config::getInstance()->setValue(Config::id_externalTasksCat_leave, $catLeaveId, Config::configType_int);
    Config::getInstance()->setValue(Config::id_externalTasksCat_otherInternal, $catOtherInternalId, Config::configType_int);
    // update existing issues
    $leaveTaskId = Config::getInstance()->getValue(Config::id_externalTask_leave);
    $query = "UPDATE `mantis_bug_table` SET `category_id`='{$catLeaveId}' WHERE `id`='{$leaveTaskId}';";
    $result = execQuery($query);
    $query = "UPDATE `mantis_bug_table` SET `category_id`='{$catOtherInternalId}' " . "WHERE `project_id`='{$extTasksProjId}' " . "AND `id` <> '{$leaveTaskId}';";
    $result = execQuery($query);
    #echo "<br>SUCCESS: Update 0.99.21 to 0.99.22 (DB v11 to DB v12)<br>";
    return TRUE;
}
Ejemplo n.º 30
0
 /**
  * get all unassigned tasks found in team projects
  *
  * Note: sideTasks and nostatsProjects excluded, resolved tasks excluded.
  *
  * @return Issue[] : issueList (id => Issue)
  */
 public function getUnassignedTasks()
 {
     $issueList = array();
     $query_projects = "SELECT project.id " . "FROM `mantis_project_table` as project " . "JOIN `codev_team_project_table` as team_project ON project.id = team_project.project_id " . "WHERE team_project.team_id = {$this->id} " . "AND team_project.type NOT IN (" . Project::type_noStatsProject . ', ' . Project::type_sideTaskProject . ') ';
     $query = "SELECT * " . "FROM `mantis_bug_table` " . "WHERE project_id IN ({$query_projects}) " . "AND handler_id = '0' " . "AND status < get_project_resolved_status_threshold(project_id) " . "ORDER BY project_id ASC, id ASC";
     $result = SqlWrapper::getInstance()->sql_query($query);
     if (!$result) {
         echo "<span style='color:red'>ERROR: Query FAILED</span>";
         exit;
     }
     while ($row = SqlWrapper::getInstance()->sql_fetch_object($result)) {
         $issueList[$row->id] = IssueCache::getInstance()->getIssue($row->id, $row);
     }
     if (self::$logger->isDebugEnabled()) {
         self::$logger->debug("getUnassignedTasks(teamid={$this->id}) nbIssues=" . count($issueList));
     }
     return $issueList;
 }