LJPc-solutions / freescout-calendar-module

A calendar module for Freescout
20 stars 7 forks source link

Unexpected data found in logs #27

Closed Maddmax76 closed 1 year ago

Maddmax76 commented 1 year ago

Hi, I'm trying your module but something is wrong. When I try to create an appointment in the calendar, it seems to work and I see the event, but if I refresh the page the event disappears, as if it can't write data. If instead I take a ticket and try to create an event in the calendar, a modal popup appears warning that there is an error in the internet connection.

In the logs I see that there are laravel errors, which I report below.

On the internet it would seem to be a problem with the date format.

Could you help me?

Thank you

Unexpected data found.

Trailing data {"userId":2,"email":"[OMISSS]","exception":"[object] (InvalidArgumentException(code: 0): Unexpected data found.
Trailing data at /var/www/FreeScout/overrides/nesbot/carbon/src/Carbon/Carbon.php:912)
[stacktrace]
#0 /var/www/FreeScout/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php(715): Carbon\\Carbon::createFromFormat()
#1 /var/www/FreeScout/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php(738): Illuminate\\Database\\Eloquent\\Model->asDateTime()
#2 /var/www/FreeScout/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php(532): Illuminate\\Database\\Eloquent\\Model->fromDateTime()
#3 /var/www/FreeScout/overrides/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(1389): Illuminate\\Database\\Eloquent\\Model->setAttribute()
#4 /var/www/FreeScout/Modules/LJPcCalendarModule/Http/Controllers/LJPcCalendarModuleController.php(153): Illuminate\\Database\\Eloquent\\Model->__set()
#5 /var/www/FreeScout/Modules/LJPcCalendarModule/Http/Controllers/LJPcCalendarModuleController.php(129): Modules\\LJPcCalendarModule\\Http\\Controllers\\LJPcCalendarModuleController->createItem()
#6 [internal function]: Modules\\LJPcCalendarModule\\Http\\Controllers\\LJPcCalendarModuleController->ajax()
#7 /var/www/FreeScout/overrides/laravel/framework/src/Illuminate/Routing/Controller.php(54): call_user_func_array()
#8 /var/www/FreeScout/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(45): Illuminate\\Routing\\Controller->callAction()
#9 /var/www/FreeScout/vendor/laravel/framework/src/Illuminate/Routing/Route.php(212): Illuminate\\Routing\\ControllerDispatcher->dispatch()
#10 /var/www/FreeScout/vendor/laravel/framework/src/Illuminate/Routing/Route.php(169): Illuminate\\Routing\\Route->runController()
#11 /var/www/FreeScout/overrides/laravel/framework/src/Illuminate/Routing/Router.php(658): Illuminate\\Routing\\Route->run()
#12 /var/www/FreeScout/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(30): Illuminate\\Routing\\Router->Illuminate\\Routing\\{closure}()
#13 /var/www/FreeScout/app/Http/Middleware/CustomHandle.php(22): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}()
#14 /var/www/FreeScout/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(149): App\\Http\\Middleware\\CustomHandle->handle()
#15 /var/www/FreeScout/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#16 /var/www/FreeScout/app/Http/Middleware/LogoutIfDeleted.php(28): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}()
#17 /var/www/FreeScout/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(149): App\\Http\\Middleware\\LogoutIfDeleted->handle()
#18 /var/www/FreeScout/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#19 /var/www/FreeScout/app/Http/Middleware/Localize.php(27): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}()
#20 /var/www/FreeScout/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(149): App\\Http\\Middleware\\Localize->handle()
#21 /var/www/FreeScout/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#22 /var/www/FreeScout/app/Http/Middleware/HttpsRedirect.php(49): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}()
#23 /var/www/FreeScout/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(149): App\\Http\\Middleware\\HttpsRedirect->handle()
#24 /var/www/FreeScout/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#25 /var/www/FreeScout/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php(41): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}()
#26 /var/www/FreeScout/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(149): Illuminate\\Routing\\Middleware\\SubstituteBindings->handle()
#27 /var/www/FreeScout/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#28 /var/www/FreeScout/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php(67): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}()
#29 /var/www/FreeScout/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(149): Illuminate\\Foundation\\Http\\Middleware\\VerifyCsrfToken->handle()
#30 /var/www/FreeScout/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#31 /var/www/FreeScout/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php(49): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}()
#32 /var/www/FreeScout/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(149): Illuminate\\View\\Middleware\\ShareErrorsFromSession->handle()
#33 /var/www/FreeScout/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#34 /var/www/FreeScout/app/Http/Middleware/TokenAuth.php(31): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}()
#35 /var/www/FreeScout/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(149): App\\Http\\Middleware\\TokenAuth->handle()
#36 /var/www/FreeScout/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#37 /var/www/FreeScout/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(63): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}()
#38 /var/www/FreeScout/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(149): Illuminate\\Session\\Middleware\\StartSession->handle()
#39 /var/www/FreeScout/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#40 /var/www/FreeScout/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php(37): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}()
#41 /var/www/FreeScout/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(149): Illuminate\\Cookie\\Middleware\\AddQueuedCookiesToResponse->handle()
#42 /var/www/FreeScout/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#43 /var/www/FreeScout/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php(59): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}()
#44 /var/www/FreeScout/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(149): Illuminate\\Cookie\\Middleware\\EncryptCookies->handle()
#45 /var/www/FreeScout/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#46 /var/www/FreeScout/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(102): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}()
#47 /var/www/FreeScout/overrides/laravel/framework/src/Illuminate/Routing/Router.php(660): Illuminate\\Pipeline\\Pipeline->then()
#48 /var/www/FreeScout/overrides/laravel/framework/src/Illuminate/Routing/Router.php(635): Illuminate\\Routing\\Router->runRouteWithinStack()
#49 /var/www/FreeScout/overrides/laravel/framework/src/Illuminate/Routing/Router.php(601): Illuminate\\Routing\\Router->runRoute()
#50 /var/www/FreeScout/overrides/laravel/framework/src/Illuminate/Routing/Router.php(590): Illuminate\\Routing\\Router->dispatchToRoute()
#51 /var/www/FreeScout/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(176): Illuminate\\Routing\\Router->dispatch()
#52 /var/www/FreeScout/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(30): Illuminate\\Foundation\\Http\\Kernel->Illuminate\\Foundation\\Http\\{closure}()
#53 /var/www/FreeScout/app/Http/Middleware/TerminateHandler.php(12): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}()
#54 /var/www/FreeScout/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(149): App\\Http\\Middleware\\TerminateHandler->handle()
#55 /var/www/FreeScout/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#56 /var/www/FreeScout/app/Http/Middleware/ResponseHeaders.php(11): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}()
#57 /var/www/FreeScout/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(149): App\\Http\\Middleware\\ResponseHeaders->handle()
#58 /var/www/FreeScout/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#59 /var/www/FreeScout/vendor/fideloper/proxy/src/TrustProxies.php(56): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}()
#60 /var/www/FreeScout/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(149): Fideloper\\Proxy\\TrustProxies->handle()
#61 /var/www/FreeScout/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#62 /var/www/FreeScout/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(30): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}()
#63 /var/www/FreeScout/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(149): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle()
#64 /var/www/FreeScout/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#65 /var/www/FreeScout/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(30): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}()
#66 /var/www/FreeScout/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(149): Illuminate\\Foundation\\Http\\Middleware\\TransformsRequest->handle()
#67 /var/www/FreeScout/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#68 /var/www/FreeScout/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php(27): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}()
#69 /var/www/FreeScout/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(149): Illuminate\\Foundation\\Http\\Middleware\\ValidatePostSize->handle()
#70 /var/www/FreeScout/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#71 /var/www/FreeScout/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php(46): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}()
#72 /var/www/FreeScout/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(149): Illuminate\\Foundation\\Http\\Middleware\\CheckForMaintenanceMode->handle()
#73 /var/www/FreeScout/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}()
#74 /var/www/FreeScout/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(102): Illuminate\\Routing\\Pipeline->Illuminate\\Routing\\{closure}()
#75 /var/www/FreeScout/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(151): Illuminate\\Pipeline\\Pipeline->then()
#76 /var/www/FreeScout/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(116): Illuminate\\Foundation\\Http\\Kernel->sendRequestThroughRouter()
#77 /var/www/FreeScout/public/index.php(83): Illuminate\\Foundation\\Http\\Kernel->handle()
#78 {main}
"}
Lars- commented 1 year ago

