Commit c0f06f2a authored by Côme Bernigaud's avatar Côme Bernigaud Committed by Benoit Mortier
Browse files

Fixes: #1922 Improved foreignKey handling

parent 53e4ddb2
......@@ -97,21 +97,28 @@ class pluglist {
}
if (isset($infos['plForeignKeys'])) {
foreach ($infos['plForeignKeys'] as $ofield => $pfk) {
$filter = NULL;
if (!is_array($pfk)) {
$class = $pfk;
$field = 'dn';
$infos['plForeignKeys'][$ofield] = array($class, $field);
} else {
$class = $pfk[0];
$field = $pfk[1];
if (isset($pfk[2])) {
$filter = $pfk[2];
}
}
if ($filter === NULL) {
$filter = "$ofield=%oldvalue%";
}
$infos['plForeignKeys'][$ofield] = array($class, $field, $filter);
if (!isset($foreign_refs[$class])) {
$foreign_refs[$class] = array();
}
if (!isset($foreign_refs[$class][$field])) {
$foreign_refs[$class][$field] = array();
}
$foreign_refs[$class][$field][] = array($cname, $ofield);
$foreign_refs[$class][$field][] = array($cname, $ofield, $filter);
}
} else {
$infos['plForeignKeys'] = array();
......
......@@ -70,77 +70,7 @@ class reference extends simplePlugin
$this->refs = NULL;
return;
}
$foreignRefs = array();
foreach (array_keys($this->parent->by_object) as $tabclass) {
$infos = pluglist::pluginInfos($tabclass);
foreach ($infos['plForeignRefs'] as $field => $refs) {
foreach ($refs as $ref) {
$class = $ref[0];
$ofield = $ref[1];
$cinfos = pluglist::pluginInfos($class);
foreach ($cinfos['plObjectType'] as $key => $objectType) {
if (!is_numeric($key)) {
$objectType = $key;
}
$foreignRefs[$objectType][$class][$ofield] = array($tabclass,$field);
}
}
}
}
$refs = array();
// For each concerned objectType
foreach ($foreignRefs as $objectType => $tabRefs) {
// Search objects
$objects = objects::ls($objectType, array('dn' => 'raw'));
// For each object of this type
foreach (array_keys($objects) as $dn) {
// Build the object
$tabobject = objects::open($dn, $objectType);
// For each tab concerned
foreach ($tabRefs as $tab => $fieldRefs) {
// If the tab is activated on this object
if (isset($tabobject->by_object[$tab])) {
// For each field
foreach ($fieldRefs as $ofield => $field_infos) {
list ($tabclass,$field) = $field_infos;
if ($tabobject->by_object[$tab]->foreignKeyCheck(
$ofield,
$this->parent->by_object[$tabclass]->$field,
$field
)) {
if (!isset($refs[$dn])) {
$refs[$dn] = array(
'link' => '',
'tabs' => array(),
);
try {
$refs[$dn]['link'] = objects::link($dn, $objectType);
} catch (Exception $e) {
$refs[$dn]['link'] = $dn;
}
}
if (!isset($refs[$dn]['tabs'][$tab])) {
$refs[$dn]['tabs'][$tab] = array(
'link' => '',
'fields' => array(),
);
try {
$refs[$dn]['tabs'][$tab]['link'] = objects::link($dn, $objectType, "tab_$tab", sprintf(_('Tab "%s"'), $tabobject->by_name[$tab]));
} catch (Exception $e) {
$refs[$dn]['tabs'][$tab]['link'] = $tab;
}
}
$refs[$dn]['tabs'][$tab]['fields'][$ofield] = array(
'tab' => $this->parent->by_name[$tabclass],
'field' => $field
);
}
}
}
}
}
}
$this->refs = $refs;
$this->refs = $this->browseForeignKeys('references');
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment