- fix: New page layout instead of not found
- fix: Rollback - fix: debug output - fix: Can't delete images at product asset fixed a problem with file/image form uploads rearranged group methods for alphabetical order removed matt's hack for group caching and replaced it with the right way
This commit is contained in:
parent
16bd394434
commit
41e655b452
10 changed files with 296 additions and 356 deletions
|
|
@ -12,6 +12,9 @@
|
|||
- fix: Manage groups in this group doesn't work
|
||||
- Fixed a problem where the not found page would not display.
|
||||
- fix: New page layout instead of not found
|
||||
- fix: Rollback
|
||||
- fix: debug output
|
||||
- fix: Can't delete images at product asset
|
||||
|
||||
6.99.2
|
||||
- fix - demo.plainblack.com getting started
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ package WebGUI::Asset::Wobject::Product;
|
|||
|
||||
use strict;
|
||||
use Tie::CPHash;
|
||||
use Tie::IxHash;
|
||||
use WebGUI::Cache;
|
||||
use WebGUI::HTMLForm;
|
||||
use WebGUI::Storage::Image;
|
||||
|
|
@ -22,28 +23,6 @@ use WebGUI::Asset::Wobject;
|
|||
|
||||
our @ISA = qw(WebGUI::Asset::Wobject);
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub _addFileTab {
|
||||
my $self = shift;
|
||||
my $tabform = $_[0];
|
||||
my $column = $_[1];
|
||||
my $internationalId = $_[2];
|
||||
my $i18n = WebGUI::International->new($self->session,"Asset_Product");
|
||||
unless ($self->get($column)){
|
||||
$tabform->getTab("properties")->file(
|
||||
-name=>$column,
|
||||
-label=>$i18n->get($internationalId),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
my $file = WebGUI::Storage->get($self->session,$self->get($column));
|
||||
$tabform->getTab("properties")->readOnly(
|
||||
-value=>'<a href="'.$self->getUrl('func=deleteFileConfirm&file='.$column).'">'.$i18n->get("deleteImage").'</a>',
|
||||
-label=>$i18n->get($internationalId),
|
||||
);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub _duplicateFile {
|
||||
my $self = shift;
|
||||
|
|
@ -56,19 +35,6 @@ sub _duplicateFile {
|
|||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub _save {
|
||||
my $self = shift;
|
||||
my $file = WebGUI::Storage::Image->create($self->session);
|
||||
my $filename = $file->addFileFromFormPost($_[0]);
|
||||
unless ($filename) {
|
||||
$file->delete;
|
||||
return "";
|
||||
}
|
||||
$file->generateThumbnail($filename);
|
||||
$self->session->db->write("update Product set $_[0]=".$self->session->db->quote($file->getId)." where assetId=".$self->session->db->quote($self->getId)." and revisionDate=".$self->session->db->quote($self->get("revisionDate")));
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 addRevision
|
||||
|
|
@ -84,7 +50,6 @@ sub addRevision {
|
|||
if ($self->get($field)) {
|
||||
my $newStorage = WebGUI::Storage->get($self->session,$self->get($field))->copy;
|
||||
$newSelf->update({$field=>$newStorage->getId});
|
||||
$self->session->db->write("update Product set $field=".$self->session->db->quote($newStorage->getId)." where assetId=".$self->session->db->quote($newSelf->getId)." and revisionDate=".$self->session->db->quote($newSelf->get("revisionDate")));
|
||||
}
|
||||
}
|
||||
return $newSelf;
|
||||
|
|
@ -96,12 +61,9 @@ sub definition {
|
|||
my $session = shift;
|
||||
my $definition = shift;
|
||||
my $i18n = WebGUI::International->new($session,"Asset_Product");
|
||||
push(@{$definition}, {
|
||||
assetName=>$i18n->get('assetName'),
|
||||
icon=>'product.gif',
|
||||
tableName=>'Product',
|
||||
className=>'WebGUI::Asset::Wobject::Product',
|
||||
properties=>{
|
||||
my %properties;
|
||||
tie %properties, 'Tie::IxHash';
|
||||
%properties = (
|
||||
cacheTimeout => {
|
||||
tab => "display",
|
||||
fieldType => "interval",
|
||||
|
|
@ -112,42 +74,83 @@ sub definition {
|
|||
},
|
||||
templateId =>{
|
||||
fieldType=>"template",
|
||||
tab => "display",
|
||||
namespace=>"Product",
|
||||
label=>$i18n->get(62),
|
||||
hoverHelp=>$i18n->get('62 description'),
|
||||
defaultValue=>'PBtmpl0000000000000056'
|
||||
},
|
||||
price=>{
|
||||
label=>$i18n->get(10),
|
||||
hoverHelp=>$i18n->get('10 description'),
|
||||
tab => "properties",
|
||||
fieldType=>"text",
|
||||
defaultValue=>undef
|
||||
},
|
||||
productNumber=>{
|
||||
tab => "properties",
|
||||
label=>$i18n->get(11),
|
||||
hoverHelp=>$i18n->get('11 description'),
|
||||
fieldType=>"text",
|
||||
defaultValue=>undef
|
||||
},
|
||||
# image1=>{
|
||||
# fieldType=>"text",
|
||||
# defaultValue=>undef
|
||||
# },
|
||||
# image2=>{
|
||||
# fieldType=>"text",
|
||||
# defaultValue=>undef
|
||||
# },
|
||||
# image3=>{
|
||||
# fieldType=>"text",
|
||||
# defaultValue=>undef
|
||||
# },
|
||||
# brochure=>{
|
||||
# fieldType=>"text",
|
||||
# defaultValue=>undef
|
||||
# },
|
||||
# manual=>{
|
||||
# fieldType=>"text",
|
||||
# defaultValue=>undef
|
||||
# },
|
||||
# warranty=>{
|
||||
# fieldType=>"text",
|
||||
# defaultValue=>undef
|
||||
# },
|
||||
}
|
||||
});
|
||||
image1=>{
|
||||
tab => "properties",
|
||||
fieldType=>"image",
|
||||
defaultValue=>undef,
|
||||
maxAttachments=>1,
|
||||
label=>$i18n->get(7),
|
||||
deleteFileUrl=>$session->url->page("func=deleteFileConfirm;file=image1;filename=")
|
||||
},
|
||||
image2=>{
|
||||
tab => "properties",
|
||||
fieldType=>"image",
|
||||
maxAttachments=>1,
|
||||
label=>$i18n->get(8),
|
||||
deleteFileUrl=>$session->url->page("func=deleteFileConfirm;file=image2;filename="),
|
||||
defaultValue=>undef
|
||||
},
|
||||
image3=>{
|
||||
tab => "properties",
|
||||
fieldType=>"image",
|
||||
maxAttachments=>1,
|
||||
label=>$i18n->get(9),
|
||||
deleteFileUrl=>$session->url->page("func=deleteFileConfirm;file=image3;filename="),
|
||||
defaultValue=>undef
|
||||
},
|
||||
brochure=>{
|
||||
tab => "properties",
|
||||
fieldType=>"file",
|
||||
maxAttachments=>1,
|
||||
label=>$i18n->get(13),
|
||||
deleteFileUrl=>$session->url->page("func=deleteFileConfirm;file=brochure;filename="),
|
||||
defaultValue=>undef
|
||||
},
|
||||
manual=>{
|
||||
tab => "properties",
|
||||
fieldType=>"file",
|
||||
maxAttachments=>1,
|
||||
label=>$i18n->get(14),
|
||||
deleteFileUrl=>$session->url->page("func=deleteFileConfirm;file=manual;filename="),
|
||||
defaultValue=>undef
|
||||
},
|
||||
warranty=>{
|
||||
tab => "properties",
|
||||
fieldType=>"file",
|
||||
maxAttachments=>1,
|
||||
label=>$i18n->get(15),
|
||||
deleteFileUrl=>$session->url->page("func=deleteFileConfirm;file=warranty;filename="),
|
||||
defaultValue=>undef
|
||||
},
|
||||
);
|
||||
push(@{$definition}, {
|
||||
assetName=>$i18n->get('assetName'),
|
||||
autoGenerateForms=>1,
|
||||
icon=>'product.gif',
|
||||
tableName=>'Product',
|
||||
className=>'WebGUI::Asset::Wobject::Product',
|
||||
properties=>\%properties
|
||||
});
|
||||
return $class->SUPER::definition($session, $definition);
|
||||
}
|
||||
|
||||
|
|
@ -204,38 +207,6 @@ sub duplicate {
|
|||
return $newAsset;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub getEditForm {
|
||||
my $self = shift;
|
||||
my ($file);
|
||||
my $i18n = WebGUI::International->new($self->session,"Asset_Product");
|
||||
my $tabform = $self->SUPER::getEditForm();
|
||||
$tabform->getTab("display")->template(
|
||||
-value=>$self->getValue('templateId'),
|
||||
-namespace=>"Product",
|
||||
-label=>$i18n->get(62),
|
||||
-hoverHelp=>$i18n->get('62 description'),
|
||||
);
|
||||
$tabform->getTab("properties")->text(
|
||||
-name=>"price",
|
||||
-label=>$i18n->get(10),
|
||||
-hoverHelp=>$i18n->get('10 description'),
|
||||
-value=>$self->getValue("price")
|
||||
);
|
||||
$tabform->getTab("properties")->text(
|
||||
-name=>"productNumber",
|
||||
-label=>$i18n->get(11),
|
||||
-hoverHelp=>$i18n->get('11 description'),
|
||||
-value=>$self->getValue("productNumber")
|
||||
);
|
||||
$self->_addFileTab($tabform,"image1",7);
|
||||
$self->_addFileTab($tabform,"image2",8);
|
||||
$self->_addFileTab($tabform,"image3",9);
|
||||
$self->_addFileTab($tabform,"brochure",13);
|
||||
$self->_addFileTab($tabform,"manual",14);
|
||||
$self->_addFileTab($tabform,"warranty",15);
|
||||
return $tabform;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub getFileIconUrl {
|
||||
|
|
@ -356,7 +327,7 @@ sub purgeCache {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
sub purgeRevision {
|
||||
sub purgeRevision {
|
||||
my $self = shift;
|
||||
WebGUI::Storage->get($self->session,$self->get("image1"))->delete if ($self->get("image1"));
|
||||
WebGUI::Storage->get($self->session,$self->get("image2"))->delete if ($self->get("image2"));
|
||||
|
|
@ -477,12 +448,13 @@ sub www_deleteFeatureConfirm {
|
|||
#-------------------------------------------------------------------
|
||||
sub www_deleteFileConfirm {
|
||||
my $self = shift;
|
||||
my $column = $self->session->form->process("file");
|
||||
return $self->session->privilege->insufficient() unless ($self->canEdit);
|
||||
my $column = $self->session->form->process("file");
|
||||
return $self->www_edit unless (isIn($column, qw(image1 image2 image3 manual warranty brochure)));
|
||||
my $store = $self->get($column);
|
||||
my $file = WebGUI::Storage->get($self->session,$store);
|
||||
$file->delete;
|
||||
$self->update({$column => ''});
|
||||
$file->delete if defined $file;
|
||||
$self->update({$column=>''});
|
||||
return $self->www_edit;
|
||||
}
|
||||
|
||||
|
|
@ -504,18 +476,6 @@ sub www_deleteSpecificationConfirm {
|
|||
return "";
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub processPropertiesFromFormPost {
|
||||
my $self = shift;
|
||||
$self->SUPER::processPropertiesFromFormPost;
|
||||
$self->_save("image1");
|
||||
$self->_save("image2");
|
||||
$self->_save("image3");
|
||||
$self->_save("brochure");
|
||||
$self->_save("manual");
|
||||
$self->_save("warranty");
|
||||
return "";
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_editBenefit {
|
||||
|
|
|
|||
|
|
@ -291,18 +291,22 @@ sub www_manageRevisions {
|
|||
|
||||
sub www_purgeRevision {
|
||||
my $self = shift;
|
||||
return $self->session->privilege->insufficient() unless $self->canEdit;
|
||||
my $revisionDate = $self->session->form->process("revisionDate");
|
||||
my $session = $self->session;
|
||||
return $session->privilege->insufficient() unless $self->canEdit;
|
||||
my $revisionDate = $session->form->process("revisionDate");
|
||||
return undef unless $revisionDate;
|
||||
|
||||
my $asset = WebGUI::Asset->new($self->session,$self->getId,$self->get("className"),$revisionDate);
|
||||
my $asset = WebGUI::Asset->new($session,$self->getId,$self->get("className"),$revisionDate);
|
||||
return undef if ($asset->get('revisionDate') != $revisionDate);
|
||||
|
||||
my $parent = $asset->getParent;
|
||||
$asset->purgeRevision;
|
||||
if ($self->session->form->process("proceed") eq "manageRevisionsInTag") {
|
||||
$self->session->http->setRedirect($self->getUrl("op=manageRevisionsInTag"));
|
||||
if ($session->form->process("proceed") eq "manageRevisionsInTag") {
|
||||
my $working = (defined $self) ? $self : $parent;
|
||||
$session->http->setRedirect($working->getUrl("op=manageRevisionsInTag"));
|
||||
return "";
|
||||
}
|
||||
unless (defined $self) {
|
||||
return $parent->www_view;
|
||||
}
|
||||
return $self->www_manageRevisions;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -209,6 +209,9 @@ sub toHtml {
|
|||
uploader.addRow();
|
||||
</script>!, $self->get("name"), $i18n->get("removeLabel"), $maxFiles;
|
||||
$uploadControl .= WebGUI::Form::Hidden->new($self->session, {-name => $self->privateName('action'), -value => 'upload'})->toHtml()."<br />";
|
||||
} else {
|
||||
$uploadControl .= WebGUI::Form::Hidden->new($self->session, {-name => $self->get("name"), -value => $self->get("value")})->toHtml()."<br />";
|
||||
$uploadControl .= WebGUI::Form::Hidden->new($self->session, {-name => $self->privateName('action'), -value => 'keep'})->toHtml()."<br />";
|
||||
}
|
||||
if (scalar(@files)) {
|
||||
foreach my $file (@{$storage->getFiles}) {
|
||||
|
|
|
|||
|
|
@ -181,6 +181,9 @@ sub toHtml {
|
|||
uploader.addRow();
|
||||
</script>!, $self->get("name"), $i18n->get("removeLabel"), $maxFiles;
|
||||
$uploadControl .= WebGUI::Form::Hidden->new($self->session, {-name => $self->privateName('action'), -value => 'upload'})->toHtml()."<br />";
|
||||
} else {
|
||||
$uploadControl .= WebGUI::Form::Hidden->new($self->session, {-name => $self->get("name"), -value => $self->get("value")})->toHtml()."<br />";
|
||||
$uploadControl .= WebGUI::Form::Hidden->new($self->session, {-name => $self->privateName('action'), -value => 'keep'})->toHtml()."<br />";
|
||||
}
|
||||
if (scalar(@files)) {
|
||||
foreach my $file (@{$storage->getFiles}) {
|
||||
|
|
|
|||
|
|
@ -222,6 +222,7 @@ sub clearCaches {
|
|||
foreach my $group ( $self->getId, @{ $groups } ) {
|
||||
WebGUI::Cache->new($self->session, $group)->delete;
|
||||
}
|
||||
$self->session->stow->delete("groupObj");
|
||||
$self->session->stow->delete("isInGroup");
|
||||
$self->session->stow->delete("gotGroupsInGroup");
|
||||
}
|
||||
|
|
@ -437,134 +438,6 @@ sub expireOffset {
|
|||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getDatabaseUsers ( )
|
||||
|
||||
Get the set of users allowed to be in this group via a database query.
|
||||
|
||||
=cut
|
||||
|
||||
sub getDatabaseUsers {
|
||||
my $self = shift;
|
||||
my @dbUsers = ();
|
||||
my $gid = $self->getId;
|
||||
### Check db database
|
||||
if ($self->get("dbQuery") && defined $self->get("databaseLinkId")) {
|
||||
my $dbLink = WebGUI::DatabaseLink->new($self->session,$self->get("databaseLinkId"));
|
||||
my $dbh = $dbLink->db;
|
||||
if (defined $dbh) {
|
||||
my $query = $self->get("dbQuery");
|
||||
WebGUI::Macro::process($self->session,\$query);
|
||||
my $sth = $dbh->unconditionalRead($query);
|
||||
unless ($sth->errorCode < 1) {
|
||||
$self->session->errorHandler->warn("There was a problem with the database query for group ID $gid.");
|
||||
}
|
||||
else {
|
||||
while(my ($userId)=$sth->array) {
|
||||
push @dbUsers, $userId;
|
||||
}
|
||||
}
|
||||
$sth->finish;
|
||||
$dbLink->disconnect;
|
||||
}
|
||||
}
|
||||
return \@dbUsers;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getKarmaUsers ( )
|
||||
|
||||
Get the set of users allowed to be in this group via their current karma setting
|
||||
and this group's karmaThreshold. The set is returned as an array ref.
|
||||
|
||||
If karma is not enabled for this site, it will return a empty array ref.
|
||||
|
||||
=cut
|
||||
|
||||
sub getKarmaUsers {
|
||||
my $self = shift;
|
||||
return [] unless $self->session->setting->get('useKarma');
|
||||
return $self->session->db->buildArrayRef('select userId from users where karma >= ?', [$self->karmaThreshold]);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getScratchUsers ( )
|
||||
|
||||
Get the set of users allowed to be in this group via session scratch variable settings
|
||||
and this group's scratchFilter. The set is returned as an array ref.
|
||||
|
||||
If no scratchFilter has been set for this group, returns an empty array ref.
|
||||
|
||||
=cut
|
||||
|
||||
sub getScratchUsers {
|
||||
my $self = shift;
|
||||
my $scratchFilter;
|
||||
return [] unless $scratchFilter = $self->scratchFilter();
|
||||
|
||||
my $time = $self->session->datetime->time();
|
||||
|
||||
$scratchFilter =~ s/\s//g;
|
||||
my @filters = split /;/, $scratchFilter;
|
||||
|
||||
my @scratchClauses = ();
|
||||
my @scratchPlaceholders = ();
|
||||
foreach my $filter (@filters) {
|
||||
my ($name, $value) = split /=/, $filter;
|
||||
push @scratchClauses, "(s.name=? AND s.value=?)";
|
||||
push @scratchPlaceholders, $name, $value;
|
||||
}
|
||||
my $scratchClause = join ' OR ', @scratchClauses;
|
||||
|
||||
my $query = <<EOQ;
|
||||
select u.userId from userSession u, userSessionScratch s where
|
||||
u.sessionId=s.sessionId AND
|
||||
u.expires > $time AND
|
||||
( $scratchClause )
|
||||
EOQ
|
||||
return $self->session->db->buildArrayRef($query, [ @scratchPlaceholders ]);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getIpUsers ( )
|
||||
|
||||
Get the set of users allowed to be in this group via the lastIP recorded in
|
||||
the user's session and this group's IpFilter. The set is returned as an array ref.
|
||||
|
||||
If no IpFilter has been set for this group, returns an empty array ref.
|
||||
|
||||
=cut
|
||||
|
||||
sub getIpUsers {
|
||||
my $self = shift;
|
||||
my $IpFilter;
|
||||
return [] unless $IpFilter = $self->ipFilter();
|
||||
|
||||
my $time = $self->session->datetime->time();
|
||||
|
||||
$IpFilter =~ s/\s//g;
|
||||
my @filters = split /;/, $IpFilter;
|
||||
|
||||
my $query = "select userId,lastIP from userSession where expires > ?";
|
||||
|
||||
my $sth = $self->session->db->read($query, [ $self->session->datetime->time() ]);
|
||||
my %localCache = ();
|
||||
my @ipUsers = ();
|
||||
$self->session->errorHandler->warn("Fetching IP users");
|
||||
while (my ($userId, $lastIP) = $sth->array() ) {
|
||||
if (!exists $localCache{$lastIP}) {
|
||||
$localCache{$lastIP} = isInSubnet($lastIP, \@filters);
|
||||
}
|
||||
push @ipUsers, $userId if $localCache{$lastIP};
|
||||
}
|
||||
return \@ipUsers;
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 find ( session, name )
|
||||
|
|
@ -636,6 +509,87 @@ sub getAllGroupsFor {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getAllUsers ( [ withoutExpired ] )
|
||||
|
||||
Returns an array reference containing a list of users that belong to this group
|
||||
and in any group that belongs to this group.
|
||||
|
||||
=head3 withoutExpired
|
||||
|
||||
A boolean that if set true will return the users list minus the expired groupings.
|
||||
|
||||
=cut
|
||||
|
||||
sub getAllUsers {
|
||||
my $self = shift;
|
||||
my $withoutExpired = shift;
|
||||
my $loopCount = shift;
|
||||
my $expireTime = 0;
|
||||
my $cache = WebGUI::Cache->new($self->session, $self->getId);
|
||||
my $value = $cache->get;
|
||||
return $value if defined $value;
|
||||
my @users = ();
|
||||
push @users,
|
||||
@{ $self->getUsers($withoutExpired) },
|
||||
@{ $self->getDatabaseUsers() },
|
||||
@{ $self->getKarmaUsers() },
|
||||
@{ $self->getScratchUsers() },
|
||||
@{ $self->getIpUsers() },
|
||||
;
|
||||
++$loopCount;
|
||||
if ($loopCount > 99) {
|
||||
$self->session->errorHandler->fatal("Endless recursive loop detected while determining groups in group.\nRequested groupId: ".$self->getId);
|
||||
}
|
||||
my $groups = $self->getGroupsIn();
|
||||
##Have to iterate twice due to the withoutExpired clause.
|
||||
foreach my $groupId (@{ $groups }) {
|
||||
my $subGroup = WebGUI::Group->new($self->session, $groupId);
|
||||
push @users, @{ $subGroup->getAllUsers(1, $withoutExpired, $loopCount) };
|
||||
}
|
||||
my %users = map { $_ => 1 } @users;
|
||||
@users = keys %users;
|
||||
$cache->set(\@users, $self->groupCacheTimeout);
|
||||
return \@users;
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getDatabaseUsers ( )
|
||||
|
||||
Get the set of users allowed to be in this group via a database query.
|
||||
|
||||
=cut
|
||||
|
||||
sub getDatabaseUsers {
|
||||
my $self = shift;
|
||||
my @dbUsers = ();
|
||||
my $gid = $self->getId;
|
||||
### Check db database
|
||||
if ($self->get("dbQuery") && defined $self->get("databaseLinkId")) {
|
||||
my $dbLink = WebGUI::DatabaseLink->new($self->session,$self->get("databaseLinkId"));
|
||||
my $dbh = $dbLink->db;
|
||||
if (defined $dbh) {
|
||||
my $query = $self->get("dbQuery");
|
||||
WebGUI::Macro::process($self->session,\$query);
|
||||
my $sth = $dbh->unconditionalRead($query);
|
||||
unless ($sth->errorCode < 1) {
|
||||
$self->session->errorHandler->warn("There was a problem with the database query for group ID $gid.");
|
||||
}
|
||||
else {
|
||||
while(my ($userId)=$sth->array) {
|
||||
push @dbUsers, $userId;
|
||||
}
|
||||
}
|
||||
$sth->finish;
|
||||
$dbLink->disconnect;
|
||||
}
|
||||
}
|
||||
return \@dbUsers;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getGroupsFor ( )
|
||||
|
||||
Returns an array reference containing a list of groups this group is in. This method
|
||||
|
|
@ -704,50 +658,111 @@ sub getGroupsIn {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getAllUsers ( [ withoutExpired ] )
|
||||
=head2 getId ( )
|
||||
|
||||
Returns an array reference containing a list of users that belong to this group
|
||||
and in any group that belongs to this group.
|
||||
|
||||
=head3 withoutExpired
|
||||
|
||||
A boolean that if set true will return the users list minus the expired groupings.
|
||||
Returns the groupId for this group.
|
||||
|
||||
=cut
|
||||
|
||||
sub getAllUsers {
|
||||
sub getId {
|
||||
my $self = shift;
|
||||
my $withoutExpired = shift;
|
||||
my $loopCount = shift;
|
||||
my $expireTime = 0;
|
||||
my $cache = WebGUI::Cache->new($self->session, $self->getId);
|
||||
my $value = $cache->get;
|
||||
return $value if defined $value;
|
||||
my @users = ();
|
||||
push @users,
|
||||
@{ $self->getUsers($withoutExpired) },
|
||||
@{ $self->getDatabaseUsers() },
|
||||
@{ $self->getKarmaUsers() },
|
||||
@{ $self->getScratchUsers() },
|
||||
@{ $self->getIpUsers() },
|
||||
;
|
||||
++$loopCount;
|
||||
if ($loopCount > 99) {
|
||||
$self->session->errorHandler->fatal("Endless recursive loop detected while determining groups in group.\nRequested groupId: ".$self->getId);
|
||||
}
|
||||
my $groups = $self->getGroupsIn();
|
||||
##Have to iterate twice due to the withoutExpired clause.
|
||||
foreach my $groupId (@{ $groups }) {
|
||||
my $subGroup = WebGUI::Group->new($self->session, $groupId);
|
||||
push @users, @{ $subGroup->getAllUsers(1, $withoutExpired, $loopCount) };
|
||||
}
|
||||
my %users = map { $_ => 1 } @users;
|
||||
@users = keys %users;
|
||||
$cache->set(\@users, $self->groupCacheTimeout);
|
||||
return \@users;
|
||||
return $self->{_groupId};
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getIpUsers ( )
|
||||
|
||||
Get the set of users allowed to be in this group via the lastIP recorded in
|
||||
the user's session and this group's IpFilter. The set is returned as an array ref.
|
||||
|
||||
If no IpFilter has been set for this group, returns an empty array ref.
|
||||
|
||||
=cut
|
||||
|
||||
sub getIpUsers {
|
||||
my $self = shift;
|
||||
my $IpFilter;
|
||||
return [] unless $IpFilter = $self->ipFilter();
|
||||
|
||||
my $time = $self->session->datetime->time();
|
||||
|
||||
$IpFilter =~ s/\s//g;
|
||||
my @filters = split /;/, $IpFilter;
|
||||
|
||||
my $query = "select userId,lastIP from userSession where expires > ?";
|
||||
|
||||
my $sth = $self->session->db->read($query, [ $self->session->datetime->time() ]);
|
||||
my %localCache = ();
|
||||
my @ipUsers = ();
|
||||
$self->session->errorHandler->warn("Fetching IP users");
|
||||
while (my ($userId, $lastIP) = $sth->array() ) {
|
||||
if (!exists $localCache{$lastIP}) {
|
||||
$localCache{$lastIP} = isInSubnet($lastIP, \@filters);
|
||||
}
|
||||
push @ipUsers, $userId if $localCache{$lastIP};
|
||||
}
|
||||
return \@ipUsers;
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getKarmaUsers ( )
|
||||
|
||||
Get the set of users allowed to be in this group via their current karma setting
|
||||
and this group's karmaThreshold. The set is returned as an array ref.
|
||||
|
||||
If karma is not enabled for this site, it will return a empty array ref.
|
||||
|
||||
=cut
|
||||
|
||||
sub getKarmaUsers {
|
||||
my $self = shift;
|
||||
return [] unless $self->session->setting->get('useKarma');
|
||||
return $self->session->db->buildArrayRef('select userId from users where karma >= ?', [$self->karmaThreshold]);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getScratchUsers ( )
|
||||
|
||||
Get the set of users allowed to be in this group via session scratch variable settings
|
||||
and this group's scratchFilter. The set is returned as an array ref.
|
||||
|
||||
If no scratchFilter has been set for this group, returns an empty array ref.
|
||||
|
||||
=cut
|
||||
|
||||
sub getScratchUsers {
|
||||
my $self = shift;
|
||||
my $scratchFilter;
|
||||
return [] unless $scratchFilter = $self->scratchFilter();
|
||||
|
||||
my $time = $self->session->datetime->time();
|
||||
|
||||
$scratchFilter =~ s/\s//g;
|
||||
my @filters = split /;/, $scratchFilter;
|
||||
|
||||
my @scratchClauses = ();
|
||||
my @scratchPlaceholders = ();
|
||||
foreach my $filter (@filters) {
|
||||
my ($name, $value) = split /=/, $filter;
|
||||
push @scratchClauses, "(s.name=? AND s.value=?)";
|
||||
push @scratchPlaceholders, $name, $value;
|
||||
}
|
||||
my $scratchClause = join ' OR ', @scratchClauses;
|
||||
|
||||
my $query = <<EOQ;
|
||||
select u.userId from userSession u, userSessionScratch s where
|
||||
u.sessionId=s.sessionId AND
|
||||
u.expires > $time AND
|
||||
( $scratchClause )
|
||||
EOQ
|
||||
return $self->session->db->buildArrayRef($query, [ @scratchPlaceholders ]);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getUsers ( [ withoutExpired ] )
|
||||
|
|
@ -774,20 +789,6 @@ sub getUsers {
|
|||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getId ( )
|
||||
|
||||
Returns the groupId for this group.
|
||||
|
||||
=cut
|
||||
|
||||
sub getId {
|
||||
my $self = shift;
|
||||
return $self->{_groupId};
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 karmaThreshold ( [ value ] )
|
||||
|
|
@ -917,11 +918,13 @@ sub new {
|
|||
my $self = {};
|
||||
$self->{_session} = shift;
|
||||
$self->{_groupId} = shift;
|
||||
return $self->{_session}->{groupData}->{$self->{_groupId}} if $self->{_session}->{groupData}->{$self->{_groupId}};
|
||||
my $override = shift;
|
||||
my $cached = $self->{_session}->stow->get("groupObj");
|
||||
return $cached->{$self->{_groupId}} if ($cached->{$self->{_groupId}});
|
||||
bless $self, $class;
|
||||
$self->_create($override) if ($self->{_groupId} eq "new");
|
||||
$self->{_session}->{groupData}->{$self->{_groupId}} = $self;
|
||||
$cached->{$self->{_groupId}} = $self;
|
||||
$self->{_session}->stow->set("groupObj", $cached);
|
||||
return $self;
|
||||
}
|
||||
|
||||
|
|
@ -1132,7 +1135,6 @@ sub set {
|
|||
my $value = shift;
|
||||
$self->get("groupId") unless ($self->{_group}); # precache group stuff
|
||||
$self->{_group}{$name} = $value;
|
||||
$self->session->{groupData}->{$self->getId} = undef;
|
||||
$self->session->db->setRow("groups","groupId",{groupId=>$self->getId, $name=>$value, lastUpdated=>$self->session->datetime->time()});
|
||||
$self->clearCaches;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -397,6 +397,7 @@ sub www_manageRevisionsInTag {
|
|||
my $session = shift;
|
||||
my $tagId = $session->form->get("tagId");
|
||||
my $tag = WebGUI::VersionTag->new($session, $tagId);
|
||||
return www_manageVersions($session) unless (defined $tag);
|
||||
return $session->privilege->insufficient() unless ($session->user->isInGroup($tag->get("groupToUse")));
|
||||
my $ac = WebGUI::AdminConsole->new($session,"versions");
|
||||
my $i18n = WebGUI::International->new($session,"VersionTag");
|
||||
|
|
|
|||
|
|
@ -117,8 +117,9 @@ sub execute {
|
|||
my $self = shift;
|
||||
my $placeholders = shift || [];
|
||||
my $sql = $self->{_sql};
|
||||
$self->db->session->errorHandler->query($sql,$placeholders);
|
||||
$self->sth->execute(@{ $placeholders }) or $self->db->session->errorHandler->fatal("Couldn't execute prepared statement: $sql : With place holders: ".join(", ", @{$placeholders}).". Root cause: ". $self->errorMessage);
|
||||
my $errorHandler = $self->db->session->errorHandler;
|
||||
$errorHandler->query($sql,$placeholders);
|
||||
$self->sth->execute(@{ $placeholders }) or $errorHandler->fatal("Couldn't execute prepared statement: $sql : With place holders: ".join(", ", @{$placeholders}).". Root cause: ". $self->errorMessage);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -292,10 +293,11 @@ sub unconditionalRead {
|
|||
my $sql = shift;
|
||||
my $db = shift;
|
||||
my $placeholders = shift;
|
||||
$db->session->errorHandler->query($sql,$placeholders);
|
||||
my $sth = $db->dbh->prepare($sql) or $db->session->errorHandler->warn("Unconditional read failed: ".$sql." : ".$db->dbh->errstr);
|
||||
my $errorHandler = $db->session->errorHandler;
|
||||
$errorHandler->query($sql,$placeholders);
|
||||
my $sth = $db->dbh->prepare($sql) or $errorHandler->warn("Unconditional read failed: ".$sql." : ".$db->dbh->errstr);
|
||||
if ($sth) {
|
||||
$sth->execute(@$placeholders) or $db->session->errorHandler->warn("Unconditional read failed: ".$sql." : ".$sth->errstr);
|
||||
$sth->execute(@$placeholders) or $errorHandler->warn("Unconditional read failed: ".$sql." : ".$sth->errstr);
|
||||
bless {_sql=>$sql, _db=>$db, _sth=>$sth}, $class;
|
||||
} else {
|
||||
return undef;
|
||||
|
|
|
|||
|
|
@ -374,6 +374,7 @@ sub open {
|
|||
my $sessionId = shift || $self->http->getCookies->{"wgSession"} || $self->id->generate;
|
||||
my $noFuss = shift;
|
||||
$self->{_var} = WebGUI::Session::Var->new($self,$sessionId, $noFuss);
|
||||
$self->errorHandler->warn("You've disabled cache in your config file and that can cause many problems on a production site.") if ($config->get("disableCache"));
|
||||
return $self;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -44,7 +44,6 @@ This package provides simple but effective error handling, debugging, and loggi
|
|||
|
||||
$logger = $errorHandler->getLogger;
|
||||
|
||||
$text = $errorHandler->getSessionVars;
|
||||
$text = $errorHandler->getStackTrace;
|
||||
$html = $errorHandler->showDebug;
|
||||
|
||||
|
|
@ -134,7 +133,7 @@ sub debug {
|
|||
my $self = shift;
|
||||
my $message = shift;
|
||||
$self->getLogger->debug($message);
|
||||
$self->session->stow->set("debug_debug", $self->session->stow->get("debug_debug").$message."\n");
|
||||
$self->{_debug_debug} .= $message."\n";
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -171,7 +170,7 @@ sub error {
|
|||
my $message = shift;
|
||||
$self->getLogger->error($message);
|
||||
$self->getLogger->debug("Stack trace for ERROR ".$message."\n".$self->getStackTrace());
|
||||
$self->session->stow->set("debug_error", $self->session->stow->get("debug_error").$message."\n");
|
||||
$self->{_debug_error} .= $message."\n";
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -224,41 +223,6 @@ sub getLogger {
|
|||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getSessionVars ( )
|
||||
|
||||
Returns a text message containing all of the session variables.
|
||||
|
||||
=cut
|
||||
|
||||
sub getSessionVars {
|
||||
my $self = shift;
|
||||
my $data;
|
||||
while (my ($section, $hash) = each %{$self->session}) {
|
||||
if (ref $hash eq 'HASH') {
|
||||
while (my ($key, $value) = each %$hash) {
|
||||
if (ref $value eq 'ARRAY') {
|
||||
$value = '['.join(', ',@$value).']';
|
||||
} elsif (ref $value eq 'HASH') {
|
||||
$value = '{'.join(', ',map {"$_ => $value->{$_}"} keys %$value).'}';
|
||||
}
|
||||
unless (lc($key) eq "password" || lc($key) eq "identifier" || lc($key) eq "dbpass") {
|
||||
$data .= "\t".$section.'.'.$key.' = '.$value."\n";
|
||||
}
|
||||
}
|
||||
} elsif (ref $hash eq 'ARRAY') {
|
||||
my $i = 1;
|
||||
foreach (@$hash) {
|
||||
$data .= "\t".$section.'.'.$i.' = '.$_."\n";
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getStackTrace ( )
|
||||
|
|
@ -296,7 +260,7 @@ sub info {
|
|||
my $self = shift;
|
||||
my $message = shift;
|
||||
$self->getLogger->info($message);
|
||||
$self->session->stow->set("debug_info", $self->session->stow->get("debug_info").$message."\n");
|
||||
$self->{_debug_info} .= $message."\n";
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -394,13 +358,13 @@ Creates an HTML formatted string
|
|||
|
||||
sub showDebug {
|
||||
my $self = shift;
|
||||
my $text = $self->session->stow->get('debug_error');
|
||||
my $text = $self->{_debug_error};
|
||||
$text =~ s/\n/\<br \/\>\n/g;
|
||||
my $output = '<div style="text-align: left;background-color: #800000;color: #ffffff;">'.$text."</div>\n";
|
||||
$text = $self->session->stow->get('debug_warn');
|
||||
$text = $self->{_debug_warn};
|
||||
$text =~ s/\n/\<br \/\>\n/g;
|
||||
$output .= '<div style="text-align: left;background-color: #ffdddd;color: #000000;">'.$text."</div>\n";
|
||||
$text = $self->session->stow->get('debug_info');
|
||||
$text = $self->{_debug_info};
|
||||
$text =~ s/\n/\<br \/\>\n/g;
|
||||
$output .= '<div style="text-align: left;background-color: #ffffdd;color: #000000;">'.$text."</div>\n";
|
||||
my $form = $self->session->form->paramsHashRef();
|
||||
|
|
@ -416,12 +380,9 @@ sub showDebug {
|
|||
$text =~ s/\n/\<br \/\>\n/g;
|
||||
$text =~ s/ / /g;
|
||||
$output .= '<div style="text-align: left;background-color: #cccccc;color: #000000;">'.$text."</div>\n";
|
||||
$text = $self->session->stow->get('debug_debug');
|
||||
$text = $self->{_debug_debug};
|
||||
$text =~ s/\n/\<br \/\>\n/g;
|
||||
$output .= '<div style="text-align: left;background-color: #dddddd;color: #000000;">'.$text."</div>\n";
|
||||
$text = $self->getSessionVars();
|
||||
$text =~ s/\n/\<br \/\>\n/g;
|
||||
$output .= '<div style="text-align: left;background-color: #ffffff;color: #000000;">'.$text."</div>\n";
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
|
@ -443,7 +404,7 @@ sub warn {
|
|||
my $self = shift;
|
||||
my $message = shift;
|
||||
$self->getLogger->warn($message);
|
||||
$self->session->stow->set("debug_warn", $self->session->stow->get("debug_warn").$message."\n");
|
||||
$self->{_debug_warn} .= $message."\n";
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue