summaryrefslogtreecommitdiffstats
path: root/advertising/NEWS
blob: 415fbe9ee5d9d27d6f52b6be04e52e711d5972df (plain)
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
Version 9.1 - 24 June 2023

- Fix typos in slideshow (developer and Languages) (mga#31872)

Version 9 - 17 April 2023

- Mageia 9 artwork

Version 8 - 11 January 2021

- Mageia 8 artwork

Version 7 - 4 May 2019

- Mageia 7

Version 6 - 8 May 2017

- Mageia 6

Version 5.1 - 18 December 2014

- Fix badly exported 03_IM_mageia.png

Version 5 - 17 December 2014

- Mageia 5

Version 4 - 8 January 2014

- Mageia 4

Version 3 - 6 april 2013

- Mageia 3

Version 2 - 25 april 2011

- make it more generic for Mageia 2

Version 1 - 12 March 2011

- new advertising for Mageia 1

Version 2011.0 - 13 Oct 2010

- bump version

Version 2010.1 - 02 May 2010

- 2010.1 images

Version 2010.0 - 28 October 2009

- 2010.0 images

Version 2009.1 - 7 March 2009

- 2009.1 images

Version 2009.0 - 11 September 2008

- 2009.0 images

Version 2008.1.1 - 21 March 2008

- 2008.1 titles

Version 2008.1 - 26 February 2008

- 2008.1 images

Version 0.6 - 18 September 2007, by Pascal "Pixel" Rigaux

- really add titles for 2008.0 adversting

Version 0.5 - 18 September 2007, by Pascal "Pixel" Rigaux

- fix 02IM_MIGRATION.png screenshot

Version 0.4 - 17 September 2007, by Pascal "Pixel" Rigaux

- add titles for 2008.0 adversting

Version 0.3 - 14 September 2007, by Pascal "Pixel" Rigaux

- 2008.0 advertising images
- drop *.pl files, not used by drakx-installer-stage2 anymore

Version 0.2 - 4 April 2007, by Pascal "Pixel" Rigaux

- 2007.1 advertising images
- move advertising out of drakx-installer-stage2 into drakx-installer-advertising

id='n258' href='#n258'>258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686
#!/usr/bin/perl -wT
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# This Source Code Form is "Incompatible With Secondary Licenses", as
# defined by the Mozilla Public License, v. 2.0.

################################################################################
# Script Initialization
################################################################################

use 5.10.1;
use strict;
use lib qw(. lib);

use Bugzilla;
use Bugzilla::Constants;
use Bugzilla::Search;
use Bugzilla::User;
use Bugzilla::Mailer;
use Bugzilla::Util;
use Bugzilla::Group;

# create some handles that we'll need
my $template = Bugzilla->template;
my $dbh      = Bugzilla->dbh;
my $sth;

# @seen_schedules is a list of all of the schedules that have already been
# touched by reset_timer.  If reset_timer sees a schedule more than once, it
# sets it to NULL so it won't come up again until the next execution of
# whine.pl
my @seen_schedules = ();

# These statement handles should live outside of their functions in order to
# allow the database to keep their SQL compiled.
my $sth_run_queries =
    $dbh->prepare("SELECT " .
                  "query_name, title, onemailperbug " .
                  "FROM whine_queries " .
                  "WHERE eventid=? " .
                  "ORDER BY sortkey");
my $sth_get_query =
    $dbh->prepare("SELECT query FROM namedqueries " .
                  "WHERE userid = ? AND name = ?");

# get the event that's scheduled with the lowest run_next value
my $sth_next_scheduled_event = $dbh->prepare(
    "SELECT " .
    " whine_schedules.eventid, " .
    " whine_events.owner_userid, " .
    " whine_events.subject, " .
    " whine_events.body, " .
    " whine_events.mailifnobugs " .
    "FROM whine_schedules " .
    "LEFT JOIN whine_events " .
    " ON whine_events.id = whine_schedules.eventid " .
    "WHERE run_next <= NOW() " .
    "ORDER BY run_next " .
    $dbh->sql_limit(1)
);

# get all pending schedules matching an eventid
my $sth_schedules_by_event = $dbh->prepare(
    "SELECT id, mailto_type, mailto " .
    "FROM whine_schedules " .
    "WHERE eventid=? AND run_next <= NOW()"
);


################################################################################
# Main Body Execution
################################################################################

# This script needs to check through the database for schedules that have
# run_next set to NULL, which means that schedule is new or has been altered.
# It then sets it to run immediately if the schedule entry has it running at
# an interval like every hour, otherwise to the appropriate day and time.

# After that, it looks over each user to see if they have schedules that need
# running, then runs those and generates the email messages.

# Send whines from the address in the 'mailfrom' Parameter so that all
# Bugzilla-originated mail appears to come from a single address.
my $fromaddress = Bugzilla->params->{'mailfrom'};

# get the current date and time
my ($now_sec, $now_minute, $now_hour, $now_day, $now_month, $now_year, 
    $now_weekday) = localtime;
# Convert year to two digits
$now_year = sprintf("%02d", $now_year % 100);
# Convert the month to January being "1" instead of January being "0".
$now_month++;

my @daysinmonth = qw(0 31 28 31 30 31 30 31 31 30 31 30 31);
# Alter February in case of a leap year.  This simple way to do it only
# applies if you won't be looking at February of next year, which whining
# doesn't need to do.
if (($now_year % 4 == 0) &&
    (($now_year % 100 != 0) || ($now_year % 400 == 0))) {
    $daysinmonth[2] = 29;
}

# run_day can contain either a calendar day (1, 2, 3...), a day of the week
# (Mon, Tue, Wed...), a range of days (All, MF), or 'last' for the last day of
# the month.
#
# run_time can contain either an hour (0, 1, 2...) or an interval
# (60min, 30min, 15min).
#
# We go over each uninitialized schedule record and use its settings to
# determine what the next time it runs should be
my $sched_h = $dbh->prepare("SELECT id, run_day, run_time " .
                            "FROM whine_schedules " .
                            "WHERE run_next IS NULL" );
$sched_h->execute();
while (my ($schedule_id, $day, $time) = $sched_h->fetchrow_array) {
    # fill in some defaults in case they're blank
    $day  ||= '0';
    $time ||= '0';

    # If this schedule is supposed to run today, we see if it's supposed to be
    # run at a particular hour.  If so, we set it for that hour, and if not,
    # it runs at an interval over the course of a day, which means we should
    # set it to run immediately.
    if (&check_today($day)) {
        # Values that are not entirely numeric are intervals, like "30min"
        if ($time !~ /^\d+$/) {
            # set it to now
            $sth = $dbh->prepare( "UPDATE whine_schedules " .
                                  "SET run_next=NOW() " .
                                  "WHERE id=?");
            $sth->execute($schedule_id);
        }
        # A time greater than now means it still has to run today
        elsif ($time >= $now_hour) {
            # set it to today + number of hours
            $sth = $dbh->prepare(
                "UPDATE whine_schedules " .
                   "SET run_next = " .
                        $dbh->sql_date_math('CURRENT_DATE', '+', '?', 'HOUR') .
                " WHERE id = ?");
            $sth->execute($time, $schedule_id);
        }
        # the target time is less than the current time
        else { # set it for the next applicable day
            $day = &get_next_date($day);
            my $run_next = $dbh->sql_date_math('(' 
                . $dbh->sql_date_math('CURRENT_DATE', '+', '?', 'DAY')
                . ')', '+', '?', 'HOUR');
            $sth = $dbh->prepare("UPDATE whine_schedules " .
                                    "SET run_next = $run_next
                                   WHERE id = ?");
            $sth->execute($day, $time, $schedule_id);
        }

    }
    # If the schedule is not supposed to run today, we set it to run on the
    # appropriate date and time
    else {
        my $target_date = &get_next_date($day);
        # If configured for a particular time, set it to that, otherwise
        # midnight
        my $target_time = ($time =~ /^\d+$/) ? $time : 0;

       my $run_next = $dbh->sql_date_math('(' 
            . $dbh->sql_date_math('CURRENT_DATE', '+', '?', 'DAY') 
            . ')', '+', '?', 'HOUR');
        $sth = $dbh->prepare("UPDATE whine_schedules " .
                                "SET run_next = $run_next
                               WHERE id = ?");
        $sth->execute($target_date, $target_time, $schedule_id);
    }
}
$sched_h->finish();

# get_next_event
#
# This function will:
#   1. Lock whine_schedules
#   2. Grab the most overdue pending schedules on the same event that must run
#   3. Update those schedules' run_next value
#   4. Unlock the table
#   5. Return an event hashref
#
# The event hashref consists of:
#   eventid - ID of the event 
#   author  - user object for the event's creator
#   users   - array of user objects for recipients
#   subject - Subject line for the email
#   body    - the text inserted above the bug lists
#   mailifnobugs - send message even if there are no query or query results

sub get_next_event {
    my $event = {};

    # Loop until there's something to return
    until (scalar keys %{$event}) {

        $dbh->bz_start_transaction();

        # Get the event ID for the first pending schedule
        $sth_next_scheduled_event->execute;
        my $fetched = $sth_next_scheduled_event->fetch;
        $sth_next_scheduled_event->finish;
        return undef unless $fetched;
        my ($eventid, $owner_id, $subject, $body, $mailifnobugs) = @{$fetched};

        my $owner = Bugzilla::User->new($owner_id);

        my $whineatothers = $owner->in_group('bz_canusewhineatothers');

        my %user_objects;   # Used for keeping track of who has been added

        # Get all schedules that match that event ID and are pending
        $sth_schedules_by_event->execute($eventid);

        # Add the users from those schedules to the list
        while (my $row = $sth_schedules_by_event->fetch) {
            my ($sid, $mailto_type, $mailto) = @{$row};

            # Only bother doing any work if this user has whine permission
            if ($owner->in_group('bz_canusewhines')) {

                if ($mailto_type == MAILTO_USER) {
                    if (not defined $user_objects{$mailto}) {
                        if ($mailto == $owner_id) {
                            $user_objects{$mailto} = $owner;
                        }
                        elsif ($whineatothers) {
                            $user_objects{$mailto} = Bugzilla::User->new($mailto);
                        }
                    }
                }
                elsif ($mailto_type == MAILTO_GROUP) {
                    my $sth = $dbh->prepare("SELECT name FROM groups " .
                                            "WHERE id=?");
                    $sth->execute($mailto);
                    my $groupname = $sth->fetch->[0];
                    my $group_id = Bugzilla::Group::ValidateGroupName(
                        $groupname, $owner);
                    if ($group_id) {
                        my $glist = join(',',
                            @{Bugzilla::Group->flatten_group_membership(
                            $group_id)});
                        $sth = $dbh->prepare("SELECT user_id FROM " .
                                             "user_group_map " .
                                             "WHERE group_id IN ($glist)");
                        $sth->execute();
                        for my $row (@{$sth->fetchall_arrayref}) {
                            if (not defined $user_objects{$row->[0]}) {
                                $user_objects{$row->[0]} =
                                    Bugzilla::User->new($row->[0]);
                            }
                        }
                    }
                }

            }

            reset_timer($sid);
        }

        $dbh->bz_commit_transaction();

        # Only set $event if the user is allowed to do whining
        if ($owner->in_group('bz_canusewhines')) {
            my @users = values %user_objects;
            $event = {
                    'eventid' => $eventid,
                    'author'  => $owner,
                    'mailto'  => \@users,
                    'subject' => $subject,
                    'body'    => $body,
                    'mailifnobugs' => $mailifnobugs,
            };
        }
    }
    return $event;
}

# Run the queries for each event
#
# $event:
#   eventid (the database ID for this event)
#   author  (user object for who created the event)
#   mailto  (array of user objects for mail targets)
#   subject (subject line for message)
#   body    (text blurb at top of message)
#   mailifnobugs (send message even if there are no query or query results)
while (my $event = get_next_event) {

    my $eventid = $event->{'eventid'};

    # We loop for each target user because some of the queries will be using
    # subjective pronouns
    $dbh = Bugzilla->switch_to_shadow_db();
    for my $target (@{$event->{'mailto'}}) {
        my $args = {
            'subject'     => $event->{'subject'},
            'body'        => $event->{'body'},
            'eventid'     => $event->{'eventid'},
            'author'      => $event->{'author'},
            'recipient'   => $target,
            'from'        => $fromaddress,
        };

        # run the queries for this schedule
        my $queries = run_queries($args);

        # If mailifnobugs is false, make sure there is something to output
        if (!$event->{'mailifnobugs'}) {
            my $there_are_bugs = 0;
            for my $query (@{$queries}) {
                $there_are_bugs = 1 if scalar @{$query->{'bugs'}};
            }
            next unless $there_are_bugs;
        }

        $args->{'queries'} = $queries;

        mail($args);
    }
    $dbh = Bugzilla->switch_to_main_db();
}

################################################################################
# Functions
################################################################################

# The mail and run_queries functions use an anonymous hash ($args) for their
# arguments, which are then passed to the templates.
#
# When run_queries is run, $args contains the following fields:
#  - body           Message body defined in event
#  - from           Bugzilla system email address
#  - queries        array of hashes containing:
#          - bugs:  array of hashes mapping fieldnames to values for this bug
#          - title: text title given to this query in the whine event
#          - columnlist: array of fieldnames to display in the mail
#          - name:  text name of this query
#  - schedule_id    integer id of the schedule being run
#  - subject        Subject line for the message
#  - recipient      user object for the recipient
#  - author         user object of the person who created the whine event
#
# In addition, mail adds two more fields to $args:
#  - alternatives   array of hashes defining mime multipart types and contents
#  - boundary       a MIME boundary generated using the process id and time
#
sub mail {
    my $args = shift;
    my $addressee = $args->{recipient};
    # Don't send mail to someone whose bugmail notification is disabled.
    return if $addressee->email_disabled;

    my $template = Bugzilla->template_inner($addressee->setting('lang'));
    my $msg = ''; # it's a temporary variable to hold the template output
    $args->{'alternatives'} ||= [];

    # put together the different multipart mime segments

    $template->process("whine/mail.txt.tmpl", $args, \$msg)
        or die($template->error());
    push @{$args->{'alternatives'}},
        {
            'content' => $msg,
            'type'    => 'text/plain',
        };
    $msg = '';

    $template->process("whine/mail.html.tmpl", $args, \$msg)
        or die($template->error());
    push @{$args->{'alternatives'}},
        {
            'content' => $msg,
            'type'    => 'text/html',
        };
    $msg = '';

    # now produce a ready-to-mail mime-encoded message

    $args->{'boundary'} = "----------" . $$ . "--" . time() . "-----";

    $template->process("whine/multipart-mime.txt.tmpl", $args, \$msg)
        or die($template->error());

    MessageToMTA($msg);

    delete $args->{'boundary'};
    delete $args->{'alternatives'};

}

# run_queries runs all of the queries associated with a schedule ID, adding
# the results to $args or mailing off the template if a query wants individual
# messages for each bug
sub run_queries {
    my $args = shift;

    my $return_queries = [];

    $sth_run_queries->execute($args->{'eventid'});
    my @queries = ();
    for (@{$sth_run_queries->fetchall_arrayref}) {
        push(@queries,
            {
              'name'          => $_->[0],
              'title'         => $_->[1],
              'onemailperbug' => $_->[2],
              'columnlist'    => [],
              'bugs'          => [],
            }
        );
    }

    foreach my $thisquery (@queries) {
        next unless $thisquery->{'name'};   # named query is blank

        my $savedquery = get_query($thisquery->{'name'}, $args->{'author'});
        next unless $savedquery;    # silently ignore missing queries

        # Execute the saved query
        my @searchfields = ('bug_id', DEFAULT_COLUMN_LIST);

        # A new Bugzilla::CGI object needs to be created to allow
        # Bugzilla::Search to execute a saved query.  It's exceedingly weird,
        # but that's how it works.
        my $searchparams = new Bugzilla::CGI($savedquery);

        # Use the columnlist for the saved query, if it exists, and make
        # sure bug_id is always in the list.
        if (my $columnlist = $searchparams->param('columnlist')) {
            @searchfields = split(/[\s,]+/, $columnlist);
            unshift(@searchfields, 'bug_id') unless grep { $_ eq 'bug_id' } @searchfields;
        }
        push @{$thisquery->{'columnlist'}}, @searchfields;

        my @orderstrings = split(/,\s*/, $searchparams->param('order') || '');
        my $search = new Bugzilla::Search(
            'fields' => \@searchfields,
            'params' => scalar $searchparams->Vars,
            'user'   => $args->{'recipient'}, # the search runs as the recipient
            'order'  => \@orderstrings
        );
        # If a query fails for whatever reason, it shouldn't kill the script.
        my $data = eval { $search->data };
        if ($@) {
            print STDERR get_text('whine_query_failed', { query_name => $thisquery->{'name'},
                                                          author => $args->{'author'},