Add the inheritUrlFromParent property, which causes the asset to prepend its

parent's URL to its own URL. Boolean, default off, found in the meta tab.
This commit is contained in:
Chris Nehren 2008-05-30 23:38:07 +00:00
parent 3dc01af30a
commit 9c77fdcce7
5 changed files with 130 additions and 4 deletions

View file

@ -1,4 +1,6 @@
7.5.11 7.5.11
- add: Assets can now inherit their parent's URL, prepended. Check the
meta tab.
- rfe: Not being limited to single-worded Tags - rfe: Not being limited to single-worded Tags
- SQL Form no longer ships with WebGUI. Use Thingy instead. However, out of - SQL Form no longer ships with WebGUI. Use Thingy instead. However, out of
respect for those using it, we only uninstall it if you have no sites using respect for those using it, we only uninstall it if you have no sites using

View file

@ -68,6 +68,7 @@ removeSqlForm($session);
migratePaymentPlugins( $session ); migratePaymentPlugins( $session );
removeRecurringPaymentActivity( $session ); removeRecurringPaymentActivity( $session );
addUserListWobject( $session ); addUserListWobject( $session );
addInheritUrlFromParent( $session );
finish($session); # this line required finish($session); # this line required
@ -1501,6 +1502,15 @@ sub addUserListWobject {
} }
#----------------------------------------------------------------------------
# Add the inheritUrlFromParent property for all assets
sub addInheritUrlFromParent {
my $session = shift;
print "\tAdding inheritUrlFromParent flag for all assets..." unless $quiet;
$session->db->write('alter table assetData add column inheritUrlFromParent int(11) not null default 0');
print "DONE!\n" unless $quiet;
}
# -------------- DO NOT EDIT BELOW THIS LINE -------------------------------- # -------------- DO NOT EDIT BELOW THIS LINE --------------------------------
#---------------------------------------------------------------------------- #----------------------------------------------------------------------------

View file

