diff --git a/docs/upgrades/templates-6.99.0/wgtemplate_center_image.tmpl b/docs/upgrades/templates-6.99.0/wgtemplate_center_image.tmpl
index e040e5c5f..292f154a0 100755
--- a/docs/upgrades/templates-6.99.0/wgtemplate_center_image.tmpl
+++ b/docs/upgrades/templates-6.99.0/wgtemplate_center_image.tmpl
@@ -27,8 +27,7 @@
-
-
+
diff --git a/docs/upgrades/templates-6.99.0/wgtemplate_default_article.tmpl b/docs/upgrades/templates-6.99.0/wgtemplate_default_article.tmpl
index e1bdf194f..6267e95fc 100755
--- a/docs/upgrades/templates-6.99.0/wgtemplate_default_article.tmpl
+++ b/docs/upgrades/templates-6.99.0/wgtemplate_default_article.tmpl
@@ -27,7 +27,7 @@
-
+
diff --git a/docs/upgrades/templates-6.99.0/wgtemplate_item.tmpl b/docs/upgrades/templates-6.99.0/wgtemplate_item.tmpl
index 87e14639f..6464a3ddc 100755
--- a/docs/upgrades/templates-6.99.0/wgtemplate_item.tmpl
+++ b/docs/upgrades/templates-6.99.0/wgtemplate_item.tmpl
@@ -6,18 +6,12 @@
-
-
-
-
-
-
-
+
-
-
+ 
diff --git a/docs/upgrades/templates-6.99.0/wgtemplate_item_with_pop_up_links.tmpl b/docs/upgrades/templates-6.99.0/wgtemplate_item_with_pop_up_links.tmpl
index 3a16f2e41..8b64407b0 100755
--- a/docs/upgrades/templates-6.99.0/wgtemplate_item_with_pop_up_links.tmpl
+++ b/docs/upgrades/templates-6.99.0/wgtemplate_item_with_pop_up_links.tmpl
@@ -6,18 +6,12 @@
-
-
-
-
-
-
-
+
-
-
+ 
diff --git a/docs/upgrades/templates-6.99.0/wgtemplate_left_align_image.tmpl b/docs/upgrades/templates-6.99.0/wgtemplate_left_align_image.tmpl
index fbdb10020..b50078206 100755
--- a/docs/upgrades/templates-6.99.0/wgtemplate_left_align_image.tmpl
+++ b/docs/upgrades/templates-6.99.0/wgtemplate_left_align_image.tmpl
@@ -29,7 +29,7 @@
-
+
diff --git a/docs/upgrades/templates-6.99.0/wgtemplate_linked_image_with_caption.tmpl b/docs/upgrades/templates-6.99.0/wgtemplate_linked_image_with_caption.tmpl
index 3611b3b17..1c26a712d 100755
--- a/docs/upgrades/templates-6.99.0/wgtemplate_linked_image_with_caption.tmpl
+++ b/docs/upgrades/templates-6.99.0/wgtemplate_linked_image_with_caption.tmpl
@@ -32,8 +32,7 @@
-
-
+
diff --git a/docs/upgrades/upgrade_6.8.8-6.99.0.pl b/docs/upgrades/upgrade_6.8.8-6.99.0.pl
index d7f111f39..088921550 100644
--- a/docs/upgrades/upgrade_6.8.8-6.99.0.pl
+++ b/docs/upgrades/upgrade_6.8.8-6.99.0.pl
@@ -17,6 +17,7 @@ use File::Path;
use WebGUI::Workflow;
use WebGUI::Workflow::Cron;
use WebGUI::Group;
+use WebGUI::Storage;
my $toVersion = "6.99.0"; # make this match what version you're going to
my $quiet; # this line required
@@ -54,6 +55,25 @@ finish($session); # this line required
sub updateArticle {
print "\tAllowing articles to have direct attachments.\n";
$session->db->write("alter table Article add column storageId varchar(22) binary");
+ my $rs = $session->db->read("select assetId from asset where className='WebGUI::Asset::Wobject::Article'");
+ while (my ($id) = $rs->array) {
+ my $asset = WebGUI::Asset->new($id, "WebGUI::Asset::Wobject::Article");
+ if (defined $asset) {
+ my $children = $asset->getLineage(["children"],{returnObjects=>1, includeOnlyClasses=>["WebGUI::Asset::File","WebGUI::Asset::File::Image"]});
+ if (scalar(@{$children})) {
+ my $storage = undef;
+ if ($asset->get("storageId")) {
+ $storage = WebGUI::Storage->get($session,$asset->get("storageId"));
+ } else {
+ $storage = WebGUI::Storage->create($session);
+ $asset->update({storageId=>$storage->getId});
+ }
+ foreach my $child (@{$children}) {
+ $child->getStorageLocation->copy($storage);
+ }
+ }
+ }
+ }
}
#-------------------------------------------------
diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm
index d9d8affd7..2f29e2842 100644
--- a/lib/WebGUI/Asset.pm
+++ b/lib/WebGUI/Asset.pm
@@ -1536,10 +1536,14 @@ sub processPropertiesFromFormPost {
$data{$property} = $definition->{properties}{$property}{defaultValue} if $self->session->form->process("assetId") eq "new";
next;
}
+ my %params = %{$definition->{properties}{$property}};
+ $params{name} = $property;
+ $params{value} = $self->get($property);
$data{$property} = $self->session->form->process(
$property,
$definition->{properties}{$property}{fieldType},
- $definition->{properties}{$property}{defaultValue}
+ $definition->{properties}{$property}{defaultValue},
+ \%params
);
}
}
diff --git a/lib/WebGUI/Asset/Post.pm b/lib/WebGUI/Asset/Post.pm
index 8e0c23bd0..93a35ef23 100644
--- a/lib/WebGUI/Asset/Post.pm
+++ b/lib/WebGUI/Asset/Post.pm
@@ -700,7 +700,7 @@ sub purge {
my $self = shift;
my $sth = $self->session->db->read("select storageId from Post where assetId=".$self->session->db->quote($self->getId));
while (my ($storageId) = $sth->array) {
- my $storage = WebGUI::Storage->get($storageId);
+ my $storage = WebGUI::Storage->get($self->session, $storageId);
$storage->delete if defined $storage;
}
$sth->finish;
diff --git a/lib/WebGUI/Asset/Wobject/Article.pm b/lib/WebGUI/Asset/Wobject/Article.pm
index 33a0880e2..acabab91d 100644
--- a/lib/WebGUI/Asset/Wobject/Article.pm
+++ b/lib/WebGUI/Asset/Wobject/Article.pm
@@ -66,6 +66,24 @@ text will come out formatted as paragraphs.
=cut
+#-------------------------------------------------------------------
+
+=head2 addRevision
+
+Override the default method in order to deal with attachments.
+
+=cut
+
+sub addRevision {
+ my $self = shift;
+ my $newSelf = $self->SUPER::addRevision(@_);
+ if ($self->get("storageId")) {
+ my $newStorage = WebGUI::Storage->get($self->session,$self->get("storageId"))->copy;
+ $newSelf->update({storageId=>$newStorage->getId});
+ }
+ return $newSelf;
+}
+
#-------------------------------------------------------------------
sub definition {
my $class = shift;
@@ -163,6 +181,39 @@ sub exportAssetData {
}
+#-------------------------------------------------------------------
+sub getStorageLocation {
+ my $self = shift;
+ unless (exists $self->{_storageLocation}) {
+ if ($self->get("storageId") eq "") {
+ $self->{_storageLocation} = WebGUI::Storage::Image->create($self->session);
+ $self->update({storageId=>$self->{_storageLocation}->getId});
+ } else {
+ $self->{_storageLocation} = WebGUI::Storage::Image->get($self->session,$self->get("storageId"));
+ }
+ }
+ return $self->{_storageLocation};
+}
+
+#-------------------------------------------------------------------
+
+=head2 indexContent ( )
+
+Indexing the content of attachments and user defined fields. See WebGUI::Asset::indexContent() for additonal details.
+
+=cut
+
+sub indexContent {
+ my $self = shift;
+ my $indexer = $self->SUPER::indexContent;
+ $indexer->addKeywords($self->get("linkTitle"));
+ $indexer->addKeywords($self->get("linkUrl"));
+ my $storage = $self->getStorageLocation;
+ foreach my $file (@{$storage->getFiles}) {
+ $indexer->addFile($storage->getPath($file));
+ }
+}
+
#-------------------------------------------------------------------
=head2 prepareView ( )
@@ -184,6 +235,19 @@ sub prepareView {
}
+#-------------------------------------------------------------------
+
+sub purge {
+ my $self = shift;
+ my $sth = $self->session->db->read("select storageId from Articlewhere assetId=?",[$self->getId]);
+ while (my ($storageId) = $sth->array) {
+ my $storage = WebGUI::Storage::Image->get($self->session,$storageId);
+ $storage->delete if defined $storage;
+ }
+ $sth->finish;
+ return $self->SUPER::purge;
+}
+
#-------------------------------------------------------------------
=head2 purgeCache ()
@@ -200,6 +264,14 @@ sub purgeCache {
#-------------------------------------------------------------------
+sub purgeRevision {
+ my $self = shift;
+ $self->getStorageLocation->delete;
+ return $self->SUPER::purgeRevision;
+}
+
+#-------------------------------------------------------------------
+
=head2 view ( )
view defines all template variables, processes the template and
@@ -215,7 +287,7 @@ sub view {
}
my %var;
if ($self->get("storageId")) {
- my $storage = WebGUI::Storage::Image->get($self->session, $self->get("storageId"));
+ my $storage = $self->getStorageLocation;
foreach my $file (@{$storage->getFiles}) {
if ($storage->isImage($file)) {
$var{'image.url'} = $storage->getUrl($file);
@@ -292,7 +364,7 @@ sub www_deleteFile {
my $self = shift;
return $self->session->privilege->insufficient unless $self->canEdit;
if ($self->get("storageId") ne "") {
- my $storage = WebGUI::Storage::Image->get($self->session, $self->get("storageId"));
+ my $storage = $self->getStorageLocation;
$storage->deleteFile($self->session->form->param("filename"));
}
return $self->www_edit;
diff --git a/lib/WebGUI/Form/File.pm b/lib/WebGUI/Form/File.pm
index eb273f0c2..8e84c2201 100644
--- a/lib/WebGUI/Form/File.pm
+++ b/lib/WebGUI/Form/File.pm
@@ -156,7 +156,12 @@ sub getValueFromPost {
} elsif ($self->session->form->param($self->privateName('action')) eq 'keep') {
return $value;
} elsif ($self->session->form->param($self->privateName('action')) eq 'upload') {
- my $storage = WebGUI::Storage::Image->create($self->session);
+ my $storage = undef;
+ if ($self->get("value") ne "") {
+ $storage = WebGUI::Storage::Image->get($self->session, $self->get("value"));
+ } else {
+ $storage = WebGUI::Storage::Image->create($self->session);
+ }
$storage->addFileFromFormPost($self->get("name"),1000);
my @files = @{ $storage->getFiles };
if (scalar(@files) < 1) {
diff --git a/lib/WebGUI/Session/Form.pm b/lib/WebGUI/Session/Form.pm
index f5c6cbbaa..594fc77aa 100644
--- a/lib/WebGUI/Session/Form.pm
+++ b/lib/WebGUI/Session/Form.pm
@@ -58,7 +58,7 @@ sub AUTOLOAD {
our $AUTOLOAD;
my $self = shift;
my $name = ucfirst((split /::/, $AUTOLOAD)[-1]);
- my $fieldName = shift;
+ my $params = shift;
my $cmd = "use WebGUI::Form::".$name;
eval ($cmd);
if ($@) {
@@ -66,7 +66,7 @@ sub AUTOLOAD {
return undef;
}
my $class = "WebGUI::Form::".$name;
- return $class->new($self->session, {name=>$fieldName})->getValueFromPost;
+ return $class->new($self->session, $params)->getValueFromPost;
}
#-------------------------------------------------------------------
@@ -181,7 +181,7 @@ sub paramsHashRef {
#-------------------------------------------------------------------
-=head2 process ( name, type [ , default ] )
+=head2 process ( name, type [ , default, params ] )
Returns whatever would be the expected result of the method type that was specified. This method also checks to make sure that the field is not returning a string filled with nothing but whitespace.
@@ -197,21 +197,26 @@ The type of form element this variable came from. Defaults to "text" if not spec
The default value for this variable. If the variable is undefined then the default value will be returned instead.
+=head3 params
+
+A full set of form params just as you'd pass into any of the form controls when building it.
+
=cut
sub process {
- my ($self, $name, $type, $default) = @_;
+ my ($self, $name, $type, $default, $params) = @_;
$type = ucfirst($type);
return $self->param($name) if ($type eq "");
+ $params->{name} = $name;
if (wantarray) {
- my @values = $self->$type($name);
+ my @values = $self->$type($params);
if (scalar(@values) < 1 && ref $default eq "ARRAY") {
return @{$default};
} else {
return @values;
}
} else {
- my $value = $self->$type($name);
+ my $value = $self->$type($params);
unless (defined $value) {
return $default;
}
diff --git a/lib/WebGUI/Storage.pm b/lib/WebGUI/Storage.pm
index e6a552f73..9ebc03aa9 100644
--- a/lib/WebGUI/Storage.pm
+++ b/lib/WebGUI/Storage.pm
@@ -289,15 +289,19 @@ sub addFileFromScalar {
#-------------------------------------------------------------------
-=head2 copy ( )
+=head2 copy ( [ storage ] )
Copies a storage location and it's contents. Returns a new storage location object. Note that this does not copy privileges or other special filesystem properties.
+
+=head3 storage
+
+Optionally pass in a storage object to copy the data to.
=cut
sub copy {
my $self = shift;
- my $newStorage = WebGUI::Storage->create($self->session);
+ my $newStorage = shift || WebGUI::Storage->create($self->session);
my $filelist = $self->getFiles(1);
foreach my $file (@{$filelist}) {
my $source = FileHandle->new($self->getPath($file),"r");