changetype delete
This commit is contained in:
parent
1cbe9d546f
commit
fe3c054825
|
@ -278,6 +278,12 @@ class Importer {
|
||||||
elseif ($type === 'modrdn') {
|
elseif ($type === 'modrdn') {
|
||||||
return $this->createModRdnTask($dn, $entry);
|
return $this->createModRdnTask($dn, $entry);
|
||||||
}
|
}
|
||||||
|
elseif ($type === 'delete') {
|
||||||
|
if (!empty($entry)) {
|
||||||
|
throw new LAMException(_('Invalid data'), htmlspecialchars($dn));
|
||||||
|
}
|
||||||
|
return new DeleteEntryTask($dn);
|
||||||
|
}
|
||||||
$changes = array();
|
$changes = array();
|
||||||
$subtasks = array();
|
$subtasks = array();
|
||||||
$currentLines = array();
|
$currentLines = array();
|
||||||
|
@ -477,6 +483,39 @@ class RenameEntryTask implements ImporterTask {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes an LDAP entry.
|
||||||
|
*
|
||||||
|
* @author Roland Gruber
|
||||||
|
*/
|
||||||
|
class DeleteEntryTask implements ImporterTask {
|
||||||
|
|
||||||
|
private $dn = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*
|
||||||
|
* @param string $dn DN
|
||||||
|
*/
|
||||||
|
public function __construct($dn) {
|
||||||
|
$this->dn = $dn;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
* @see \LAM\TOOLS\IMPORT_EXPORT\ImporterTask::run()
|
||||||
|
*/
|
||||||
|
public function run() {
|
||||||
|
$ldap = $_SESSION['ldap']->server();
|
||||||
|
$success = @ldap_delete($ldap, $this->dn);
|
||||||
|
if ($success) {
|
||||||
|
return Importer::formatMessage('INFO', sprintf(_('Successfully deleted DN %s'), $this->dn), '');
|
||||||
|
}
|
||||||
|
throw new LAMException(_('Could not delete the entry.') . '<br>' . $this->dn, getExtendedLDAPErrorMessage($ldap));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Combines multiple import tasks.
|
* Combines multiple import tasks.
|
||||||
*
|
*
|
||||||
|
|
|
@ -4,6 +4,7 @@ use LAM\TOOLS\IMPORT_EXPORT\MultiTask;
|
||||||
use LAM\TOOLS\IMPORT_EXPORT\AddAttributesTask;
|
use LAM\TOOLS\IMPORT_EXPORT\AddAttributesTask;
|
||||||
use LAM\TOOLS\IMPORT_EXPORT\AddEntryTask;
|
use LAM\TOOLS\IMPORT_EXPORT\AddEntryTask;
|
||||||
use LAM\TOOLS\IMPORT_EXPORT\RenameEntryTask;
|
use LAM\TOOLS\IMPORT_EXPORT\RenameEntryTask;
|
||||||
|
use LAM\TOOLS\IMPORT_EXPORT\DeleteEntryTask;
|
||||||
/*
|
/*
|
||||||
|
|
||||||
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
|
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
|
||||||
|
@ -220,4 +221,40 @@ class ImporterTest extends PHPUnit_Framework_TestCase {
|
||||||
$this->assertEquals(RenameEntryTask::class, get_class($task));
|
$this->assertEquals(RenameEntryTask::class, get_class($task));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Change entry with delete changetype with extra line.
|
||||||
|
*/
|
||||||
|
public function testChangeDeleteInvalid() {
|
||||||
|
$lines = array(
|
||||||
|
"version: 1",
|
||||||
|
"",
|
||||||
|
"dn: uid=test,dc=example,dc=com",
|
||||||
|
"changeType: delete",
|
||||||
|
"uid: test",
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->setExpectedException(LAMException::class, 'uid=test,dc=example,dc=com');
|
||||||
|
|
||||||
|
$importer = new Importer();
|
||||||
|
$tasks = $importer->getTasks($lines);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Change entry with delete changetype.
|
||||||
|
*/
|
||||||
|
public function testChangeDelete() {
|
||||||
|
$lines = array(
|
||||||
|
"version: 1",
|
||||||
|
"",
|
||||||
|
"dn: uid=test,dc=example,dc=com",
|
||||||
|
"changeType: delete",
|
||||||
|
);
|
||||||
|
|
||||||
|
$importer = new Importer();
|
||||||
|
$tasks = $importer->getTasks($lines);
|
||||||
|
$this->assertEquals(1, sizeof($tasks));
|
||||||
|
$task = $tasks[0];
|
||||||
|
$this->assertEquals(DeleteEntryTask::class, get_class($task));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue