documentation of the migration of wobjects
This commit is contained in:
parent
920fa27263
commit
d0cfbd7a8e
3 changed files with 386 additions and 4 deletions
|
|
@ -105,6 +105,36 @@ sub definition {
|
|||
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 deleteCollateral ( tableName, keyName, keyValue )
|
||||
|
||||
Deletes a row of collateral data.
|
||||
|
||||
=head3 tableName
|
||||
|
||||
The name of the table you wish to delete the data from.
|
||||
|
||||
=head3 keyName
|
||||
|
||||
The name of the column that is the primary key in the table.
|
||||
|
||||
=head3 keyValue
|
||||
|
||||
An integer containing the key value.
|
||||
|
||||
=cut
|
||||
|
||||
sub deleteCollateral {
|
||||
my $self = shift;
|
||||
my $table = shift;
|
||||
my $keyName = shift;
|
||||
my $keyValue = shift;
|
||||
WebGUI::SQL->write("delete from $table where $keyName=".quote($keyValue));
|
||||
$self->updateHistory("deleted collateral item ".$keyName." ".$keyValue);
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 confirm ( message, yesURL, [ , noURL, vitalComparison ] )
|
||||
|
|
@ -161,6 +191,38 @@ sub duplicate {
|
|||
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getCollateral ( tableName, keyName, keyValue )
|
||||
|
||||
Returns a hash reference containing a row of collateral data.
|
||||
|
||||
=head3 tableName
|
||||
|
||||
The name of the table you wish to retrieve the data from.
|
||||
|
||||
=head3 keyName
|
||||
|
||||
The name of the column that is the primary key in the table.
|
||||
|
||||
=head3 keyValue
|
||||
|
||||
An integer containing the key value. If key value is equal to "new" or null, then an empty hashRef containing only keyName=>"new" will be returned to avoid strict errors.
|
||||
|
||||
=cut
|
||||
|
||||
sub getCollateral {
|
||||
my $self = shift;
|
||||
my $table = shift;
|
||||
my $keyName = shift;
|
||||
my $keyValue = shift;
|
||||
if ($keyValue eq "new" || $keyValue eq "") {
|
||||
return {$keyName=>"new"};
|
||||
} else {
|
||||
return WebGUI::SQL->quickHashRef("select * from $table where $keyName=".quote($keyValue),WebGUI::SQL->getSlave);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
|
|
@ -248,6 +310,112 @@ sub logView {
|
|||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 moveCollateralDown ( tableName, keyName, keyValue [ , setName, setValue ] )
|
||||
|
||||
Moves a collateral data item down one position. This assumes that the collateral data table has a column called "assetId" that identifies the wobject, and a column called "sequenceNumber" that determines the position of the data item.
|
||||
|
||||
=head3 tableName
|
||||
|
||||
A string indicating the table that contains the collateral data.
|
||||
|
||||
=head3 keyName
|
||||
|
||||
A string indicating the name of the column that uniquely identifies this collateral data item.
|
||||
|
||||
=head3 keyValue
|
||||
|
||||
An iid that uniquely identifies this collateral data item.
|
||||
|
||||
=head3 setName
|
||||
|
||||
By default this method assumes that the collateral will have an assetId in the table. However, since there is not always a assetId to separate one data set from another, you may specify another field to do that.
|
||||
|
||||
=head3 setValue
|
||||
|
||||
The value of the column defined by "setName" to select a data set from.
|
||||
|
||||
=cut
|
||||
|
||||
### NOTE: There is a redundant use of assetId in some of these statements on purpose to support
|
||||
### two different types of collateral data.
|
||||
|
||||
sub moveCollateralDown {
|
||||
my $self = shift;
|
||||
my $table = shift;
|
||||
my $keyName = shift;
|
||||
my $keyValue = shift;
|
||||
my $setName = shift || "assetId";
|
||||
my $setValue = shift;
|
||||
unless (defined $setValue) {
|
||||
$setValue = $self->get($setName);
|
||||
}
|
||||
WebGUI::SQL->beginTransaction;
|
||||
my ($seq) = WebGUI::SQL->quickArray("select sequenceNumber from $table where $keyName=".quote($keyValue)." and $setName=".quote($setValue));
|
||||
my ($id) = WebGUI::SQL->quickArray("select $keyName from $table where $setName=".quote($setValue)." and sequenceNumber=$seq+1");
|
||||
if ($id ne "") {
|
||||
WebGUI::SQL->write("update $table set sequenceNumber=sequenceNumber+1 where $keyName=".quote($keyValue)." and $setName=" .quote($setValue));
|
||||
WebGUI::SQL->write("update $table set sequenceNumber=sequenceNumber-1 where $keyName=".quote($id)." and $setName=" .quote($setValue));
|
||||
}
|
||||
WebGUI::SQL->commit;
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 moveCollateralUp ( tableName, keyName, keyValue [ , setName, setValue ] )
|
||||
|
||||
Moves a collateral data item up one position. This assumes that the collateral data table has a column called "assetId" that identifies the wobject, and a column called "sequenceNumber" that determines the position of the data item.
|
||||
|
||||
=head3 tableName
|
||||
|
||||
A string indicating the table that contains the collateral data.
|
||||
|
||||
=head3 keyName
|
||||
|
||||
A string indicating the name of the column that uniquely identifies this collateral data item.
|
||||
|
||||
=head3 keyValue
|
||||
|
||||
An id that uniquely identifies this collateral data item.
|
||||
|
||||
=head3 setName
|
||||
|
||||
By default this method assumes that the collateral will have a asset in the table. However, since there is not always a assetId to separate one data set from another, you may specify another field to do that.
|
||||
|
||||
=head3 setValue
|
||||
|
||||
The value of the column defined by "setName" to select a data set from.
|
||||
|
||||
=cut
|
||||
|
||||
### NOTE: There is a redundant use of assetId in some of these statements on purpose to support
|
||||
### two different types of collateral data.
|
||||
|
||||
sub moveCollateralUp {
|
||||
my $self = shift;
|
||||
my $table = shift;
|
||||
my $keyName = shift;
|
||||
my $keyValue = shift;
|
||||
my $setName = shift || "assetId";
|
||||
my $setValue = shift;
|
||||
unless (defined $setValue) {
|
||||
$setValue = $self->get($setName);
|
||||
}
|
||||
WebGUI::SQL->beginTransaction;
|
||||
my ($seq) = WebGUI::SQL->quickArray("select sequenceNumber from $table where $keyName=".quote($keyValue)." and $setName=".quote($setValue));
|
||||
my ($id) = WebGUI::SQL->quickArray("select $table from $keyName where $setName=".quote($setValue)
|
||||
." and sequenceNumber=$seq-1");
|
||||
if ($id ne "") {
|
||||
WebGUI::SQL->write("update $table set sequenceNumber=sequenceNumber-1 where $keyName=".quote($keyValue)." and $setName="
|
||||
.quote($setValue));
|
||||
WebGUI::SQL->write("update $table set sequenceNumber=sequenceNumber+1 where $keyName=".quote($id)." and $setName="
|
||||
.quote($setValue));
|
||||
}
|
||||
WebGUI::SQL->commit;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 processMacros ( output )
|
||||
|
|
@ -318,10 +486,141 @@ Removes this wobject and it's descendants from the database.
|
|||
sub purge {
|
||||
my $self = shift;
|
||||
$self->SUPER::purge();
|
||||
WebGUI::MetaData::metaDataDelete($self->get("wobjectId"));
|
||||
WebGUI::MetaData::metaDataDelete($self->getId);
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 reorderCollateral ( tableName, keyName [ , setName, setValue ] )
|
||||
|
||||
Resequences collateral data. Typically useful after deleting a collateral item to remove the gap created by the deletion.
|
||||
|
||||
=head3 tableName
|
||||
|
||||
The name of the table to resequence.
|
||||
|
||||
=head3 keyName
|
||||
|
||||
The key column name used to determine which data needs sorting within the table.
|
||||
|
||||
=head3 setName
|
||||
|
||||
Defaults to "assetId". This is used to define which data set to reorder.
|
||||
|
||||
=head3 setValue
|
||||
|
||||
Used to define which data set to reorder. Defaults to the assetId for this instance. Defaults to the value of "setName" in the wobject properties.
|
||||
|
||||
=cut
|
||||
|
||||
sub reorderCollateral {
|
||||
my $self = shift;
|
||||
my $table = shift;
|
||||
my $keyName = shift;
|
||||
my $setName = shift || "assetId";
|
||||
my $setValue = shift || $self->get($setName);
|
||||
my $i = 1;
|
||||
my $sth = WebGUI::SQL->read("select $keyName from $table where $setName=".quote($setValue)." order by sequenceNumber");
|
||||
while (my ($id) = $sth->array) {
|
||||
WebGUI::SQL->write("update $keyName set sequenceNumber=$i where $setName=".quote($setValue)." and $keyName=".quote($id));
|
||||
$i++;
|
||||
}
|
||||
$sth->finish;
|
||||
}
|
||||
|
||||
|
||||
#-----------------------------------------------------------------
|
||||
|
||||
=head2 setCollateral ( tableName, keyName, properties [ , useSequenceNumber, useAssetId, setName, setValue ] )
|
||||
|
||||
Performs and insert/update of collateral data for any wobject's collateral data. Returns the primary key value for that row of data.
|
||||
|
||||
=head3 tableName
|
||||
|
||||
The name of the table to insert the data.
|
||||
|
||||
=head3 keyName
|
||||
|
||||
The column name of the primary key in the table specified above.
|
||||
|
||||
=head3 properties
|
||||
|
||||
A hash reference containing the name/value pairs to be inserted into the database where the name is the column name. Note that the primary key should be specified in this list, and if it's value is "new" or null a new row will be created.
|
||||
|
||||
=head3 useSequenceNumber
|
||||
|
||||
If set to "1", a new sequenceNumber will be generated and inserted into the row. Note that this means you must have a sequenceNumber column in the table. Also note that this requires the presence of the assetId column. Defaults to "1".
|
||||
|
||||
=head3 useAssetId
|
||||
|
||||
If set to "1", the current assetId will be inserted into the table upon creation of a new row. Note that this means the table better have a assetId column. Defaults to "1".
|
||||
|
||||
=head3 setName
|
||||
|
||||
If this collateral data set is not grouped by assetId, but by another column then specify that column here. The useSequenceNumber parameter will then use this column name instead of assetId to generate the sequenceNumber.
|
||||
|
||||
=head3 setValue
|
||||
|
||||
If you've specified a setName you may also set a value for that set. Defaults to the value for this id from the wobject properties.
|
||||
|
||||
=cut
|
||||
|
||||
sub setCollateral {
|
||||
my $self = shift;
|
||||
my $table = shift;
|
||||
my $keyName = shift;
|
||||
my $properties = shift;
|
||||
my $useSequence = shift;
|
||||
my $useAssetId = shift;
|
||||
my $setName = shift || "assetId";
|
||||
my $setValue = shift || $self->get($setName);
|
||||
my ($key, $sql, $seq, $dbkeys, $dbvalues, $counter);
|
||||
my $counter = 0;
|
||||
my $sql;
|
||||
if ($properties->{$keyName} eq "new" || $properties->{$keyName} eq "") {
|
||||
$properties->{$keyName} = WebGUI::Id::generate();
|
||||
$sql = "insert into $table (";
|
||||
my $dbkeys = "";
|
||||
my $dbvalues = "";
|
||||
unless ($useSequence eq "0") {
|
||||
unless (exists $properties->{sequenceNumber}) {
|
||||
my ($seq) = WebGUI::SQL->quickArray("select max(sequenceNumber) from $table where $setName=".quote($setValue));
|
||||
$properties->{sequenceNumber} = $seq+1;
|
||||
}
|
||||
}
|
||||
unless ($useAssetId eq "0") {
|
||||
$properties->{assetId} = $self->get("assetId");
|
||||
}
|
||||
foreach my $key (keys %{$properties}) {
|
||||
if ($counter++ > 0) {
|
||||
$dbkeys .= ',';
|
||||
$dbvalues .= ',';
|
||||
}
|
||||
$dbkeys .= $key;
|
||||
$dbvalues .= quote($properties->{$key});
|
||||
}
|
||||
$sql .= $dbkeys.') values ('.$dbvalues.')';
|
||||
$self->updateHistory("added collateral item ".$table." ".$properties->{$keyName});
|
||||
} else {
|
||||
$sql = "update $table set ";
|
||||
foreach my $key (keys %{$properties}) {
|
||||
unless ($key eq "sequenceNumber") {
|
||||
$sql .= ',' if ($counter++ > 0);
|
||||
$sql .= $key."=".quote($properties->{$key});
|
||||
}
|
||||
}
|
||||
$sql .= " where $keyName=".quote($properties->{$keyName});
|
||||
$self->updateHistory("edited collateral item ".$table." ".$properties->{$keyName});
|
||||
}
|
||||
WebGUI::SQL->write($sql);
|
||||
$self->reorderCollateral($table,$keyName,$setName,$setValue) if ($properties->{sequenceNumber} < 0);
|
||||
return $properties->{$keyName};
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
|
|
|
|||
|
|
@ -272,9 +272,18 @@ sub processPropertiesFromFormPost {
|
|||
$property->{'a'.$i} = $answer[($i-1)];
|
||||
}
|
||||
$self->update($property);
|
||||
$self->deleteCollateral("Poll_answer","assetId",$self->getId) if ($session{form}{resetVotes});
|
||||
WebGUI::SQL->write("delete from Poll_answers where assetId=".quote($self->getId)) if ($session{form}{resetVotes});
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub purge {
|
||||
my $self = shift;
|
||||
WebGUI::SQL->write("delete from Poll_answers where assetId=".quote($self->getId));
|
||||
$self->SUPER::purge();
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub view {
|
||||
my $self = shift;
|
||||
|
|
@ -295,7 +304,7 @@ sub view {
|
|||
my ($totalResponses) = WebGUI::SQL->quickArray("select count(*) from Poll_answer where assetId=".quote($self->getId));
|
||||
$var{"responses.label"} = WebGUI::International::get(12,"Poll");
|
||||
$var{"responses.total"} = $totalResponses;
|
||||
$var{"form.start"} = WebGUI::Form::formHeader();
|
||||
$var{"form.start"} = WebGUI::Form::formHeader({action=>$self->getUrl});
|
||||
$var{"form.start"} .= WebGUI::Form::hidden({name=>'func',value=>'vote'});
|
||||
$var{"form.submit"} = WebGUI::Form::submit({value=>WebGUI::International::get(11,"Poll")});
|
||||
$var{"form.end"} = WebGUI::Form::formFooter();
|
||||
|
|
@ -333,7 +342,7 @@ sub www_vote {
|
|||
my $self = shift;
|
||||
my $u;
|
||||
if ($session{form}{answer} ne "" && WebGUI::Grouping::isInGroup($self->get("voteGroup")) && !($self->_hasVoted())) {
|
||||
WebGUI::SQL->write("insert into Poll_answer values (".quote($self->getId).",
|
||||
WebGUI::SQL->write("insert into Poll_answer (assetId, answer, userId, ipAddress) values (".quote($self->getId).",
|
||||
".quote($session{form}{answer}).", ".quote($session{user}{userId}).", '$session{env}{REMOTE_ADDR}')");
|
||||
if ($session{setting}{useKarma}) {
|
||||
$u = WebGUI::User->new($session{user}{userId});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue