Bug - When uploading the file, the correct file name is not set, while setting permissions in logichook - after_relationship_add #4136

Closed
opened 2026-02-20 16:14:06 -05:00 by deekerman · 3 comments
Owner

Originally created by @Ortman123 on GitHub (Nov 24, 2019).

Issue

In the AOS_Contracts module, I created logic_hook after_relationship_add to set permissions for attached documents. When the document was created in the AOS_Contrats module in the documents subpanel, an error appears when trying to check its content.
If the file is created in the Documents module and then add a link to the Contract than is ok.

Expected Behavior

changing the file name to valid or document_revision_id in the database

Actual Behavior

Error in suitecrm.log:
[1b191896-0b35-c7bb-f09a-5b18c84cf2f1][FATAL] Mysqli_query failed.
[1b191896-0b35-c7bb-f09a-5b18c84cf2f1][FATAL] Query Failed: INSERT INTO documents_cstm (id_c ,add_view_sec_1_c ) VALUES ('3a3108bc-bdc5-fcca-dd05-5e14bc83acd6' ,'^^' ): MySQL error 1062: Duplicate entry '3a3108bc-bdc5-fcca-dd05-5e14bc83acd6' for key 'PRIMARY'
[1b191896-0b35-c7bb-f09a-5b18c84cf2f1][FATAL] Mysqli_query failed.
[1b191896-0b35-c7bb-f09a-5b18c84cf2f1][FATAL] Error inserting into table: documents: Query Failed: INSERT INTO documents (id,date_entered,date_modified,modified_user_id,created_by,description,deleted,assigned_user_id,document_name,doc_id,doc_type,doc_url,active_date,exp_date,category_id,status_id,document_revision_id,is_template) VALUES ('3a3108bc-bdc5-fcca-dd05-5e14bc83acd6','2020-01-07 17:15:10','2020-01-07 17:15:10','1b191896-0b35-c7bb-f09a-5b18c84cf2f1','1b191896-0b35-c7bb-f09a-5b18c84cf2f1','',0,'1b191896-0b35-c7bb-f09a-5b18c84cf2f1','test30','','Sugar','','2020-01-07',NULL,'contracts','Active','22e4a3d1-9870-4555-79c9-5e14bcb265b6',0): MySQL error 1062: Duplicate entry '3a3108bc-bdc5-fcca-dd05-5e14bc83acd6' for key 'PRIMARY'
[1b191896-0b35-c7bb-f09a-5b18c84cf2f1][FATAL] Exception handling in /var/www/html/SuiteCRM/include/MVC/Controller/SugarController.php:400
[1b191896-0b35-c7bb-f09a-5b18c84cf2f1][FATAL] Exception in Controller: Database Error. Details were recorded in the SuiteCRM log.
[1b191896-0b35-c7bb-f09a-5b18c84cf2f1][FATAL] backtrace:
#0 /var/www/html/SuiteCRM/include/database/DBManager.php(353): sugar_die('Database Err...')
#1 /var/www/html/SuiteCRM/include/database/DBManager.php(328): DBManager->registerError('Error inserting...', 'Error inserting...', true)
#2 /var/www/html/SuiteCRM/include/database/MysqliManager.php(179): DBManager->checkError('Error inserting...', true)
#3 /var/www/html/SuiteCRM/include/database/DBManager.php(519): MysqliManager->query('INSERT INTO doc...', true, 'Error inserting...')
#4 /var/www/html/SuiteCRM/data/SugarBean.php(2411): DBManager->insert(Object(Document))
#5 /var/www/html/SuiteCRM/include/SugarObjects/templates/file/File.php(98): SugarBean->save(false)
#6 /var/www/html/SuiteCRM/modules/Documents/Document.php(219): File->save(false)

Error in apache after upload files: "PHP Warning: rename (upload / 8fcd69c1-5550-4556-e64d-5ddad04c3859, upload / b7972d35-162c-e430-5b17-5ddad0cf3020): No such file or directory in /var/www/html/SuiteCRM-7.11.10/include /UploadStream.php on line 214, referer: https://xxx.xxx.xxx.xxx/index.php?action=ajaxui"

Invalid "document_revision_id" is visible in the database, manual file name change is required.

Possible Fix

Steps to Reproduce

  1. In AOS_Contracts add logichook after_relationship_add
class Add_Doc_Rights
{
    function Add_Rights($bean,$event,$arguments)
    {
         if ($arguments['related_module'] =='Documents'){
                $document = BeanFactory::getBean('Documents',$arguments['related_id']);

                $securityTeam = new SecurityGroup();
                $bean->load_relationship('SecurityGroups');
                $securityTeam->retrieve_by_string_fields(array('name' => 'Group Users' ));  
                $bean->SecurityGroups->add($securityTeam-> id); 

                $documents=$bean->get_linked_beans('documents','Documents'); 

                foreach($documents as $document){
                       $document->load_relationship('SecurityGroups');
                       $document->SecurityGroups->add($securityTeam-> id); 
                       $document->save();
                }
        }
    }
}

Context

It is not possible to simultaneously upload the file and set securitygroups permissions.

Your Environment

  • SuiteCRM Version: 7.11.10 (fresh installed)
  • Environment: MySQL, PHP 7.2
  • Operating System: Ubuntu 18.04
Originally created by @Ortman123 on GitHub (Nov 24, 2019). #### Issue In the AOS_Contracts module, I created logic_hook after_relationship_add to set permissions for attached documents. When the document was created in the AOS_Contrats module in the documents subpanel, an error appears when trying to check its content. If the file is created in the Documents module and then add a link to the Contract than is ok. #### Expected Behavior changing the file name to valid or document_revision_id in the database #### Actual Behavior Error in suitecrm.log: [1b191896-0b35-c7bb-f09a-5b18c84cf2f1][FATAL] Mysqli_query failed. [1b191896-0b35-c7bb-f09a-5b18c84cf2f1][FATAL] Query Failed: INSERT INTO documents_cstm (id_c ,add_view_sec_1_c ) VALUES ('3a3108bc-bdc5-fcca-dd05-5e14bc83acd6' ,'^^' ): MySQL error 1062: Duplicate entry '3a3108bc-bdc5-fcca-dd05-5e14bc83acd6' for key 'PRIMARY' [1b191896-0b35-c7bb-f09a-5b18c84cf2f1][FATAL] Mysqli_query failed. [1b191896-0b35-c7bb-f09a-5b18c84cf2f1][FATAL] Error inserting into table: documents: Query Failed: INSERT INTO documents (id,date_entered,date_modified,modified_user_id,created_by,description,deleted,assigned_user_id,document_name,doc_id,doc_type,doc_url,active_date,exp_date,category_id,status_id,document_revision_id,is_template) VALUES ('3a3108bc-bdc5-fcca-dd05-5e14bc83acd6','2020-01-07 17:15:10','2020-01-07 17:15:10','1b191896-0b35-c7bb-f09a-5b18c84cf2f1','1b191896-0b35-c7bb-f09a-5b18c84cf2f1','',0,'1b191896-0b35-c7bb-f09a-5b18c84cf2f1','test30','','Sugar','','2020-01-07',NULL,'contracts','Active','22e4a3d1-9870-4555-79c9-5e14bcb265b6',0): MySQL error 1062: Duplicate entry '3a3108bc-bdc5-fcca-dd05-5e14bc83acd6' for key 'PRIMARY' [1b191896-0b35-c7bb-f09a-5b18c84cf2f1][FATAL] Exception handling in /var/www/html/SuiteCRM/include/MVC/Controller/SugarController.php:400 [1b191896-0b35-c7bb-f09a-5b18c84cf2f1][FATAL] Exception in Controller: Database Error. Details were recorded in the SuiteCRM log. [1b191896-0b35-c7bb-f09a-5b18c84cf2f1][FATAL] backtrace: #0 /var/www/html/SuiteCRM/include/database/DBManager.php(353): sugar_die('Database Err...') #1 /var/www/html/SuiteCRM/include/database/DBManager.php(328): DBManager->registerError('Error inserting...', 'Error inserting...', true) #2 /var/www/html/SuiteCRM/include/database/MysqliManager.php(179): DBManager->checkError('Error inserting...', true) #3 /var/www/html/SuiteCRM/include/database/DBManager.php(519): MysqliManager->query('INSERT INTO doc...', true, 'Error inserting...') #4 /var/www/html/SuiteCRM/data/SugarBean.php(2411): DBManager->insert(Object(Document)) #5 /var/www/html/SuiteCRM/include/SugarObjects/templates/file/File.php(98): SugarBean->save(false) #6 /var/www/html/SuiteCRM/modules/Documents/Document.php(219): File->save(false) Error in apache after upload files: "PHP Warning: rename (upload / 8fcd69c1-5550-4556-e64d-5ddad04c3859, upload / b7972d35-162c-e430-5b17-5ddad0cf3020): No such file or directory in /var/www/html/SuiteCRM-7.11.10/include /UploadStream.php on line 214, referer: https://xxx.xxx.xxx.xxx/index.php?action=ajaxui" Invalid "document_revision_id" is visible in the database, manual file name change is required. #### Possible Fix <!--- Not obligatory, but suggest a fix or reason for the bug --> #### Steps to Reproduce <!--- Provide a link to a live example, or an unambiguous set of steps to --> <!--- reproduce this bug include code to reproduce, if relevant --> 1. In AOS_Contracts add logichook after_relationship_add ``` class Add_Doc_Rights { function Add_Rights($bean,$event,$arguments) { if ($arguments['related_module'] =='Documents'){ $document = BeanFactory::getBean('Documents',$arguments['related_id']); $securityTeam = new SecurityGroup(); $bean->load_relationship('SecurityGroups'); $securityTeam->retrieve_by_string_fields(array('name' => 'Group Users' )); $bean->SecurityGroups->add($securityTeam-> id); $documents=$bean->get_linked_beans('documents','Documents'); foreach($documents as $document){ $document->load_relationship('SecurityGroups'); $document->SecurityGroups->add($securityTeam-> id); $document->save(); } } } } ``` #### Context <!--- How has this bug affected you? What were you trying to accomplish? --> <!--- If you feel this should be a low/medium/high priority then please state so --> It is not possible to simultaneously upload the file and set securitygroups permissions. #### Your Environment <!--- Include as many relevant details about the environment you experienced the bug in --> * SuiteCRM Version: 7.11.10 (fresh installed) * Environment: MySQL, PHP 7.2 * Operating System: Ubuntu 18.04
Author
Owner

