App-Office-CMS
view release on metacpan or search on metacpan
lib/App/Office/CMS/Database/Page.pm view on Meta::CPAN
if ($context eq 'add')
{
$$page{id} = $self -> db -> insert_hash_get_id($table_name, $data);
}
else
{
$self -> db -> simple -> update($table_name, $data, {id => $$page{id} });
}
if ($$data{homepage} eq 'Yes')
{
# If this is a homepage, no other page in this design can be a homepage...
$self -> db -> simple -> update
(
'pages',
{
homepage => 'No',
},
{
design_id => $$page{design_id},
id => {'!=' => $$page{id} },
site_id => $$page{site_id},
}
);
}
$self -> log(debug => "Saved ($context) page '$$page{name}' with id $$page{id}");
} # End of save_page_record.
# --------------------------------------------------
sub search
{
my($self, $name, $result) = @_;
$self -> log(debug => "search($name)");
my($page_set) = $self -> get_pages_by_approx_name($name);
$self -> log(debug => "Page match count: " . scalar @$page_set);
my($design);
my($site);
for my $page (@$page_set)
{
$design = $self -> db -> design -> get_design_by_id($$page{design_id});
$site = $self -> db -> site -> get_site_by_id($$page{site_id});
$self -> build_search_result('Page', $result, $site, $design, $page);
}
return $result;
} # End of search.
# --------------------------------------------------
sub update
{
my($self, $page, $asset) = @_;
my($action) = $$page{exact_match} ? 'update' : 'add';
# If the update is really an add, because the user changed the name of the page,
# then we have to execute the 'add' code, and then update the default asset.
#
# Calling add_sibling() rather than add_child() is my arbitrary decision.
# We can't call add(), because that wouldn't add the page to the menu.
#
# We set $$page{exact_match} and $$asset{id} so that asset -> update()
# will update the default asset.
#
# Lastly, we set $$asset{page_id} since the default page had no id - it was undef,
# and it was that id which was put into the default asset's page_id.
if ($action eq 'add')
{
my($result) = $self -> add_sibling($page, 'below');
$$page{exact_match} = 1;
$$asset{id} = $$page{asset_id};
$$asset{page_id} = $$page{id};
$self -> db -> asset -> update($page, $asset);
return $result;
}
$self -> log(debug => "update($$page{name})");
$self -> log(debug => '-' x 50);
$self -> log(debug => "Page: $_ => $$page{$_}") for sort keys %$page;
$self -> log(debug => '-' x 50);
$self -> log(debug => "Asset: $_ => $$asset{$_}") for sort keys %$asset;
$self -> log(debug => '-' x 50);
$self -> save_page_record($action, $page);
$$asset{page_id} = $$page{id};
$self -> db -> asset -> update($page, $asset);
return ucfirst "$action page '$$page{name}'";
} # End of update.
# --------------------------------------------------
1;
( run in 1.124 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )