DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (d5c3254b3e56)

VCS Links

Line Code
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 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
#!/usr/bin/perl -w
# -*- mode: cperl; c-basic-offset: 8; indent-tabs-mode: nil; -*-

# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is Litmus.
#
# The Initial Developer of the Original Code is
# the Mozilla Corporation.
# Portions created by the Initial Developer are Copyright (C) 2006
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
#   Chris Cooper <ccooper@deadsquid.com>
#   Zach Lipton <zach@zachlipton.com>
#
# ***** END LICENSE BLOCK *****

use strict;
$|++;

#use Time::HiRes qw( gettimeofday tv_interval );
#my $t0 = [gettimeofday];

use Litmus;
use Litmus::Auth;
use Litmus::Cache;
use Litmus::Error;
use Litmus::FormWidget;

use CGI;
use Date::Manip;
use JSON -convert_blessed_universally;

Litmus->init();
Litmus::Auth::requireRunDayAdmin("manage_testdays.cgi");
Litmus::Auth::requireProductAdmin("manage_testdays.cgi");

my $c = Litmus->cgi();
print $c->header();

my $message;
my $status;
my $rv;
my $defaults;
my $warning;

if ($c->param) {
  # Process testday changes.
  if ($c->param("delete_testday_button") and 
      $c->param("testday_id")) {
    my $testday_id = $c->param("testday_id");
    my $testday = Litmus::DB::TestDay->retrieve($testday_id);
    if ($testday) {
      Litmus::Auth::requireProductAdmin("manage_testdays.cgi", $testday->product());
      $rv = $testday->delete_with_refs;
      if ($rv) {
        $status = "success";
        $message = "Testday ID# $testday_id deleted successfully.";
      } else {
        $status = "failure";
        $message = "Failed to delete testday ID# $testday_id.";
      }
    } else { 
      $status = "failure";
      $message = "Testday ID# $testday_id does not exist. (Already deleted?)";
    }
  } elsif ($c->param("edit_testday_form_mode")) {
    my $now = &Date::Manip::UnixDate("now","%q");
    my $user_id = Litmus::Auth::getCurrentUser();

    if ($c->param("edit_testday_form_mode") eq "add") {
      my %hash = ( 
                  description => $c->param('edit_testday_form_desc'),
                  start_timestamp => $c->param('edit_testday_form_start_timestamp'),
                  finish_timestamp => $c->param('edit_testday_form_finish_timestamp'),
                  creation_date => $now,
                  creator_id => $c->param('edit_testday_form_created_by'),
                 );
      my @subgroups;
      
      if ($c->param('product')) {
        Litmus::Auth::requireProductAdmin("manage_testdays.cgi", $c->param('product'));
        $hash{product_id} = $c->param('product');
      }
      if ($c->param('branch')) {
        $hash{branch_id} = $c->param('branch');
      }
      if ($c->param('testgroup')) {
        $hash{testgroup_id} = $c->param('testgroup');
      }
      if ($c->param('subgroup')) {
        @subgroups = $c->param('subgroup');
      }
      if ($c->param('build_id')) {
        $hash{build_id} = $c->param('build_id');
      }
      if ($c->param('locale') and 
          $c->param('locale') ne "") {
        $hash{locale_abbrev} = $c->param('locale');
      }
      
      # Search for other testdays that overlap this one and let the user
      # know about them:
      my @overlap = Litmus::DB::TestDay->search_daterange(
                                                          $hash{'finish_timestamp'},
                                                          $hash{'start_timestamp'}
                                                         );
      
      my $new_testday = 
        Litmus::DB::TestDay->create(\%hash);
      if ($new_testday) {
        if (scalar @subgroups) {
          $new_testday->update_subgroups(\@subgroups);
        }
        $status = "success";
        $message = "Testday added successfully. New testday ID# is " . $new_testday->testday_id;
        if (@overlap) {
          $warning = 1;
        }
                
        $defaults->{'testday_id'} = $new_testday->testday_id;
      } else {
        $status = "failure";
        $message = "Failed to add testday.";
      }
    } elsif ($c->param("edit_testday_form_mode") eq "edit") {
      my $testday_id = $c->param("edit_testday_form_testday_id");
      my $testday = Litmus::DB::TestDay->retrieve($testday_id);
      if ($testday) {
        my @subgroups;
        Litmus::Auth::requireProductAdmin("manage_testdays.cgi", $testday->product());
        $testday->description($c->param('edit_testday_form_desc'));
        $testday->start_timestamp($c->param('edit_testday_form_start_timestamp'));
        $testday->finish_timestamp($c->param('edit_testday_form_finish_timestamp'));
        $testday->creator_id($c->param('edit_testday_form_created_by'));
        if ($c->param('product')) {
          Litmus::Auth::requireProductAdmin("manage_testdays.cgi", $c->param('product'));
          $testday->product_id($c->param('product'));
        }
        if ($c->param('branch')) {
          $testday->branch_id($c->param('branch'));
        }
        if ($c->param('testgroup')) {
          $testday->testgroup_id($c->param('testgroup'));
        }
        if ($c->param('subgroup')) {
          @subgroups = $c->param('subgroup');
        }
        if ($c->param('build_id')) {
          $testday->build_id($c->param('build_id'));
        }
        if ($c->param('locale') and
            $c->param('locale') ne "") {        
          $testday->locale_abbrev($c->param('locale'));
        }

        $rv = $testday->update();
        if ($rv) {
          $testday->update_subgroups(\@subgroups);
          $status = "success";
          $message = "Testday ID# $testday_id updated successfully.";
          $defaults->{'testday_id'} = $testday_id;
        } else {
          $status = "failure";
          $message = "Failed to update testday ID# $testday_id.";
        }
      } else {
        $status = "failure";
        $message = "Testday ID# $testday_id not found.";        
      }
    }
  }

}

my $products = Litmus::FormWidget->getProducts();
my $branches = Litmus::FormWidget->getBranches();
my $testgroups = Litmus::FormWidget->getTestgroups();
my $subgroups = Litmus::FormWidget->getSubgroups();
my $testdays = Litmus::FormWidget->getTestdays();
my $locales = Litmus::FormWidget->getLocales;
my $authors = Litmus::FormWidget->getAuthors();

my $json = new JSON;
my $products_js = $json->allow_unknown->convert_blessed->encode($products);
my $branches_js = $json->allow_unknown->convert_blessed->encode($branches);
my $testgroups_js = $json->allow_unknown->convert_blessed->encode($testgroups);
my $subgroups_js = $json->allow_unknown->convert_blessed->encode($subgroups);

my $vars = {
            title => 'Manage Testdays',
            products => $products,
            branches => $branches,
            testdays => $testdays,
            locales  => $locales,
            warning  => $warning,
           };
  
$vars->{'products_js'} = $products_js;
$vars->{'branches_js'} = $branches_js;
$vars->{'testgroups_js'} = $testgroups_js;
$vars->{'subgroups_js'} = $subgroups_js;
$vars->{'authors'} = $authors;
$vars->{'user'} = Litmus::Auth::getCurrentUser();

if ($status and $message) {
  $vars->{'onload'} = "toggleMessage('$status','$message');";
}

my $cookie =  Litmus::Auth::getCookie();
$vars->{"defaultemail"} = $cookie;
$vars->{"show_admin"} = Litmus::Auth::istrusted($cookie);

Litmus->template()->process("admin/manage_testdays.tmpl", $vars) ||
  internalError(Litmus->template()->error());

#my $elapsed = tv_interval ( $t0 );
#printf  "<div id='pageload'>Page took %f seconds to load.</div>", $elapsed;

exit 0;