Thanks for reporting this. Can you send a dump of a network payload when you create an item and can you let me know what locale you are using in freescout?

Maddmax76 commented 1 year ago

Hi, I can't provide the dump, the locale is Italian IT. Thank you

Lars- commented 1 year ago

Okay, then I can't see what's wrong.

Maddmax76 commented 1 year ago

thank you so much you are very kind.

All the solutions found in the various forums refer to date management, it seems that having a format other than the native one it must be converted.

For example in the following code, taken from https://stackoverflow.com/questions/25223958/laravel-unexpected-data-found-error-when-trying-to-change-format-of-carbon-cre , set both timezone and date/time format:

public function getCreatedAtAttribute($date)
{
    if(Auth::check())
        return Carbon\Carbon::createFromFormat('Y-m-d H:i:s', $date)->copy()->tz(Auth::user()->timezone)->format('F j, Y @ g:i A');
    else
        return Carbon\Carbon::createFromFormat('Y-m-d H:i:s', $date)->copy()->tz('America/Toronto')->format('F j, Y @ g:i A');
}

public function getUpdatedAtAttribute($date)
{
    return Carbon\Carbon::createFromFormat('Y-m-d H:i:s', $date)->format('F j, Y @ g:i A');
}

I hope it can help you.

Thanks again

Lars- commented 1 year ago

If I don't know what is sent to the server, I don't know why Carbon would parse it wrong. Maybe it's some weird JavaScript issue due to your locale, but that's why I need to see at least one request to the server.

Maddmax76 commented 1 year ago

unfortunately I only have access to the logs, I can't do network sniffing..

Lars- commented 1 year ago

Just add a calendar item with the network tab with chrome inspect elements opened. Copy the call that happens when you add the item and put it here. No need for sniffing the network.

Maddmax76 commented 1 year ago

Done, found an element in error, error 500 strict-origin-when-cross-origin, it's probably some apache security setting like X-Frame-Options... Is this information enough for you or do I have to copy something else from the network tab? But you have to explain how and what to copy because I don't know how :-(

URL Di Richiesta:
https://helpdesk.mydomain.local/calendar/ajax
Metodo Di Richiesta:
POST
Codice Di Stato:
500 Internal Server Error
Indirizzo Remoto:
192.168.1.217:443
Criterio Relativo Al Referrer:
strict-origin-when-cross-origin
Maddmax76 commented 1 year ago

I read on the internet that you could try using JSONP in your Ajax call. It will bypass the Same Origin Policy.

I don't know if this is the case, I hope it helps.

Maddmax76 commented 1 year ago

Browsing through the chrome inspector I also found this: DevTools failed to load source map: Could not load content for https://helpdesk.mydomain.local/modules/ljpccalendarmodule/js/moment-with-locales.min.js.map: Errore HTTP: codice di stato 404, net::ERR_HTTP_RESPONSE_CODE_FAILURE

Lars- commented 1 year ago

Peek 2023-06-21 09-20 Just do it like that^

Maddmax76 commented 1 year ago

Hi Lars, :-) I love your pragmatism!

thanks for the clear example, it was very helpful to me. I report the data below:

action: create calendar[id]: 1 calendar[name]: Ufficio IT calendar[checked]: true calendar[external]: false calendar[color]: #ffffff calendar[bgColor]: #3498db calendar[borderColor]: #2980b9 calendar[dragBgColor]: #3498db schedule[id]: c4194cb8-e344-4bd9-bd18-5136d85817dd schedule[title]: prova schedule[isAllDay]: false schedule[start]: 1687332600 schedule[end]: 1687334400 schedule[category]: time schedule[dueDateClass]: schedule[color]: #ffffff schedule[bgColor]: #3498db schedule[dragBgColor]: #3498db schedule[borderColor]: #2980b9 schedule[location]: ciao schedule[isPrivate]: false schedule[state]: Occupato

Lars- commented 1 year ago

