documentation of the migration of wobjects
This commit is contained in:
parent
920fa27263
commit
d0cfbd7a8e
3 changed files with 386 additions and 4 deletions
|
|
@ -27,6 +27,75 @@ for the Ids being strings. Also, anything using the setCollateral method will st
|
|||
GUIDs as well.
|
||||
|
||||
|
||||
1.2 Converting Wobjects To Asset Wobjects
|
||||
|
||||
In WebGUI 6.3 we made the first major change to the Wobject API. This should
|
||||
be the last major change until versioning is introduced in 6.7. In order to
|
||||
migrate your wobjects you will probably want to look at lib/WebGUI/Asset.pm,
|
||||
and lib/WebGUI/Asset/Wobject.pm as well as the wobjects that come with WebGUI.
|
||||
The following tips should also help make your migration easer:
|
||||
|
||||
1.2.1 The wobjectId field has been changed to assetId. In addition the Wobject ID
|
||||
should no longer be passed in the URL as wid. Instead all wobjects now have
|
||||
their own unique URL. Use this to call your methods.
|
||||
|
||||
Old: WebGUI::URL::page("func=edit&wid=".$self->get("wobjectId"))
|
||||
New: $self->getUrl("func=edit")
|
||||
|
||||
1.2.2 You can no longer assume that your forms and links are on the page they need
|
||||
to be to be called. Therefore use the getUrl() method inherited from Asset to
|
||||
build your forms and links.
|
||||
|
||||
EXAMPLE: WebGUI::Form::formHeader({action=>$self->getUrl});
|
||||
|
||||
1.2.3 Your wobject instance data (the data in the wobject table and the namespace
|
||||
table) will automatically be assigned an assetId. The wobjectId field in the
|
||||
namespace table will be left in place so that you have a reference of what the
|
||||
old ID was. Use this information (the assetId and wobjectId) to write a
|
||||
conversion script to convert the wobject data (if necessary).
|
||||
|
||||
1.2.4 Use the definition of the the fields in your old new() method to create a
|
||||
new definition method. See other wobjects as an example.
|
||||
|
||||
1.2.5 The concept of namespace no longer exists. While it still works very well
|
||||
in practice, it is no longer required that you call your table by the same
|
||||
name as your class. And the same goes for help, internationalization, etc. We
|
||||
still recommend using something like that, it's just not required.
|
||||
|
||||
1.2.6 Because namespace no longer exists you can't call the namespace to get
|
||||
international ids etc. Instead, hard code the international namespace. This is
|
||||
important for a number of reasons, but the most pressing is inheritance.
|
||||
Wobjects are now truely objects in that they support inheritance. To avoid
|
||||
subclass wobjects having to define a whole new international file with the
|
||||
exact same labels you have in your your international file, you need to hard
|
||||
code your namespace.
|
||||
|
||||
Old: WebGUI::International::get("label",$self->get("namespace"));
|
||||
New: WebGUI::International::get("label","Example");
|
||||
|
||||
1.2.7 Convert your www_edit() method into the two methods getEditForm() and
|
||||
www_edit(). See other wobjects for details.
|
||||
|
||||
1.2.8 Convert your www_view() method into a view() method. It should no longer
|
||||
have a check to see if the user can view it. The www_view() method in the
|
||||
Wobject superclass will do that.
|
||||
|
||||
1.2.9 Add a getIcon() method to your wobject. See other wobjects for examples.
|
||||
If you don't wish to make icons, then exclude this method, it will be
|
||||
inherited from the Asset superclass with the generic asset icon.
|
||||
|
||||
1.2.10 Rename your uiLevel() method to getUiLevel().
|
||||
|
||||
1.2.11 Rename your name() method to getName().
|
||||
|
||||
1.2.12 If your wobject used the forum system, then check out the new
|
||||
lib/WebGUI/Asset/Wobject/Forum.pm system.
|
||||
|
||||
1.2.13 If your wobject used attachments, then at bare minimum check
|
||||
lib/WebGUI/Storage.pm, but also consider using loose coupling with
|
||||
lib/WebGUI/Asset/File.pm or lib/WebGUI/Asset/File/Image.pm the same
|
||||
way that the Article wobject does.
|
||||
|
||||
|
||||
2. Macro Migration
|
||||
-------------------
|
||||
|
|
@ -43,6 +112,11 @@ If you absolutely must write a navigation macro for some reason that our nav
|
|||
system does not accomodate you, then please check out the new API in
|
||||
WebGUI::Navigation.
|
||||
|
||||
2.1 Navigation Macros Revisited
|
||||
|
||||
As of 6.3 check out lib/WebGUI/Asset/Wobject/Navigation.pm if you want to
|
||||
write custom navigation macros.
|
||||
|
||||
|
||||
|
||||
3. Authentication Migration
|
||||
|
|
|
|||
|
|
@ -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