App-Office-CMS

 view release on metacpan or  search on metacpan

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

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

	my($design_id) = $$page{design_id};
	my($design)    = $self -> param('db') -> design -> get_design_by_id($design_id);
	my($site_id)   = $$page{site_id};
	my($site)      = $self -> param('db') -> site -> get_site_by_id($site_id);
	my($base_dir)  = $$design{output_directory};
	my($tree)      = $self -> param('db')-> menu -> get_menu_by_context($$page{context});
	my($opt)       =
	{
		base_dir => $base_dir,
		callback => \&generate_web_page,
		count    => 0,
		_depth   => 0,
		design   => $design,
		error    => [],
		menu     => $self -> build_menu($design, $page),
		os_type  => $self -> param('db') -> get_os_type($$design{os_type_id}),
		self     => $self,
		site     => $site,
	};

	$tree -> walk_down($opt);

	my($result);

	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});



( run in 1.363 second using v1.01-cache-2.11-cpan-39bf76dae61 )