Fix Keywords so that by default, only Keywords from published assets are returned.
Reported as bug against the StoryManager, but also affects Wiki, Shelf.
This commit is contained in:
parent
75c8ec1e59
commit
c668226651
3 changed files with 96 additions and 16 deletions
|
|
@ -9,6 +9,7 @@
|
|||
- fixed #10652: Story Archive: hover help confusing
|
||||
- fixed #10653: Story Archive: Description text doesn't display
|
||||
- fixed #10656: Story: Photo caption doesn't appear
|
||||
- fixed #10658: Delete in Story Archive doesn't delete in Story Topic
|
||||
|
||||
7.7.15
|
||||
- fixed #10629: WebGUI::ProfileField create new field bug
|
||||
|
|
|
|||
|
|
@ -223,16 +223,25 @@ sub generateCloud {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getKeywordsForAsset ( { asset => $asset } )
|
||||
=head2 getKeywordsForAsset ( $options )
|
||||
|
||||
Returns a string of keywords separated by spaces. If the keyword has spaces in it, it
|
||||
will be quoted.
|
||||
Looks up the keywords for an asset, identified by either an asset object
|
||||
or an asset GUID in the options. Returns a string of keywords separated
|
||||
by spaces. If the keyword has spaces in it, it will be quoted.
|
||||
|
||||
=head3 asset
|
||||
=head3 $options
|
||||
|
||||
A hash reference of options.
|
||||
|
||||
=head4 asset
|
||||
|
||||
An asset that you want to get the keywords for.
|
||||
|
||||
=head3 asArrayRef
|
||||
=head4 assetId
|
||||
|
||||
The GUID of an asset you want to get the keywords for.
|
||||
|
||||
=head4 asArrayRef
|
||||
|
||||
A boolean, that if set to 1 will return the keywords as an array reference rather than a string.
|
||||
|
||||
|
|
@ -254,40 +263,50 @@ sub getKeywordsForAsset {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getMatchingAssets ( { startAsset => $asset, keyword => $keyword } )
|
||||
=head2 getMatchingAssets ( $options )
|
||||
|
||||
Returns an array reference of asset ids matching the params. Assets are returned in order of creationDate.
|
||||
Only published assets are returned, unless the C<states> options is used.
|
||||
|
||||
=head3 startAsset
|
||||
=head3 $options
|
||||
|
||||
A hash reference of options.
|
||||
|
||||
=head4 startAsset
|
||||
|
||||
An asset object where you'd like to start searching for matching keywords. Doesn't search any particular branch if one isn't specified.
|
||||
|
||||
=head3 keyword
|
||||
=head4 keyword
|
||||
|
||||
The keyword to match.
|
||||
|
||||
=head3 keywords
|
||||
=head4 keywords
|
||||
|
||||
An array reference of keywords to match.
|
||||
|
||||
=head3 matchAssetKeywords
|
||||
=head4 matchAssetKeywords
|
||||
|
||||
A reference to an asset that has a list of keywords to match. This can help locate assets that are similar to another asset.
|
||||
If the referenced asset does not have any keywords, then an empty array reference is returned.
|
||||
|
||||
=head3 isa
|
||||
=head4 isa
|
||||
|
||||
A classname pattern to match. For example, if you provide 'WebGUI::Asset::Sku' then everything that has a class name that starts with that including 'WebGUI::Asset::Sku::Product' will be included.
|
||||
|
||||
=head3 usePaginator
|
||||
=head4 usePaginator
|
||||
|
||||
Instead of returning an array reference of assetId's, return a paginator object.
|
||||
|
||||
=head3 rowsPerPage
|
||||
=head4 rowsPerPage
|
||||
|
||||
If usePaginator is passed, then this variable will set the number of rows per page that the paginator uses.
|
||||
If usePaginator is not passed, then this variable will limit the number of assetIds that are returned.
|
||||
|
||||
=head4 states
|
||||
|
||||
An array reference of asset states. The ids of assets in those states will be returned. If this option
|
||||
is missing, only assets in the C<published> state will be returned.
|
||||
|
||||
=cut
|
||||
|
||||
sub getMatchingAssets {
|
||||
|
|
@ -324,6 +343,20 @@ sub getMatchingAssets {
|
|||
push @params, $options->{keyword};
|
||||
}
|
||||
|
||||
# looking for a single keyword
|
||||
my @states;
|
||||
if (exists $options->{states} && scalar(@{ $options->{states} } )) {
|
||||
@states = @{ $options->{states} };
|
||||
}
|
||||
else {
|
||||
@states = 'published';
|
||||
}
|
||||
{
|
||||
my @placeholders = ('?') x scalar @states;
|
||||
push @params, @states;
|
||||
push @clauses, 'state in ('.join(',', @placeholders).')';
|
||||
}
|
||||
|
||||
# looking for a list of keywords
|
||||
if (exists $options->{keywords} && scalar(@{$options->{keywords}})) {
|
||||
my @placeholders = ();
|
||||
|
|
|
|||
52
t/Keyword.t
52
t/Keyword.t
|
|
@ -17,7 +17,9 @@ use WebGUI::Keyword;
|
|||
use WebGUI::Asset;
|
||||
# load your modules here
|
||||
|
||||
use Test::More tests => 9; # increment this value for each test you create
|
||||
use Test::More tests => 14; # increment this value for each test you create
|
||||
use Test::Deep;
|
||||
use Data::Dumper;
|
||||
|
||||
my $session = WebGUI::Test->session;
|
||||
|
||||
|
|
@ -31,6 +33,19 @@ isa_ok($keyword, "WebGUI::Keyword");
|
|||
$keyword->setKeywordsForAsset({ asset=>$home, keywords=>"test key, word, foo bar"});
|
||||
my ($count) = $session->db->quickArray("select count(*) from assetKeyword where assetId=?", [$home->getId]);
|
||||
is($count, 3, "setKeywordsForAsset() create");
|
||||
cmp_bag(
|
||||
$keyword->getKeywordsForAsset({ asset => $home, asArrayRef => 1}),
|
||||
['test key', 'word', 'foo bar'],
|
||||
'... check correct keywords set, returns array ref'
|
||||
);
|
||||
|
||||
my $keywords = $keyword->getKeywordsForAsset({ asset => $home, });
|
||||
my @keywords = split ',\s*', $keywords;
|
||||
cmp_bag(
|
||||
\@keywords,
|
||||
['test key', 'word', 'foo bar'],
|
||||
'... check correct keywords set, returns string'
|
||||
);
|
||||
|
||||
$keyword->setKeywordsForAsset({ asset=>$home, keywords=>"webgui, rules"});
|
||||
my ($count) = $session->db->quickArray("select count(*) from assetKeyword where assetId=?", [$home->getId]);
|
||||
|
|
@ -46,8 +61,39 @@ like($keyword->getKeywordsForAsset({asset=>$home }), qr/owns/, "getLatestVersion
|
|||
$keyword->deleteKeyword({keyword => "owns"});
|
||||
unlike($keyword->getKeywordsForAsset({asset=>$home }), qr/owns/, "getLatestVersionNumber()");
|
||||
|
||||
my $snippet = $home->addChild({
|
||||
className => 'WebGUI::Asset::Snippet',
|
||||
title => 'keyword snippet',
|
||||
snippet => 'keyword snippet',
|
||||
keywords => 'webgui',
|
||||
});
|
||||
|
||||
my $tag = WebGUI::VersionTag->getWorking($session);
|
||||
WebGUI::Test->tagsToRollback($tag);
|
||||
$tag->commit;
|
||||
|
||||
my $assetIds = $keyword->getMatchingAssets({ keyword => 'webgui', });
|
||||
|
||||
cmp_deeply(
|
||||
$assetIds,
|
||||
[$snippet->getId, $home->getId, ],
|
||||
'getMatchingAssets, by keyword, assetIds in order by creationDate, descending'
|
||||
);
|
||||
|
||||
$snippet->trash();
|
||||
|
||||
cmp_deeply(
|
||||
$keyword->getMatchingAssets({ keyword => 'webgui', }),
|
||||
[$home->getId, ],
|
||||
'... only published assets'
|
||||
);
|
||||
|
||||
cmp_deeply(
|
||||
$keyword->getMatchingAssets({ keyword => 'webgui', states => [ qw/published trash/, ]}),
|
||||
[$snippet->getId, $home->getId, ],
|
||||
'... retrieving assets in more than one state'
|
||||
);
|
||||
|
||||
$keyword->deleteKeywordsForAsset($home);
|
||||
is(scalar(@{$keyword->getKeywordsForAsset({ asset=>$home, asArrayRef=>1})}), 0, "getKeywordsForAsset()");
|
||||
undef $keyword;
|
||||
undef $home;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue