Dolibarr / dolibarr

Dolibarr ERP CRM is a modern software package to manage your company or foundation's activity (contacts, suppliers, invoices, orders, stocks, agenda, accounting, ...). it's an open source Web application (written in PHP) designed for businesses of any sizes, foundations and freelancers.
https://www.dolibarr.org
GNU General Public License v3.0
5.46k stars 2.79k forks source link

Rest API tickets: PUT tickets doesn't written in DB #15707

Closed matDOTviguier closed 12 months ago

matDOTviguier commented 3 years ago

Bug

No API POST on tickets have no effect in Database at all.

Environment

Seem to be environment independant

Expected and actual behavior

Expected, a new row in ticket table. Actual behavior, none. Get a 500 error.

Steps to reproduce the behavior

Explore the API once connected, send the data by :

{ "subject": "S1", "message": "M1" }

2020-12-08 16:19:34 INFO    127.0.0.1   --- Access to /api/index.php/tickets - action=, massaction=
2020-12-08 16:19:34 DEBUG   127.0.0.1   sql=SELECT transkey, transvalue FROM llx_overwrite_trans where lang='fr_FR' OR lang IS NULL AND entity IN (0, 1) ORDER BY lang DESC
2020-12-08 16:19:34 INFO    127.0.0.1   Load a dedicated API file moduleobject=tickets moduledirforclass=ticket
2020-12-08 16:19:34 INFO    127.0.0.1   Search api file /ticket/class/api_tickets.class.php => dir_part_file=/var/www/html/www.site.fr/htdocs/ticket/class/api_tickets.class.php classname=Tickets
2020-12-08 16:19:34 DEBUG   127.0.0.1   sql=SELECT u.login, u.datec, u.api_key,  u.tms as date_modification, u.entity FROM llx_user as u WHERE u.api_key = '_KEY_SNIPPED_'
2020-12-08 16:19:34 DEBUG   127.0.0.1   sql=SELECT u.rowid, u.lastname, u.firstname, u.employee, u.gender, u.birth, u.email, u.personal_email, u.job, u.socialnetworks, u.signature, u.office_phone, u.office_fax, u.user_mobile, u.personal_mobile, u.address, u.zip, u.town, u.fk_state as state_id, u.fk_country as country_id, u.admin, u.login, u.note as note_private, u.note_public, u.pass, u.pass_crypted, u.pass_temp, u.api_key, u.fk_soc, u.fk_socpeople, u.fk_member, u.fk_user, u.ldap_sid, u.fk_user_expense_validator, u.fk_user_holiday_validator, u.statut, u.lang, u.entity, u.datec as datec, u.tms as datem, u.datelastlogin as datel, u.datepreviouslogin as datep, u.photo as photo, u.openid as openid, u.accountancy_code, u.thm, u.tjm, u.salary, u.salaryextra, u.weeklyhours, u.color, u.dateemployment, u.dateemploymentend, u.fk_warehouse, u.ref_ext, u.default_range, u.default_c_exp_tax_cat, c.code as country_code, c.label as country, d.code_departement as state_code, d.nom as state FROM llx_user as u LEFT JOIN llx_c_country as c ON u.fk_country = c.rowid LEFT JOIN llx_c_departements as d ON u.fk_state = d.rowid WHERE u.entity IS NOT NULL AND u.login = 'm.viguier' ORDER BY u.entity ASC
2020-12-08 16:19:34 DEBUG   127.0.0.1   sql=SELECT rowid,name,label,type,size,elementtype,fieldunique,fieldrequired,param,pos,alwayseditable,perms,langs,list,printable,totalizable,fielddefault,fieldcomputed,entity,enabled,help FROM llx_extrafields WHERE elementtype = 'user' ORDER BY pos
2020-12-08 16:19:34 DEBUG   127.0.0.1   sql=SELECT DISTINCT r.module, r.perms, r.subperms FROM llx_user_rights as ur, llx_rights_def as r WHERE r.id = ur.fk_id AND ur.entity = 1 AND ur.fk_user= 1 AND r.perms IS NOT NULL
2020-12-08 16:19:34 DEBUG   127.0.0.1   sql=SELECT DISTINCT r.module, r.perms, r.subperms FROM llx_usergroup_rights as gr, llx_usergroup_user as gu, llx_rights_def as r WHERE r.id = gr.fk_id AND gr.entity = 1 AND gu.entity = 1 AND r.entity = 1 AND gr.fk_usergroup = gu.fk_usergroup AND gu.fk_user = 1 AND r.perms IS NOT NULL
2020-12-08 16:19:34 DEBUG   127.0.0.1   sql=SELECT MAX(CAST(SUBSTRING(ref FROM 8) AS SIGNED)) as max FROM llx_ticket WHERE ref LIKE 'TS____-%' AND entity = 1
2020-12-08 16:19:34 INFO    127.0.0.1   mod_ticket_simple::getNextValue return TS2012-0086
2020-12-08 16:19:34 DEBUG   127.0.0.1   BEGIN Transaction
2020-12-08 16:19:34 DEBUG   127.0.0.1    Ticket::create sql=INSERT INTO llx_ticket(ref,track_id,fk_soc,fk_project,origin_email,fk_user_create,fk_user_assign,subject,message,fk_statut,resolution,progress,timing,type_code,category_code,severity_code,datec,date_read,date_close,entity,notify_tiers_at_create) VALUES ( 'TS2012-0086', 'zb3sg79haia31yd4', null, null, NULL, 1, NULL, 'S1', 'M1', 0, NULL, 0, NULL, NULL, NULL, NULL, '2020-12-08 16:19:34', NULL, NULL, 1, 1)
2020-12-08 16:19:34 DEBUG   127.0.0.1    sql=INSERT INTO llx_ticket(ref,track_id,fk_soc,fk_project,origin_email,fk_user_create,fk_user_assign,subject,message,fk_statut,resolution,progress,timing,type_code,category_code,severity_code,datec,date_read,date_close,entity,notify_tiers_at_create) VALUES ( 'TS2012-0086', 'zb3sg79haia31yd4', null, null, NULL, 1, NULL, 'S1', 'M1', 0, NULL, 0, NULL, NULL, NULL, NULL, '2020-12-08 16:19:34', NULL, NULL, 1, 1)
2020-12-08 16:19:34 INFO    127.0.0.1    Trigger 'ActionsAuto' for action 'TICKET_CREATE' launched by /var/www/html/www.site.fr/htdocs/core/triggers/interface_50_modAgenda_ActionsAuto.class.php. id=134
2020-12-08 16:19:34 DEBUG   127.0.0.1    CActionComm::fetch
2020-12-08 16:19:34 DEBUG   127.0.0.1    sql=SELECT id, code, type, libelle as label, color, active, picto FROM llx_c_actioncomm WHERE code='AC_OTH_AUTO'
2020-12-08 16:19:34 DEBUG   127.0.0.1     ActionComm::add
2020-12-08 16:19:34 DEBUG   127.0.0.1     sql=INSERT INTO llx_actioncomm(datec,datep,datep2,durationp,fk_action,code,ref_ext,fk_soc,fk_project,note,fk_contact,fk_user_author,fk_user_action,fk_user_done,label,percent,priority,fulldayevent,location,transparency,fk_element,elementtype,entity,extraparams,email_msgid,email_from,email_sender,email_to,email_tocc,email_tobcc,email_subject,errors_to) VALUES ('2020-12-08 16:19:34', '2020-12-08 16:19:34', '2020-12-08 16:19:34', null, 40,'AC_TICKET_CREATE', null, null, null,  'Auteur: m.viguier\nTicket TS2012-0086 créé', null, 1, 1, null, 'Ticket TS2012-0086 créé','-1','0','0','', '0', 134, 'ticket', 1,null, null, null, null, null, null, null, null, null)
2020-12-08 16:19:34 DEBUG   127.0.0.1     sql=INSERT INTO llx_actioncomm_resources(fk_actioncomm, element_type, fk_element, mandatory, transparency, answer_status) VALUES(4563, 'user', 1, 0, 0, 0)
2020-12-08 16:19:34 INFO    127.0.0.1    Trigger 'TicketEmail' for action 'TICKET_CREATE' launched by /var/www/html/www.site.fr/htdocs/core/triggers/interface_50_modTicket_TicketEmail.class.php. id=134
2020-12-08 16:19:34 DEBUG   127.0.0.1    Ticket::fetch sql=SELECT t.rowid, t.ref, t.track_id, t.fk_soc, t.fk_project, t.origin_email, t.fk_user_create, t.fk_user_assign, t.subject, t.message, t.fk_statut as status, t.resolution, t.progress, t.timing, t.type_code, t.category_code, t.severity_code, t.datec, t.date_read, t.date_close, t.tms, type.code as type_code, type.label as type_label, category.code as category_code, category.label as category_label, severity.code as severity_code, severity.label as severity_label FROM llx_ticket as t LEFT JOIN llx_c_ticket_type as type ON type.code=t.type_code LEFT JOIN llx_c_ticket_category as category ON category.code=t.category_code LEFT JOIN llx_c_ticket_severity as severity ON severity.code=t.severity_code WHERE t.entity IN (1) AND t.ref = 'zb3sg79haia31yd4'
2020-12-08 16:19:34 DEBUG   127.0.0.1    sql=SELECT t.rowid, t.ref, t.track_id, t.fk_soc, t.fk_project, t.origin_email, t.fk_user_create, t.fk_user_assign, t.subject, t.message, t.fk_statut as status, t.resolution, t.progress, t.timing, t.type_code, t.category_code, t.severity_code, t.datec, t.date_read, t.date_close, t.tms, type.code as type_code, type.label as type_label, category.code as category_code, category.label as category_label, severity.code as severity_code, severity.label as severity_label FROM llx_ticket as t LEFT JOIN llx_c_ticket_type as type ON type.code=t.type_code LEFT JOIN llx_c_ticket_category as category ON category.code=t.category_code LEFT JOIN llx_c_ticket_severity as severity ON severity.code=t.severity_code WHERE t.entity IN (1) AND t.ref = 'zb3sg79haia31yd4'
2020-12-08 16:19:34 DEBUG   127.0.0.1    CMailFile::CMailfile: sendmode=swiftmailer charset=UTF-8 from=Service Informatique<contact@service-informatique.fr>, to=ticket@service-informatique.fr, addr_cc=, addr_bcc=fmerpsi@service-informatique.fr, errors_to=, trackid= sendcontext=standard
2020-12-08 16:19:34 DEBUG   127.0.0.1    CMailFile::CMailfile: subject=[Service Informatique] Nouveau ticket créé - Réf (ID publique du ticket ), deliveryreceipt=, msgishtml=-1
2020-12-08 16:19:34 INFO    127.0.0.1    --- End access to /api/index.php/tickets

No TS2012-0086, no mail, no action ...

ATM-Nicolas commented 3 years ago

Can you please specify the dolibarr version in which you have encountered this problem ?

matDOTviguier commented 3 years ago

12.04, Nicolas. I cannot figure why it fails. I mean by spending not enough time on it. I'll try to debug again next week.

Hystepik commented 3 years ago

Hello matDOTviguier, I cannot reproduce the bug on version 12.0.4

matDOTviguier commented 3 years ago

1/ Open the API EXPLORER 2/ Type a POST content like this : Capture__ 3/ Read the log via : capture____ 4/ Search Line containing "M1" and relative to your action. Mine is : INSERT INTO llx_ticket(ref,track_id,fk_soc,fk_project,origin_email,fk_user_create,fk_user_assign,subject,message,fk_statut,resolution,progress,timing,type_code,category_code,severity_code,datec,date_read,date_close,entity,notify_tiers_at_create) VALUES ( 'TS2101-0119', '7sjze638vxeqwpr8', null, null, NULL, 1, NULL, 'S1', 'M1', 0, NULL, 0, NULL, NULL, NULL, NULL, '2021-01-20 14:17:37', NULL, NULL, 1, 1) 5/ Now, try to select in db : SELECT * from llx_ticket WHERE llx_ticket.ref='TS2101-0119' 6/ No data, you can see here (heidiSQL client, but ... any works) : Capture______ 7/ Apache log says : [Wed Jan 20 14:27:31.287005 2021] [php7:error] [pid 7243] [client 92.131.160.175:49286] PHP Recoverable fatal error: Object of class Closure could not be converted to string in /var/www/html/erp.service-informatique.fr/htdocs/includes/r estler/framework/Luracast/Restler/AutoLoader.php on line 266, referer: https://erp.service-informatique.fr/api/index.php/explorer/

