App-Office-CMS
view release on metacpan or search on metacpan
lib/App/Office/CMS/Controller/Content.pm view on Meta::CPAN
package App::Office::CMS::Controller::Content;
use parent 'App::Office::CMS::Controller';
use strict;
use warnings;
use App::Office::CMS::Util::Validator;
use File::Path 'make_path';
use File::Slurper 'write_text';
use JSON::XS;
use Path::Class; # For file().
use String::Dirify;
use Try::Tiny;
# We don't use Moo because we isa CGI::Application.
our $VERSION = '0.93';
# -----------------------------------------------
sub backup
{
my($self) = @_;
$self -> log(debug => 'backup()');
my($target_div) = 'update_content_message_div';
my($result);
try
{
my($message, $page, $content) = $self -> process_content_form('update');
if (! $message)
{
# Success.
$message = $self -> param('db') -> content -> backup($page, $content);
$result = $self -> build_success_result($page, $message, $target_div);
}
}
catch
{
$result = $self -> build_error_result($_, $target_div);
};
# update_content_message_div is on screen (under the Edit Content tab)
# because we're displaying content.
return JSON::XS -> new -> utf8 -> encode({results => $result});
} # End of backup.
# -----------------------------------------------
sub build_content_hash
{
my($self, $valid) = @_;
$self -> log(debug => 'build_content_hash()');
my($content) =
{
design_id => $self -> param('session') -> param('edit_design_id'),
page_id => $self -> param('session') -> param('edit_page_id'),
site_id => $self -> param('session') -> param('edit_site_id'),
};
my($page) = $self -> param('db') -> page -> get_page_by_id($$content{page_id});
for my $field_name (qw/body_text head_text/)
{
$$content{$field_name} = $$valid{$field_name};
( run in 1.122 second using v1.01-cache-2.11-cpan-39bf76dae61 )