Menu

Need Help : AttributeBlob & method OnInsert()

2024-02-09
2024-02-23
  • Benjamin LAURENCE

    Hello,

    When creating new Class (Say "MyNewClass") having field Attribute "AttributeBlob",

                <field id="report" xsi:type="AttributeBlob">
                    <is_null_allowed>true</is_null_allowed>
                    <always_load_in_tables>true</always_load_in_tables>
                </field>
    

    In that same class :

                <method id="OnInsert">
                  <comment>/**
                    *
                    > * @author Benjamin LAURENCE
                    */
                  </comment>
                  <static>false</static>
                  <access>public</access>
                  <code><![CDATA[
                                public function OnInsert()
                                {
                                    parent::OnInsert();
                                    $this->Set('report', '../myfile.pdf');
                                     $this->SetIfNull('creation_date', time());   
                                }
                        ]]></code>
                </method>
    

    Created profile for that Class :

    <user_rights>
        <profiles>
            <profile id="2050" _delta="define">
              <name>MyProfileName</name>
              <description>Users Allowed to manage XXXXX</description>
              <groups>
    
                <group id="MyNewClass">
                  <actions>
                    <action id="action:read">allow</action>
                    <action id="action:write">allow</action>
                    <action id="action:delete">allow</action>
                    <action id="action:bulk read">allow</action>
                    <action id="action:bulk write">allow</action>
                    <action id="action:bulk delete">allow</action>
                  </actions>
                </group>
              </groups>
            </profile>
        </profiles>
        <groups>
          <group id="MyNewClass" _delta="define">
            <classes>
              <class id="MyNewClass"/>
            </classes>
          </group>  
        </groups>
    </user_rights>
    

    Pdf is successfully stored only when using "Admin profile", when using profile "MyProfileName" objet is created but the pdf is note stored in database.

     

    Last edit: Benjamin LAURENCE 2024-02-09
  • Pierre Goiffon

    Pierre Goiffon - 2024-02-13

    Hello,
    Can you check the grant matrix (Administration, Profiles, open the profile, grant matrix tab) of the profile you created ?

     
  • Pierre Goiffon

    Pierre Goiffon - 2024-02-13

    Can you also share the whole MyNewClass definition ? Might be blocking elsewhere...
    By the way, are there anything in the log/error.log file when creating with a non admin profile ?

     
  • Benjamin LAURENCE

    Hi pierre,

    Thank you for your help.
    Matrix definition in 1.png

    I added :

    IssueLog::Info('Start Setting report file');
    $this->Set('report', '../myfile.pdf');
    IssueLog::Info('End Setting report file');
    

    but i have no error when using created profile :

    2024-02-13 09:46:20 | Info    | 1203  | Start Setting report file | IssueLog |||
    2024-02-13 09:46:20 | Info    | 1203  | End Setting report file | IssueLog |||
    

    When using admin profile "report" : Object is created and attribute "report" is correctly defined
    When using created profile : Object is created and attribute "report" is not setted

    Do you know if there is "restriction" on non admin user reading file on disk ?

     
  • Pierre Goiffon

    Pierre Goiffon - 2024-02-16

    Hello,
    You might want to try :
    - setting an absolute path instead of a relative path
    - set an ormDocument instead of just a path

     
  • Benjamin LAURENCE

    Hello,

    Same "problem" when saving pdf to disk and sending absolute path.
    But using ormDocument all is ok !!!!

    Thank you for your help.

     
  • Pierre Goiffon

    Pierre Goiffon - 2024-02-16

    Glad to hear your problem is solved !
    What class needs to be used when getting or setting an object isn't very clear for now, we didn't document it very well for now. Best it to look for other code samples O:)

     
  • Benjamin LAURENCE

    That's ok, i wasn't aware of "ormDocument" class (Thank you again) so i looked in the github project and the usage is quite simple.

    $ormDocument = new ormDocument($oPdf->getPdfOutput(), 'application/pdf', $oPdf->getPdfFileName());
    $this->Set('report', $ormDocument);
    

    I think it should be docummented, maybe here : https://www.itophub.io/wiki/page?id=3_1_0:customization:actions-on-transitions in section "Set"

     
  • Pierre Goiffon

    Pierre Goiffon - 2024-02-23

    The Set action in transition is just an indirection to DBObject::Set
    I've updated some phpdoc, it will be there next time O:) (but there is still work to do in order to be exhaustive)
    https://github.com/Combodo/iTop/commit/f6fec506b18f20578f3c9ff37889461bcbc08ee3

     

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.