PS : DateTime doesn't match, it's because of a replay of the action in order to catch the log. Intial log was about Gigs !

matDOTviguier commented 3 years ago

And the function that throw the error is :

 private function loadLastResort($className, $loader = null) {
        $loaders = array_unique(static::$rogueLoaders);               <==== LINE 266
        if (isset($loader)) {
            if (false === array_search($loader, $loaders))
                static::$rogueLoaders[] = $loader;
            return $this->loadThisLoader($className, $loader);
        }
        foreach ($loaders as $loader)
            if (false !== $file = $this->loadThisLoader($className, $loader))
                return $file;

        return false;
    }
dpriskorn commented 3 years ago

The API is unfortunately still in alpha state. We need more tests. If you want we can get together and write some tests 😃 It would be really nice to get an overview of what is working and not. When I wrote a python program to sync into dolibarr I found that the API is not covering more than half of what I wanted so I interfaced directly with the db in some cases which is not optimal.

matDOTviguier commented 3 years ago

I'm yours ! I'm facing the same problem. Python server-side code, SPA in frontend. I need to launch a test server with the nightly and replicated db. This is the first step here. I come back asap.

matDOTviguier commented 3 years ago

Due to time to market restrictions, i have to bypass the option of the API. I have done a complete sqldiff in order to guess what "Crate a ticket" means ... and rewrote it from 0. Old school Python <=> db action

