Page 1 of 1

[fixed] Missing function into class.CmsLayoutCollection.php

Posted: Sun Apr 19, 2015 7:19 pm
by bess
as i playing with the installation of design with my modules (very nice stuff btw) i founded this surprise :

deleting a design + its css / template without any test :
$design = CmsLayoutCollection::load("Wiki Design With Foundation");

$css_all = $design->get_stylesheets();
foreach ($css_all as $css) {
try{
$css_obj = CmsLayoutStylesheet::load($css);
if($css_obj != null){$css_obj->delete();}
} catch (CmsDataNotFoundException $e){ echo "css ".$css." not found"; }

$design->delete_stylesheet($css);
}

$tpl_all = $design->get_templates();
foreach ($tpl_all as $tpl) {
try{
$tpl_obj = CmsLayoutTemplate::load($tpl);
if($tpl_obj != null){$tpl_obj->delete();}
} catch (CmsDataNotFoundException $e){ echo "template ".$tpl." not found"; }

$design->set_templates(array());
}

try{
$design->delete();
echo "<br/>design ".$design->get_name()." deleted";
} catch (CmsException $e){ echo "design ".$design->get_name()." cannot be deleted"; echo $e->getMessage();}
as you can see we must remove "logically" the links between the design and the css/tpl even if we just remove physically the stuff in the database... ok why not even if it would be more logical to make a verification directly in the database in case of error "just to be sure" but i can understand that for the performances issues.

But if you can found in the apidoc a clear function delete_stylesheet, there is not function delete_template...

the workaround right now is to setting a empty array with set_templates(array()) ... it's not very consistent (IMHO) ;)

one more time Calguy1000 : thank you for the works you done !

Re: [Minor] Missing function into class.CmsLayoutCollection.

Posted: Sun Apr 19, 2015 7:59 pm
by calguy1000
Well, when calling $stylesheet->delete() or $template->delete() we delete the template/stylesheet from all designs the opposite is not true.

A stylesheet or a template is only optionally attached to one or more designs.

However, you are right. And I've added the method for deleting a template, and also fixed some issues with delete_stylesheet().

Re: [Minor] Missing function into class.CmsLayoutCollection.

Posted: Sun Apr 19, 2015 8:07 pm
by bess
thank you ;)