Menu

Error with new N-N link

2012-02-14
2012-12-19
  • Chambionnat

    Chambionnat - 2012-02-14

    Hi all!
    I'm trying to put a N-N relation between a newly created object which I call "Server_function" (for example dns, web, time-server…) and two server's type (the basic "Server" instance and a new one "VirtualServer", all two having  Device -> InfrastructureCI as ancestors).
    Here is what I wrote in model.itop-config-mgmt.php:

    class ServerFunction extends cmdbAbstractObject
    {
            public static function Init()
            {
                    $aParams = array
                    (
                            "category" => "bizmodel,searchable,configmgmt",
                            "key_type" => "autoincrement",
                            "name_attcode" => "name",
                            "state_attcode" => "",
                            "reconc_keys" => array("name"),
                            "db_table" => "serverfunction",
                            "db_key_field" => "id",
                            "db_finalclass_field" => "",
                            "display_template" => "",
                    );
                    MetaModel::Init_Params($aParams);
                    MetaModel::Init_InheritAttributes();
                    MetaModel::Init_AddAttribute(new AttributeString("name", array("allowed_values"=>null, "sql"=>"name", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array())));
                    MetaModel::Init_AddAttribute(new AttributeLinkedSetIndirect("server_list", array("linked_class"=>"lnkFunctionToServer", "ext_key_to_me"=>"function_id", "ext_key_to_remote"=>"server_id", "allowed_values"=>null, "count_min"=>0, "count_max"=>0, "depends_on"=>array())));
                    MetaModel::Init_SetZListItems('details', array('name', 'server_list'));
                    MetaModel::Init_SetZListItems('advanced_search', array('name', 'server_list'));
                    MetaModel::Init_SetZListItems('standard_search', array('name', 'server_list'));
                    MetaModel::Init_SetZListItems('list', array('name', 'server_list'));
            }
    }
    class lnkFunctionToServer extends cmdbAbstractObject
    {
            public static function Init()
            {
                    $aParams = array
                    (
                            "category" => "bizmodel,searchable,configmgmt",
                            "key_type" => "autoincrement",
                            "name_attcode" => "function_id",
                            "state_attcode" => "",
                            "reconc_keys" => array("function_id","server_id"),
                            "db_table" => "lnkfunctiontoserver",
                            "db_key_field" => "id",
                            "db_finalclass_field" => "",
                            "display_template" => "",
                    );
                    MetaModel::Init_Params($aParams);
                    MetaModel::Init_InheritAttributes();
                    MetaModel::Init_AddAttribute(new AttributeExternalKey("function_id", array("targetclass"=>"ServerFunction", "jointype"=>null, "allowed_values"=>null, "sql"=>"function_id", "is_null_allowed"=>false, "on_target_delete"=>DEL_AUTO, "depends_on"=>array())));
                    MetaModel::Init_AddAttribute(new AttributeExternalField("function_name", array("allowed_values"=>null, "extkey_attcode"=>"function_id", "target_attcode"=>"name", "is_null_allowed"=>true, "depends_on"=>array())));
                    MetaModel::Init_AddAttribute(new AttributeExternalKey("server_id", array("targetclass"=>"Device", "jointype"=>null, "allowed_values"=>null, "sql"=>"server_id", "is_null_allowed"=>false, "on_target_delete"=>DEL_AUTO, "depends_on"=>array())));
                    MetaModel::Init_AddAttribute(new AttributeExternalField("server_name", array("allowed_values"=>null, "extkey_attcode"=>"server_id", "target_attcode"=>"name", "is_null_allowed"=>true, "depends_on"=>array())));
                    MetaModel::Init_SetZListItems('details', array('function_id', 'server_id' ));
                    MetaModel::Init_SetZListItems('advanced_search', array('function_id', 'server_id' ));
                    MetaModel::Init_SetZListItems('standard_search', array('function_id', 'server_id' ));
                    MetaModel::Init_SetZListItems('list', array('function_id', 'server_id' ));
            }
    }
    abstract class Device extends ConnectableCI
    {
    ..........
                    MetaModel::Init_AddAttribute(new AttributeLinkedSetIndirect("function_list", array("linked_class"=>"lnkFunctionToServer", "ext_key_to_me"=>"server_id", "ext_key_to_remote"=>"function_id", "allowed_values"=>null, "count_min"=>0, "count_max"=>0, "depends_on"=>array())));
     }
    class Server extends InfrastructureCI
    {
    ..........
                    MetaModel::Init_SetZListItems('details', array('name', 'function_list','status', .... ));
    }
    

    And in dictionaries :

    // 
    // Class: ServerFunction
    //
    Dict::Add('EN US', 'English', 'English', array(
            'Class:ServerFunction' => 'ServerFunction',
            'Class:ServerFunction+' => '',
            'Class:ServerFunction/Attribute:name' => 'Function',
            'Class:ServerFunction/Attribute:name+' => '',
            'Class:ServerFunction/Attribute:server_list' => 'Servers List',
            'Class:ServerFunction/Attribute:server_list+' => '',
    ));
    // 
    // Class: lnkFunctionToServer
    //
    Dict::Add('EN US', 'English', 'English', array(
            'Class:lnkFunctionToServer' => 'lnkFunctionToServer',
            'Class:lnkFunctionToServer+' => '',
            'Class:lnkFunctionToServer/Attribute:function_id' => 'function_id',
            'Class:lnkFunctionToServer/Attribute:function_id+' => '',
            'Class:lnkFunctionToServer/Attribute:function_name' => 'name',
            'Class:lnkFunctionToServer/Attribute:function_name+' => '',
            'Class:lnkFunctionToServer/Attribute:function_type' => 'function',
            'Class:lnkFunctionToServer/Attribute:function_type+' => '',
            'Class:lnkFunctionToServer/Attribute:server_id' => 'server_id',
            'Class:lnkFunctionToServer/Attribute:server_id+' => '',
            'Class:lnkFunctionToServer/Attribute:server_name' => 'Name',
            'Class:lnkFunctionToServer/Attribute:server_name+' => '',
            'Class:lnkFunctionToServer/Attribute:friendlyname' => 'friendlyname',
            'Class:lnkFunctionToServer/Attribute:friendlyname+' => '',
    ));
    //^M
    // Class: Server^M
    //^M
    ^M
    Dict::Add('EN US', 'English', 'English', array(^M
            'Class:Server' => 'Server',^M
            'Class:Server+' => '',^M
            'Class:Server/Attribute:function_list' => 'function_list',
            'Class:Server/Attribute:function_list+' => '',
            .....
    ));
    

    But as soon as I want to see a "Server" Object (or a "VirtualServer" one), I get a white board, and this error in httpd/error_log :

    [error] [client X.X.X.X] PHP Notice:  Undefined index: server_list in /opt/data/apache2_htdocs/itop/core/metamodel.class.php on line 801, referer: http://Y.Y.Y.Y/itop/pages/UI.php?c%5Bmenu%5D=21
    [error] [client X.X.X.X] PHP Fatal error:  Call to a member function GetAllowedValues() on a non-object in /opt/data/apache2_htdocs/itop/core/metamodel.class.php on line 1100, referer: http://Y.Y.Y.Y/itop/pages/UI.php?c%5Bmenu%5D=21
    

    What is wrong?

    Thank's in advance for your help!

     
  • Chambionnat

    Chambionnat - 2012-02-15

    OK, I found why.

    In the objects which have an AttributeLinkedSetIndirect, you should not put this AttributeLinkedSetIndirect in the standard_search and list of Init_SetZListItems.

    Without it, it's okay.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.