Menu

PHP code from XML file is not being compiled

2023-04-27
2023-04-28
  • Abdullah Noman

    Abdullah Noman - 2023-04-27

    Hello there,

    I have a xml file name datamodel.network.xml for my extensions and inside it I have the following code:
    <methods>
    <method id="OnUpdate" _delta="define">
    <static>false</static> <access>public</access>
    <type>Overload-DBObject</type>
    <![CDATA[public function onUpdate() {
    try { $iCommunityID = $this->Get("community");
    $oCommunity = MetaModel::GetObject('Comm_clli', $iCommunityID, true, false, null);
    if ($oCommunity === null) {
    throw new Exception('Failed to load Community object with ID: ' . $iCommunityID);
    }
    $sClli = $oCommunity->Get("clli");
    if ($sClli === null) {
    throw new Exception('Community object with ID ' . $iCommunityID . ' does not have a value for "clli" attribute');
    }
    $this->Set('clli', $sClli);
    $this->DBUpdate();
    } catch (Exception $e) {
    $this->Set('clli', null); $this->DBUpdate(); throw $e;
    }
    parent::OnUpdate(); }
    ]
    ]>

    </method>
    </methods>

    These codes are not compiling into the model.network.php file and I can not figure out why. If anyone have any idea please help. Thanks
    Kind Regards,

    Abdullah

     
  • Guillaume Lajarige

    Hello Abdullah,

    Do you have a "model.network.php" file in your module?
    Is it referenced in the "datamodel" section of the "module.network.php" file of the module?

    If you can share the whole module here, it might be easier to help :)

    Hope it helps,
    Guillaume

     
  • Abdullah Noman

    Abdullah Noman - 2023-04-27

    Hello Guillaume,
    Thanks for the quick response. I do have a model.network.php file and it is also being referenced in the module.network.php file. Check the attachements please.
    the file name mb-network-db is the actual file name of my xml file , I used network previosult just to keep things concise and no issue is there with the name.

     
  • Guillaume Lajarige

    Can you share the complete XML please?

     
  • Abdullah Noman

    Abdullah Noman - 2023-04-27

    Here it is:
    <class id="LocationMB" _delta="define">
    <parent>cmdbAbstractObject</parent>
    <properties>
    <category>bizmodel,searchable</category>
    <abstract>false</abstract>
    <key_type>autoincrement</key_type>
    <db_table>locationmb</db_table>
    <db_key_field>id</db_key_field>
    <db_final_class_field>
    <naming>
    <format>%1$s</format>

    <attributes>
    <attribute id="community">
    </attribute></attributes>
    </naming>
    <display_template>
    <style><br> <icon>/icons/icons8-map-marker.svg</icon><br> </style>

    <reconciliation>
    <attributes>
    <attribute id="community">
    </attribute></attributes>
    </reconciliation>
    </display_template></db_final_class_field></properties>

    <fields></fields></class>

                <field id="org_id" xsi:type="AttributeExternalKey">
                    <sql>org_id</sql>
                    <target_class>OrganizationMB</target_class>
                    <is_null_allowed>true</is_null_allowed>
                    <on_target_delete>DEL_MANUAL</on_target_delete>
                    <allow_target_creation>false</allow_target_creation>
                </field>
                <field id="location_id" xsi:type="AttributeInteger">
                    <sql>location_id</sql>
                    <default_value/>
                    <is_null_allowed>true</is_null_allowed>
                </field>
    
                <field id="facility_contact_name" xsi:type="AttributeString">
                    <sql>facility_contact_name</sql>
                    <default_value/>
                    <is_null_allowed>true</is_null_allowed>
                </field>
                <field id="address" xsi:type="AttributeString">
                    <sql>address</sql>
                    <default_value/>
                    <is_null_allowed>true</is_null_allowed>
                </field>
                <field id="facility_email" xsi:type="AttributeEmailAddress">
                    <sql>facility_email</sql>
                    <default_value/>
                    <is_null_allowed>true</is_null_allowed>
                </field>
                <field id="gps_coord" xsi:type="AttributeString">
                    <sql>gps_coord</sql>
                    <default_value/>
                    <is_null_allowed>true</is_null_allowed>
                </field>
                <field id="loc_desc" xsi:type="AttributeString">
                    <sql>loc_desc</sql>
                    <default_value/>
                    <is_null_allowed>true</is_null_allowed>
                </field>
                <field id="clli" xsi:type="AttributeString">
                    <sql>clli</sql>
                    <default_value/>
                    <is_null_allowed>true</is_null_allowed>
                </field>
                <field id="facility_contact_num" xsi:type="AttributePhoneNumber">
                    <sql>facility_contact_num</sql>
                    <default_value/>
                    <is_null_allowed>true</is_null_allowed>
                </field>
                <field id="community" xsi:type="AttributeExternalKey">
                    <sql>community</sql>
                    <target_class>Comm_clli</target_class>
                    <is_null_allowed>true</is_null_allowed>
                    <on_target_delete>DEL_MANUAL</on_target_delete>
                    <allow_target_creation>false</allow_target_creation>
                </field>
                <field id="notes" xsi:type="AttributeText">
                    <sql>notes</sql>
                    <default_value/>
                    <is_null_allowed>true</is_null_allowed>
                </field>
                <field id="devices" xsi:type="AttributeLinkedSet" _delta="define">
                    <linked_class>Device</linked_class>
                    <ext_key_to_me>location_id</ext_key_to_me>
                    <edit_mode>add_only</edit_mode>
                    <count_min>0</count_min>
                    <count_max>0</count_max>
                    <relation_type>link</relation_type>
                    <read_only>false</read_only>
                </field>
                <field id="circuits" xsi:type="AttributeLinkedSet" _delta="define">
                    <linked_class>Circuit</linked_class>
                    <ext_key_to_me>location_id</ext_key_to_me>
                    <edit_mode>add_only</edit_mode>
                    <count_min>0</count_min>
                    <count_max>0</count_max>
                    <relation_type>link</relation_type>
                    <read_only>false</read_only>
                </field>
            </fields>
      <methods> 
            </methods>
            <presentation>
                <!-- fields that will show up in the presentation-->
                <details>
                    <items>
                        <item id="community">
                            <rank>20</rank>
                        </item>
                        <item id="devices">
                            <rank>30</rank>
                        </item>
                        <item id="circuits">
                            <rank>40</rank>
                        </item>
                        <item id="facility_contact_name">
                            <rank>50</rank>
                        </item>
                        <item id="address">
                            <rank>60</rank>
                        </item>
                        <item id="facility_email">
                            <rank>70</rank>
                        </item>
                        <item id="gps_coord">
                            <rank>80</rank>
                        </item>
                        <item id="loc_desc">
                            <rank>90</rank>
                        </item>
                        <item id="clli">
                            <rank>100</rank>
                        </item>
                        <item id="facility_contact_num">
                            <rank>110</rank>
                        </item>
                        <item id="org_id">
                            <rank>120</rank>
                        </item>
                        <item id="notes">
                            <rank>130</rank>
                        </item>
                    </items>
                </details>
                <!-- fields that shows up in the search list -->
                <search>
                    <items>
                        <item id="community">
                            <rank>10</rank>
                        </item>
                        <item id="devices">
                            <rank>20</rank>
                        </item>
                        <item id="circuits">
                            <rank>30</rank>
                        </item>
                        <item id="facility_contact_name">
                            <rank>40</rank>
                        </item>
                        <item id="address">
                            <rank>50</rank>
                        </item>
                        <item id="facility_email">
                            <rank>60</rank>
                        </item>
                        <item id="gps_coord">
                            <rank>70</rank>
                        </item>
                        <item id="loc_desc">
                            <rank>80</rank>
                        </item>
                        <item id="clli">
                            <rank>90</rank>
                        </item>
                        <item id="facility_contact_num">
                            <rank>100</rank>
                        </item>
                        <item id="org_id">
                            <rank>110</rank>
                        </item>
                        <item id="notes">
                            <rank>120</rank>
                        </item>
                    </items>
                </search>
                <!-- fields that shows up in the table list -->
                <list>
                    <items>
                        <item id="devices">
                            <rank>10</rank>
                        </item>
                        <item id="circuits">
                            <rank>20</rank>
                        </item>
                        <item id="facility_contact_name">
                            <rank>30</rank>
                        </item>
                        <item id="address">
                            <rank>40</rank>
                        </item>
                        <item id="facility_email">
                            <rank>50</rank>
                        </item>
                        <item id="gps_coord">
                            <rank>60</rank>
                        </item>
                        <item id="loc_desc">
                            <rank>70</rank>
                        </item>
                        <item id="clli">
                            <rank>80</rank>
                        </item>
                        <item id="facility_contact_num">
                            <rank>90</rank>
                        </item>
                        <item id="org_id">
                            <rank>100</rank>
                        </item>
                        <item id="notes">
                            <rank>110</rank>
                        </item>
                    </items>
                </list>
            </presentation>
            <methods>
        <method id="OnUpdate" _delta="define">
        <static>false</static>
        <access>public</access>
        <type>Overload-DBObject</type>
        <code>
                            <![CDATA[   
          public function onUpdate()
            {
                 try {
                $iCommunityID = $this->Get("community");
                $oCommunity = MetaModel::GetObject('Comm_clli', $iCommunityID, true, false, null);
                if ($oCommunity === null) {
                throw new Exception('Failed to load Community object with ID: ' . $iCommunityID);
                }
                $sClli = $oCommunity->Get("clli");
                if ($sClli === null) {
                  throw new Exception('Community object with ID ' . $iCommunityID . ' does not have a value for "clli" attribute');
                }
                $this->Set('clli', $sClli);
                $this->DBUpdate();
            } catch (Exception $e) {
            $this->Set('clli', null);
            $this->DBUpdate();
            throw $e;
            }
            parent::OnUpdate();
    
            }
          ]]></code>
        </method>
            </methods>
        </class>
    
     
  • Abdullah Noman

    Abdullah Noman - 2023-04-27

    The field tag are fine, while I was pasting it got mixed up with my comments. here is the ss

     
  • Guillaume Lajarige

    The XML should be within the itop_design/classes tags, that might be your issue.

     
  • Abdullah Noman

    Abdullah Noman - 2023-04-27

    It is within the itop_design/classes tags. I just have few more other class before and after this which I didn't include here. It is strange that It was working fine the day beofore yesterday, and all of a suddent after I added another method it stopped working. I tried writing the class from scratch still getting the same issue.

     
  • Guillaume Lajarige

    Can your share the zip file of your module? Or send it by email so I can check?

     

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.