/**
  * Saves a structure
  *
  * @param StructureModel $structure
  *
  * @throws Exception
  * @return bool
  */
 public function saveStructure(StructureModel $structure)
 {
     if ($structure->id) {
         $structureRecord = StructureRecord::model()->findById($structure->id);
         if (!$structureRecord) {
             throw new Exception(Craft::t('No structure exists with the ID “{id}”.', array('id' => $structure->id)));
         }
     } else {
         $structureRecord = new StructureRecord();
     }
     $structureRecord->maxLevels = $structure->maxLevels;
     $success = $structureRecord->save();
     if ($success) {
         $structure->id = $structureRecord->id;
     } else {
         $structure->addErrors($structureRecord->getErrors());
     }
     return $success;
 }