public function downgrade() {
		$template = $this->getTemplate($this->getTemplateName());
		$fieldgroup = $template->fieldgroup;

		$fg = $this->wire('fieldgroups')->get($template->name);
		$minNumberToError = $fg->id == $fieldgroup->id ? 2 : 1;

		if($fg->numTemplates() >= $minNumberToError) 
			throw new WireException("Cannot delete $template->name, because it's fieldgroup is used by at least one other template.");

		// Remove all pages of that template
		$selector = "template=$template, include=all, check_access=0";
		$this->eachPageUncache($selector, function($p) { $this->pages->delete($p, true); });

		// Delete fieldgroup and template
		$this->templates->delete($template);
		$this->fieldgroups->delete($fieldgroup);
	}
public function downgrade() {
		$template = $this->getTemplate($this->getTemplateName());
		$fieldgroup = $template->fieldgroup;

		$fg = $this->wire('fieldgroups')->get($template->name);
		$minNumberToError = $fg->id == $fieldgroup->id ? 2 : 1;

		if($fg->numTemplates() >= $minNumberToError) 
			throw new WireException("Cannot delete $template->name, because it's fieldgroup is used by at least one other template.");

		// Remove all pages of that template
		$selector = "template=$template, include=all, check_access=0";
		$this->eachPageUncache($selector, function($p) { $this->pages->delete($p, true); });

		// Delete fieldgroup and template
		$this->templates->delete($template);
		$this->fieldgroups->delete($fieldgroup);
	}
public function downgrade ( ) { $ template = $ this -> getTemplate ( $ this -> getTemplateName ( ) ) ; $ fieldgroup = $ template -> fieldgroup ; $ fg = $ this -> wire ( 'fieldgroups' ) -> get ( $ template -> name ) ; $ minNumberToError = $ fg -> id == $ fieldgroup -> id ? 2 : 1 ; if ( $ fg -> numTemplates ( ) >= $ minNumberToError ) throw new WireException ( "Cannot delete $template->name, because it's fieldgroup is used by at least one other template." ) ; // Remove all pages of that template $ selector = "template=$template, include=all, check_access=0" ; $ this -> eachPageUncache ( $ selector , function ( $ p ) { $ this -> pages -> delete ( $ p , true ) ; } ) ; // Delete fieldgroup and template $ this -> templates -> delete ( $ template ) ; $ this -> fieldgroups -> delete ( $ fieldgroup ) ; }
Delete the template
Does delete all pages of that template and does even delete system templates
Delete the template Does delete all pages of that template and does even delete system templates