I found no documentation with the API and what works, and what doesn't work.

frederic34 commented 3 years ago

I tried this on v14, I have got fatal errors because one external module autoload files which conflicts with restler when calling call_trigger

frederic34 commented 3 years ago

@matDOTviguier look at https://github.com/Luracast/Restler/pull/515/files

matDOTviguier commented 3 years ago

@frederic34 so, the 14 is not ready to ticket via API ?

dpriskorn commented 2 years ago

Still present in v16?

FredBl79 commented 1 year ago

Hello,

I'm facing the same issue on V16.0.4 and found that is unfortuantely related to the automatic email when you assign an user. I have an external module which trigger an email when an user is assign, if I uncheck this module, the ticket is correctly created by the API, if I activate the module, I got same error as @matDOTviguier during the CMailFile action.

I don't know if that should be resolved or if somebody has an idea ?

frederic34 commented 1 year ago

restler autoloader may remove your autoload and then is unable to find the right files to load https://github.com/Dolibarr/dolibarr/blob/969ecf6dccde96d6a6acf535ac5ff850fe58a940/htdocs/includes/restler/framework/Luracast/Restler/AutoLoader.php#L78

public static function thereCanBeOnlyOne() {

FredBl79 commented 1 year ago

@frederic34

Merci ! Too complex for me....I deep dived a little bit in this Autoload, but except that the error is somewhere into the declaration of my new cMailFile. (trigger of the custom module) ..I have no clue how to fix it.

As the module works well with a UI ticket creation....that may be too complex for me

Fred

Fado84 commented 1 year ago

Hi, same issue V17.0.1

Fado84 commented 1 year ago

Hi, if I remove this option (Notify ticket creation to this e-mail address) inside the ticket mdoule the PUSH of ticket works!

FredBl79 commented 1 year ago

Correct, the issue happens only if notification is on.

Unfortunately, Without this option, that make less sense to push tickets by API.

Fred

Le mar. 23 mai 2023, 19:25, Fado84 @.***> a écrit :

Hi, if I remove this option (Notify ticket creation to this e-mail address) inside the ticket mdoule the PUSH of ticket works!

— Reply to this email directly, view it on GitHub https://github.com/Dolibarr/dolibarr/issues/15707#issuecomment-1559863440, or unsubscribe https://github.com/notifications/unsubscribe-auth/AX4STMUWZGJCQEP2LKIBS7LXHTXJVANCNFSM4USEIHEA . You are receiving this because you commented.Message ID: @.***>

ksar-ksar commented 1 year ago

Hello,

Is it still the case ?

ksar-ksar commented 12 months ago

I'm closing the issue, you can ask to re-open it if needed.