HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Send Invitation as a member got "Fatal Error in Gdn_Database.Query()" in version 2.1.11

Hello there,

I just installed the vnailla 2.1.11 on my winxp. Everything is all right, but when I as a member sent invitation, I got a "Fatal Error in Gdn_Database.Query()".

I wonder if it is a bug or just I got something wrong?

The registration method I set is "Invitation", "invitations per month" for member is 2.

The output debug info as follow:

Fatal Error in Gdn_Database.Query();

Incorrect datetime value: 'Y-m-01' for column 'DateSetInvitations' at row 1
update GDN_User User
set CountInvitations = :CountInvitations,
DateSetInvitations = :DateSetInvitations
where UserID = :UserID

The error occurred on or near: E:\VincentPing\vincentping\output\v\library\database\class.database.php
291:
292: if (!is_object($PDOStatement)) {
293: trigger_error(ErrorMessage('PDO Statement failed to prepare', $this->ClassName, 'Query', $this->GetPDOErrorMessage($this->Connection()->errorInfo())), E_USER_ERROR);
294: } else if ($PDOStatement->execute($InputParameters) === FALSE) {
295: trigger_error(ErrorMessage($this->GetPDOErrorMessage($PDOStatement->errorInfo()), $this->ClassName, 'Query', $Sql), E_USER_ERROR);
296: }
297: } else {
298: $PDOStatement = $this->Connection()->query($Sql);
299: }

Backtrace:
E:\VincentPing\vincentping\output\v\library\database\class.database.phpPHP::Gdn_ErrorHandler();
[E:\VincentPing\vincentping\output\v\library\database\class.database.php:295] PHP::trigger_error();
[E:\VincentPing\vincentping\output\v\library\database\class.sqldriver.php:1630] Gdn_Database->Query();
[E:\VincentPing\vincentping\output\v\library\database\class.sqldriver.php:1595] Gdn_SQLDriver->Query();
[E:\VincentPing\vincentping\output\v\applications\dashboard\models\class.usermodel.php:2680] Gdn_SQLDriver->Put();
[E:\VincentPing\vincentping\output\v\applications\dashboard\controllers\class.profilecontroller.php:452] UserModel->GetInvitationCount();
[E:\VincentPing\vincentping\output\v\applications\dashboard\controllers\class.profilecontroller.php:452] ProfileController->Invitations();
[E:\VincentPing\vincentping\output\v\library\core\class.dispatcher.php:350] PHP::call_user_func_array();
[E:\VincentPing\vincentping\output\v\index.php:46] Gdn_Dispatcher->Dispatch();

Variables in local scope:
[Sql] 'update GDN_User User
set CountInvitations = :CountInvitations,
DateSetInvitations = :DateSetInvitations
where UserID = :UserID'
[InputParameters] array (
':CountInvitations' => '2',
':DateSetInvitations' => 'Y-m-01',
':UserID' => '3',
)
[Options] array (
'ReturnType' => NULL,
)
[ReturnType] NULL
[PDOStatement] array (
'queryString' => 'update GDN_User User
set CountInvitations = :CountInvitations,
DateSetInvitations = :DateSetInvitations
where UserID = :UserID',
)

Comments

  • It seems strftime('%Y-%m-01', $Timestamp) doesn't work as expected for you.

    Can you add
    var_dump($Format);var_dump($Timestamp);var_dump($Result);die();
    directly after
    $Result = strftime($Format, $Timestamp);
    in function date() in library/core/class.format.php and show us the result when trying to send an invitation?

    -

    peregrine
  • Hi,mtschirs,

    Thanks for your reply!

    But when I add the code according to your instruction, I can only get the following ui when I visit the main page :

  • I just tried again in my centOS server, the invitation sending is ok.

    It should be some problems with the windows time format.

  • mtschirsmtschirs ✭✭✭
    edited September 2015

    Replace

    • Gdn_Format::Date($User->DateSetInvitations, 'n Y')
      with Gdn_Format::Date($User->DateSetInvitations, '%n %Y')

    • Gdn_Format::Date('', 'n Y')
      with Gdn_Format::Date(time(), '%n %Y')

    • Gdn_Format::Date('', 'Y-m-01')
      with Gdn_Format::Date(time(), '%Y-%m-01')

    in applications/dashboard/models/class.usermodel.php and you should be all set.

    It seems this error just doesn't surface on Linux, but that code definitely has a bug.

    This is kind of fixed in Vanilla 2.2 master, but not in the 2.1 branch.

    -

    peregrinevincentpinghgtonight
  • peregrineperegrine MVP
    edited September 2015

    I saw that as well.

    as an aside, I also wonder if he had strict mode set in mysql on windows machine.

    <?php
    // kind of odd 
    $Now = time();
    $Format = 'Y-m-01';
    
    echo strftime($Format, $Now);
    

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

    mtschirs
  • Hi,mtschirs,

    Great, the replacement in applications/dashboard/models/class.usermodel.php sets the problem!

    Thanks!

    And just as peregrine said, the mysql here is strict mode:

    sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

    So I tried again with deleting the strict mode, and the invitation function is also ok(without change the code in class.usermodel.php)!

    Thank you all!

    By the way, could you tell me what plugin this forum uses to support the markdown editing?

  • @vincentping said:

    By the way, could you tell me what plugin this forum uses to support the markdown editing?

    see Q18 in FAQ

    http://vanillaforums.org/discussion/comment/219888/#Comment_219888

    the editor plugin is part of vanilla 2.2

    buttonbar plugin in vanilla 2.1 supports markdown

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

    hgtonight
  • Thanks, peregrine!

    Have a nice day!

    hgtonight
Sign In or Register to comment.