Exemplo n.º 1
0
/** Given a user check if we should send an email based on labels */
function checkEmailLabel($projectid, $userid, $buildid, $emailcategory = 62)
{
    include_once "models/labelemail.php";
    include_once "models/build.php";
    $LabelEmail = new LabelEmail();
    $LabelEmail->UserId = $userid;
    $LabelEmail->ProjectId = $projectid;
    $labels = $LabelEmail->GetLabels();
    if (count($labels) == 0) {
        return true;
    }
    $Build = new Build();
    $Build->Id = $buildid;
    $labelarray = array();
    if (check_email_category("update", $emailcategory)) {
        $labelarray['update']['errors'] = 1;
    }
    if (check_email_category("configure", $emailcategory)) {
        $labelarray['configure']['errors'] = 1;
    }
    if (check_email_category("warning", $emailcategory)) {
        $labelarray['build']['warnings'] = 1;
    }
    if (check_email_category("error", $emailcategory)) {
        $labelarray['build']['errors'] = 1;
    }
    if (check_email_category("test", $emailcategory)) {
        $labelarray['test']['errors'] = 1;
    }
    $buildlabels = $Build->GetLabels($labelarray);
    if (count(array_intersect($labels, $buildlabels)) > 0) {
        return true;
    }
    return false;
}
Exemplo n.º 2
0
/** Given a user check if we should send an email based on labels */
function checkEmailLabel($projectid, $userid, $buildid, $emailcategory = 62)
{
    include_once 'models/labelemail.php';
    include_once 'models/build.php';
    $LabelEmail = new LabelEmail();
    $LabelEmail->UserId = $userid;
    $LabelEmail->ProjectId = $projectid;
    $labels = $LabelEmail->GetLabels();
    if (count($labels) == 0) {
        // if the number of subscribed labels is zero we send the email
        return true;
    }
    $Build = new Build();
    $Build->Id = $buildid;
    $labelarray = array();
    if (check_email_category('update', $emailcategory)) {
        $labelarray['update']['errors'] = 1;
    }
    if (check_email_category('configure', $emailcategory)) {
        $labelarray['configure']['errors'] = 1;
    }
    if (check_email_category('warning', $emailcategory)) {
        $labelarray['build']['warnings'] = 1;
    }
    if (check_email_category('error', $emailcategory)) {
        $labelarray['build']['errors'] = 1;
    }
    if (check_email_category('test', $emailcategory)) {
        $labelarray['test']['errors'] = 1;
    }
    $buildlabels = $Build->GetLabels($labelarray);
    if (count(array_intersect($labels, $buildlabels)) > 0) {
        return true;
    }
    return false;
}
Exemplo n.º 3
0
 @($Unsubscribe = $_POST["unsubscribe"]);
 @($Role = $_POST["role"]);
 @($Credentials = $_POST["credentials"]);
 @($EmailType = $_POST["emailtype"]);
 if (!isset($_POST["emailmissingsites"])) {
     $EmailMissingSites = 0;
 } else {
     $EmailMissingSites = $_POST["emailmissingsites"];
 }
 if (!isset($_POST["emailsuccess"])) {
     $EmailSuccess = 0;
 } else {
     $EmailSuccess = $_POST["emailsuccess"];
 }
 // Deals with label email
 $LabelEmail = new LabelEmail();
 $Label = new Label();
 $LabelEmail->ProjectId = $projectid;
 $LabelEmail->UserId = $userid;
 if ($Unsubscribe) {
     pdo_query("DELETE FROM user2project WHERE userid='{$userid}' AND projectid='{$projectid}'");
     pdo_query("DELETE FROM user2repository WHERE userid='{$userid}' AND projectid='{$projectid}'");
     // Remove the claim sites for this project if they are only part of this project
     pdo_query("DELETE FROM site2user WHERE userid='{$userid}'\n               AND siteid NOT IN\n              (SELECT build.siteid FROM build,user2project as up WHERE\n               up.projectid = build.projectid AND up.userid='{$userid}' AND up.role>0\n               GROUP BY build.siteid)");
     header('location: user.php?note=unsubscribedtoproject');
 } else {
     if ($UpdateSubscription) {
         @($emailcategory_update = $_POST["emailcategory_update"]);
         @($emailcategory_configure = $_POST["emailcategory_configure"]);
         @($emailcategory_warning = $_POST["emailcategory_warning"]);
         @($emailcategory_error = $_POST["emailcategory_error"]);
Exemplo n.º 4
0
 /** endElement function */
 public function endElement($parser, $name)
 {
     parent::endElement($parser, $name);
     global $CDASH_DELETE_OLD_SUBPROJECTS;
     if (!$this->ProjectNameMatches) {
         return;
     }
     if ($name == 'PROJECT') {
         foreach ($this->SubProjects as $subproject) {
             if ($CDASH_DELETE_OLD_SUBPROJECTS) {
                 // Remove dependencies that do not exist anymore,
                 // but only for those relationships where both sides
                 // are present in $this->SubProjects.
                 //
                 $dependencyids = $subproject->GetDependencies();
                 $removeids = array_diff($dependencyids, $this->Dependencies[$subproject->GetId()]);
                 foreach ($removeids as $removeid) {
                     if (array_key_exists($removeid, $this->SubProjects)) {
                         $subproject->RemoveDependency($removeid);
                     } else {
                         $dep = pdo_get_field_value("SELECT name FROM subproject WHERE id='{$removeid}'", 'name', "{$removeid}");
                         add_log("Not removing dependency {$dep}({$removeid}) from " . $subproject->GetName() . 'because it is not a SubProject element in this Project.xml file', 'ProjectHandler:endElement', LOG_WARNING, $this->projectid);
                     }
                 }
             }
             // Add dependencies that were queued up as we processed the DEPENDENCY
             // elements:
             //
             foreach ($this->Dependencies[$subproject->GetId()] as $addid) {
                 if (array_key_exists($addid, $this->SubProjects)) {
                     $subproject->AddDependency($addid);
                 } else {
                     add_log('impossible condition: should NEVER see this: unknown DEPENDENCY clause should prevent this case', 'ProjectHandler:endElement', LOG_WARNING, $this->projectid);
                 }
             }
         }
         if ($CDASH_DELETE_OLD_SUBPROJECTS) {
             // Delete old subprojects that weren't included in this file.
             $previousSubProjectIds = $this->Project->GetSubProjects();
             foreach ($previousSubProjectIds as $previousId) {
                 $found = false;
                 foreach ($this->SubProjects as $subproject) {
                     if ($subproject->GetId() == $previousId) {
                         $found = true;
                         break;
                     }
                 }
                 if (!$found) {
                     $subProjectToRemove = new SubProject();
                     $subProjectToRemove->SetId($previousId);
                     $subProjectToRemove->Delete();
                     add_log("Deleted " . $subProjectToRemove->GetName() . " because it was not mentioned in Project.xml", 'ProjectHandler:endElement', LOG_WARNING, $this->projectid);
                 }
             }
         }
     } elseif ($name == 'SUBPROJECT') {
         // Insert the SubProject.
         $this->SubProject->Save();
         // Insert the label.
         $Label = new Label();
         $Label->Text = $this->SubProject->GetName();
         $Label->Insert();
         $this->SubProjects[$this->SubProject->GetId()] = $this->SubProject;
         // Handle dependencies here too.
         $this->Dependencies[$this->SubProject->GetId()] = array();
         foreach ($this->CurrentDependencies as $dependencyid) {
             $added = false;
             if ($dependencyid !== false && is_numeric($dependencyid)) {
                 if (array_key_exists($dependencyid, $this->SubProjects)) {
                     $this->Dependencies[$this->SubProject->GetId()][] = $dependencyid;
                     $added = true;
                 }
             }
             if (!$added) {
                 add_log('Project.xml DEPENDENCY of ' . $this->SubProject->GetName() . ' not mentioned earlier in file.', 'ProjectHandler:endElement', LOG_WARNING, $this->projectid);
             }
         }
         // Check if the user is in the database.
         $User = new User();
         $posat = strpos($this->Email, '@');
         if ($posat !== false) {
             $User->FirstName = substr($this->Email, 0, $posat);
             $User->LastName = substr($this->Email, $posat + 1);
         } else {
             $User->FirstName = $this->Email;
             $User->LastName = $this->Email;
         }
         $User->Email = $this->Email;
         $User->Password = md5($this->Email);
         $User->Admin = 0;
         $userid = $User->GetIdFromEmail($this->Email);
         if (!$userid) {
             $User->Save();
             $userid = $User->Id;
         }
         // Insert into the UserProject
         $UserProject = new UserProject();
         $UserProject->EmailType = 3;
         // any build
         $UserProject->EmailCategory = 54;
         // everything except warnings
         $UserProject->UserId = $userid;
         $UserProject->ProjectId = $this->projectid;
         $UserProject->Save();
         // Insert the labels for this user
         $LabelEmail = new LabelEmail();
         $LabelEmail->UserId = $userid;
         $LabelEmail->ProjectId = $this->projectid;
         $Label = new Label();
         $Label->SetText($this->SubProject->GetName());
         $labelid = $Label->GetIdFromText();
         if (!empty($labelid)) {
             $LabelEmail->LabelId = $labelid;
             $LabelEmail->Insert();
         }
     }
 }
Exemplo n.º 5
0
 /** startElement function */
 public function startElement($parser, $name, $attributes)
 {
     parent::startElement($parser, $name, $attributes);
     // Check that the project name matches
     if ($name == 'PROJECT') {
         if (get_project_id($attributes['NAME']) != $this->projectid) {
             add_log("Wrong project name: " . $attributes['NAME'], "ProjectHandler::startElement", LOG_ERR, $this->projectid);
             $this->ProjectNameMatches = false;
         }
     }
     if (!$this->ProjectNameMatches) {
         return;
     }
     if ($name == 'PROJECT') {
         $this->SubProjects = array();
         $this->Dependencies = array();
     } else {
         if ($name == 'SUBPROJECT') {
             $this->SubProject = new SubProject();
             $this->SubProject->SetProjectId($this->projectid);
             $this->SubProject->SetName($attributes['NAME']);
             if (array_key_exists("GROUP", $attributes)) {
                 $this->SubProject->SetGroup($attributes['GROUP']);
             }
             $this->SubProject->Save();
             // Insert the label
             $Label = new Label();
             $Label->Text = $this->SubProject->GetName();
             $Label->Insert();
             $this->SubProjects[$this->SubProject->GetId()] = $this->SubProject;
             $this->Dependencies[$this->SubProject->GetId()] = array();
         } else {
             if ($name == 'DEPENDENCY') {
                 // A DEPENDENCY is expected to be:
                 //
                 //  - another subproject that already exists (from a previous element in
                 //      this submission)
                 //
                 $dependentProject = new SubProject();
                 $dependentProject->SetName($attributes['NAME']);
                 $dependentProject->SetProjectId($this->projectid);
                 // The subproject's Id is automatically loaded once its name & projectid
                 // are set.
                 $dependencyid = $dependentProject->GetId();
                 $added = false;
                 if ($dependencyid !== false && is_numeric($dependencyid)) {
                     if (array_key_exists($dependencyid, $this->SubProjects)) {
                         $this->Dependencies[$this->SubProject->GetId()][] = $dependencyid;
                         $added = true;
                     }
                 }
                 if (!$added) {
                     add_log("Project.xml DEPENDENCY of " . $this->SubProject->GetName() . " not mentioned earlier in file: " . $attributes['NAME'], "ProjectHandler:startElement", LOG_WARNING, $this->projectid);
                 }
             } else {
                 if ($name == 'EMAIL') {
                     $email = $attributes['ADDRESS'];
                     // Check if the user is in the database
                     $User = new User();
                     $posat = strpos($email, '@');
                     if ($posat !== false) {
                         $User->FirstName = substr($email, 0, $posat);
                         $User->LastName = substr($email, $posat + 1);
                     } else {
                         $User->FirstName = $email;
                         $User->LastName = $email;
                     }
                     $User->Email = $email;
                     $User->Password = md5($email);
                     $User->Admin = 0;
                     $userid = $User->GetIdFromEmail($email);
                     if (!$userid) {
                         $User->Save();
                         $userid = $User->Id;
                     }
                     // Insert into the UserProject
                     $UserProject = new UserProject();
                     $UserProject->EmailType = 3;
                     // any build
                     $UserProject->EmailCategory = 54;
                     // everything except warnings
                     $UserProject->UserId = $userid;
                     $UserProject->ProjectId = $this->projectid;
                     $UserProject->Save();
                     // Insert the labels for this user
                     $LabelEmail = new LabelEmail();
                     $LabelEmail->UserId = $userid;
                     $LabelEmail->ProjectId = $this->projectid;
                     $Label = new Label();
                     $Label->SetText($this->SubProject->GetName());
                     $labelid = $Label->GetIdFromText();
                     if (!empty($labelid)) {
                         $LabelEmail->LabelId = $labelid;
                         $LabelEmail->Insert();
                     }
                 }
             }
         }
     }
 }