Awesome! Can you try changing the following lines in Http/Controllers/LJPcCalendarModuleController.php in the createItem function from this:

$calendarItem->start    = date( DATE_ATOM, $schedule['start'] );
$calendarItem->end      = date( DATE_ATOM, $schedule['end'] );

To this:

$calendarItem->start = Carbon::createFromTimeStamp( $schedule['start'] );
$calendarItem->end = Carbon::createFromTimeStamp( $schedule['end'] );

You also need to add this to the other use-rows at the top of the file:

use Carbon;

Let me know if that works. If it does, I will create a new version with these changes.

Maddmax76 commented 1 year ago

Thank you. Done, unfortunately it doesn't work.

I'm attaching the playload (now that I know how to get it! :-) )

action: create calendar[id]: 1 calendar[name]: Ufficio IT calendar[checked]: true calendar[external]: false calendar[color]: #ffffff calendar[bgColor]: #3498db calendar[borderColor]: #2980b9 calendar[dragBgColor]: #3498db schedule[id]: 6268adc6-04fa-460b-a068-0eb386d78a46 schedule[title]: prova schedule[isAllDay]: true schedule[start]: 1687384800 schedule[end]: 1687471199 schedule[category]: allday schedule[dueDateClass]: schedule[color]: #ffffff schedule[bgColor]: #3498db schedule[dragBgColor]: #3498db schedule[borderColor]: #2980b9 schedule[location]: schedule[isPrivate]: false schedule[state]: Occupato

Lars- commented 1 year ago

Okay, is the error in the logs still the same?

Maddmax76 commented 1 year ago

No, it's changed:

Class "Carbon" not found {"userId":2,"email":"OMISS","exception":"[object] (Symfony\Component\Debug\Exception\FatalThrowableError(code: 0): Class \"Carbon\" not found at /var/www/FreeScout/Modules/LJPcCalendarModule/Http/Controllers/LJPcCalendarModuleController.php:156)

Maddmax76 commented 1 year ago

Eureka! Funziona!!

just add 'use Carbon\Carbon;' at the top of the file and it started working.

Maddmax76 commented 1 year ago

Thank you so much for your patience and support

Maddmax76 commented 1 year ago

Hi, I'm starting to populate the calendar, logically I'm not an ace, so I entered some appointments incorrectly. Going to modify the same problem arises again.

Probably it is necessary to apply the same modifications not only to the creation of the occurrence, but also to the modification.

action: update schedule[id]: 5 schedule[title]: Max 18:50 schedule[body]: empty
Created by: OMISSOMISS schedule[isAllDay]: 0 schedule[start][_date]: 2023-06-28T14:00:00.000Z schedule[end][_date]: 2023-06-28T15:00:00.000Z schedule[color]: #ffffff schedule[isVisible]: true schedule[bgColor]: #3498db schedule[dragBgColor]: #3498db schedule[borderColor]: #2980b9 schedule[calendarId]: 1 schedule[category]: time schedule[dueDateClass]: schedule[customStyle]: schedule[isPending]: false schedule[isFocused]: false schedule[isReadOnly]: false schedule[isPrivate]: false schedule[location]: schedule[recurrenceRule]: schedule[state]: Occupato schedule[goingDuration]: 0 schedule[comingDuration]: 0 schedule[raw][creator][id]: 2 schedule[raw][creator][name]: OMISS schedule[raw][creator][email]: OMISS schedule[raw][creator][avatar]: https://OMISS/img/default-avatar.png schedule[raw][creator][phone]: 243 schedule[__fe_id]: 151 changes[title]: MAX changes[start]: 1687971000 changes[end]: 1687973400 changes[isAllDay]: false changes[category]: time

Lars- commented 1 year ago

Check release 1.3.13

Maddmax76 commented 1 year ago

ah! meanwhile I fixed it by modifying the edit element function:

$calendarItem->start = isset( $changes['start'] ) ? Carbon::createFromTimeStamp( $schedule['start'] ) : $calendarItem->start; $calendarItem->end= isset( $changes['end'] ) ? Carbon::createFromTimeStamp( $schedule['end'] ) : $calendarItem->end;

thanks anyway for the new release, I apply it now