Verified Commit eeea7186 authored by Côme Chilliet's avatar Côme Chilliet
Browse files

🚜 feat(plugins) Use error classes instead of msg_dialog::display

issue #6061
parent ae351f2b
......@@ -166,7 +166,8 @@ class argonautAction extends ManagementDialog
$o_queue = new supportDaemon();
$o_queue->append($this);
if ($o_queue->is_error()) {
msg_dialog::display(_('Infrastructure service'), msgPool::siError($o_queue->get_error()), ERROR_DIALOG);
$error = new FusionDirectoryError(msgPool::siError($o_queue->get_error()));
$error->display();
}
$this->parent->closeDialogs();
}
......
......@@ -112,19 +112,16 @@ class argonautImportFile extends simplePlugin
return;
} elseif (isset($_POST['start_import'])) {
$events = $this->events;
$error = FALSE;
$failed = FALSE;
foreach ($events as $event) {
if (!empty($event['ERROR'])) {
$error = TRUE;
$failed = TRUE;
break;
}
}
if ($error) {
msg_dialog::display(
_('Import'),
_('Fix the errors in your CSV file first'),
ERROR_DIALOG
);
if ($failed) {
$error = new FusionDirectoryError(htmlescape(_('Fix the errors in your CSV file first')));
$error->display();
} else {
$success = 0;
$fail = 0;
......@@ -138,7 +135,8 @@ class argonautImportFile extends simplePlugin
}
$this->parent->o_queue->append_call($event['HEADER'], [$event['MAC']], $data);
if ($this->parent->o_queue->is_error()) {
msg_dialog::display(_('Infrastructure service'), msgPool::siError($this->parent->o_queue->get_error()), ERROR_DIALOG);
$error = new FusionDirectoryError(msgPool::siError($this->parent->o_queue->get_error()));
$error->display();
$fail++;
} else {
unset($events[$key]);
......@@ -157,7 +155,8 @@ class argonautImportFile extends simplePlugin
/* Some file checks */
$lines = preg_split('/\n/', $str);
if (empty($str) || !count($lines)) {
msg_dialog::display(_('Import'), msgPool::incorrectUpload(_('file is empty')), ERROR_DIALOG);
$error = new FusionDirectoryError(msgPool::incorrectUpload(_('file is empty')));
$error->display();
return;
}
......
......@@ -313,7 +313,7 @@ class argonautQueue extends management
{
if (count($action['targets']) == 1) {
$entry = $this->listing->getEntry($action['targets'][0]);
msg_dialog::display(_('Error detail'), $entry['ERROR']);
msg_dialog::display(_('Error detail'), $entry['ERROR'], INFO_DIALOG);
}
}
......@@ -345,7 +345,8 @@ class argonautQueue extends management
/* Tell the daemon that we want to update some entries */
if (count($update_ids)) {
if (!$this->o_queue->process_entries_now($update_ids)) {
msg_dialog::display(_('Error'), sprintf(_('Cannot update queue entries.')), ERROR_DIALOG);
$error = new FusionDirectoryError(htmlescape(_('Cannot update queue entries.')));
$error->display();
return FALSE;
}
}
......
......@@ -63,7 +63,8 @@ class argonautQueueFilter extends managementFilter
$argonautEntries = $this->parent->o_queue->get_queued_entries($event_tags, 0, 9999999, 'id');
if ($this->parent->o_queue->is_error()) {
msg_dialog::display(_('Error'), sprintf(_('Cannot load queue entries: <br/><br/>%s'), $this->parent->o_queue->get_error()), ERROR_DIALOG);
$error = new FusionDirectoryError(msgPool::siError($this->parent->o_queue->get_error()));
$error->display();
return [[], []];
}
......
......@@ -228,8 +228,13 @@ class mailMethodCyrus extends mailMethod
}
if (!imap_set_quota($this->imap_handle, $this->account_id, $this->quotaValue)) {
msg_dialog::display(_("IMAP error"), sprintf(_("Cannot modify IMAP mailbox quota: %s"),
'<br><br><i>'.imap_last_error().'</i>'), ERROR_DIALOG);
$error = new FusionDirectoryError(
htmlescape(sprintf(
_('Cannot modify IMAP mailbox quota: %s'),
imap_last_error()
))
);
$error->display();
@DEBUG(DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__, "<b>".$this->account_id.": (".$debug_number.")</b>",
"<b>IMAP: Set account quota</b> on server '".$this->parent->gosaMailServer."' <b>".imap_last_error()."</b>");
return FALSE;
......
......@@ -68,7 +68,8 @@ class DebconfEntriesAttribute extends CompositeAttribute
//~ 'owners'
//~ 'template'
} else {
msg_dialog::display(_("Error"), _("There is no template for this profile"), ERROR_DIALOG);
$error = new SimplePluginError($this, htmlescape(_('There is no template for this profile')));
$error->display();
}
}
}
......@@ -82,9 +83,15 @@ class DebconfEntriesAttribute extends CompositeAttribute
$dn = "cn=$cn,ou=questions,".$this->plugin->dn;
$ldap->cat($dn, ["objectClass"]);
if ($ldap->count() != 1) {
msg_dialog::display(_("Error"),
sprintf(_("Can't find entry %s in LDAP for profile %s"), $cn, $this->plugin->dn),
ERROR_DIALOG);
$error = new SimplePluginError(
$this,
htmlescape(sprintf(
_('Can\'t find entry %s in LDAP for profile %s'),
$cn,
$this->plugin->dn
))
);
$error->display();
} else {
$attrs = [
'value' => [$attribute->getValue()],
......@@ -135,13 +142,17 @@ class DebconfImportAttribute extends FileAttribute
$ldap->import_complete_ldif($str, FALSE, FALSE);
$this->plugin->initially_was_account = TRUE;
} catch (FusionDirectoryException $e) {
msg_dialog::display(_('LDAP error'), $e->getMessage(), ERROR_DIALOG);
$error = new SimplePluginError($this, htmlescape($e->getMessage()), 0, $e);
$error->display();
}
} else {
msg_dialog::display(_("LDIF error"), "Could not found template name in the ldif ".
"was expecting ou=<b>name</b>,ou=templates,".
get_ou("debconfRDN").$config->current['BASE'],
ERROR_DIALOG);
$error = new SimplePluginError(
$this,
"Could not find template name in the ldif ".
"was expecting ou=<b>name</b>,ou=templates,".
htmlescape(get_ou("debconfRDN").$config->current['BASE'])
);
$error->display();
}
}
......
......@@ -432,7 +432,8 @@ class DhcpSectionsAttribute extends DialogOrderedArrayAttribute
}
/* That should not happen... */
msg_dialog::display(_('Error'), _('The DHCP configuration set is unkown. Please contact your system administrator.'), ERROR_DIALOG);
$error = new SimplePluginError($this, htmlescape(_('The DHCP configuration set is unkown. Please contact your system administrator.')));
$error->display();
return '';
}
......
......@@ -76,16 +76,28 @@ class dnsManagement extends management
list ($fqdn) = explode(' ', $entry['sOARecord'][0]);
$servers = static::findServerByFQDN($fqdn, $zoneDn);
if (count($servers) > 1) {
msg_dialog::display(_('Could not run ldap2zone'), _('More than one server matches the SOA'), ERROR_DIALOG);
$error = new FusionDirectoryError(
htmlescape(sprintf(
_('Could not run ldap2zone: %s'),
_('More than one server matches the SOA')
))
);
$error->display();
} elseif (count($servers) == 0) {
msg_dialog::display(_('Could not run ldap2zone'), sprintf(_('Could not find the primary server "%s"'), $fqdn), ERROR_DIALOG);
$error = new FusionDirectoryError(
htmlescape(sprintf(
_('Could not run ldap2zone: %s'),
sprintf(_('Could not find the primary server "%s"'), $fqdn)
))
);
$error->display();
} else {
$serverTabs = objects::open(key($servers), 'server');
if ($serverTabs->by_object['argonautClient']->is_account) {
$s_daemon = new supportDaemon();
if ($s_daemon->is_error()) {
msg_dialog::display(_('Could not run ldap2zone'), msgPool::siError($s_daemon->get_error()), ERROR_DIALOG
);
$error = new FusionDirectoryError(msgPool::siError($s_daemon->get_error()));
$error->display();
} else {
$target = $serverTabs->getBaseObject()->macAddress;
if (is_array($target)) {
......@@ -94,13 +106,15 @@ class dnsManagement extends management
$zoneName = $entry['zoneName'];
$s_daemon->append_call('Ldap2Zone.start', $target, ['args' => [$zoneName]]);
if ($s_daemon->is_error()) {
msg_dialog::display(_('Could not get run ldap2zone'), msgPool::siError($s_daemon->get_error()), ERROR_DIALOG);
$error = new FusionDirectoryError(msgPool::siError($s_daemon->get_error()));
$error->display();
} else {
msg_dialog::display(_('Ldap2zone'), sprintf(_('Ldap2Zone called for zone "%s"'), $zoneName), INFO_DIALOG);
}
}
} else {
msg_dialog::display(_('Error'), _('Argonaut client needs to be activated to use ldap2zone remotely'), ERROR_DIALOG);
$error = new FusionDirectoryError(htmlescape(_('Argonaut client needs to be activated to use ldap2zone remotely')));
$error->display();
}
}
}
......
......@@ -376,11 +376,15 @@ class DnsRecordsAttribute extends DialogOrderedArrayAttribute
list ($domain, $type, $content, $reverse) = $line;
if (!empty($reverse)) {
if (!DnsRecordAttribute::matchReverseZone($type, $content, $reverse)) {
msg_dialog::display(
_('Error'),
sprintf(_('The IP %s does not match the selected reverse %s, it has been ignored'), $content, $reverse),
ERROR_DIALOG
$error = new SimplePluginError(
$this,
htmlescape(sprintf(
_('The IP %s does not match the selected reverse %s, it has been ignored'),
$content,
$reverse
))
);
$error->display();
} else {
if (!isset($ptrs[$reverse])) {
$ptrs[$reverse] = [];
......@@ -480,7 +484,8 @@ class DnsRecordsAttribute extends DialogOrderedArrayAttribute
}
$ldap->modify($node);
if (!$ldap->success()) {
msg_dialog::display(_('LDAP error'), msgPool::ldaperror($ldap->get_error(), $reverseDn, LDAP_MOD, get_class()), LDAP_ERROR);
$error = new SimplePluginLdapError($this, $reverseDn, LDAP_MOD, $ldap->get_error(), $ldap->get_errno());
$error->display();
}
unset($oldReverseZones[$reverseDn]);
} else {
......@@ -489,7 +494,8 @@ class DnsRecordsAttribute extends DialogOrderedArrayAttribute
}
$ldap->add($node);
if (!$ldap->success()) {
msg_dialog::display(_('LDAP error'), msgPool::ldaperror($ldap->get_error(), $reverseDn, LDAP_ADD, get_class()), LDAP_ERROR);
$error = new SimplePluginLdapError($this, $reverseDn, LDAP_ADD, $ldap->get_error(), $ldap->get_errno());
$error->display();
}
}
}
......@@ -497,7 +503,8 @@ class DnsRecordsAttribute extends DialogOrderedArrayAttribute
foreach (array_keys($oldReverseZones) as $dn) {
$ldap->rmdir_recursive($dn);
if (!$ldap->success()) {
msg_dialog::display(_('LDAP error'), msgPool::ldaperror($ldap->get_error(), $dn, LDAP_DEL, get_class()), LDAP_ERROR);
$error = new SimplePluginLdapError($this, $dn, LDAP_DEL, $ldap->get_error(), $ldap->get_errno());
$error->display();
}
}
/* Delete old records not present in new list */
......@@ -505,7 +512,8 @@ class DnsRecordsAttribute extends DialogOrderedArrayAttribute
if (!isset($nodes[$dn])) {
$ldap->rmdir_recursive($dn);
if (!$ldap->success()) {
msg_dialog::display(_('LDAP error'), msgPool::ldaperror($ldap->get_error(), $dn, LDAP_DEL, get_class()), LDAP_ERROR);
$error = new SimplePluginLdapError($this, $dn, LDAP_DEL, $ldap->get_error(), $ldap->get_errno());
$error->display();
}
}
}
......@@ -522,11 +530,14 @@ class DnsRecordsAttribute extends DialogOrderedArrayAttribute
}
}
$ldap->modify($node);
$operation = LDAP_MOD;
} else {
$ldap->add($node);
$operation = LDAP_ADD;
}
if (!$ldap->success()) {
msg_dialog::display(_('LDAP error'), msgPool::ldaperror($ldap->get_error(), $dn, LDAP_MOD, get_class()), LDAP_ERROR);
$error = new SimplePluginLdapError($this, $dn, $operation, $ldap->get_error(), $ldap->get_errno());
$error->display();
}
}
......@@ -560,13 +571,15 @@ class DnsRecordsAttribute extends DialogOrderedArrayAttribute
if (isset($initialPtrs[$reverseZone][$ip])) {
$ldap->modify($node);
if (!$ldap->success()) {
msg_dialog::display(_('LDAP error'), msgPool::ldaperror($ldap->get_error(), $dn, LDAP_MOD, get_class()), LDAP_ERROR);
$error = new SimplePluginLdapError($this, $dn, LDAP_MOD, $ldap->get_error(), $ldap->get_errno());
$error->display();
}
unset($initialPtrs[$reverseZone][$ip]);
} else {
$ldap->add($node);
if (!$ldap->success()) {
msg_dialog::display(_('LDAP error'), msgPool::ldaperror($ldap->get_error(), $dn, LDAP_ADD, get_class()), LDAP_ERROR);
$error = new SimplePluginLdapError($this, $dn, LDAP_ADD, $ldap->get_error(), $ldap->get_errno());
$error->display();
}
}
}
......@@ -578,7 +591,8 @@ class DnsRecordsAttribute extends DialogOrderedArrayAttribute
$dn = 'relativeDomainName='.$relativeDomainName.','.$reverseDn;
$ldap->rmdir_recursive($dn);
if (!$ldap->success()) {
msg_dialog::display(_('LDAP error'), msgPool::ldaperror($ldap->get_error(), $dn, LDAP_DEL, get_class()), LDAP_ERROR);
$error = new SimplePluginLdapError($this, $dn, LDAP_DEL, $ldap->get_error(), $ldap->get_errno());
$error->display();
}
}
}
......
......@@ -334,8 +334,8 @@ class dnsHost extends simplePlugin
if ($this->parent->by_object['argonautClient']->is_account) {
$s_daemon = new supportDaemon();
if ($s_daemon->is_error()) {
msg_dialog::display(_('Could not run ldap2zone'), msgPool::siError($s_daemon->get_error()), ERROR_DIALOG
);
$error = new SimplePluginError($this, msgPool::siError($s_daemon->get_error()));
$error->display();
} else {
$target = $this->parent->getBaseObject()->macAddress;
if (is_array($target)) {
......@@ -343,13 +343,15 @@ class dnsHost extends simplePlugin
}
$s_daemon->append_call('Ldap2Zone.start', $target, ['args' => [$zone]]);
if ($s_daemon->is_error()) {
msg_dialog::display(_('Could not run ldap2zone'), msgPool::siError($s_daemon->get_error()), ERROR_DIALOG);
$error = new SimplePluginError($this, msgPool::siError($s_daemon->get_error()));
$error->display();
} else {
msg_dialog::display(_('Ldap2zone'), sprintf(_('Ldap2Zone called for zone "%s"'), $zone), INFO_DIALOG);
}
}
} else {
msg_dialog::display(_('Error'), _('Argonaut client needs to be activated to use ldap2zone remotely'), ERROR_DIALOG);
$error = new SimplePluginError($this, htmlescape(_('Argonaut client needs to be activated to use ldap2zone remotely')));
$error->display();
}
}
}
......
......@@ -142,11 +142,13 @@ class DiskPartitionsAttribute extends DialogOrderedArrayAttribute
*/
if (isset($list[$this->postValue[$key]['cn']])) {
$used = implode(',', array_values($list[$this->postValue[$key]['cn']]));
msg_dialog::display(
_('Error'),
sprintf(_('The partition cannot be deleted while it is used in the "%s" disk definition!'), $used),
ERROR_DIALOG
$error = new FusionDirectoryError(
htmlescape(sprintf(
_('The partition cannot be deleted while it is used in the "%s" disk definition!'),
$used
))
);
$error->display();
} else {
unset($this->postValue[$key]);
}
......
......@@ -56,7 +56,8 @@ class faiPackageConfiguration extends simplePlugin
$q = new supportDaemon();
$ret = $q->FAI_get_packages($release, ['package','template'], [$this->packageName], 0, 1, TRUE);
if ($q->is_error()) {
msg_dialog::display(_('Infrastructure service'), msgPool::siError($q->get_error()), ERROR_DIALOG);
$error = new FusionDirectoryError(msgPool::siError($q->get_error()));
$error->display();
}
$tpl = '';
......
......@@ -243,7 +243,8 @@ class PartitionTableAttribute extends DialogOrderedArrayAttribute
foreach ($delete as $dn) {
$ldap->rmdir_recursive($dn);
if (!$ldap->success()) {
msg_dialog::display(_('LDAP error'), msgPool::ldaperror($ldap->get_error(), $dn, LDAP_ADD, get_class()), LDAP_ERROR);
$error = new SimplePluginLdapError($this, $dn, LDAP_DEL, $ldap->get_error(), $ldap->get_errno());
$error->display();
}
}
/* Then add our values */
......@@ -284,7 +285,8 @@ class PartitionTableAttribute extends DialogOrderedArrayAttribute
}
$ldap->add($attrs);
if (!$ldap->success()) {
msg_dialog::display(_('LDAP error'), msgPool::ldaperror($ldap->get_error(), $dn, LDAP_ADD, get_class()), LDAP_ERROR);
$error = new SimplePluginLdapError($this, $dn, LDAP_ADD, $ldap->get_error(), $ldap->get_errno());
$error->display();
}
}
......
......@@ -106,7 +106,8 @@ class FAITemplateFilesAttribute extends DialogOrderedArrayAttribute
}
$ldap->add($attrs);
if (!$ldap->success()) {
msg_dialog::display(_('LDAP error'), msgPool::ldaperror($ldap->get_error(), $dn, LDAP_ADD, get_class()), LDAP_ERROR);
$error = new SimplePluginLdapError($this, $dn, LDAP_ADD, $ldap->get_error(), $ldap->get_errno());
$error->display();
}
}
......
......@@ -206,7 +206,8 @@ class PackagesAttribute extends DialogOrderedArrayAttribute
}
$ldap->add($attrs);
if (!$ldap->success()) {
msg_dialog::display(_('LDAP error'), msgPool::ldaperror($ldap->get_error(), $vardn, LDAP_ADD, get_class()), LDAP_ERROR);
$error = new SimplePluginLdapError($this, $vardn, LDAP_ADD, $ldap->get_error(), $ldap->get_errno());
$error->display();
}
}
}
......@@ -242,7 +243,8 @@ class PackagesAttribute extends DialogOrderedArrayAttribute
}
$ret = $q->FAI_get_packages($release, $attrs, array_keys($packages), -1, -1, TRUE);
if ($q->is_error()) {
msg_dialog::display(_("Infrastructure service"), msgPool::siError($q->get_error()), ERROR_DIALOG);
$error = new FusionDirectoryError(msgPool::siError($q->get_error()));
$error->display();
return $this->buffer;
} else {
foreach ($ret as $attr) {
......@@ -261,7 +263,13 @@ class PackagesAttribute extends DialogOrderedArrayAttribute
}
if (count($packages) > 0) {
msg_dialog::display(_("Unkown packages"), "The following packages were not found on the repository : ".join(",", $packages), ERROR_DIALOG);
$error = new FusionDirectoryError(
htmlescape(sprintf(
_('The following packages were not found on the repository : %s'),
join(',', $packages)
))
);
$error->display();
foreach ($packages as $p => $pp) {
unset($this->value[$p]);
}
......
......@@ -47,12 +47,14 @@ class packageSelectManagementFilter extends managementFilter
$ret = $q->FAI_get_packages($release, $attrs, $filter, 0, 200);
if ($q->is_error()) {
msg_dialog::display(_('Infrastructure service'), msgPool::siError($q->get_error()), ERROR_DIALOG);
$error = new FusionDirectoryError(msgPool::siError($q->get_error()));
$error->display();
} else {
for ($i = 0;(count($ret) < 200) && ($i < count($customs));$i++) {
$ret2 = $q->FAI_get_packages($customs[$i], $attrs, $filter, 0, 200 - count($ret));
if ($q->is_error()) {
msg_dialog::display(_('Infrastructure service'), msgPool::siError($q->get_error()), ERROR_DIALOG);
$error = new FusionDirectoryError(msgPool::siError($q->get_error()));
$error->display();
return [];
}
$ret = array_merge($ret, $ret2);
......
......@@ -195,7 +195,8 @@ class faiLogView extends simplePlugin
/* Query for log files */
$res = $this->o_queue->get_log_info_for_mac($this->mac);
if ($this->o_queue->is_error()) {
msg_dialog::display(_("Error"), $this->o_queue->get_error(), ERROR_DIALOG);
$error = new FusionDirectoryError(msgPool::siError($this->o_queue->get_error()));
$error->display();
}
/* Check if there is at least one log file */
......@@ -237,7 +238,8 @@ class faiLogView extends simplePlugin
{
$res = $this->o_queue->get_log_file($mac, $date, $file);
if ($this->o_queue->is_error()) {
msg_dialog::display(_('Error'), $this->o_queue->get_error(), ERROR_DIALOG);
$error = new FusionDirectoryError(msgPool::siError($this->o_queue->get_error()));
$error->display();
}
$res = nl2br(htmlescape($res));
return $res;
......
......@@ -260,7 +260,8 @@ class serviceRepository extends simpleService
}
}
} else {
msg_dialog::display(_('LDAP error'), msgPool::ldaperror($ldap->get_error(), $dn, LDAP_ADD, get_class()), LDAP_ERROR);
$error = new FusionDirectoryLdapError($dn, LDAP_ADD, $ldap->get_error(), $ldap->get_errno());
$error->display();
}
}
}
......
......@@ -63,7 +63,8 @@ class pgpKeySelect extends selectManagement
$infos = objects::infos($this->objectTypes[0]);
if ($infos['ou'] == 'unknown') {
msg_dialog::display(_('Configuration error'), _('You need to configure GPG base dn through the addons section first'));
$error = new FusionDirectoryError(htmlescape(_('You need to configure GPG base dn through the addons section first')));
$error->display();
}
}
......
......@@ -30,7 +30,8 @@ class RegistrationLastChangeAttribute extends DisplayLDAPAttribute
try {
$date = new DateTime($ldapDate);
} catch (Exception $e) {
msg_dialog::display(_('Error'), $e->getMessage(), ERROR_DIALOG);
$error = new FusionDirectoryError(htmlescape($e->getMessage()), 0, $e);
$error->display();
$date = new DateTime();
}
$date->setTimezone(timezone::getDefaultTimeZone());
......
......@@ -127,11 +127,14 @@ class registrationManagement extends management
foreach ($action['targets'] as $dn) {
// Lock registration object
if ($user = get_lock($dn)) {
msg_dialog::display(
_('Error'),
sprintf(_('Cannot accept %s. It has been locked by %s.'), $dn, $user),
ERROR_DIALOG
$error = new FusionDirectoryError(
htmlescape(sprintf(
_('Cannot accept %s. It has been locked by %s.'),
$dn,
$user
))
);
$error->display();
continue;
}
add_lock($dn, $ui->dn);
......@@ -139,22 +142,27 @@ class registrationManagement extends management
$entry = $this->listing->getEntry($dn);
if (!$this->enableAcceptReject('accept', $entry)) {
msg_dialog::display(
_('Error'),
sprintf(_('Cannot accept registration %s, it\'s not in status "Filled".'), $dn),
ERROR_DIALOG
$error = new FusionDirectoryError(
htmlescape(sprintf(
_('Cannot accept registration %s, it\'s not in status "Filled".'),
$dn
))
);
$error->display();
del_lock($dn);
continue;
}
// Lock user object
if ($user = get_lock($entry['fdRegistrationUserDN'][0])) {
msg_dialog::display(
_('Error'),
sprintf(_('Cannot move %s. It has been locked by %s.'), $entry['fdRegistrationUserDN'][0], $user),
ERROR_DIALOG
$error = new FusionDirectoryError(
htmlescape(sprintf(
_('Cannot move %s. It has been locked by %s.'),
$entry['fdRegistrationUserDN'][0],
$user