Krang::Site - a means to access information on sites
use Krang::ClassLoader 'Site';
# construct object
my $site = Krang::Site->new(preview_url => 'preview.com', # required
preview_path => 'preview/path/',# required
publish_path => 'publish/path/',# required
url => 'site.com'); # required
# saves object to the DB and creates the root category '/' of the site $site->save();
# getters my $id = $site->site_id(); # undef until save() my $path = $site->preview_path(); my $path = $site->publish_path(); my $url = $site->preview_url(); my $url = $site->url();
# setters $site->preview_path( $new_preview_path ); $site->publish_path( $new_publish_path ); $site->url( $url );
# delete the site from the database $site->delete();
# a hash of search parameters
my %params =
( order_desc => 1, # result ascend unless this flag is set
limit => 5, # return 5 or less site objects
offset => 1, # start counting result from the
# second row
order_by => 'url' # sort on the 'url' field
preview_path_like => '%bob%', # match sites with preview_path
# LIKE '%bob%'
publish_path_like => '%fred%',
preview_url => 'preview', # match sites where preview_url is
# 'preview'
site_id => 8,
url_like => '%.com%' );
# any valid object field can be appended with '_like' to perform a # case-insensitive sub-string match on that field in the database
# returns an array of site objects matching criteria in %params
my @sites = pkg('Site')->find( %params );
A site is the basic organizational unit within a Krang instance. A site may correspond to a web-site but only necessarily maps to a unique URL. Content within the site is stored within categories; see Krang::Category.
On preview, site output is written to paths under 'preview_path' and then the user is redirected to 'preview_url' - it is the same for 'publish_path' and 'url' upon publishing an asset.
This module serves as a means of adding, deleting, accessing site objects for a given Krang instance. Site objects, at present, do little other than act as a means to determine the urls and path associated with a site.
N.B - On save(), the root category for the site '/' is created.
Access to fields for this object is provided my Krang::MethodMaker. The value of fields can be obtained and set in the following fashion:
$value = $site->field_name(); $site->field_name( $some_value );
The available fields for a site object are:
delete()This method's underlying call to dependent_check() may result in a
Krang::Site::Dependency exception if an object in the system is found that
relies upon the Site in question.
N.B. - This call will result in the deletion of the Site's root category.
dependent_check()The exception's 'category_id' field contains a list of the ids of depending categories. You might wish to handle the exception thusly:
eval {$site->dependent_check()};
if ($@ and $@->isa('Krang::Site::Dependency')) {
croak("This Site cannot be deleted. Categories with the following" .
" ids depend upon it: " . join(",", $@->category_id) . "\n");
}
N.B. - the root category of the site is excluded from this lookup.
duplicate_check()Additional criteria which affect the search results are:
The method croaks if an invalid search criteria is provided or if both the 'count' and 'ids_only' options are specified.
save()update_child_categories() if its 'url' field has changed since the last
save.
The method croaks if the save would result in a duplicate site object (i.e. if the object has the same path or url as another object). It also croaks if its database query affects no rows in the database.
update_child_categories()url()$site->serialize_xml(writer => $writer, set => $set)$site = Krang::Site->deserialize_xml(xml => $xml, set => $set, no_update => 0, skip_update => 0)If an incoming site has the same URL as an existing site then the
incoming site is skipped. This change from the usual
deserialize_xml() behavior was made on the theory that preview_path
and publish_path are likely to vary between alpha, beta and production
instances of the same site.
Krang, Krang::DB