# Subclass Helpers
#####################################################################
-sub _build_model {
- my ($self) = @_;
- require Bugzilla::Model;
- Bugzilla::Model->connect($self->dsn, $self->user, $self->pass, $self->attrs);
-}
-
sub _build_connector {
my ($self) = @_;
my ($dsn, $user, $pass, $override_attrs)
+++ /dev/null
-# 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.
-
-package Bugzilla::Model;
-use Mojo::Base 'DBIx::Class::Schema';
-
-__PACKAGE__->load_namespaces(default_resultset_class => 'ResultSet');
-__PACKAGE__->load_components('Helper::Schema::QuoteNames');
-
-1;
-
-=head1 NAME
-
-Bugzilla::Model - a DBIx::Class::Schema for Bugzilla
-
-=head1 SYNOPSIS
-
- my $model = Bugzilla->dbh->model;
- my $firefox_rs = $model->resultset('Bug')->search({'product.name' => 'Firefox'},
- {join => ['product', {bug_keywords => 'keyword'}]});
- my @report = $firefox_rs->group_by('bug_id')->columns({
- bug_id => 'bug.bug_id',
- summary => 'bug.short_desc',
- product => 'product.name',
- keywords => {group_concat => 'keyword.name'}
- })->hri->all;
- is(
- \@report,
- [
- {
- bug_id => 1,
- keywords => 'regression,relnote',
- product => 'Firefox',
- summary => 'Some bug'
- },
- {
- bug_id => 2,
- keywords => undef,
- product => 'Firefox',
- summary => 'some other bug'
- }
- ]
- );
-
-=head1 SEE ALSO
-
-See L<DBIx::Class> and L<DBIx::Class::Helper::ResultSet::Shortcut> for more examples of usage.
+++ /dev/null
-# 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.
-
-package Bugzilla::Model::Result::Bug;
-use Mojo::Base 'DBIx::Class::Core';
-
-__PACKAGE__->load_components(qw( Helper::Row::NumifyGet InflateColumn::DateTime ));
-
-__PACKAGE__->table(Bugzilla::Bug->DB_TABLE);
-__PACKAGE__->add_columns(Bugzilla::Bug->DB_COLUMN_NAMES);
-__PACKAGE__->add_columns(
- '+bug_id' => {is_numeric => 1},
- '+reporter' => {is_numeric => 1},
- '+qa_contact' => {is_numeric => 1},
- '+assigned_to' => {is_numeric => 1},
- '+delta_ts' => {data_type => 'timestamp'},
-);
-__PACKAGE__->set_primary_key(Bugzilla::Bug->ID_FIELD);
-
-__PACKAGE__->has_one(
- reporter => 'Bugzilla::Model::Result::User',
- {'foreign.userid' => 'self.reporter'}
-);
-
-__PACKAGE__->has_one(
- assigned_to => 'Bugzilla::Model::Result::User',
- {'foreign.userid' => 'self.assigned_to'}
-);
-__PACKAGE__->might_have(
- qa_contact => 'Bugzilla::Model::Result::User',
- {'foreign.userid' => 'self.qa_contact'}
-);
-
-__PACKAGE__->has_many(
- map_keywords => 'Bugzilla::Model::Result::BugKeyword',
- 'bug_id'
-);
-
-__PACKAGE__->many_to_many(keywords => 'map_keywords', 'keyword');
-
-__PACKAGE__->has_many(flags => 'Bugzilla::Model::Result::Flag', 'bug_id');
-
-__PACKAGE__->has_many(
- map_groups => 'Bugzilla::Model::Result::BugGroup',
- 'bug_id'
-);
-__PACKAGE__->many_to_many(groups => 'map_groups', 'group');
-
-__PACKAGE__->has_many(
- map_depends_on => 'Bugzilla::Model::Result::Dependency',
- 'dependson'
-);
-__PACKAGE__->many_to_many(depends_on => 'map_depends_on', 'depends_on');
-
-__PACKAGE__->has_many(
- map_blocked_by => 'Bugzilla::Model::Result::Dependency',
- 'blocked'
-);
-__PACKAGE__->many_to_many(blocked_by => 'map_depends_on', 'blocked_by');
-
-__PACKAGE__->has_one(
- product => 'Bugzilla::Model::Result::Product',
- {'foreign.id' => 'self.product_id'}
-);
-
-__PACKAGE__->has_one(
- component => 'Bugzilla::Model::Result::Component',
- {'foreign.id' => 'self.component_id'}
-);
-
-
-__PACKAGE__->has_many(
- map_duplicates => 'Bugzilla::Model::Result::Duplicate',
- 'dupe_of'
-);
-
-__PACKAGE__->many_to_many('duplicates', 'map_duplicates', 'duplicate');
-
-__PACKAGE__->might_have( map_duplicate_of => 'Bugzilla::Model::Result::Duplicate', 'dupe');
-
-sub duplicate_of {
- my ($self) = @_;
-
- my $duplicate = $self->map_duplicate_of;
- return $duplicate->duplicate_of if $duplicate;
- return undef;
-}
-
-1;
-
+++ /dev/null
-# 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.
-
-package Bugzilla::Model::Result::BugGroup;
-use Mojo::Base 'DBIx::Class::Core';
-
-__PACKAGE__->table('bug_group_map');
-__PACKAGE__->add_columns('bug_id', 'group_id');
-__PACKAGE__->set_primary_key('bug_id', 'group_id');
-
-__PACKAGE__->belongs_to(bug => 'Bugzilla::Model::Result::Bug', 'bug_id');
-__PACKAGE__->belongs_to(group => 'Bugzilla::Model::Result::Group', 'group_id');
-
-
-1;
+++ /dev/null
-# 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.
-
-package Bugzilla::Model::Result::BugKeyword;
-use Mojo::Base 'DBIx::Class::Core';
-
-__PACKAGE__->table('keywords');
-__PACKAGE__->add_columns('bug_id', 'keywordid');
-__PACKAGE__->set_primary_key('bug_id', 'keywordid');
-
-__PACKAGE__->belongs_to(bug => 'Bugzilla::Model::Result::Bug', 'bug_id');
-__PACKAGE__->belongs_to(keyword => 'Bugzilla::Model::Result::Keyword', 'keywordid');
-
-1;
+++ /dev/null
-# 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.
-
-package Bugzilla::Model::Result::Component;
-use Mojo::Base 'DBIx::Class::Core';
-
-__PACKAGE__->table(Bugzilla::Component->DB_TABLE);
-__PACKAGE__->add_columns(Bugzilla::Component->DB_COLUMN_NAMES);
-__PACKAGE__->set_primary_key(Bugzilla::Component->ID_FIELD);
-
-__PACKAGE__->belongs_to(product => 'Bugzilla::Model::Result::Product', 'product_id');
-
-1;
+++ /dev/null
-# 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.
-
-package Bugzilla::Model::Result::Dependency;
-use Mojo::Base 'DBIx::Class::Core';
-
-__PACKAGE__->load_components('Helper::Row::NumifyGet');
-
-__PACKAGE__->table('dependencies');
-__PACKAGE__->add_columns(qw[ blocked dependson ]);
-__PACKAGE__->set_primary_key(qw[ blocked dependson ]);
-
-__PACKAGE__->add_columns(
- '+blocked' => {is_numeric => 1},
- '+dependson' => {is_numeric => 1},
-);
-
-__PACKAGE__->belongs_to(
- blocked_by => 'Bugzilla::Model::Result::Bug',
- {'foreign.bug_id' => 'self.blocked'}
-);
-
-__PACKAGE__->belongs_to(
- depends_on => 'Bugzilla::Model::Result::Bug',
- {'foreign.bug_id' => 'self.dependson'}
-);
-
-
-1;
+++ /dev/null
-# 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.
-
-package Bugzilla::Model::Result::Duplicate;
-use Mojo::Base 'DBIx::Class::Core';
-
-__PACKAGE__->table('duplicates');
-__PACKAGE__->add_columns(qw[ dupe_of dupe ]);
-__PACKAGE__->set_primary_key(qw[ dupe ]);
-
-__PACKAGE__->belongs_to(
- duplicate => 'Bugzilla::Model::Result::Bug',
- {'foreign.bug_id' => 'self.dupe'}
-);
-
-__PACKAGE__->belongs_to(
- duplicate_of => 'Bugzilla::Model::Result::Bug',
- {'foreign.bug_id' => 'self.dupe_of'}
-);
-
-1;
+++ /dev/null
-# 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.
-
-package Bugzilla::Model::Result::Flag;
-use Mojo::Base 'DBIx::Class::Core';
-
-__PACKAGE__->load_components('Helper::Row::NumifyGet');
-
-__PACKAGE__->table(Bugzilla::Flag->DB_TABLE);
-__PACKAGE__->add_columns(Bugzilla::Flag->DB_COLUMN_NAMES);
-
-__PACKAGE__->add_columns(
- '+id' => {is_numeric => 1},
- '+type_id' => {is_numeric => 1},
- '+bug_id' => {is_numeric => 1},
- '+attach_id' => {is_numeric => 1},
- '+setter_id' => {is_numeric => 1},
- '+requestee_id' => {is_numeric => 1},
-);
-
-__PACKAGE__->set_primary_key(Bugzilla::Flag->ID_FIELD);
-
-__PACKAGE__->belongs_to(bug => 'Bugzilla::Model::Result::Bug', 'bug_id');
-__PACKAGE__->belongs_to(type => 'Bugzilla::Model::Result::FlagType', 'type_id');
-__PACKAGE__->has_one(
- setter => 'Bugzilla::Model::Result::User',
- {'foreign.userid' => 'self.setter_id'}
-);
-
-__PACKAGE__->might_have(
- requestee => 'Bugzilla::Model::Result::User',
- {'foreign.userid' => 'self.requestee_id'}
-);
-
-
-1;
+++ /dev/null
-
-# 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.
-
-package Bugzilla::Model::Result::FlagType;
-use Mojo::Base 'DBIx::Class::Core';
-
-__PACKAGE__->table(Bugzilla::FlagType->DB_TABLE);
-__PACKAGE__->add_columns(Bugzilla::FlagType->DB_COLUMN_NAMES);
-__PACKAGE__->set_primary_key(Bugzilla::FlagType->ID_FIELD);
-
-__PACKAGE__->has_many(flags => 'Bugzilla::Model::Result::Flag', 'type_id');
-
-1;
+++ /dev/null
-# 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.
-
-package Bugzilla::Model::Result::Group;
-use Mojo::Base 'DBIx::Class::Core';
-
-__PACKAGE__->table(Bugzilla::Group->DB_TABLE);
-__PACKAGE__->add_columns(Bugzilla::Group->DB_COLUMN_NAMES);
-__PACKAGE__->set_primary_key(Bugzilla::Group->ID_FIELD);
-
-1;
+++ /dev/null
-# 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.
-
-package Bugzilla::Model::Result::Keyword;
-use Mojo::Base 'DBIx::Class::Core';
-
-__PACKAGE__->table(Bugzilla::Keyword->DB_TABLE);
-__PACKAGE__->add_columns(Bugzilla::Keyword->DB_COLUMN_NAMES);
-__PACKAGE__->set_primary_key(Bugzilla::Keyword->ID_FIELD);
-
-1;
+++ /dev/null
-# 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.
-
-package Bugzilla::Model::Result::Product;
-use Mojo::Base 'DBIx::Class::Core';
-
-__PACKAGE__->table(Bugzilla::Product->DB_TABLE);
-__PACKAGE__->add_columns(Bugzilla::Product->DB_COLUMN_NAMES);
-__PACKAGE__->set_primary_key(Bugzilla::Product->ID_FIELD);
-
-__PACKAGE__->has_many('components', 'Bugzilla::Model::Result::Component', 'product_id');
-
-1;
+++ /dev/null
-# 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.
-
-package Bugzilla::Model::Result::User;
-use Mojo::Base 'DBIx::Class::Core';
-
-__PACKAGE__->load_components('Helper::Row::NumifyGet');
-
-__PACKAGE__->table(Bugzilla::User->DB_TABLE);
-__PACKAGE__->add_columns(Bugzilla::User->DB_COLUMN_NAMES);
-__PACKAGE__->add_columns('+userid' => {is_numeric => 1});
-__PACKAGE__->set_primary_key(Bugzilla::User->ID_FIELD);
-
-sub name {
- my ($self) = @_;
- $self->realname;
-}
-
-sub login {
- my ($self) = @_;
- $self->login_name;
-}
-
-1;
+++ /dev/null
-# 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.
-
-package Bugzilla::Model::ResultSet;
-use Mojo::Base 'DBIx::Class::ResultSet';
-
-__PACKAGE__->load_components('Helper::ResultSet');
-
-1;
+++ /dev/null
-# 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.
-
-package Bugzilla::Report::Ping;
-use 5.10.1;
-use Moo::Role;
-
-use Bugzilla::Types qw(URL);
-use JSON::Validator;
-use Mojo::Promise;
-use Scalar::Util qw(blessed);
-use Type::Utils qw(class_type);
-use Types::Standard qw(Str Num Int);
-use UUID::Tiny qw(:std);
-
-has 'model' =>
- (is => 'ro', required => 1, isa => class_type({class => 'Bugzilla::Model'}));
-
-has '_base_url' => (
- is => 'ro',
- init_arg => 'base_url',
- required => 1,
- isa => URL,
- coerce => 1,
- handles => {base_url => 'clone'}
-);
-
-has 'page' => (is => 'ro', isa => Int, default => 1);
-
-has 'rows' => (is => 'ro', default => 10);
-
-has 'since' => (is => 'ro', predicate => 1);
-
-has 'user_agent' => (
- is => 'lazy',
- init_arg => undef,
- isa => class_type({class => 'Mojo::UserAgent'})
-);
-
-sub _build_user_agent {
- return Mojo::UserAgent->new;
-}
-
-has 'validator' => (
- is => 'lazy',
- init_arg => undef,
- isa => class_type({class => 'JSON::Validator'}),
- handles => ['validate'],
-);
-
-requires '_build_validator';
-
-has 'resultset' => (
- is => 'lazy',
- init_arg => undef,
- isa => class_type({class => 'DBIx::Class::ResultSet'}),
- handles => ['pager'],
-);
-
-requires '_build_resultset';
-
-around '_build_resultset' => sub {
- my ($method, $self, @args) = @_;
- my $rs = $self->$method(@args);
- $rs = $rs->rows($self->rows)->page($self->page) if defined $rs;
-
- return $rs;
-};
-
-has 'namespace' => (is => 'lazy', isa => Str);
-
-sub _build_namespace {
- return 'bugzilla';
-}
-
-has 'doctype' => (is => 'lazy', isa => Str);
-
-sub _build_doctype {
- my ($self) = @_;
- my @class_parts = split(/::/, blessed $self);
- return lc $class_parts[-1];
-}
-
-has 'docversion' => (is => 'lazy', init_arg => undef, isa => Num);
-
-sub _build_docversion {
- my ($self) = @_;
- return $self->VERSION;
-}
-
-has 'uuid_namespace' => (is => 'lazy', init_arg => undef, isa => Str);
-
-sub _build_uuid_namespace {
- my ($self) = @_;
-
- my $name = $self->namespace . '/' . $self->doctype . ':' . $self->docversion;
- return create_uuid(UUID_SHA1, UUID_NIL, $name);
-}
-
-requires 'extract_id', 'extract_content';
-
-around 'extract_id' => sub {
- my ($method, $self, $row) = @_;
-
- return create_uuid_as_string(UUID_SHA1, $self->uuid_namespace, $self->$method($row));
-};
-
-sub send_row {
- my ($self, $row) = @_;
- my $url = $self->base_url;
- my $id = $self->extract_id($row);
- my $content = $self->extract_content($row);
- push @{$url->path}, $self->namespace, $self->doctype, $self->docversion, $id;
- return $self->user_agent->put_p($url, json => $content);
-}
-
-sub test_row {
- my ($self, $row) = @_;
- my $id = $self->extract_id($row);
- my $doc = $self->extract_content($row);
- die 'id is not a uuid string' unless is_uuid_string($id);
-
- return $self->validate($doc);
-}
-
-1;
+++ /dev/null
-# 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.
-
-use 5.10.1;
-use strict;
-use warnings;
-use lib qw( . lib local/lib/perl5 );
-
-BEGIN {
- unlink('data/db/model_test') if -f 'data/db/model_test';
- $ENV{test_db_name} = 'model_test';
-}
-
-use Bugzilla::Test::MockDB;
-use Bugzilla::Test::MockParams (password_complexity => 'no_constraints');
-use Bugzilla::Test::Util qw(create_bug create_user);
-use Bugzilla;
-use Bugzilla::Constants;
-use Bugzilla::Hook;
-BEGIN { Bugzilla->extensions }
-use Test2::V0;
-use Test2::Tools::Mock qw(mock mock_accessor);
-use Test2::Tools::Exception qw(dies lives);
-use PerlX::Maybe qw(provided);
-
-Bugzilla->dbh->model->resultset('Keyword')
- ->create({name => 'regression', description => 'the regression keyword'});
-
-my $user = create_user('reportuser@invalid.tld', '*');
-$user->{groups} = [Bugzilla::Group->get_all];
-Bugzilla->set_user($user);
-
-create_bug(
- short_desc => "test bug $_",
- comment => "Hello, world: $_",
- provided $_ % 3 == 0, keywords => ['regression'],
- assigned_to => 'reportuser@invalid.tld'
-) for (1..10);
-
-my $model = Bugzilla->dbh->model;
-my $bug3 = $model->resultset('Bug')->find(3);
-isa_ok($bug3, 'Bugzilla::Model::Result::Bug');
-
-is([map { $_->name } $bug3->keywords->all], ['regression']);
-
-is($bug3->reporter->login_name, Bugzilla::Bug->new($bug3->id)->reporter->login);
-
-
-done_testing;
-