Save Call Error - Updating Assigned To field

[color=#ff0000]Here is an extract from /var/log/apache2/error_log when attempting to save changes made to the assigned to field:

[Mon Jun 05 09:39:44.340898 2017] [:error] [pid 27071] [client ::1:58975] PHP Catchable fatal error:  Argument 1 passed to TimeDate::asUser() must be an instance of DateTime, boolean given, called in /Users/atadmin/Sites/suitecrm/modules/Calls/Call.php on line 563 and defined in /Users/atadmin/Sites/suitecrm/include/TimeDate.php on line 592, referer: http://localhost/suitecrm/index.php
[Mon Jun 05 09:39:44.340956 2017] [:error] [pid 27071] [client ::1:58975] PHP Stack trace:, referer: http://localhost/suitecrm/index.php
[Mon Jun 05 09:39:44.340965 2017] [:error] [pid 27071] [client ::1:58975] PHP   1. {main}() /Users/atadmin/Sites/suitecrm/index.php:0, referer: http://localhost/suitecrm/index.php
[Mon Jun 05 09:39:44.340975 2017] [:error] [pid 27071] [client ::1:58975] PHP   2. SugarApplication->execute() /Users/atadmin/Sites/suitecrm/index.php:52, referer: http://localhost/suitecrm/index.php
[Mon Jun 05 09:39:44.340982 2017] [:error] [pid 27071] [client ::1:58975] PHP   3. SugarController->execute() /Users/atadmin/Sites/suitecrm/include/MVC/SugarApplication.php:105, referer: http://localhost/suitecrm/index.php
[Mon Jun 05 09:39:44.341002 2017] [:error] [pid 27071] [client ::1:58975] PHP   4. SugarController->processView() /Users/atadmin/Sites/suitecrm/include/MVC/Controller/SugarController.php:310, referer: http://localhost/suitecrm/index.php
[Mon Jun 05 09:39:44.341010 2017] [:error] [pid 27071] [client ::1:58975] PHP   5. SugarView->process() /Users/atadmin/Sites/suitecrm/include/MVC/Controller/SugarController.php:363, referer: http://localhost/suitecrm/index.php
[Mon Jun 05 09:39:44.341016 2017] [:error] [pid 27071] [client ::1:58975] PHP   6. ViewClassic->display() /Users/atadmin/Sites/suitecrm/include/MVC/View/SugarView.php:169, referer: http://localhost/suitecrm/index.php
[Mon Jun 05 09:39:44.341023 2017] [:error] [pid 27071] [client ::1:58975] PHP   7. SugarView->includeClassicFile() /Users/atadmin/Sites/suitecrm/include/MVC/View/views/view.classic.php:74, referer: http://localhost/suitecrm/index.php
[Mon Jun 05 09:39:44.341029 2017] [:error] [pid 27071] [client ::1:58975] PHP   8. include_once() /Users/atadmin/Sites/suitecrm/include/MVC/View/SugarView.php:761, referer: http://localhost/suitecrm/index.php
[Mon Jun 05 09:39:44.341036 2017] [:error] [pid 27071] [client ::1:58975] PHP   9. CallFormBase->handleSave() /Users/atadmin/Sites/suitecrm/modules/Calls/Save.php:51, referer: http://localhost/suitecrm/index.php
[Mon Jun 05 09:39:44.341042 2017] [:error] [pid 27071] [client ::1:58975] PHP  10. Call->save() /Users/atadmin/Sites/suitecrm/modules/Calls/CallFormBase.php:423, referer: http://localhost/suitecrm/index.php
[Mon Jun 05 09:39:44.341048 2017] [:error] [pid 27071] [client ::1:58975] PHP  11. SugarBean->save() /Users/atadmin/Sites/suitecrm/modules/Calls/Call.php:226, referer: http://localhost/suitecrm/index.php
[Mon Jun 05 09:39:44.341055 2017] [:error] [pid 27071] [client ::1:58975] PHP  12. SugarBean->_sendNotifications() /Users/atadmin/Sites/suitecrm/data/SugarBean.php:1912, referer: http://localhost/suitecrm/index.php
[Mon Jun 05 09:39:44.341061 2017] [:error] [pid 27071] [client ::1:58975] PHP  13. SugarBean->send_assignment_notifications() /Users/atadmin/Sites/suitecrm/data/SugarBean.php:2608, referer: http://localhost/suitecrm/index.php
[Mon Jun 05 09:39:44.341067 2017] [:error] [pid 27071] [client ::1:58975] PHP  14. SugarBean->create_notification_email() /Users/atadmin/Sites/suitecrm/data/SugarBean.php:2648, referer: http://localhost/suitecrm/index.php
[Mon Jun 05 09:39:44.341073 2017] [:error] [pid 27071] [client ::1:58975] PHP  15. Call->set_notification_body() /Users/atadmin/Sites/suitecrm/data/SugarBean.php:2739, referer: http://localhost/suitecrm/index.php
[Mon Jun 05 09:39:44.341079 2017] [:error] [pid 27071] [client ::1:58975] PHP  16. TimeDate->asUser() /Users/atadmin/Sites/suitecrm/modules/Calls/Call.php:563, referer: http://localhost/suitecrm/index.php

[/color]

Letā€™s make one more attempt at getting these variables logged.

In include/TimeDate.php change around line 694

where it says


    public function fromDb($date)
    {
        try {
            return SugarDateTime::createFromFormat(self::DB_DATETIME_FORMAT, $date, self::$gmtTimezone);

change to


    public function fromDb($date)
    {
        try {
            $GLOBALS['log']->fatal(print_r(self::DB_DATETIME_FORMAT) . '-----------' . print_r($date). '----------' . print_r(self::$gmtTimezone));
            $GLOBALS['log']->fatal(print_r(SugarDateTime::createFromFormat(self::DB_DATETIME_FORMAT, $date, self::$gmtTimezone)));
            return SugarDateTime::createFromFormat(self::DB_DATETIME_FORMAT, $date, self::$gmtTimezone);

If I can see what these values are in your system, I can reproduce it in my system, and then write a fixā€¦

Thanks again as always, and apologies for my limited knowledge.

Just for reference that extract in my TimeDate.php looks as follows:

/**
     * Get DateTime from DB datetime string
     *
     * @param string $date
     * @return SugarDateTime
     */
    public function fromDb($date)
    {
        try {
            return SugarDateTime::createFromFormat(self::DB_DATETIME_FORMAT, $date, self::$gmtTimezone);
        } catch (Exception $e) {
            $GLOBALS['log']->error("fromDb: Conversion of $date from DB format failed: {$e->getMessage()}");
            return null;
        }
    }

However Iā€™ve made the amendments you suggested but I now cannot log in as get the following errors:

Fatal error: Cannot use try without catch or finally in /Users/atadmin/Sites/suitecrm/include/TimeDate.php on line 704
Fatal error: Class 'TimeDate' not found in /Users/atadmin/Sites/suitecrm/include/database/DBManager.php on line 265

Think i missed something off!!

Now showing the following error:

Y-m-d H:i:sDateTimeZone Object ( [timezone_type] => 3 [timezone] => UTC ) Y-m-d H:i:sDateTimeZone Object ( [timezone_type] => 3 [timezone] => UTC ) 

Jeez, your PHP is killing me! What is it doing to my dashes? Why arenā€™t they in the log? :blink:

Can you please remove those two logging lines and add all these:


            $GLOBALS['log']->fatal('ONE');
            $GLOBALS['log']->fatal(var_dump(self::DB_DATETIME_FORMAT));
            $GLOBALS['log']->fatal('TWO');
            $GLOBALS['log']->fatal(var_dump($date));
            $GLOBALS['log']->fatal('THREE);
            $GLOBALS['log']->fatal(var_dump(self::$gmtTimezone));
            $GLOBALS['log']->fatal('FOUR');
            $GLOBALS['log']->fatal(var_dump(SugarDateTime::createFromFormat(self::DB_DATETIME_FORMAT, $date, self::$gmtTimezone)));
            $GLOBALS['log']->fatal('FIVE');

Thanks!

Sorry for being thick but where do i need to add those lines, everything I seem to try generates the following error:

Parse error: parse error in /Users/atadmin/Sites/suitecrm/include/TimeDate.php on line 701

The section is currently back to default as I got in a mess!!

    public function fromDb($date)
    {
        try {
            return SugarDateTime::createFromFormat(self::DB_DATETIME_FORMAT, $date, self::$gmtTimezone);
        } catch (Exception $e) {
            $GLOBALS['log']->error("fromDb: Conversion of $date from DB format failed: {$e->getMessage()}");
            return null;
        }
    }
1 Like

Itā€™s ok, youā€™re not ā€œthickā€, Iā€™m using you as a non-developer human debugger at my own risk :slight_smile:

You add the lines between the ā€œtryā€ and the ā€œreturn sugarDateTime etcā€

The full function will look like this:


public function fromDb($date)
    {
        try {
            $GLOBALS['log']->fatal('ONE');
            $GLOBALS['log']->fatal(var_dump(self::DB_DATETIME_FORMAT));
            $GLOBALS['log']->fatal('TWO');
            $GLOBALS['log']->fatal(var_dump($date));
            $GLOBALS['log']->fatal('THREE);
            $GLOBALS['log']->fatal(var_dump(self::$gmtTimezone));
            $GLOBALS['log']->fatal('FOUR');
            $GLOBALS['log']->fatal(var_dump(SugarDateTime::createFromFormat(self::DB_DATETIME_FORMAT, $date, self::$gmtTimezone)));
            $GLOBALS['log']->fatal('FIVE');
            return SugarDateTime::createFromFormat(self::DB_DATETIME_FORMAT, $date, self::$gmtTimezone);
        } catch (Exception $e) {
            $GLOBALS['log']->error("fromDb: Conversion of $date from DB format failed: {$e->getMessage()}");
            return null;
        }
    }

Ok then yes I did have that correct initially and got this when trying to launch server:

Can you please post the full contents of the text file again? There seems to be some syntactical problem, the code is not runningā€¦

TimeDate.php

1 Like

See, I can be thick too!

I missed an apostrophe after the word THREE, so it should look like


            $GLOBALS['log']->fatal('THREE');

Sorry about that.

I shouldā€™ve spotted that too!!

Well at least itā€™s giving some output now:

/Users/atadmin/Sites/suitecrm/include/TimeDate.php:698:string 'Y-m-d H:i:s' (length=11)
/Users/atadmin/Sites/suitecrm/include/TimeDate.php:700:string '' (length=0)
/Users/atadmin/Sites/suitecrm/include/TimeDate.php:702:
object(DateTimeZone)[5]
  public 'timezone_type' => int 3
  public 'timezone' => string 'UTC' (length=3)
/Users/atadmin/Sites/suitecrm/include/TimeDate.php:704:boolean false
/Users/atadmin/Sites/suitecrm/include/TimeDate.php:698:string 'Y-m-d H:i:s' (length=11)
/Users/atadmin/Sites/suitecrm/include/TimeDate.php:700:string '' (length=0)
/Users/atadmin/Sites/suitecrm/include/TimeDate.php:702:
object(DateTimeZone)[5]
  public 'timezone_type' => int 3
  public 'timezone' => string 'UTC' (length=3)
/Users/atadmin/Sites/suitecrm/include/TimeDate.php:704:boolean false

Now weā€™re getting somewhereā€¦

But Iā€™m still puzzled at the lack of output in your log. How exactly are you extracting those errors? There should be those words there (ONE, TWO, etc). Are you looking in suitecrm.log?

About your actual problem: it seems your call has an empty start date. But start date is a mandatory field in ā€œCallsā€ module, so you should never have been able to create a Call without a start date.

I actually found a ā€œCallā€ in my test system also without a start date, but it was created by a Workflow I had made (apparently not very well made).

Is there anything special about the way you created the call? Does it show a start date? If so, which one?

And how are you changing the assigned user? Are you editing the entire Call record, or just using inline-edit by double-clicking?

Errors appear in the browser, however i have found the details in suitecrm/log:

Mon Jun  5 15:22:29 2017 [38267][1][FATAL] ONE
Mon Jun  5 15:22:29 2017 [38267][1][FATAL]
Mon Jun  5 15:22:29 2017 [38267][1][FATAL] TWO
Mon Jun  5 15:22:29 2017 [38267][1][FATAL]
Mon Jun  5 15:22:29 2017 [38267][1][FATAL] THREE
Mon Jun  5 15:22:29 2017 [38267][1][FATAL]
Mon Jun  5 15:22:29 2017 [38267][1][FATAL] FOUR
Mon Jun  5 15:22:29 2017 [38267][1][FATAL]
Mon Jun  5 15:22:29 2017 [38267][1][FATAL] FIVE
Mon Jun  5 15:22:29 2017 [38267][1][DEBUG] Hook called: ::server_round_trip
Mon Jun  5 15:22:29 2017 [38267][1][DEBUG] Calling MySQLi::disconnect()

I am editing by selecting Actions >Edit and just changing the Assigned To field from Administrator (Call creator) to myself.

Start Date & Time are not appearing in my edit view, also they are not marked as ā€˜Requiredā€™ I have added them and now get a different error on screen:

/Users/atadmin/Sites/suitecrm/include/TimeDate.php:698:string 'Y-m-d H:i:s' (length=11)
/Users/atadmin/Sites/suitecrm/include/TimeDate.php:700:string '2017-06-05 11:00:00' (length=19)
/Users/atadmin/Sites/suitecrm/include/TimeDate.php:702:
object(DateTimeZone)[5]
  public 'timezone_type' => int 3
  public 'timezone' => string 'UTC' (length=3)
/Users/atadmin/Sites/suitecrm/include/TimeDate.php:704:
object(SugarDateTime)[118]
  protected 'formats' => 
    array (size=15)
      'sec' => string 's' (length=1)
      'min' => string 'i' (length=1)
      'hour' => string 'G' (length=1)
      'zhour' => string 'H' (length=1)
      'day' => string 'j' (length=1)
      'zday' => string 'd' (length=1)
      'days_in_month' => string 't' (length=1)
      'day_of_week' => string 'w' (length=1)
      'day_of_year' => string 'z' (length=1)
      'week' => string 'W' (length=1)
      'month' => string 'n' (length=1)
      'zmonth' => string 'm' (length=1)
      'year' => string 'Y' (length=1)
      'am_pm' => string 'A' (length=1)
      'hour_12' => string 'g' (length=1)
  protected 'var_gets' => 
    array (size=5)
      '24_hour' => string 'hour' (length=4)
      'day_of_week' => string 'day_of_week_long' (length=16)
      'day_of_week_short' => string 'day_of_week_short' (length=17)
      'month_name' => string 'month_long' (length=10)
      'hour' => string 'hour_12' (length=7)
  protected '_strings' => null
  public 'date' => string '2017-06-05 11:00:00.000000' (length=26)
  public 'timezone_type' => int 3
  public 'timezone' => string 'UTC' (length=3)

Error below this are:

Warning: DateTime::modify(): Failed to parse time string (+ hours mins) at position 0 (+): Unexpected character in /Users/atadmin/Sites/suitecrm/modules/Calls/Call.php on line 187

and

Fatal error: Call to a member function asDb() on a non-object in /Users/atadmin/Sites/suitecrm/modules/Calls/Call.php on line 187

Start date IS a required field in Calls!

See this screenshot form the demo:

It is very strange if you donā€™t see those fields, or if your system lets you save a Call without a start date. We should focus on that bug first and foremost, all other weird behaviors after that are probably caused by that initial issueā€¦

I donā€™t remember if Iā€™ve already asked you this: are you using any language pack, or is your system in plain English?

There was a similar bug for a user with a specific language pack that had a bug:
https://github.com/salesagility/SuiteCRM/issues/3609

Okay iā€™ll restore the original views and try and recreate the issue.

Iā€™m using English (US) itā€™s the only installed language pack.

Thanks for you help!

Iā€™ve restored it back and set a default value so itā€™s populated but itā€™s still giving the same errorā€¦

Is it looking like a re-install job??

Found this solution on #44220

Not sure what impact it has but itā€™s resolved my issues :cheer:

Exactly what do you mean by restoring views and fields? Was your Calls module customized?

And you might want to check the timezone settings in MySQL, maybe thatā€™s where the problem isā€¦