Krang::Template - Interface for managing template objects
# create a new template
my $template = pkg('Template')->new(category => $category,
content => '<tmpl_var test>',
filename => 'test.tmpl');
# save contents of the object to the DB. $template->save();
# put the object back into circulation for other users $template->checkin();
# checkout object to work on it $template->checkout();
# saves to the db again, increments version field of the object $template->save();
# use this template for testing, will override deployed versions of the # same template $template->mark_for_testing();
# no longer use this template for testing $template->unmark_for_testing();
# Mark the template as having been deployed to the Krang publish path. # unsets testing flag in the database $template->mark_as_deployed();
# Mark the template as not existing in the publish path. # unsets deployed, deploy_version, deploy_date. $template->mark_as_undeployed();
# reverts to template revision specified by $version $template->revert( $version );
# deploy template $template->deploy
# remove all references to the object in the template and # template_version tables $template->delete();
# returns array of template objects matching criteria in %params
my @templates = pkg('Template')->find( %params );
# Get permissions for this object
$template->may_see() || croak("Not allowed to see");
$template->may_edit() || croak("Not allowed to edit");
Templates determine the form of this system's output. This module provides a means to check in, check out, edit, revert, save, and search Template objects.
A template is either associated with an element class and hence determines its formatting or it may serve as some manner of miscellaneous utility whether formatting or otherwise. Template data, i.e. the 'content' field, is, at present, intended to be in HTML::Template format. All template filenames will end in the extension '.tmpl'. Users have the ability to revert to any previous version of a template.
This module interfaces or will interface with Krang::CGI::Template, Krang::Burner, the FTP interface, and the SOAP interface.
This module employs Krang::MethodMaker to provide accessors for all and mutators for some of the object's fields. The fields can be accessed and set in the following manner:
# accessor $value = $template_obj->readable_field();
# mutator $template->obj->readable_and_writeable_field( $value );
The four read/write fields for the object are:
The remaining read-only fields are:
new() to the current date and
time.
init() method. The
valid keys to this hash are:
The filename arguement is required.
checkin()Will throw Krang::Template::NoEditAccess unless user has edit access.
If the call to verify_checkout() fails, a Checkout exception is thrown.
checkout()Will throw Krang::Template::NoEditAccess unless user has edit access.
This method throws Krang::Template::Checkout if the object is already checked out by another user.
delete()Deletion means deleting all instances of the object in the version table as well as the current version in the template.
This method attempts to check out the template before deleting; checkout() will
croak if the object is checked out by another user.
Will throw Krang::Template::NoEditAccess unless user has edit access.
'1' is returned if the deletion was successful.
deploy()duplicate_check()mark_as_deployed()The method updates the 'deployed', 'deploy_date', 'deployed_version', and 'testing' fields in the db.
mark_as_undeployed()The method updates the 'deployed', 'deploy_date', and 'deployed_version' fields in the db.
Fields may be matched using SQL matching. Appending ``_like'' to a field name will specify a case-insensitive SQL match.
@templates = Krang::Template->find(filename_like => '%' . $string . '%');
Notice that it is necessary to surround terms with '%' to perform sub-string matches.
The list valid search fields is:
Additional criteria which affect the search results are:
find() should not return live
templates. The default is 1.
NOTE:When searching for template_id, these three include_* flags are not taken into account!
The method croaks if an invalid search criteria is provided or if both the 'count' and 'ids_only' options are specified.
mark_for_testing()The method croaks if the template is not checked out or checked out by another user.
mark_for_testing()The method croaks if the template is not checked out or checked out by another user.
$all_version_numbers = $template->all_versions();$template->prune_versions(number_to_keep => 10);prune_versions() keeps
the number of versions specified by SavedVersionsPerTemplate in krang.conf;
this can be overridden as above. In either case, it returns the number of
versions actually deleted.
Reverting to a previous version effectively means deserializing the previous version from the database and using it to create a new, identical version, overwriting the values currently in the object.
The method croaks if the template is not checked out, checked out by another user, or it can't deserialize the retrieved version.
Otherwise, if the new version is successfully written to disk (no duplicate URL errors, etc.), the object itself is returned; if not, an error is returned.
save()Stores a copy of the objects current contents to the template table. The version field is incremented on each save unless called with 'keep_version' set to 1.
duplicate_check() throws an exception if the template's url isn't unique.
verify_checkout() throws an exception if the template isn't checked out or if
it's checked out to another user. The method croaks if its executed SQL affects
no rows in the DB.
Will throw Krang::Template::NoEditAccess unless user has edit access.
Will throw Krang::Template::NoCategoryEditAccess unless user has edit access to the specified category.
$template = Krang::Template->deserialize_xml(xml => $xml, set => $set, no_update => 0)If an incoming template has the same URL as an existing template then an update will occur, unless no_update is set.
Note that the creation_date, version, deploy_date, deployed_version fields are ignored when importing templates.
Also, all templates are deployed after deserialization.
verify_checkout()A Krang::Template::Checkout exception is thrown if the template isn't checked out or is checked out by another user, otherwise, '1' is returned.
$template->retire()Krang::Template->retire(template_id => $template_id)$template->unretire()Krang::Template->unretire(template_id => $template_id)$template->trash()Krang::Template->trash(template_id => $template_id)$template->untrash()Krang::Template->untrash(template_id => $template_id)$template->clone(category_id => $category_id)
* Prevent duplicate template objects and paths once pkg('Category') is
completed
Krang, Krang::DB, Krang::Log