<?php
namespace nur\ldap\app;

use nulib\output\msg;
use nur\ldap\LdapSearch;
use nur\ldap\LdapWalker;

class LdapDeleteApp extends LdapApplication {
  const ARGS = [
    "merge" => parent::ARGS,
    ["-s", "--scope", "args" => 1],
    ["-b", "--searchbase", "args" => 1],
    ["-B", "--searchbase-exact", "args" => 1],
  ];

  protected $scope;
  protected $searchbase, $searchbaseExact;
  protected $args;

  function main() {
    $conn = $this->getConn();

    $params = [];
    LdapSearch::parse_args($params, $this->args
      , $this->searchbase, $this->searchbaseExact
      , $this->scope);
    /** @var LdapWalker $lo */
    $lo = $conn->search(null, $params);
    while ($lo->next($first)) {
      msg::action("Suppression $lo[dn]");
      $lo->delete();
      msg::asuccess();
    }
  }
}