@ -461,6 +461,14 @@ sub definition {
uiLevel=>9, uiLevel=>9,
fieldType=>'yesNo', fieldType=>'yesNo',
defaultValue=>1, defaultValue=>1,
},
inheritUrlFromParent=>{
tab=>'meta',
label=>$i18n->get('does asset inherit URL from parent'),
hoverHelp=>$i18n->get('does asset inherit URL from parent description'),
uiLevel=>9,
fieldType=>'yesNo',
defaultValue=>0,
}, },
status=>{ status=>{
noFormPost=>1, noFormPost=>1,
@ -1971,6 +1979,11 @@ sub update {
} }
# check the definition of all properties against what was given to us # check the definition of all properties against what was given to us
# get a DB object for the two tight inner loops below, and the description
my $db = $self->session->db;
my $assetDataDescription = $db->buildHashRef('describe assetData');
foreach my $definition (reverse @{$self->definition($self->session)}) { foreach my $definition (reverse @{$self->definition($self->session)}) {
my %setPairs = (); my %setPairs = ();
@ -1987,13 +2000,48 @@ sub update {
# database field for it exists. if not, setting it will break, so # database field for it exists. if not, setting it will break, so
# skip it. this facilitates updating from previous versions. # skip it. this facilitates updating from previous versions.
if($property eq 'isExportable') { if($property eq 'isExportable') {
my $db = $self->session->db;
my $assetDataDescription = $db->buildHashRef('describe assetData');
unless(grep { $_ =~ /^isExportable/ } keys %{$assetDataDescription}) { unless(grep { $_ =~ /^isExportable/ } keys %{$assetDataDescription}) {
next; next;
} }
} }
# similarly, if this is the new-to-7.5 inheritUrlFromParent field,
# do the same.
elsif($property eq 'inheritUrlFromParent') {
unless(grep { $_ =~ /^inheritUrlFromParent/ } keys %{$assetDataDescription}) {
next;
}
next unless $properties->{inheritUrlFromParent} == 1;
# if we're still here, we have the property in the DB. so process it.
# only prepend the URL once
my $parentUrl = $self->getParent->getUrl;
# handle either being passed a new URL or updating the current one
my $currentUrl;
if(exists $properties->{url}) {
$currentUrl = $properties->{url};
}
else {
$currentUrl = $self->getUrl;
}
# if there's only one / then leave it alone.
unless($currentUrl =~ tr{/}{} == 1) {
$currentUrl =~ s{/[^/]+$}{};
}
# prepend if it's not a match
my $newUrl = $currentUrl;
if($currentUrl ne $parentUrl) {
$newUrl = $parentUrl . '/' . $currentUrl;
}
# replace the non-prepended value in the properties hash with this value
$self->{_properties}{url} = $newUrl;
}
# use the update value # use the update value
my $value = $properties->{$property}; my $value = $properties->{$property};
@ -2266,6 +2314,11 @@ sub www_editSave {
} }
} }
# handle inheritsUrlFromParent field
#if($self->session->form->process('inheritsUrlFromParent') == 1) {
# $object->update( { url => $self->getUrl . '/' . $object->getUrl } );
#}
$object->updateHistory("edited"); $object->updateHistory("edited");
# Handle Save & Commit button # Handle Save & Commit button

View file

@ -1048,6 +1048,16 @@ Couldn't open %-s because %-s <br />
lastUpdated => 0, lastUpdated => 0,
}, },
'does asset inherit URL from parent' => {
message => q|Prepend URL from parent?|,
lastUpdated => 1212183809,
},
'does asset inherit URL from parent description' => {
message => q|<p>Will this asset have its URL prepended with its parent URL?</p>|,
lastUpdated => 1212183809,
},
'search' => { 'search' => {
message => q{Search}, message => q{Search},
lastUpdated => 0, lastUpdated => 0,

View file

@ -146,7 +146,7 @@ $canViewMaker->prepare(
}, },
); );
plan tests => 94 plan tests => 97
+ scalar(@fixIdTests) + scalar(@fixIdTests)
+ scalar(@fixTitleTests) + scalar(@fixTitleTests)
+ 2*scalar(@getTitleTests) #same tests used for getTitle and getMenuTitle + 2*scalar(@getTitleTests) #same tests used for getTitle and getMenuTitle
@ -738,6 +738,57 @@ $product1->purge;
$product2->purge; $product2->purge;
$product3->purge; $product3->purge;
################################################################
#
# inheritUrlFromParent
#
################################################################
my $versionTag4 = WebGUI::VersionTag->getWorking($session);
$versionTag4->set( { name => 'inheritUrlFromParent tests' } );
$properties = {
# '1234567890123456789012'
id => 'inheritUrlFromParent01',
title => 'inheritUrlFromParent01',
className => 'WebGUI::Asset::Wobject::Layout',
url => 'inheriturlfromparent01',
};
my $iufpAsset = $defaultAsset->addChild($properties, $properties->{id});
$iufpAsset->commit;
$properties2 = {
# '1234567890123456789012'
id => 'inheritUrlFromParent02',
title => 'inheritUrlFromParent02',
className => 'WebGUI::Asset::Wobject::Layout',
url => 'inheriturlfromparent02',
};
my $iufpAsset2 = $iufpAsset->addChild($properties2, $properties2->{id});
$iufpAsset2->update( { inheritUrlFromParent => 1 } );
is($iufpAsset2->getUrl, '/inheriturlfromparent01/inheriturlfromparent02', 'inheritUrlFromParent works');
# works for setting, now try disabling. Should not change the URL.
$iufpAsset2->update( { inheritUrlFromParent => 0 } );
is($iufpAsset2->getUrl, '/inheriturlfromparent01/inheriturlfromparent02', 'setting inheritUrlFromParent to 0 works');
# works for setting and disabling, now ensure it recurses
my $properties3 = {
# '1234567890123456789012'
id => 'inheritUrlFromParent03',
title => 'inheritUrlFromParent03',
className => 'WebGUI::Asset::Wobject::Layout',
url => 'inheriturlfromparent03',
};
my $iufpAsset3 = $iufpAsset2->addChild($properties3, $properties3->{id});
$iufpAsset2->update( { inheritUrlFromParent => 1 } );
$iufpAsset3->update( { inheritUrlFromParent => 1 } );
is($iufpAsset3->getUrl, '/inheriturlfromparent01/inheriturlfromparent02/inheriturlfromparent03', 'inheritUrlFromParent recurses properly');
END { END {
$session->config->set( 'extrasURL', $origExtras); $session->config->set( 'extrasURL', $origExtras);
@ -756,7 +807,7 @@ END {
else { else {
$session->config->delete('assetUiLevel'); $session->config->delete('assetUiLevel');
} }
foreach my $vTag ($versionTag, $versionTag2, $versionTag3, ) { foreach my $vTag ($versionTag, $versionTag2, $versionTag3, $versionTag4, ) {
$vTag->rollback; $vTag->rollback;
} }
foreach my $user (values %testUsers) { foreach my $user (values %testUsers) {