Duplicate objects

DemonCcC
2011-11-03
2013-09-30
  • DemonCcC
    DemonCcC
    2011-11-03

    Anybody knows what do I need to modify in order to set a attribute as non-duplicate attribute between objects of the same class? Now I can add objects with the same name and serial number for example. I would like prevent that someone adds a object that already exists.

    Thanks!

     
  • jitsobullet
    jitsobullet
    2013-09-27

    Hi,

    Did you get this fixed, i have the same issue!

    Kind regards

     
  • Alexander K.
    Alexander K.
    2013-09-28

    Hi,

    I had a similar problem. My solution is quite inconvenient...

    In my self-developed module with the class "DNS" each domain name has to be unique.
    Therefore I use the method "DoCheckToWrite" (based on userrights.class.inc.php). The function ensures that you cannot add a domain that already exists.

    Maybe a starting point for you...

    Best regards
    Alexander

    XML Code snippet (example code from userrights.class.inc.php):

    <method id="DoCheckToWrite">
          <static>false</static>
          <access>protected</access>
          <type>Overload-DBObject</type>
          <code><![CDATA[       public function DoCheckToWrite()
        {
                parent::DoCheckToWrite();
    
                // Note: This MUST be factorized later: declare unique keys (set of columns) in the data model
                $aChanges = $this->ListChanges();
                if (array_key_exists('login', $aChanges))
                {
                        $sNewLogin = $aChanges['login'];
                        $oSearch = DBObjectSearch::FromOQL_AllData("SELECT User WHERE login = :newlogin");
                        $oSet = new DBObjectSet($oSearch, array(), array('newlogin' => $sNewLogin));
                        if ($oSet->Count() > 0)
                        {
                                $this->m_aCheckIssues[] = Dict::Format('Class:User/Error:LoginMustBeUnique', $sNewLogin);
                        }
                }        
            }]]></code>
    </method>
    
     
    • jitsobullet
      jitsobullet
      2013-09-29

      Hi Alexander,

      Thank you for your response.

      Would you mind sharing the code for your DNS class please, as i want to see how you have implemented the above code.

      Many Thanks

       
  • jitsobullet
    jitsobullet
    2013-09-30

    Never mind, i managed to configure it - and it works a charm!

    Thank you once again Alexander

     
  • Alexander K.
    Alexander K.
    2013-09-30

    I'm glad I was able to help :)

    Maybe for others: I wrote a small SAMPLE extension "alx-conf-module-infra":

    Features:
    - Server Class: define Server name as unique
    - Server Class: additional field "local_disk"
    - IPinterface Class: allow interface speed up to 10.000 MBit/s (7 digits)
    - Language Files DE/EN

    Install:

    1. Download the SAMPLE: http://www.bitingbytes.de/files/itop/alx-conf-module-infra.zip
    2. unzip in iTop extensions folder
    3. re-run setup and add the module

    Best regards
    Alexander