During 7.7.2 upgrade, adding routines to unlink unused .pm and correctly port over rss item limit.
This commit is contained in:
parent
c052468a5b
commit
ff22d81b92
3 changed files with 16 additions and 387 deletions
|
|
@ -35,6 +35,7 @@ my $session = start(); # this line required
|
||||||
recalculateMatrixListingMedianValue( $session );
|
recalculateMatrixListingMedianValue( $session );
|
||||||
addRssFeedAspect($session);
|
addRssFeedAspect($session);
|
||||||
addRssFeedAspectToAssets($session);
|
addRssFeedAspectToAssets($session);
|
||||||
|
addRssFeedAspectToCollaboration($session);
|
||||||
removeRssCapableAsset($session);
|
removeRssCapableAsset($session);
|
||||||
|
|
||||||
finish($session); # this line required
|
finish($session); # this line required
|
||||||
|
|
@ -93,7 +94,7 @@ sub addRssFeedAspect {
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
sub addRssFeedAspectToAssets {
|
sub addRssFeedAspectToAssets {
|
||||||
my $session = shift;
|
my $session = shift;
|
||||||
foreach my $asset_class (qw( WikiMaster Collaboration SyndicatedContent Gallery GalleryAlbum )) {
|
foreach my $asset_class (qw( WikiMaster SyndicatedContent Gallery GalleryAlbum )) {
|
||||||
print "\tAdding RssFeed aspect to $asset_class table..." unless $quiet;
|
print "\tAdding RssFeed aspect to $asset_class table..." unless $quiet;
|
||||||
my $db = $session->db;
|
my $db = $session->db;
|
||||||
my $pages = $db->read("select assetId,revisionDate from $asset_class");
|
my $pages = $db->read("select assetId,revisionDate from $asset_class");
|
||||||
|
|
@ -104,12 +105,26 @@ sub addRssFeedAspectToAssets {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
sub addRssFeedAspectToCollaboration {
|
||||||
|
my $session = shift;
|
||||||
|
print "\tAdding RssFeed aspect to Collaboration, (porting rssCapableRssLimit to itemsPerFeed)..." unless $quiet;
|
||||||
|
my $db = $session->db;
|
||||||
|
my $pages = $db->read("select assetId,revisionDate,rssCapableRssLimit from RSSCapable");
|
||||||
|
while (my ($id, $rev, $limit) = $pages->array) {
|
||||||
|
$db->write("insert into assetAspectRssFeed (assetId, revisionDate, itemsPerFeed, feedTitle, feedDescription, feedImage, feedImageLink, feedImageDescription) values (?,?,?,'','',NULL,'','')",[$id,$rev,$limit]);
|
||||||
|
}
|
||||||
|
print "Done.\n" unless $quiet;
|
||||||
|
}
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
sub removeRssCapableAsset {
|
sub removeRssCapableAsset {
|
||||||
my $session = shift;
|
my $session = shift;
|
||||||
print "\tRemoving prior RssCapable asset..." unless $quiet;
|
print "\tRemoving prior RssCapable asset..." unless $quiet;
|
||||||
$session->db->write("drop table RSSCapable");
|
$session->db->write("drop table RSSCapable");
|
||||||
$session->db->write("drop table RSSFromParent");
|
$session->db->write("drop table RSSFromParent");
|
||||||
|
unlink ( $webguiRoot . '/lib/WebGUI/Asset/RSSCapable.pm' ) if -e $webguiRoot . '/lib/WebGUI/Asset/Wobject/RSSCapable.pm';
|
||||||
|
unlink ( $webguiRoot . '/lib/WebGUI/Asset/RSSFromParent.pm' ) if -e $webguiRoot . '/lib/WebGUI/Asset/Wobject/RSSFromParent.pm';
|
||||||
print "Done.\n" unless $quiet;
|
print "Done.\n" unless $quiet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,212 +0,0 @@
|
||||||
package WebGUI::Asset::RSSCapable;
|
|
||||||
|
|
||||||
=head1 LEGAL
|
|
||||||
|
|
||||||
-------------------------------------------------------------------
|
|
||||||
WebGUI is Copyright 2001-2009 Plain Black Corporation.
|
|
||||||
-------------------------------------------------------------------
|
|
||||||
Please read the legal notices (docs/legal.txt) and the license
|
|
||||||
(docs/license.txt) that came with this distribution before using
|
|
||||||
this software.
|
|
||||||
-------------------------------------------------------------------
|
|
||||||
http://www.plainblack.com info@plainblack.com
|
|
||||||
-------------------------------------------------------------------
|
|
||||||
|
|
||||||
=cut
|
|
||||||
|
|
||||||
use strict;
|
|
||||||
use NEXT;
|
|
||||||
use WebGUI::Asset::RSSFromParent;
|
|
||||||
|
|
||||||
=head1 NAME
|
|
||||||
|
|
||||||
WebGUI::Asset::RSSCapable
|
|
||||||
|
|
||||||
=head1 DESCRIPTION
|
|
||||||
|
|
||||||
An extra mixin class to be included before WebGUI::Asset in any asset
|
|
||||||
class that wishes its instances to be capable of generating RSS feeds
|
|
||||||
using the RSSFromParent asset.
|
|
||||||
|
|
||||||
=head1 SYNOPSIS
|
|
||||||
|
|
||||||
use base 'WebGUI::Asset::RSSCapable';
|
|
||||||
|
|
||||||
=cut
|
|
||||||
|
|
||||||
sub definition {
|
|
||||||
my $class = shift;
|
|
||||||
my $session = shift;
|
|
||||||
my $definition = shift;
|
|
||||||
my %properties;
|
|
||||||
tie %properties, 'Tie::IxHash';
|
|
||||||
my $i18n = WebGUI::International->new($session, 'Asset_RSSCapable');
|
|
||||||
|
|
||||||
# We do this prefixing to avoid name collisions because properties aren't namespaced.
|
|
||||||
%properties =
|
|
||||||
(
|
|
||||||
rssCapableRssEnabled => { tab => 'display',
|
|
||||||
fieldType => 'yesNo',
|
|
||||||
defaultValue => 1,
|
|
||||||
label => $i18n->get('rssEnabled label'),
|
|
||||||
hoverHelp => $i18n->get('rssEnabled hoverHelp')
|
|
||||||
},
|
|
||||||
rssCapableRssTemplateId => { tab => 'display',
|
|
||||||
fieldType => 'template',
|
|
||||||
defaultValue => 'PBtmpl0000000000000142',
|
|
||||||
namespace => 'RSSCapable/RSS',
|
|
||||||
label => $i18n->get('rssTemplateId label'),
|
|
||||||
hoverHelp => $i18n->get('rssTemplateId hoverHelp')
|
|
||||||
},
|
|
||||||
rssCapableRssLimit => { tab => 'display',
|
|
||||||
fieldType => 'integer',
|
|
||||||
defaultValue => 10,
|
|
||||||
namespace => 'RSSCapable/RSS',
|
|
||||||
label => $i18n->get('rssLimit label'),
|
|
||||||
hoverHelp => $i18n->get('rssLimit hoverHelp')
|
|
||||||
},
|
|
||||||
rssCapableRssFromParentId => { fieldType => 'hidden',
|
|
||||||
noFormPost => 1,
|
|
||||||
defaultValue => undef,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
push @$definition, { assetName => $i18n->get('assetName'),
|
|
||||||
tableName => 'RSSCapable',
|
|
||||||
autoGenerateForms => 1,
|
|
||||||
className => 'WebGUI::Asset::RSSCapable',
|
|
||||||
icon => 'rssCapable.gif',
|
|
||||||
properties => \%properties
|
|
||||||
};
|
|
||||||
return $class->NEXT::definition($session, $definition);
|
|
||||||
}
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
|
||||||
sub _rssFromParentValid {
|
|
||||||
my $self = shift;
|
|
||||||
my $rssFromParentId = $self->get('rssCapableRssFromParentId');
|
|
||||||
return undef unless $rssFromParentId;
|
|
||||||
|
|
||||||
my $rssFromParent = WebGUI::Asset->newByDynamicClass($self->session, $rssFromParentId);
|
|
||||||
return undef unless $rssFromParent;
|
|
||||||
return ($rssFromParent->isa('WebGUI::Asset::RSSFromParent')
|
|
||||||
&& $rssFromParent->getParent->getId eq $self->getId);
|
|
||||||
}
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
|
||||||
sub _updateRssFromParentProperties {
|
|
||||||
my $self = shift;
|
|
||||||
my $rssFromParent = WebGUI::Asset->newByDynamicClass($self->session,
|
|
||||||
$self->get('rssCapableRssFromParentId'));
|
|
||||||
$rssFromParent->update({ title => $self->get('title'),
|
|
||||||
menuTitle => $self->get('menuTitle') });
|
|
||||||
}
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
|
||||||
sub _purgeExtraRssFromParentAssets {
|
|
||||||
my $self = shift;
|
|
||||||
my $rssFromParentId = $self->get('rssCapableRssFromParentId');
|
|
||||||
|
|
||||||
foreach my $rssFromParent (@{$self->getLineage(['children'],
|
|
||||||
{returnObjects => 1,
|
|
||||||
includeOnlyClasses =>
|
|
||||||
['WebGUI::Asset::RSSFromParent']})}) {
|
|
||||||
$rssFromParent->purge unless $rssFromParent->getId eq $rssFromParentId;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
|
||||||
sub _ensureRssFromParentPresent {
|
|
||||||
my $self = shift;
|
|
||||||
if (!$self->_rssFromParentValid) {
|
|
||||||
# Create a new one.
|
|
||||||
my $rssFromParent = $self->addChild({ className => 'WebGUI::Asset::RSSFromParent',
|
|
||||||
title => $self->get('title'),
|
|
||||||
menuTitle => $self->get('menuTitle'),
|
|
||||||
url => $self->get('url').'.rss'
|
|
||||||
});
|
|
||||||
$self->update({ rssCapableRssFromParentId => $rssFromParent->getId });
|
|
||||||
}
|
|
||||||
|
|
||||||
$self->_updateRssFromParentProperties;
|
|
||||||
$self->_purgeExtraRssFromParentAssets;
|
|
||||||
}
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
|
||||||
sub _ensureRssFromParentAbsent {
|
|
||||||
my $self = shift;
|
|
||||||
# Invalidate it, and then it'll get purged along with any others.
|
|
||||||
$self->update({ rssCapableRssFromParentId => undef });
|
|
||||||
$self->_purgeExtraRssFromParentAssets;
|
|
||||||
}
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
|
||||||
sub processPropertiesFromFormPost {
|
|
||||||
my $self = shift;
|
|
||||||
my $error = $self->NEXT::processPropertiesFromFormPost(@_);
|
|
||||||
return $error if ref $error eq 'ARRAY';
|
|
||||||
if ($self->get('rssCapableRssEnabled')) {
|
|
||||||
$self->_ensureRssFromParentPresent;
|
|
||||||
} else {
|
|
||||||
$self->_ensureRssFromParentAbsent;
|
|
||||||
}
|
|
||||||
|
|
||||||
return undef;
|
|
||||||
}
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
|
||||||
|
|
||||||
=head2 getRssUrl ( )
|
|
||||||
|
|
||||||
Returns the site-relative URL to the RSS feed for this asset, or undef
|
|
||||||
if there is no such feed.
|
|
||||||
|
|
||||||
=cut
|
|
||||||
|
|
||||||
sub getRssUrl {
|
|
||||||
my $self = shift;
|
|
||||||
my $rssFromParentId = $self->get('rssCapableRssFromParentId');
|
|
||||||
return undef unless $rssFromParentId;
|
|
||||||
my $rssAsset = WebGUI::Asset->newByDynamicClass($self->session, $rssFromParentId);
|
|
||||||
return undef unless $rssAsset;
|
|
||||||
return $rssAsset->getUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
|
||||||
|
|
||||||
=head2 getRssItems ( )
|
|
||||||
|
|
||||||
Returns a list of RSS items for a feed corresponding to this asset.
|
|
||||||
Each item may be another asset, or a hash of (properly XMLized)
|
|
||||||
properties for the <item>..</item> tag. Defaults to no items.
|
|
||||||
|
|
||||||
This is the primary method that RSSCapable assets should override.
|
|
||||||
|
|
||||||
=cut
|
|
||||||
|
|
||||||
sub getRssItems { () }
|
|
||||||
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
|
||||||
|
|
||||||
=head2 www_viewRSS ( )
|
|
||||||
|
|
||||||
Default www method for methods that return RSS. This will redirect to the getRssUrl unless overridden.
|
|
||||||
|
|
||||||
=cut
|
|
||||||
|
|
||||||
sub www_viewRSS {
|
|
||||||
my $self = shift;
|
|
||||||
my $session = $self->session;
|
|
||||||
|
|
||||||
my $rssUrl = $self->getRssUrl;
|
|
||||||
|
|
||||||
if($rssUrl) {
|
|
||||||
$session->http->setRedirect($self->getRssUrl);
|
|
||||||
}
|
|
||||||
|
|
||||||
return undef;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
1;
|
|
||||||
|
|
@ -1,174 +0,0 @@
|
||||||
package WebGUI::Asset::RSSFromParent;
|
|
||||||
|
|
||||||
=head1 LEGAL
|
|
||||||
|
|
||||||
-------------------------------------------------------------------
|
|
||||||
WebGUI is Copyright 2001-2009 Plain Black Corporation.
|
|
||||||
-------------------------------------------------------------------
|
|
||||||
Please read the legal notices (docs/legal.txt) and the license
|
|
||||||
(docs/license.txt) that came with this distribution before using
|
|
||||||
this software.
|
|
||||||
-------------------------------------------------------------------
|
|
||||||
http://www.plainblack.com info@plainblack.com
|
|
||||||
-------------------------------------------------------------------
|
|
||||||
|
|
||||||
=cut
|
|
||||||
|
|
||||||
use strict;
|
|
||||||
use HTML::Entities;
|
|
||||||
use Tie::IxHash;
|
|
||||||
use base 'WebGUI::Asset';
|
|
||||||
use WebGUI::Utility;
|
|
||||||
|
|
||||||
=head1 NAME
|
|
||||||
|
|
||||||
Package WebGUI::Asset::RSSFromParent
|
|
||||||
|
|
||||||
=head1 DESCRIPTION
|
|
||||||
|
|
||||||
Generates an RSS feed from the children/descendants of its parent.
|
|
||||||
|
|
||||||
=head1 SYNOPSIS
|
|
||||||
|
|
||||||
use WebGUI::Asset::RSSFromParent;
|
|
||||||
|
|
||||||
=cut
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
|
||||||
|
|
||||||
=head2 definition
|
|
||||||
|
|
||||||
=cut
|
|
||||||
|
|
||||||
sub definition {
|
|
||||||
my $class = shift;
|
|
||||||
my $session = shift;
|
|
||||||
my $definition = shift;
|
|
||||||
my %properties;
|
|
||||||
tie %properties, 'Tie::IxHash';
|
|
||||||
my $i18n = WebGUI::International->new($session, "Asset_RSSFromParent");
|
|
||||||
|
|
||||||
%properties = ();
|
|
||||||
|
|
||||||
push(@{$definition}, {
|
|
||||||
assetName=>$i18n->get('assetName'),
|
|
||||||
icon=>'rssGear.gif',
|
|
||||||
autoGenerateForms=>1,
|
|
||||||
tableName=>'RSSFromParent',
|
|
||||||
className=>'WebGUI::Asset::RSSFromParent',
|
|
||||||
properties=>\%properties
|
|
||||||
});
|
|
||||||
|
|
||||||
return $class->SUPER::definition($session, $definition);
|
|
||||||
}
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
|
||||||
|
|
||||||
=head2 update
|
|
||||||
|
|
||||||
=cut
|
|
||||||
|
|
||||||
sub update {
|
|
||||||
# Re-force isHidden to 1 on each update; these should always be hidden.
|
|
||||||
my $self = shift;
|
|
||||||
my $properties = shift;
|
|
||||||
$self->SUPER::update(+{%$properties, isHidden => 1});
|
|
||||||
}
|
|
||||||
|
|
||||||
#------------------------------------------------
|
|
||||||
|
|
||||||
=head2 _escapeXml
|
|
||||||
|
|
||||||
=cut
|
|
||||||
|
|
||||||
sub _escapeXml {
|
|
||||||
my $text = shift;
|
|
||||||
return $text unless (ref $text eq "");
|
|
||||||
return HTML::Entities::encode_numeric($text)
|
|
||||||
}
|
|
||||||
|
|
||||||
#------------------------------------------------
|
|
||||||
|
|
||||||
=head2 _tlsOfAsset
|
|
||||||
|
|
||||||
=cut
|
|
||||||
|
|
||||||
sub _tlsOfAsset {
|
|
||||||
my $self = shift;
|
|
||||||
my $asset = shift;
|
|
||||||
#Fix Title
|
|
||||||
my $title = _escapeXml($asset->get('title'));
|
|
||||||
#Fix Url
|
|
||||||
my $url = _escapeXml($self->session->url->getSiteURL() . $asset->getUrl);
|
|
||||||
#Fix Description
|
|
||||||
my $description = _escapeXml($asset->get('synopsis'));
|
|
||||||
return ($title,$url,$description);
|
|
||||||
}
|
|
||||||
|
|
||||||
#------------------------------------------------
|
|
||||||
|
|
||||||
=head2 {
|
|
||||||
|
|
||||||
=cut
|
|
||||||
|
|
||||||
sub isValidRssItem { 0 }
|
|
||||||
|
|
||||||
#------------------------------------------------
|
|
||||||
|
|
||||||
=head2 displayInFolder2
|
|
||||||
|
|
||||||
=cut
|
|
||||||
|
|
||||||
sub displayInFolder2 { 0 }
|
|
||||||
|
|
||||||
#------------------------------------------------
|
|
||||||
|
|
||||||
=head2 www_view
|
|
||||||
|
|
||||||
=cut
|
|
||||||
|
|
||||||
sub www_view {
|
|
||||||
my $self = shift;
|
|
||||||
return '' unless $self->session->asset->getId eq $self->getId;
|
|
||||||
return '' unless $self->getParent->isa('WebGUI::Asset::RSSCapable');
|
|
||||||
return '' unless $self->getParent->canView; # Go to parent for auth
|
|
||||||
my $parent = $self->getParent;
|
|
||||||
my $template = WebGUI::Asset::Template->new($self->session, $parent->get('rssCapableRssTemplateId'));
|
|
||||||
$template->prepare($self->getMetaDataAsTemplateVariables);
|
|
||||||
$self->session->http->setMimeType('text/xml');
|
|
||||||
|
|
||||||
my $var = {};
|
|
||||||
@$var{'title', 'link', 'description'} = $self->_tlsOfAsset($parent);
|
|
||||||
$var->{'generator'} = "WebGUI $WebGUI::VERSION";
|
|
||||||
$var->{'lastBuildDate'} = $self->session->datetime->epochToMail($parent->getContentLastModified);
|
|
||||||
$var->{'webMaster'} = $self->session->setting->get('companyEmail');
|
|
||||||
$var->{'docs'} = 'http://blogs.law.harvard.edu/tech/rss';
|
|
||||||
|
|
||||||
my @items = $parent->getRssItems;
|
|
||||||
$var->{'item_loop'} = [];
|
|
||||||
my $counter = 0;
|
|
||||||
foreach my $item (@items) {
|
|
||||||
my $subvar = {};
|
|
||||||
|
|
||||||
if (UNIVERSAL::isa($item, 'WebGUI::Asset')) {
|
|
||||||
next unless $item->isValidRssItem;
|
|
||||||
$subvar = {};
|
|
||||||
@$subvar{'title', 'link', 'description'} = $self->_tlsOfAsset($item);
|
|
||||||
$subvar->{guid} = $subvar->{link};
|
|
||||||
$subvar->{pubDate} = _escapeXml($self->session->datetime->epochToMail($item->get('creationDate')));
|
|
||||||
} elsif (ref $item eq 'HASH') {
|
|
||||||
foreach my $key (keys %$item) {
|
|
||||||
$subvar->{$key} = _escapeXml($item->{$key});
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
$self->session->errorHandler->error("Don't know what to do with this RSS item: $item");
|
|
||||||
next;
|
|
||||||
}
|
|
||||||
$counter++;
|
|
||||||
push @{$var->{'item_loop'}}, $subvar;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $self->processTemplate($var, undef, $template);
|
|
||||||
}
|
|
||||||
|
|
||||||
1;
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue