Location: PHPKode > projects > iF.SVNAdmin > svnadmin/actions/delete_user.php
<?php
/**
 * iF.SVNAdmin
 * Copyright (c) 2010 by Manuel Freiholz
 * http://www.insanefactory.com/
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; version 2
 * of the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.
 */
if( !defined('ACTION_HANDLING') ) {
  die("HaHa!");
}
$appEngine->forwardInvalidModule(!$appEngine->isUserEditActive());
$appEngine->checkUserAuthentication(true, ACL_MOD_USER, ACL_ACTION_DELETE);

$selusers = get_request_var('selected_users');

if( $selusers == NULL )
{
  $appTemplate->addDefine("WARNING");
  $appTemplate->addReplacement("WARNINGMSG",$appTR->tr("You have to select at least one user."));
}
else
{
  $doneList = array();
  $warnList = array();
  $failedList = array();
  $selusersCount = count($selusers);

  for($i=0; $i<$selusersCount; $i++)
  {
    $u = new \svnadmin\core\entities\User;
    $u->id = $selusers[$i];
    $u->name = $selusers[$i];

    // Skip * user.
    if ($selusers[$i] == "*")
    {
      $failedList[] = $selusers[$i];
      continue;
    }

    // Remove user from groups.
    if ($appEngine->isGroupEditActive())
    {
      $appEngine->getGroupEditProvider()->removeUserFromAllGroups($u);
    }

    // Remove user from Access-Path's.
    if ($appEngine->isAccessPathEditActive())
    {
      $appEngine->getAccessPathEditProvider()->removeUserFromAllAccessPaths($u);
    }

    // Remove project-manager associations.
    if ($appEngine->isAclManagerActive())
    {
      if ($appEngine->getAclManager()->isUserAccessPathManager($u->name))
      {
        if (!$appEngine->getAclManager()->deleteAccessPathAdmin($u->name))
        {
          $warnList[] = $u->name;
        }
      }
    }

    // Remove roles of user.
    if ($appEngine->isAclManagerActive())
    {
      if ($appEngine->getAclManager()->removeAllRolesFromUser($u->name))
      {
      }
    }

    // Delete the user.
    $done = $appEngine->getUserEditProvider()->deleteUser($u);
    if ($done)
      $doneList[] = $u->name;
    else
      $failedList = $u->name;
  }
  $appEngine->getUserEditProvider()->save();

  if ($appEngine->isGroupEditActive())
    $appEngine->getGroupEditProvider()->save();

  if ($appEngine->isAccessPathEditActive())
    $appEngine->getAccessPathEditProvider()->save();

  if ($appEngine->isAclManagerActive())
    $appEngine->getAclManager()->save();

  //////////////////////////////////////////////////////////////////////////////
  // Result
  //////////////////////////////////////////////////////////////////////////////

  if (count($doneList) > 0)
  {
    $msg = tr("The following user's has been deleted:");
    $msg.= "<br>";
    $msg.= "<ul>";
    $doneList = array_unique($doneList);
    foreach ($doneList as &$valPath)
    {
      $msg.= "<li>".$valPath."</li>";
    }
    $msg.= "</ul>";
    $appTemplate->addDefine("INFO");
    $appTemplate->addReplacement("INFOMSG", $msg);
  }

  if (count($warnList) > 0)
  {
    $msg = tr("Could not remove user's Access-Path-Manager associations:");
    $msg.= "<br>";
    $msg.= "<ul>";
    $noPermList = array_unique($warnList);
    foreach ($warnList as &$valPath)
    {
      $msg.= "<li>".$valPath."</li>";
    }
    $msg.= "</ul>";
    $appTemplate->addDefine("WARNING");
    $appTemplate->addReplacement("WARNINGMSG", $msg);
  }

  if (count($failedList) > 0)
  {
    $msg = tr("Due to an unknown error, the following user's could not been deleted:");
    $msg.= "<br>";
    $msg.= "<ul>";
    $failedList = array_unique($failedList);
    foreach ($failedList as &$valPath)
    {
      $msg.= "<li>".$valPath."</li>";
    }
    $msg.= "</ul>";
    $appTemplate->addDefine("ERROR");
    $appTemplate->addReplacement("ERRORMSG", $msg);
  }
}
?>
Return current item: iF.SVNAdmin