refactored WebGUI::Id to use new session api
This commit is contained in:
parent
2735385050
commit
925906ca7e
22 changed files with 130 additions and 44 deletions
|
|
@ -773,6 +773,13 @@ perl -pi.bak -e 's!WebGUI\:\:Icon\:\:(\w+)Icon\(!\$self->session->icon->$1(!g' f
|
|||
perl -pi.bak -e 's!(help|become|cut|copy|delete|edit|manage|moveBottom|moveDown|moveLeft|moveRight|moveTop|moveUp|locked|drag|shortcut|paste|view|export)Icon\(!\$self->session->icon->$1(!g' fileNameGoesHere
|
||||
|
||||
|
||||
5.23.16 WebGUI::Id API Refactored
|
||||
|
||||
WebGUI::Id is now accessible through $session->id
|
||||
|
||||
perl -pi.bak -e 's!WebGUI\:\:Id\:\:generate!\$self->session->id->generate!g' fileNameGoesHere
|
||||
|
||||
|
||||
|
||||
6. Automatic list of Assets in Help System.
|
||||
-------------------------------------
|
||||
|
|
|
|||
|
|
@ -148,7 +148,7 @@ sub processPropertiesFromFormPost {
|
|||
my $until = $self->session->datetime->setToEpoch($self->session->form->process("until"));
|
||||
$until = $self->get("eventEndDate") unless ($until >= $self->get("eventEndDate"));
|
||||
my $interval = ($self->session->form->process("interval") < 1) ? 1 : $self->session->form->process("interval");
|
||||
my $recurringEventId = WebGUI::Id::generate();
|
||||
my $recurringEventId = $self->session->id->generate();
|
||||
$self->update({EventsCalendar_recurringId=>$recurringEventId});
|
||||
my $start = $self->get("eventStartDate");
|
||||
my $end = $self->get("eventEndDate");
|
||||
|
|
|
|||
|
|
@ -511,7 +511,7 @@ sub setCollateral {
|
|||
my $counter = 0;
|
||||
my $sql;
|
||||
if ($properties->{$keyName} eq "new" || $properties->{$keyName} eq "") {
|
||||
$properties->{$keyName} = WebGUI::Id::generate();
|
||||
$properties->{$keyName} = $self->session->id->generate();
|
||||
$sql = "insert into $table (";
|
||||
my $dbkeys = "";
|
||||
my $dbvalues = "";
|
||||
|
|
|
|||
|
|
@ -431,7 +431,7 @@ sub view {
|
|||
$self->getUrl.'?calMonthStart='.$prevCalMonthStart.';calMonthEnd='.$prevCalMonthEnd;
|
||||
$var{'pagination.previousPage'} = '<form method="GET" style="inline;" action="'.
|
||||
$self->getUrl.'?calMonthStart='.$calMonthStart.
|
||||
';reload='.WebGUI::Id::generate().'"><a href="'.$self->getUrl.
|
||||
';reload='.$self->session->id->generate().'"><a href="'.$self->getUrl.
|
||||
'?calMonthStart='.$prevCalMonthStart.';calMonthEnd='.$prevCalMonthEnd.'">'.
|
||||
WebGUI::International::get(558,"Asset_EventsCalendar")." ".$monthRangeLength." ".
|
||||
$monthLabel.'</a>';
|
||||
|
|
|
|||
|
|
@ -135,7 +135,7 @@ sub duplicate {
|
|||
$self = shift;
|
||||
|
||||
$newAsset = $self->SUPER::duplicate(shift);
|
||||
$newSurveyId = WebGUI::Id::generate();
|
||||
$newSurveyId = $self->session->id->generate();
|
||||
$newAsset->update({
|
||||
Survey_id=>$newSurveyId
|
||||
});
|
||||
|
|
@ -211,7 +211,7 @@ sub getEditForm {
|
|||
|
||||
$tabform->getTab('properties')->hidden(
|
||||
-name => "Survey_id",
|
||||
-value => ($self->get("Survey_id") || WebGUI::Id::generate())
|
||||
-value => ($self->get("Survey_id") || $self->session->id->generate())
|
||||
);
|
||||
$tabform->getTab('display')->template(
|
||||
-name => 'templateId',
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ A unique 22 character ID. By default WebGUI will generate this and you should a
|
|||
sub addChild {
|
||||
my $self = shift;
|
||||
my $properties = shift;
|
||||
my $id = shift || WebGUI::Id::generate();
|
||||
my $id = shift || $self->session->id->generate();
|
||||
my $lineage = $self->get("lineage").$self->getNextChildRank;
|
||||
$self->{_hasChildren} = 1;
|
||||
$self->session->db->beginTransaction;
|
||||
|
|
@ -599,7 +599,7 @@ sub setRank {
|
|||
return 1 if ($newRank == $currentRank); # do nothing if we're moving to ourself
|
||||
my $parentLineage = $self->getParentLineage;
|
||||
my $siblings = $self->getLineage(["siblings"],{returnObjects=>1});
|
||||
my $temp = substr(WebGUI::Id::generate(),0,6);
|
||||
my $temp = substr($self->session->id->generate(),0,6);
|
||||
if ($newRank < $currentRank) { # have to do the ordering in reverse when the new rank is above the old rank
|
||||
@{$siblings} = reverse @{$siblings};
|
||||
}
|
||||
|
|
@ -636,7 +636,7 @@ sub swapRank {
|
|||
my $self = shift;
|
||||
my $second = shift;
|
||||
my $first = shift || $self->get("lineage");
|
||||
my $temp = substr(WebGUI::Id::generate(),0,6); # need a temp in order to do the swap
|
||||
my $temp = substr($self->session->id->generate(),0,6); # need a temp in order to do the swap
|
||||
$self->session->db->beginTransaction;
|
||||
$self->cascadeLineage($temp,$first);
|
||||
$self->cascadeLineage($first,$second);
|
||||
|
|
|
|||
|
|
@ -236,7 +236,7 @@ sub www_editMetaDataFieldSave {
|
|||
return $ac->render(WebGUI::International::get("errorEmptyField", "Asset"),WebGUI::International::get('Edit Metadata',"Asset"));
|
||||
}
|
||||
if($self->session->form->process("fid") eq 'new') {
|
||||
$self->session->form->process("fid") = WebGUI::Id::generate();
|
||||
$self->session->form->process("fid") = $self->session->id->generate();
|
||||
$self->session->db->write("insert into metaData_properties (fieldId, fieldName, defaultValue, description, fieldType, possibleValues) values (".
|
||||
$self->session->db->quote($self->session->form->process("fid")).",".
|
||||
$self->session->db->quote($self->session->form->process("fieldName")).",".
|
||||
|
|
|
|||
|
|
@ -225,7 +225,7 @@ sub createAccountSave {
|
|||
$properties->{status} = 'Deactivated' if ($self->session->setting->get("webguiValidateEmail"));
|
||||
$self->SUPER::createAccountSave($username,$properties,$password,$profile);
|
||||
if ($self->session->setting->get("webguiValidateEmail")) {
|
||||
my $key = WebGUI::Id::generate();
|
||||
my $key = $self->session->id->generate();
|
||||
$self->saveParams($self->userId,"WebGUI",{emailValidationKey=>$key});
|
||||
WebGUI::Mail::send(
|
||||
$profile->{email},
|
||||
|
|
|
|||
|
|
@ -421,7 +421,7 @@ sub new {
|
|||
$userId = shift || $self->session->user->profileField("userId");
|
||||
|
||||
if ($transactionId eq 'new') {
|
||||
$transactionId = WebGUI::Id::generate;
|
||||
$transactionId = $self->session->id->generate;
|
||||
|
||||
$self->session->db->write("insert into transaction ".
|
||||
"(transactionId, userId, amount, gatewayId, initDate, completionDate, status) values ".
|
||||
|
|
|
|||
|
|
@ -115,7 +115,7 @@ The addressee email address. Defaults to company email.
|
|||
|
||||
sub addEntry {
|
||||
my ($u, @users, $messageLogId, $sth, $userId, $groupId, $subject, $message, $url, $status, $user, $from);
|
||||
$messageLogId = WebGUI::Id::generate();
|
||||
$messageLogId = $self->session->id->generate();
|
||||
$userId = $_[0];
|
||||
$groupId = $_[1];
|
||||
$subject = $_[2];
|
||||
|
|
@ -185,7 +185,7 @@ Defaults to 'notice'. Can be 'pending', 'notice', or 'completed'.
|
|||
|
||||
sub addInternationalizedEntry {
|
||||
my ($u, $userId, $url, $groupId, $internationalId, @users, $messageLogId,$sth, $user, %message, %subject, $message, $subject, $namespace, $status);
|
||||
$messageLogId = WebGUI::Id::generate();
|
||||
$messageLogId = $self->session->id->generate();
|
||||
$userId = $_[0];
|
||||
$groupId = $_[1];
|
||||
$url = $_[2];
|
||||
|
|
|
|||
|
|
@ -59,7 +59,6 @@ sub www_copyLDAPLink {
|
|||
$db{ldapLinkId} = "new";
|
||||
$db{ldapLinkName} = "Copy of ".$db{ldapLinkName};
|
||||
$session->db->setRow("ldapLink","ldapLinkId",\%db);
|
||||
#$session->db->write("insert into databaseLink (databaseLinkId,title,DSN,username,identifier) values (".$session->db->quote(WebGUI::Id::generate()).", ".$session->db->quote($db{title}." (copy)").", ".$session->db->quote($db{DSN}).", ".$session->db->quote($db{username}).", ".$session->db->quote($db{identifier}).")");
|
||||
$session->form->process("op") = "listLDAPLinks";
|
||||
return www_listLDAPLinks();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -122,7 +122,7 @@ sub www_createSubscriptionCodeBatchSave {
|
|||
$numberOfCodes = $session->form->process("noc");
|
||||
$description = $session->form->process("description");
|
||||
$expires = $session->form->interval('expires');
|
||||
$batchId = WebGUI::Id::generate;
|
||||
$batchId = $session->id->generate;
|
||||
|
||||
push(@error, $i18n->get('no description error')) unless ($description);
|
||||
push(@error, $i18n->get('no association error')) unless ($session->form->process("subscriptionId"));
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ sub add {
|
|||
return unless ($self->session->setting->get("passiveProfilingEnabled"));
|
||||
my $assetId = shift;
|
||||
my $sql = "insert into passiveProfileLog (passiveProfileLogId, userId, sessionId, assetId, dateOfEntry)
|
||||
values (".$self->session->db->quote(WebGUI::Id::generate()).",".
|
||||
values (".$self->session->db->quote($self->session->id->generate()).",".
|
||||
$self->session->db->quote($self->session->user->profileField("userId")).",".
|
||||
$self->session->db->quote($self->session->var->get("sessionId")).",".
|
||||
$self->session->db->quote($assetId).",".
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ sub addOptionToParameter {
|
|||
$parameterId = shift;
|
||||
$properties = shift || {};
|
||||
|
||||
$optionId = WebGUI::Id::generate;
|
||||
$optionId = $self->session->id->generate;
|
||||
|
||||
$self->session->db->write("insert into productParameterOptions ".
|
||||
"(optionId, parameterId) values ".
|
||||
|
|
@ -52,7 +52,7 @@ sub addParameter {
|
|||
$self = shift;
|
||||
$properties = shift;
|
||||
|
||||
$parameterId = WebGUI::Id::generate;
|
||||
$parameterId = $self->session->id->generate;
|
||||
|
||||
$self->session->db->write("insert into productParameters (parameterId, productId) values ".
|
||||
"(".$self->session->db->quote($parameterId).", ".$self->session->db->quote($self->get('productId')).")");
|
||||
|
|
@ -210,7 +210,7 @@ sub new {
|
|||
$options = {};
|
||||
|
||||
if ($productId eq 'new') {
|
||||
$productId = WebGUI::Id::generate;
|
||||
$productId = $self->session->id->generate;
|
||||
$properties = {productId => $productId};
|
||||
$self->session->db->write("insert into products (productId) values (".$self->session->db->quote($productId).")");
|
||||
} else {
|
||||
|
|
@ -400,7 +400,7 @@ sub updateVariants {
|
|||
if (exists $variants{$var{composition}}) {
|
||||
$var{variantId} = $variants{$var{composition}}{variantId},
|
||||
} else {
|
||||
$var{variantId} = WebGUI::Id::generate;
|
||||
$var{variantId} = $self->session->id->generate;
|
||||
}
|
||||
|
||||
push (@newVariants, {%var});
|
||||
|
|
|
|||
|
|
@ -644,7 +644,7 @@ Use this ID to create a new row. Same as setting the key value to "new" except t
|
|||
sub setRow {
|
||||
my ($self, $table, $keyColumn, $data, $id) = @_;
|
||||
if ($data->{$keyColumn} eq "new" || $id) {
|
||||
$data->{$keyColumn} = $id || WebGUI::Id::generate();
|
||||
$data->{$keyColumn} = $id || $self->session->id->generate();
|
||||
$self->write("insert into $table ($keyColumn) values (".$self->quote($data->{$keyColumn}).")");
|
||||
}
|
||||
my (@pairs);
|
||||
|
|
|
|||
|
|
@ -113,7 +113,7 @@ Cleans up a WebGUI session information from memory and disconnects from any reso
|
|||
|
||||
sub close {
|
||||
my $self = shift;
|
||||
$self->session->asset->DESTROY() if (exists $self->session->asset && $self->session->asset ne "");
|
||||
$self->asset->DESTROY() if (exists $self->asset && $self->asset ne "");
|
||||
foreach my $slavedbh (@{$self->{_slave}}) {
|
||||
$slavedbh->disconnect();
|
||||
}
|
||||
|
|
@ -146,7 +146,7 @@ Returns a WebGUI::Session::DateTime object.
|
|||
sub datetime {
|
||||
my $self = shift;
|
||||
if (exists $self->{_datetime}) {
|
||||
$self->{_datetime} = WebGUI::Session::DateTime->new($session);
|
||||
$self->{_datetime} = WebGUI::Session::DateTime->new($self);
|
||||
}
|
||||
return $self->{_datetime};
|
||||
}
|
||||
|
|
@ -162,7 +162,7 @@ Returns a WebGUI::SQL object, which is connected to the WebGUI database.
|
|||
sub db {
|
||||
my $self = shift;
|
||||
if (exists $self->{_db}) {
|
||||
$self->{_db} = $self->session->db->connect($self->config->get("dsn"), $self->config->get("dbuser"), $self->config->get("dbpass"), $self);
|
||||
$self->{_db} = $self->db->connect($self->config->get("dsn"), $self->config->get("dbuser"), $self->config->get("dbpass"), $self);
|
||||
}
|
||||
return $self->{_db};
|
||||
}
|
||||
|
|
@ -181,7 +181,7 @@ sub dbSlave {
|
|||
foreach (1..3) {
|
||||
my $slave = $self->config->get("dbslave".$_);
|
||||
if (exists $slave->{dsn}) {
|
||||
push(@{$self->{_slave}},$self->session->db->connect($slave->{dsn},$slave->{user},$slave->{pass}, $self));
|
||||
push(@{$self->{_slave}},$self->db->connect($slave->{dsn},$slave->{user},$slave->{pass}, $self));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -250,7 +250,7 @@ Returns a reference to the WebGUI::Session::Http object.
|
|||
sub http {
|
||||
my $self = shift;
|
||||
unless ($self->{_http}) {
|
||||
$self->{_http} = WebGUI::Session::Http->new($session);
|
||||
$self->{_http} = WebGUI::Session::Http->new($self);
|
||||
}
|
||||
return $self->{_http};
|
||||
}
|
||||
|
|
@ -267,12 +267,29 @@ Returns a WebGUI::Session::Icon object.
|
|||
sub icon {
|
||||
my $self = shift;
|
||||
unless ($self->{_icon}) {
|
||||
$self->{_icon} = WebGUI::Session::Icon->new($session);
|
||||
$self->{_icon} = WebGUI::Session::Icon->new($self);
|
||||
}
|
||||
return $self->{_icon};
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 id ( )
|
||||
|
||||
Returns a reference to the WebGUI::Session::Id object.
|
||||
|
||||
=cut
|
||||
|
||||
sub id {
|
||||
my $self = shift;
|
||||
unless ($self->{_id}) {
|
||||
$self->{_id} = WebGUI::Session::Id->new($self);
|
||||
}
|
||||
return $self->{_id};
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 open ( webguiRoot, configFile [, requestObject, serverObject, sessionId ] )
|
||||
|
|
@ -483,7 +500,7 @@ sub user {
|
|||
$self->{_var}{userId} = $option->{userId} || $option->{user}->userId;
|
||||
$self->db-setRow("userSession","sessionId", $self->{_var});
|
||||
if ($self->setting("passiveProfilingEnabled")) {
|
||||
$self->db->write("update passiveProfileLog set userId = ".$self->session->db->quote($self->{_var}{userId})." where sessionId = ".$self->session->db->quote($self->getId));
|
||||
$self->db->write("update passiveProfileLog set userId = ".$self->db->quote($self->{_var}{userId})." where sessionId = ".$self->db->quote($self->getId));
|
||||
}
|
||||
delete $self->{_stow};
|
||||
$self->{_user} = $option->{user} || WebGUI::User->new($session, $self->{_var}{userId});
|
||||
|
|
|
|||
|
|
@ -471,6 +471,25 @@ sub moveUp {
|
|||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 new ( session )
|
||||
|
||||
Constructor.
|
||||
|
||||
=head3 session
|
||||
|
||||
A reference to the current session.
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my $class = shift;
|
||||
my $session = shift;
|
||||
bless {_session=>$session}, $class;
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 paste ( urlParameters [, pageURL ] )
|
||||
|
|
@ -496,6 +515,20 @@ sub paste {
|
|||
return $output;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 session ( )
|
||||
|
||||
Returns a reference to the current session.
|
||||
|
||||
=cut
|
||||
|
||||
sub session {
|
||||
my $self = shift;
|
||||
return $self->{_session};
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 shortcut ( urlParameters [, pageURL ] )
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
package WebGUI::Id;
|
||||
package WebGUI::Session::Id;
|
||||
|
||||
|
||||
=head1 LEGAL
|
||||
|
|
@ -15,14 +15,10 @@ package WebGUI::Id;
|
|||
|
||||
=cut
|
||||
|
||||
use Digest::MD5;
|
||||
use strict;
|
||||
use Digest::MD5;
|
||||
use Time::HiRes qw( gettimeofday usleep );
|
||||
use WebGUI::Session;
|
||||
|
||||
BEGIN {
|
||||
srand;
|
||||
}
|
||||
|
||||
|
||||
=head1 NAME
|
||||
|
|
@ -37,13 +33,13 @@ B<NOTE:> There is no such thing as perfectly unique ID's, but the chances of a d
|
|||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
use WebGUI::Id;
|
||||
use WebGUI::Session::Id;
|
||||
|
||||
my $id = WebGUI::Id::generate();
|
||||
my $id = $session->id->generate();
|
||||
|
||||
=head1 FUNCTIONS
|
||||
=head1 METHODS
|
||||
|
||||
These subroutines are available from this package:
|
||||
These methods are available from this class:
|
||||
|
||||
=cut
|
||||
|
||||
|
|
@ -56,14 +52,48 @@ This function generates a global unique id.
|
|||
=cut
|
||||
|
||||
sub generate {
|
||||
my $self = shift;
|
||||
my($s,$us)=gettimeofday();
|
||||
my($v)=sprintf("%09d%06d%10d%06d%255s",rand(999999999),$us,$s,$$,$WebGUI::Session::session{config}{defaultSiteName});
|
||||
my($v)=sprintf("%09d%06d%10d%06d%255s",rand(999999999),$us,$s,$$,$self->session->config->getFilename);
|
||||
my $id = Digest::MD5::md5_base64($v);
|
||||
$id =~ s/\+/_/g;
|
||||
$id =~ s/\//-/g;
|
||||
return $id;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 new ( session )
|
||||
|
||||
Constructor.
|
||||
|
||||
=head3 session
|
||||
|
||||
A reference to the current session.
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my $class = shift;
|
||||
my $session = shift;
|
||||
srand;
|
||||
bless {_session=>$session}, $class;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 session ( )
|
||||
|
||||
Returns a reference to the current session.
|
||||
|
||||
=cut
|
||||
|
||||
sub session {
|
||||
my $self = shift;
|
||||
return $self->{_session};
|
||||
}
|
||||
|
||||
|
||||
1;
|
||||
|
||||
|
||||
|
|
@ -326,7 +326,7 @@ Creates a new storage location on the file system.
|
|||
|
||||
sub create {
|
||||
my $class = shift;
|
||||
my $id = WebGUI::Id::generate();
|
||||
my $id = $self->session->id->generate();
|
||||
my $self = $class->get($id);
|
||||
$self->_makePath;
|
||||
return $self;
|
||||
|
|
@ -341,7 +341,7 @@ Creates a temporary storage location on the file system.
|
|||
|
||||
sub createTemp {
|
||||
my $class = shift;
|
||||
my $id = WebGUI::Id::generate();
|
||||
my $id = $self->session->id->generate();
|
||||
$id =~ m/^(.{2})/;
|
||||
my $self = {_id => $id, _part1 => 'temp', _part2 => $1};
|
||||
bless $self, ref($class)||$class;
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ sub addFileFromCaptcha {
|
|||
my $challenge;
|
||||
srand;
|
||||
$challenge.= ('A'..'Z')[rand(26)] foreach (1..6);
|
||||
my $filename = "captcha.".WebGUI::Id::generate().".png";
|
||||
my $filename = "captcha.".$self->session->id->generate().".png";
|
||||
my $image = Image::Magick->new();
|
||||
$image->Set(size=>'105x26');
|
||||
$image->ReadImage('xc:white');
|
||||
|
|
|
|||
|
|
@ -130,7 +130,7 @@ sub new {
|
|||
$subscriptionId = shift;
|
||||
|
||||
if ($subscriptionId eq 'new') {
|
||||
$subscriptionId = WebGUI::Id::generate;
|
||||
$subscriptionId = $self->session->id->generate;
|
||||
$self->session->db->write("insert into subscription (subscriptionId) values (".$self->session->db->quote($subscriptionId).")");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ These methods are available from this class:
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
sub _create {
|
||||
my $userId = shift || WebGUI::Id::generate();
|
||||
my $userId = shift || $self->session->id->generate();
|
||||
$self->session->db->write("insert into users (userId,dateCreated) values (".$self->session->db->quote($userId).","$self->session->datetime->time().")");
|
||||
require WebGUI::Grouping;
|
||||
$group->addUsers([$userId],[2,7]);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue