Issue in Emails::createEmailRecord - Printable Version +- CoreBOSBB (https://discussions.corebos.org) +-- Forum: Development (https://discussions.corebos.org/forumdisplay.php?fid=18) +--- Forum: coreBOS Development (https://discussions.corebos.org/forumdisplay.php?fid=4) +---- Forum: coreBOS Mail (https://discussions.corebos.org/forumdisplay.php?fid=3) +---- Thread: Issue in Emails::createEmailRecord (/showthread.php?tid=1974) Pages:
1
2
|
Issue in Emails::createEmailRecord - gmarcog - 10-08-2020 When I try to register an email using this code: $element = array(); $element['saved_toid'] = $correo; $element['parent_type'] = $modulo; $element['parent_id'] = vtws_getEntityId($modulo).'x'.$accountid; $element['from_email'] = $from; $element['ccmail'] = $ccmail; $element['bccmail'] = $bccmail; $element['subject'] = $asunto; $element['description'] = $cuerpoMensaje; $emailid = Emails::createEmailRecord($element); $rdo = send_mail( $modulo, $correo, 'xxxxxx', $from, $asunto, $cuerpoMensaje, $ccmail, $bccmail, array(), $emailid, 'test/logo/logosmall.png' ); if (!$rdo) { $mensaje .= 'ERROR: '.$mail->ErrorInfo; } else { $mensaje .= 'Se ha enviado el correo al mail '.$datos['email1'] .'<br>'; } return $mensaje But it dont works. With debug active shows this: INFO - PearDatabase ->ADODB disconnect DEBUG - SQL: SET NAMES utf8 DEBUG - EXEC: 0.00052905082702637 micros [START=1602155802.9709, END=1602155802.9714] DEBUG - DEBUG - Prepared sql query being executed : select id from vtiger_ws_entity where name=? DEBUG - Prepared sql query parameters : [Accounts] DEBUG - SQL: select id from vtiger_ws_entity where name=? DEBUG - PARAMS: [Accounts] DEBUG - EXEC: 0.00032305717468262 micros [START=1602155803.2723, END=1602155803.2726] DEBUG - DEBUG - Prepared sql query being executed : SELECT id FROM vtiger_users WHERE is_admin='On' and status='Active' limit 1 DEBUG - SQL: SELECT id FROM vtiger_users WHERE is_admin='On' and status='Active' limit 1 DEBUG - EXEC: 0.00026106834411621 micros [START=1602155803.2727, END=1602155803.273] DEBUG - DEBUG - Entering Users() method ... DEBUG - Entering getColumnFields(Users) method ... DEBUG - Entering getTabid(Users) method ... DEBUG - Prepared sql query being executed : select tabid from vtiger_tab where name=? DEBUG - Prepared sql query parameters : [Users] DEBUG - SQL: select tabid from vtiger_tab where name=? DEBUG - PARAMS: [Users] DEBUG - EXEC: 0.00022006034851074 micros [START=1602155803.2731, END=1602155803.2733] DEBUG - DEBUG - Exiting getTabid method ... DEBUG - Entering getTabid(Users) method ... DEBUG - Exiting getTabid method ... DEBUG - Prepared sql query being executed : SELECT tabid, fieldname, fieldid, fieldlabel, columnname, tablename, uitype, typeofdata, presence FROM vtiger_field WHERE tabid in (?) DEBUG - Prepared sql query parameters : [29] DEBUG - SQL: SELECT tabid, fieldname, fieldid, fieldlabel, columnname, tablename, uitype, typeofdata, presence FROM vtiger_field WHERE tabid in (?) DEBUG - PARAMS: [29] DEBUG - EXEC: 0.00023794174194336 micros [START=1602155803.2734, END=1602155803.2736] DEBUG - DEBUG - Entering getTabid(Users) method ... DEBUG - Exiting getTabid method ... DEBUG - Exiting getColumnFields method ... DEBUG - Exiting Users() method ... Sorry! Attempt to access restricted file. We are looking for this file path: user_privileges/user_privileges_1.php We are looking here: Real file path: Root dir path: /homepages/35/d489224962/htdocs/corebosPruebas/crm/ What can go wrong? Thanks RE: Issue in Emails::createEmailRecord - joebordes - 10-08-2020 If the code above is all the code you have you are missing some includes and I do not know what this method is: $emailid = Emails::createEmailRecord($element); that is a static method call on a function inside the Emails object. As far as I can see that method does not exist in a standard corebos so you may have added it yourself and I don't know what it contains. You don't need to add any function You just include modules/Emails/mail.php and you get the function createEmailRecord($email) already available for you. Have a read at this blog post see if that helps. Compare your createEmailRecord method with the function in mail.php and let me know how it goes. https://blog.corebos.org/blog/sendemail RE: Issue in Emails::createEmailRecord - gmarcog - 10-09-2020 Hello Joe: This isnĀ“t all the code. The code are in a funciones.php file, that contains two require_once: This: require_once 'modules/Emails/Emails.php'; require_once 'modules/Emails/mail.php'; In modules/Emails/Emails.php exists the function: public static function createEmailRecord($element, $attachmentids = array()) { global $adb, $log; $user = Users::getActiveAdminUser(); $elementType = 'Emails'; $webserviceObject = VtigerWebserviceObject::fromName($adb, $elementType); $handlerPath = $webserviceObject->getHandlerPath(); $handlerClass = $webserviceObject->getHandlerClass(); require_once $handlerPath; $handler = new $handlerClass($webserviceObject, $user, $adb, $log); $date = new DateTimeField(null); if (empty($element['date_start'])) { $element['date_start'] = $date->getDisplayDate($user); } if (empty($element['time_start'])) { $element['time_start'] = date('H:i'); } $element['activitytype'] = 'Emails'; if (empty($element['assigned_user_id'])) { $element['assigned_user_id'] = vtws_getEntityId('Users').'x'.$user->id; } if (empty($element['email_flag'])) { $element['email_flag'] = 'SENT'; } $result = $handler->create($elementType, $element); if (!empty($result['id']) && !empty($attachmentids)) { list($void, $id) = explode('x', $result['id']); $aids = explode(',', trim($attachmentids, ',')); $query = 'SELECT vtiger_attachments.path, vtiger_attachments.name, vtiger_attachments.attachmentsid FROM vtiger_attachments INNER JOIN vtiger_seattachmentsrel ON vtiger_seattachmentsrel.attachmentsid = vtiger_attachments.attachmentsid INNER JOIN vtiger_crmentity ON vtiger_attachments.attachmentsid=vtiger_crmentity.crmid WHERE deleted=0 AND vtiger_seattachmentsrel.crmid = ?'; $insrel = 'INSERT INTO vtiger_seattachmentsrel(crmid, attachmentsid) VALUES(?,?)'; foreach ($aids as $docid) { $docrs = $adb->pquery($query, array($docid)); if ($docrs && $adb->num_rows($docrs)==1) { $adb->pquery($insrel, array($id, $adb->query_result($docrs, 0, 'attachmentsid'))); } } return $result['id']; } return ''; } } And if I comment the line, the email is sent , and dont appear the message. Sorry! Attempt to access restricted file. We are looking for this file path: user_privileges/user_privileges_1.php We are looking here: Real file path: Root dir path: /homepages/35/d489224962/htdocs/corebosPruebas/crm/ Only appears when the system try to register it. Thanks RE: Issue in Emails::createEmailRecord - joebordes - 10-09-2020 the code seems to be correct. activate debug log and see if there is any error in that file. Not SQL log, the vtigercrm log https://github.com/tsolucio/corebos/blob/master/log4php.properties#L15 set that line to debug and search the file logs/vtigercrm.log for an "error" RE: Issue in Emails::createEmailRecord - inspectorflint - 10-20-2020 Hello , Joe. I feel the delay in the answer. I configure the debug but in that file I do not find any error. The content is too long for publish it in a post. How could I post it so you can see it? RE: Issue in Emails::createEmailRecord - joebordes - 10-20-2020 No problem for the delay, I can imagine... :-) send it to my email, I'll have a look RE: Issue in Emails::createEmailRecord - inspectorflint - 11-04-2020 sent! Thanks RE: Issue in Emails::createEmailRecord - inspectorflint - 09-02-2023 Hello: I am trying to register an email , using the code shows in https://blog.corebos.org/blog/sendemail. The email sends perfectly, but when I try to register it, returns Fatal error: Uncaught WebServiceException: Database error while performing required operation in /home/coralloagency/www/pruebas/include/Webservices/VtigerEmailOperation.php:78 Stack trace: #0 /home/coralloagency/www/pruebas/modules/Emails/mail.php(795): VtigerEmailOperation->create('Emails', Array) #1 /home/coralloagency/www/pruebas/modules/Invoice/customInvoicePDF.php(239): createEmailRecord(Array) #2 {main} thrown in /home/coralloagency/www/pruebas/include/Webservices/VtigerEmailOperation.php on line 78 The problem is in the value that returns this function: $accountid = vtws_getEntityId('Accounts').'x5'; // I change the account id for one in the database If I comment the value parent_in the $email array, the email sends, but it don't register in the database $email = array( 'saved_toid' => $to_email, 'parent_type' => 'Accounts', 'parent_id' => $accountid, 'from_email' => $from_email, 'subject' => $subject, 'description' => $content, ); the value that vtws_getEntityId('Accounts') returns is 11 ( the value of accounts in vtiger_ws_entity), and 5 is a register user in the aplication ... Any idea? Thank you RE: Issue in Emails::createEmailRecord - joebordes - 09-02-2023 the errors that give this message 'Database error while performing required operation' are usually easy to debug. The steps are: - Activate full debug logging - Reproduce the error - Look for the SQL error in the log file - Fix the error as needed activate the debug log and share the SQL error with us RE: Issue in Emails::createEmailRecord - inspectorflint - 09-03-2023 Hello, Joe: Thanks for the quick response The Database debug returns Query: insert into vtiger_seactivityrel values('12',13850) failed. Cannot add or update a child row: a foreign key constraint fails (`corallo_8_penultima`.`vtiger_seactivityrel`, CONSTRAINT `fk_2_vtiger_seactivityrel` FOREIGN KEY (`crmid`) REFERENCES `vtiger_crmentity` (`crmid`) ON DELETE CASCADE) 1452: Cannot add or update a child row: a foreign key constraint fails (`corallo_8_penultima`.`vtiger_seactivityrel`, CONSTRAINT `fk_2_vtiger_seactivityrel` FOREIGN KEY (`crmid`) REFERENCES `vtiger_crmentity` (`crmid`) ON DELETE CASCADE) ADOConnection._Execute(insert into vtiger_seactivityrel values('12',13850)) % line 1217, file: adodb.inc.php ADOConnection.Execute(insert into vtiger_seactivityrel values('12',13850), Array[1]) % line 448, file: PearDatabase.php PearDatabase.pquery(insert into vtiger_seactivityrel values(?,?), Array[2]) % line 152, file: Emails.php Emails.save_module(Emails) % line 193, file: CRMEntity.php CRMEntity.saveentity(Emails) % line 1463, file: CRMEntity.php Fatal error: Uncaught WebServiceException: Database error while performing required operation in /home/coralloagency/www/pruebas/include/Webservices/VtigerEmailOperation.php:78 Stack trace: #0 /home/coralloagency/www/pruebas/modules/Emails/mail.php(795): VtigerEmailOperation->create('Emails', Array) #1 /home/coralloagency/www/pruebas/modules/Invoice/customInvoicePDF.php(240): createEmailRecord(Array) #2 {main} thrown in /home/coralloagency/www/pruebas/include/Webservices/VtigerEmailOperation.php on line 78 The problems is that the params of vtws_getEntityId('Accounts').'x5'; 5 must be the id of the account related to email, not the id of the user, When i change this value, solved. Thanks!! |