App-Office-CMS

 view release on metacpan or  search on metacpan

lib/App/Office/CMS/Controller/Content.pm  view on Meta::CPAN


	if (@{$$opt{error} })
	{
		for (@{$$opt{error} })
		{
			$self -> log(error => $_);
		}

		# The '. ' is because the caller appends this message to another one.

		$result = '. Failed to generate pages. See log';
	}
	else
	{
		$result = $$opt{count} == 1 ? '1 page' : "$$opt{count} pages";
		$result = ". Generated $result under $base_dir";
	}

	return $result;

} # End of generate_web_site.

# -----------------------------------------------

sub process_content_form
{
	my($self, $action) = @_;

	$self -> log(debug => "process_content_form($action)");

	my($data) = App::Office::CMS::Util::Validator -> new
	(
	 config => $self -> param('config'),
	 db     => $self -> param('db'),
	 query  => $self -> query,
	) -> validate_content;

	my($content);
	my($message);
	my($page);

	if ($$data{_rejects})
	{
		$self -> log(debug => 'Content data is not valid');

		$message => $self -> param('view') -> format_errors($$data{_rejects});
	}
	else
	{
		$self -> log(debug => 'Content data valid');

		($page, $content) = $self -> build_content_hash($data);
	}

	return ($message, $page, $content);

} # End of process_content_form.

# -----------------------------------------------

sub update
{
	my($self) = @_;

	$self -> log(debug => 'update()');

	# Expect the worst.

	my($target_div) = 'update_page_message_div';

	my($result);

	try
	{
		my($message, $page, $content) = $self -> process_content_form('update');

		if (! $message)
		{
			# Success.

			$message = $self -> param('db') -> content -> update($page, $content);
			$result  = $self -> build_success_result($page, $message, 'update_content_message_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.
	# update_page_message_div is on screen (under the Edit Pages tab)
	# because we're displaying a page.

	return JSON::XS -> new -> utf8 -> encode({results => $result});

} # End of update.

# -----------------------------------------------

1;



( run in 0.887 second using v1.01-cache-2.11-cpan-600a1bdf6e4 )