@samus-aran commented on GitHub (Jul 28, 2020):

I have a feeling this is expected behaviour to be honest. You are saving in an after relationship add with adding a relationship. The thing that is throwing me is your SQL error saying it's a duplicate document. There must be some loop somewhere to be kicking that off.

@samus-aran commented on GitHub (Jul 28, 2020): I have a feeling this is expected behaviour to be honest. You are saving in an after relationship add with adding a relationship. The thing that is throwing me is your SQL error saying it's a duplicate document. There must be some loop somewhere to be kicking that off.
Author
Owner

@serhiisamko091184 commented on GitHub (Mar 14, 2024):

Hello, @Ortman123

The issue has been marked as stale because there has been no recent activity. It will be closed if no further activity occurs.
Thanks for your contributions.

Regards,
Serhii

@serhiisamko091184 commented on GitHub (Mar 14, 2024): Hello, @Ortman123 The issue has been marked as stale because there has been no recent activity. It will be closed if no further activity occurs. Thanks for your contributions. Regards, Serhii
Author
Owner

@serhiisamko091184 commented on GitHub (Apr 8, 2024):

Hey @Ortman123

Closing this issue due to inactivity.
Thank you.

Regards,
Serhii

@serhiisamko091184 commented on GitHub (Apr 8, 2024): Hey @Ortman123 Closing this issue due to inactivity. Thank you. Regards, Serhii
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/SuiteCRM-SuiteCRM#4136
No description provided.