Exemplo n.º 1
0
 /**
  * Delete a group
  *
  * @param \Model\Group\Group $group
  * @throws \Model\Group\RuntimeException if group is locked
  */
 public function deleteGroup(\Model\Group\Group $group)
 {
     if (!$group->lock()) {
         throw new RuntimeException('Cannot delete group because it is locked');
     }
     $id = $group['Id'];
     $connection = $this->_serviceManager->get('Db')->getDriver()->getConnection();
     $connection->beginTransaction();
     try {
         $this->_serviceManager->get('Database\\Table\\GroupMemberships')->delete(array('group_id' => $id));
         $this->_serviceManager->get('Database\\Table\\ClientConfig')->delete(array('hardware_id' => $id));
         $this->_serviceManager->get('Database\\Table\\GroupInfo')->delete(array('hardware_id' => $id));
         $this->_serviceManager->get('Database\\Table\\ClientsAndGroups')->delete(array('id' => $id));
         $connection->commit();
     } catch (\Exception $e) {
         $connection->rollBack();
         $group->unlock();
         throw $e;
     }
     $group->unlock();
 }